Skip to main content
The Codex agent plugin integrates OpenAI’s Codex CLI, providing automatic metadata updates via shell wrappers, session introspection from JSONL rollout files, and native thread resumption.

Overview

Codex is OpenAI’s AI coding assistant CLI. The plugin:
  • Automatically resolves the Codex binary (npm global, Homebrew, Cargo)
  • Injects ~/.ao/bin into PATH to wrap gh and git commands
  • Updates metadata transparently when agents create PRs or switch branches
  • Streams JSONL rollout files to extract token usage and session data
  • Supports native thread resumption via codex resume <thread-id>
This plugin requires Codex CLI. Install from OpenAI’s repository.

Installation

Configuration

Configure in agent-orchestrator.yaml:

Configuration Options

string
Codex model (e.g., o4-mini, o3-mini, gpt-4-turbo)
enum
Approval policy:
  • skip: Bypass all approvals and sandbox (--dangerously-bypass-approvals-and-sandbox)
  • auto-edit: Never ask (--ask-for-approval never)
  • suggest: Ask for untrusted operations only (--ask-for-approval untrusted)
string
Developer instructions passed via -c developer_instructions=...
string
Path to instructions file (preferred for long prompts) Uses -c model_instructions_file=...

Automatic Metadata Updates

The plugin installs shell wrappers in ~/.ao/bin/ that intercept gh and git commands:

Tracked Commands

  1. Plugin prepends ~/.ao/bin to PATH during agent launch
  2. Wrapper scripts intercept gh/git commands
  3. Wrapper strips ~/.ao/bin from PATH and calls the real binary
  4. On success, wrapper parses output and updates metadata via update_ao_metadata()
  5. All other commands pass through transparently
The wrappers are installed once in ~/.ao/bin and reused across all sessions.

Wrapper Scripts

~/.ao/bin/gh
~/.ao/bin/git
~/.ao/bin/ao-metadata-helper.sh
Wrappers are versioned. The plugin only rewrites them if .ao-version marker changes, minimizing disk writes.

Session Introspection

Codex stores session data in date-sharded JSONL files:

Finding Session Files

The plugin:
  1. Recursively scans ~/.codex/sessions/ (max depth 4)
  2. Reads the first 4 KB of each .jsonl file
  3. Matches session_meta entries where cwd equals the workspace path
  4. Returns the most recently modified matching file
For large projects with many Codex sessions, the initial scan can take 1-2 seconds. Results are cached for 30 seconds.

Extracting Data

The plugin streams JSONL files line-by-line (never loads entire file into memory):

Cost Estimation

Token usage is aggregated from event_msg lines with type: "token_count":
Estimated cost uses GPT-4 Turbo pricing (2.50/1Minput,2.50/1M input, 10/1M output) as a baseline.
Cost estimates are approximate. For accurate billing, check OpenAI’s usage dashboard.

Usage Examples

Spawn an Agent

The orchestrator:
  1. Resolves the Codex binary (cached after first call)
  2. Creates workspace and sets up wrappers
  3. Launches Codex with prompt included in command
  4. Monitors session file mtime for activity

Resume a Thread

The plugin extracts the threadId from the session JSONL and builds:

Check Session Cost

Output:

Advanced Features

Binary Resolution

The plugin auto-detects Codex installation on first launch:
  1. Try which codex
  2. Check common locations:
    • /usr/local/bin/codex (Homebrew Intel)
    • /opt/homebrew/bin/codex (Homebrew ARM)
    • ~/.cargo/bin/codex (Cargo)
    • ~/.npm/bin/codex (npm global)
  3. Fallback to "codex" (let shell resolve)
Resolved path is cached for the lifetime of the agent instance.

Reasoning Models (o-series)

The plugin auto-detects o-series models and enables reasoning:
This sets model_reasoning_effort=high for o3/o4 models automatically.

Session File Caching

To avoid redundant filesystem scans, the plugin caches session file paths:
Cache is shared across getActivityState() and getSessionInfo() calls.

AGENTS.md Integration

The plugin appends a section to AGENTS.md in each workspace:
This serves as a secondary signal if PATH wrappers are bypassed.

Troubleshooting

Cause: PATH not set correctly or wrappers not executableSolution:
  1. Check if ~/.ao/bin is first in PATH:
  2. Verify wrappers are executable:
  3. Check if real binaries exist:
Cause: No Codex session created yet, or cwd mismatchSolution:
  1. Check if Codex has created any sessions:
  2. Verify workspace path matches session_meta cwd:
  3. Wait for Codex to make its first API call (session files are created lazily)
Cause: Codex installed in non-standard locationSolution: Add Codex to PATH or create a symlink:
Cause: AO_DATA_DIR or AO_SESSION environment variables not setSolution: Check agent environment:
Verify metadata file exists:
Cause: Codex writes to session file in bursts, not continuouslySolution: This is expected. Activity detection uses file mtime, which only updates when Codex makes API calls or writes events. During long reasoning periods (o-series models), the file may not be modified. Check process status with ao status <session> for ground truth.

Comparison with Other Agents

Environment Variables

The plugin sets these variables in the agent environment:
string
required
Session identifier for metadata lookups
string
Project identifier (set by caller, not the plugin)
string
Issue/ticket identifier if applicable
string
required
Prepended with ~/.ao/bin to enable command interception
Do not modify PATH in workspace setup scripts (.bashrc, .zshrc) as it may interfere with wrapper priority.