Codex Integration
Codex integration uses a notify hook for turn completion and PTY mode for message delivery.Message Delivery
Automatic (PTY mode only): Messages are delivered via PTY injection when agent goes idle. Manual (vanilla mode): Agent must poll for messages usinghcom listen.
Why PTY only?
- Codex has only one hook:
codex-notify(turn completion) - No hook fires when agent goes idle (unlike Claude/Gemini)
- PTY wrapper detects idle and injects messages
Hook Installation
Hooks are installed to~/.codex/config.toml and policies to ~/.codex/rules/hcom.rules.
Automatic Install
Run Codex via hcom launcher:Manual Install
If you prefer to run Codex directly:Verify Installation
Launch Modes
PTY Mode (Required for Automatic Messages)
Launch with hcom for automatic message delivery:- Automatic message delivery via terminal injection
- Terminal screen capture (
hcom term) - Automatic cleanup on kill (
hcom kill) - Fork and resume support
Vanilla Mode (Manual Polling)
Run Codex directly after installing hooks:- Hook tracks turn completion only
- No automatic message delivery
- Agent must poll:
hcom listenorhcom events - Binding happens at notify hook via transcript marker
Hook Types
Codex has 1 hook type:| Hook | When | Purpose |
|---|---|---|
| codex-notify | Agent turn completes | Update status to listening, trigger PTY delivery |
- Parse JSON from argv[2]
- Resolve instance via thread-id or process binding
- Update status to
listening - Set
idle_sincetimestamp - Notify PTY wrapper via TCP wake
Configuration
Default Arguments
System Prompt
Sandbox Mode
Auto-Approval (Execpolicy)
Codex uses execpolicy rules for auto-approval. Enable auto-approval:~/.codex/rules/hcom.rules:
prefix_rule()matches command prefixdecision="allow"auto-approves- Priority handled by Codex
Transcript Path Derivation
Codex transcript path is derived from thread-id: Path pattern:$CODEX_HOME/sessions/**/rollout-*-{thread_id}.jsonl
Search logic:
- Use
CODEX_HOMEenv var or~/.codexdefault - Glob search for
rollout-*-{thread_id}.jsonl - Return most recently modified match
- Transcript path not always in notify payload
- Needed for vanilla binding
- Auto-derived when missing
Session Binding
PTY Mode
Binding happens at notify hook:HCOM_PROCESS_IDenv var present- Bind thread-id to process
- Update directory, session_id, transcript_path
- Set listening status
- Notify PTY wrapper
Vanilla Mode
Binding happens via transcript marker search:- Run
hcom startinside Codex - Output contains
[hcom:instance-name]marker - Notify hook searches transcript for marker
- Binds thread-id to instance automatically
- Reads last 50KB of transcript
- Searches for
[hcom:name]pattern - Returns instance name if found
Launch Examples
Single Agent
Multiple Agents
Fork and Resume
PTY Injection
Codex message delivery works differently than Claude/Gemini: Why no hook-based delivery?- Codex only has turn-complete hook
- No hook fires when agent is idle
- Can’t inject messages via hook output
- Notify hook sets status to
listening - Notify hook writes
idle_sincetimestamp - Notify hook sends TCP wake to PTY wrapper
- PTY wrapper detects idle state
- PTY wrapper injects messages via terminal
- Codex sees injected text at next prompt
- Monitors transcript file for changes
- Detects idle by lack of activity
- Alternative to hook-based detection
Manual Polling (Vanilla Mode)
Since vanilla mode has no automatic delivery, agents must poll:Using listen
Using events
Loop polling
Advanced
Hook Command Format
config.toml:hcom codex-notify '{json_payload}'
Payload passed as argv[2].
Stale Command Detection
hcom detects stale hook commands (e.g.,/old/path/hcom) and auto-updates:
setup_codex_hooks()checks existing notify line- If contains
codex-notifybut path differs - Removes old line and re-adds with current path
- Preserves other config settings
Orphaned Process Recovery
If Codex process is orphaned (no session binding):Troubleshooting
Messages not arriving (PTY mode)
- Check Codex is idle:
hcom listshowslisteningstatus - Verify PTY wrapper running:
ps aux | grep hcom | grep pty - Check idle_since timestamp:
hcom list <name> idle_since - Try manual wake:
hcom send @codex-instance -- test
Messages not arriving (vanilla mode)
Expected behavior. Vanilla Codex must poll manually:Hooks not working
Transcript path not found
- Check
CODEX_HOMEenv var - Verify transcript exists:
ls ~/.codex/sessions/*/rollout-*.jsonl - Check thread-id in hook payload
Config.toml has existing notify
hcom refuses to overwrite non-hcom notify hooks:Reference
Hook configuration:~/.codex/config.toml
Policy configuration: ~/.codex/rules/hcom.rules
Config path function: