Gemini CLI Integration
Gemini CLI integration provides automatic message delivery through lifecycle hooks and supports PTY mode for instant injection.Message Delivery
Automatic: Messages are delivered at BeforeAgent and AfterTool hooks. When messages arrive:- Before agent turn: Delivered at BeforeAgent hook
- After tool execution: Delivered at AfterTool hook
- Idle notification: AfterAgent hook triggers PTY injection (if PTY mode)
Hook Installation
Hooks are installed to~/.gemini/settings.json and policies to ~/.gemini/policies/hcom.toml.
Automatic Install
Run Gemini via hcom launcher:Manual Install
If you prefer to run Gemini directly:Verify Installation
Requirements
Minimum Gemini version: 0.26.0 Version 0.26.0 introduced thehooksConfig.enabled schema required by hcom.
Check your version:
Launch Modes
PTY Mode (Recommended)
Launch with hcom for full integration:- Instant message delivery via terminal injection
- Terminal screen capture (
hcom term) - Automatic cleanup on kill (
hcom kill) - Resume support (no fork for Gemini)
Vanilla Mode
Run Gemini directly after installing hooks:- Messages delivered at BeforeAgent/AfterTool hooks
- Automatic binding via tool response marker
- No terminal screen capture
- Manual binding via
hcom startoutput marker
Headless Not Supported
Gemini does not support headless mode. Use interactive mode with initial prompt instead:- Gemini requires interactive session
- No equivalent to Claude’s
-pflag - Use
-i/--prompt-interactivefor initial prompt
Hook Types
Gemini CLI has 7 hook types:| Hook | When | Purpose |
|---|---|---|
| SessionStart | Session begins | Bind session, set terminal title |
| BeforeAgent | Before agent turn | Bootstrap fallback, message delivery |
| AfterAgent | After agent turn | Set listening status, notify |
| BeforeTool | Before tool execution | Track tool status |
| AfterTool | After tool execution | Message delivery, vanilla binding |
| Notification | Approval prompt | Track blocked status |
| SessionEnd | Session ends | Stop instance, finalize |
Configuration
Default Arguments
System Prompt
Auto-Approval
Gemini uses a policy engine for auto-approval (not the deprecatedtools.allowed).
Enable auto-approval:
~/.gemini/policies/hcom.toml with approval rules:
Transcript Path Derivation
Gemini’s transcript path is not available at SessionStart (ChatRecordingService not initialized yet). Workaround:- Derive path from session_id at BeforeAgent/AfterTool
- Search
~/.gemini/tmp/*/chats/session-*-{prefix}*.json - Use most recently modified match
- Transcript path needed for vanilla binding
- Also needed for transcript reading
- Auto-derived when not in payload
Session Binding
PTY Mode
Binding happens at SessionStart:HCOM_PROCESS_IDenv var present- Bind session_id to process
- Set listening status
- Bootstrap injection moved to BeforeAgent
- SessionStart output not shown after
/clear - BeforeAgent ensures bootstrap is always visible
Vanilla Mode
Binding happens at AfterTool via marker detection:- Run
hcom startinside Gemini - Tool response contains
[hcom:instance-name]marker - AfterTool hook detects marker
- Binds session to instance automatically
Launch Examples
Single Agent
Multiple Agents
Resume (No Fork)
Auto-Subscribe
Gemini agents can auto-subscribe to events:hcom start.
Session Recovery
Gemini sessions can be recovered after/clear or restart:
Automatic recovery:
- Session binding persists across
/clear - BeforeAgent re-binds session_id
- Bootstrap re-injected if needed
Advanced
Hook Migration (0.26.0+)
Gemini 0.26.0 changed hook configuration: Old (pre-0.26):Policy Engine
Gemini replacedtools.allowed array with policy engine:
Old approach (deprecated):
PTY Injection
Similar to Claude, PTY mode delivers messages via terminal injection:- AfterAgent hook sets status to listening
- Notifies PTY wrapper via TCP wake
- PTY wrapper injects message text
- Gemini sees injected text at next prompt
Troubleshooting
Messages not arriving
- Check Gemini is idle:
hcom listshowslisteningstatus - Verify hooks installed:
hcom hooks status - Check Gemini version:
gemini --version(need 0.26.0+) - Try manual send:
hcom send @gemini-instance -- test
Hooks not working
Version too old
If you’re on Gemini < 0.26.0:Session binding lost after /clear
Gemini’s/clear command clears session. Re-run:
Reference
Hook configuration:~/.gemini/settings.json
Policy configuration: ~/.gemini/policies/hcom.toml
Settings path function: