Codex Setup
This page covers the Codex-specific steps after the shared install-and-run flow.
Unlike Claude Code, Codex does not currently have a plugin packaging surface that Agent Tracer can publish into. The current Codex integration uses:
- repo-local Codex hooks for interactive sessions
- a repo-local
.codex/config.tomlthat enables Codex hooks by default
1. Bootstrap the target project
Run external-setup.md first:
npm run setup:external -- --target /absolute/path/to/your-projectFor Codex, the setup script creates:
target/.codex/config.tomltarget/.codex/hooks.json
These files reference the Agent Tracer checkout directly with absolute paths. After setup, the intended usage is simply:
cd /absolute/path/to/your-project
codex2. Prerequisites
- The monitor server is running (
npm run devornpm run dev:server) curl -sf http://127.0.0.1:3847/api/v1/overviewreturns 200- Codex CLI is installed and working
3. Interactive Codex with hooks
Use plain Codex from the target project root:
cd /absolute/path/to/your-project
codexsetup:external writes .codex/config.toml with codex_hooks = true, and the generated .codex/hooks.json embeds MONITOR_BASE_URL directly in each hook command. No extra wrapper is required for the normal interactive path.
What this captures today
The default external setup registers all six official Codex hook events:
SessionStart->context.savedUserPromptSubmit->user.messagePreToolUse(matcherBash|apply_patch|Edit|Write) -> runtime-session-ensure (session guarantee)PostToolUse(Bash)->terminal.commandPostToolUse(apply_patch|Edit|Write)->tool.used(handled byPostToolUse/ApplyPatch.ts)PostToolUse(mcp__.*)->agent.activity.logged(handled byPostToolUse/Mcp.ts)PermissionRequest->rule.logged(rulePolicy: codex_permission,ruleStatus: requested)Stop->assistant.response
The rollout observer also runs in parallel (spawned by SessionStart) and emits the same apply_patch / mcp__* events with a crossCheck.source = "rollout" marker so the server can merge the two sources by dedupeKey. WebSearch remains rollout-only (Codex has no web hook):
- rollout
response_item.custom_tool_call(apply_patch)->tool.used(cross-check) - rollout
response_item.function_call(mcp__...)->agent.activity.logged(cross-check) - rollout
response_item.web_search_call->tool.used - rollout
event_msg.token_count/turn_context->context.snapshot
The hook handlers use the shared runHook() wrapper and the typed payload readers at packages/runtime/src/shared/hooks/codex/payloads.ts. Turn-scoped events capture the official turn_id and model fields when Codex includes them in the payload.
Privacy contract
Every Codex PostToolUse handler reads tool_input only and ignores tool_response. The rollout observer parses apply_patch.input solely to extract touched file paths from the patch headers (*** Add File: / *** Update File: / *** Delete File: / *** Move to:); the diff body itself is never stored. No stdout, stderr, file content, web response, MCP result, or search result list ever leaves the host machine.
4. Current capture scope
The current Codex integration focuses on interactive hooks.
Default events that can be captured:
context.saveduser.messageterminal.command(Bash)assistant.responsetool.usedforapply_patch/Edit/Writealiases (PostToolUse hook + rollout cross-check)tool.usedfor web search/fetch (rollout only — Codex has no web hook yet)agent.activity.loggedfor MCP calls (PostToolUse hook + rollout cross-check)rule.loggedfor permission dialogs (PermissionRequest hook,rulePolicy: codex_permission)context.snapshotfor token / rate-limit / turn telemetry (rollout observer)
In other words, this stage focuses on capturing the baseline activity of users who run Codex normally with codex.
Smoke test
Verify the setup in this order:
- Run
codexin the target project - Submit one short prompt
- Trigger one Bash command
- Optionally let Codex apply a patch and call an MCP tool
- Confirm the following events in the dashboard
context.saveduser.messageterminal.commandassistant.responsetool.usedif Codex usedapply_patchor web search/fetch — forapply_patchyou should see one merged event (hook + rollout) withmetadata.crossCheck.merged: trueagent.activity.loggedif Codex used an MCP tool — also merged viacrossCheckrule.loggedif Codex hit a permission prompt
5. Context / model observer
Codex does not currently expose a Claude-style statusLine hook. Agent Tracer now derives status telemetry from the session rollout .jsonl that plain codex already writes under ~/.codex/sessions/<YYYY>/<MM>/<DD>/.
The observer:
- reads the latest Codex session hint written by hooks
- locates the matching
rollout-*.jsonlfor that session id - tails it for
event_msg/token_countentries - emits
context.snapshotevents from the rollout's token-usage and rate-limit fields - emits
tool.usedfor rolloutapply_patchandweb_search_callentries - emits
agent.activity.loggedfor rolloutmcp__...function calls - prints a compact status string such as
[monitor] ctx 30% · 15m 25%
This observer is now started automatically by the Codex SessionStart hook. In the normal path you do not need to launch a second command manually.
If you want to debug or run it by hand, use:
cd /absolute/path/to/agent-tracer
npm run codex:observe -- --latest-in /absolute/path/to/your-projectYou can also target a specific thread directly:
npm run codex:observe -- --thread-id <codex-thread-id>The observer posts:
context.snapshotcontextWindowUsedPctas soon as Codex writes atoken_counteventcontextWindowSizecontextWindowTotalTokensmodelId(hint fromSessionStart; provider from rolloutsession_meta)- generic primary/secondary rate-limit windows
Since the observer tails the same rollout file that plain codex writes, it does not need to share a transport with the running turn — both context and rate-limit telemetry are now populated in plain codex mode.
6. End-to-end check
- Monitor server is running
setup:externalhas been run for the target project- Run
codexfrom the target project root - Submit a prompt that causes one Bash command
- Confirm the dashboard shows:
context.saveduser.messageterminal.commandassistant.response
- If the prompt causes file edits, MCP calls, or web search/fetch, confirm:
tool.usedagent.activity.logged
- Confirm the dashboard starts receiving
context.snapshotevents automatically
7. Current limitations
- No dedicated
SessionEndhook mapping - No subagent hierarchy mapping in v1
- No hook-time interception for non-Bash tools
- Non-Bash tool activity is observed after Codex writes rollout response items; it is not a pre-execution policy/interception hook.
- Rollout-backed observation covers
apply_patch, MCP function calls, and web search/fetch. Other future Codex item types need explicit parser support.
For the adapter internals and exact event mapping, see packages/runtime/CODEX_DATA_FLOW.md in the repository.