Codex

View as Markdown

Use this guide to observe local Codex CLI sessions and local Codex GUI or app sessions that honor the same local config and gateway routing. Cloud or remote Codex tasks are partial or unsupported for local gateway LLM capture because the local gateway cannot observe provider traffic that never reaches the machine.

Requirements

codex-cli >= 0.129.0. The gateway uses the features.hooks flag and the nemo-relay-openai provider alias, both of which require this version. Earlier versions either reject the provider override or do not recognize the hooks feature flag.

As of Codex 0.129, Codex requires hooks to be manually reviewed and activated before they run. Generated NeMo Relay hook configuration is not enough on its own if Codex leaves those hooks inactive. Review and activate the installed or injected hooks in Codex before expecting NeMo Relay events. This is being tracked upstream as openai/codex#21639.

Transparent Run

Use the wrapper for no-install local observability:

$nemo-relay codex

Pass Codex arguments after --:

$nemo-relay codex -- exec "Summarize this repository."

This shortcut is equivalent to nemo-relay run -- codex. The wrapper starts a gateway on a dynamic 127.0.0.1 port, enables Codex hooks with CLI config overrides, injects hook commands that use NEMO_RELAY_GATEWAY_URL, and points Codex at a temporary nemo-relay-openai provider alias that uses the gateway URL while preserving Codex’s OpenAI auth path.

Inspect what would be launched without starting Codex:

$nemo-relay run \
> --dry-run \
> --print \
> -- codex

Persistent Plugin Install

Install the persistent plugin for Codex. It should start normally and load NeMo Relay from its plugin marketplace:

$nemo-relay install codex

The installer creates a local marketplace, installs nemo-relay-plugin@nemo-relay-local, enables Codex hooks, and configures the nemo-relay-openai provider alias at http://127.0.0.1:47632. It then uses the existing nemo-relay binary on PATH but does not install a plugin-local Relay binary.

Codex plugin mode uses hook-supervised on-demand startup only. It does not install a wrapper, user-level daemon, launch agent, system user service, scheduled task, login item, or persistent supervisor.

To check for the installed plugin, enter:

$nemo-relay doctor --plugin codex

To remove the plugin, enter:

$nemo-relay uninstall codex

Refer to Plugin Installation for install directories, first-request capture limits, rollback behavior, and source marketplace notes.

Shared Config

Create .nemo-relay/config.toml for project defaults or ~/.config/nemo-relay/config.toml for user defaults:

1[upstream]
2openai_base_url = "https://api.openai.com/v1"
3
4[agents.codex]
5command = "codex"

Then configure observability with nemo-relay plugins edit --project or .nemo-relay/plugins.toml:

1version = 1
2
3[[components]]
4kind = "observability"
5enabled = true
6
7[components.config.atif]
8enabled = true
9output_directory = ".nemo-relay/atif"

Run nemo-relay run --agent codex to use the configured command and plugin config. User config takes priority over project and system config.

Standalone Gateway

Use the long-running gateway only when you want Codex running outside the wrapper:

$nemo-relay --bind 127.0.0.1:4040

Then edit ~/.codex/config.toml and configure local Codex to use a gateway provider alias instead of overriding the reserved built-in openai provider:

1model_provider = "nemo-relay-openai"
2
3[model_providers.nemo-relay-openai]
4name = "NeMo Relay OpenAI"
5base_url = "http://127.0.0.1:4040"
6wire_api = "responses"
7requires_openai_auth = true
8supports_websockets = false

After saving the file, restart the Codex GUI or app so it reloads the provider configuration. For CLI usage, start a new codex process.

Some Codex GUI or app versions appear to scope visible conversation history by the active provider configuration. If existing conversations disappear after switching model_provider to nemo-relay-openai, the history has not been removed if it returns after restoring the previous provider configuration. Use this standalone provider alias only while capturing gateway telemetry, or prefer the transparent wrapper for CLI sessions. See the upstream Codex history visibility discussion for context.

Local Codex GUI or app sessions have the same support level only when they read the same local hook/plugin config and provider routing. Cloud tasks may still emit some lifecycle hooks, but complete LLM lifecycle capture requires model traffic to pass through the gateway.

Captured Events

Generated Codex hooks include SessionStart, SessionEnd, SubagentStart, SubagentStop, PreToolUse, PostToolUse, PostToolUseFailure, Notification, and PreCompact for scope, tool, and mark events. UserPromptSubmit, AfterAgentResponse, AfterAgentThought, and Stop are retained as private LLM correlation hints and are not emitted as standalone NeMo Relay events.

The transparent wrapper passes hook entries as Codex CLI config overrides and sets features.hooks=true for that launched process. Persistent install writes .codex/config.toml with features.hooks = true and merges generated hook entries into .codex/hooks.json.

Smoke Test

Run a small Codex prompt that starts a session and uses one simple tool. Then check hook forwarding directly:

$curl -f http://127.0.0.1:4040/healthz
$printf '{"session_id":"smoke-codex","hook_event_name":"sessionStart"}' \
> | NEMO_RELAY_GATEWAY_URL=http://127.0.0.1:4040 nemo-relay hook-forward codex --fail-closed

The response should match Codex hook semantics. For most lifecycle events it is an empty JSON object.

Verify Export

End the Codex session and confirm Agent Trajectory Interchange Format (ATIF) exists:

$ls .nemo-relay/atif

The gateway writes <session-id>.atif.json after every conversation turn for Codex sessions (Codex’s hook surface has no SessionEnd-equivalent event, so the gateway uses each per-turn Stop hook to snapshot the trajectory; the file grows cumulatively across turns and the final write reflects the full session). For agents that do emit a session-end hook, the same file is written once on session close. If the file is missing, confirm features.hooks = true, hook config loading, and that plugins.toml enables the ATIF exporter with a writable output_directory.

Troubleshoot LLM Lifecycle

If agent/tool events exist but LLM spans are missing, the active Codex provider is not pointing at the gateway for the active Codex process. If only GUI sessions are missing spans, confirm the GUI is using local provider configuration rather than a remote execution path.

If LLM spans exist but attach to the session instead of a subagent, pass x-nemo-relay-subagent-id on gateway requests or include shared conversation_id, generation_id, or request_id values in both hook payloads and provider requests.