Harness Notes

Subagents

Updated 2026-11-24,

On this page

How each harness starts and configures subagents, what they can see and change, which lifecycle hooks run, and how their transcripts are saved and read.

Worktrees: creation, setup, integration and cleanup

Starting one

QuestionCodex CLIchecked at 0.162.1
Is there one, and how does it start

Yes, and they are on by default ([agents] enabled = true). Ask in plain language, e.g. "spawn one agent per point and wait for all of them", or put delegation instructions in AGENTS.md or a skill; the main agent then calls its spawn_agent tool. There is no slash command or @-mention to start one, and local Codex does not delegate on its own without such a request.

Set [agents] enabled = false in config.toml to remove the multi-agent tools.

Built-in subagents

Three built-in agent types ship: default (general-purpose fallback), worker (execution-focused, for implementation and fixes) and explorer (fast, read-heavy codebase questions). The main agent picks one with spawn_agent's agent_type; omitting it uses default.

Define your own

Add one standalone TOML file per agent under .codex/agents/ (project) or ~/.codex/agents/ (personal); each must set name, description and developer_instructions, and the name field (not the filename) identifies the agent. You can also declare roles in config.toml as [agents.<name>] with description and config_file. Project-level definitions override personal ones with the same name, and a custom agent named like a built-in (e.g. explorer) replaces the built-in.

Malformed files are skipped with a startup warning rather than failing the session.

What a definition can set

Partly

Besides name, description and developer_instructions, a definition can set model, model_reasoning_effort, model_reasoning_summary, model_verbosity and nickname_candidates. It can also turn capabilities off with features.shell_tool, features.apps, features.plugins, features.memories or features.request_permissions_tool set to false, and adjust skills with skills.config, skills.bundled.enabled and skills.include_instructions. sandbox_mode, approval_policy, model_provider and mcp_servers in an agent file are ignored: those always come from the parent session.

There is no per-agent tool allowlist or memory setting; tools can only be removed through the features.* switches.

While it runs

QuestionCodex CLIchecked at 0.162.1
What it sees, and what comes back

By default a subagent starts fresh, with only the task message the main agent writes plus the usual project instructions and skills. If the main agent sets fork_context: true, the subagent gets a full copy of the current thread history. Only the subagent's final status and message go back to the main agent (through wait_agent or a completion notification), not its logs or tool output.

0.162.0 removed partial-history forks: a fork now copies either all of the history or none of it.

Several at once

Yes. Several subagents can run at once, capped by [agents] max_concurrent_threads_per_session (legacy alias max_threads), which defaults to 6 open subagent threads, not counting the main thread. Finished agents still count toward the cap until the main agent closes them with close_agent.

The docs recommend running read-heavy work in parallel and warn that parallel edits can conflict.

Keep working while it runs

Partly

spawn_agent returns immediately, so the main agent can keep working while subagents run. It then collects their results with wait_agent (default timeout 30 s, up to 1 hour) or from a completion notification. By default the main turn waits for every requested result before it gives you a consolidated answer. There is no detached mode where you keep chatting while a subagent works, though you can switch to its thread with /subagents while it runs.

Separate background chats (desktop Worktree mode, /side, or the codex agents command center on a shared server) are top-level sessions, not subagents.

Your checkout or its own copy

Not supported

Subagents work directly in the parent session's checkout; they get no worktree or copy of their own, so there is nothing to merge. Their edits land immediately, and parallel writers can collide. The built-in worker guidance tells the main agent to give each worker its own files. Git worktree isolation exists only for a whole chat (/worktree in the CLI, Worktree mode in the desktop app), not for each subagent.

Its permissions

Subagents inherit the parent turn's current sandbox and approval settings, including changes made with /permissions or --yolo, and a custom agent file cannot change them. Setting sandbox_mode or approval_policy in the file has no effect, and instructions like "do not edit files" are not a read-only sandbox. In the interactive CLI, approval requests from subagent threads pop up over the main thread (press o to open the source thread). In non-interactive runs, an action that needs new approval fails and the error is returned to the parent.

A definition can only narrow capabilities, e.g. features.shell_tool = false.

Subagents of subagents

Partly

Nesting is controlled by [agents] max_depth, which defaults to 1. With the default, the main agent's subagents cannot spawn their own (they get "Agent depth limit reached. Solve the task yourself."). Raise max_depth to allow deeper trees. close_agent also closes an agent's open descendants.

max_depth is missing from the subagents docs page. It applies to the default (V1) multi-agent tools and is ignored when the opt-in features.multi_agent_v2 is enabled.

Watching and handing off

QuestionCodex CLIchecked at 0.162.1
Watch, steer or stop one

In the CLI, type /subagents to pick an agent thread and inspect or continue its work while it runs. The IDE extension shows active subagents above the composer, with a button to stop all of them. To steer, stop or close one, ask the main agent; it uses send_input (with interrupt: true to redirect immediately) and close_agent.

/agents (and codex agents) opens a separate command center for top-level chats on a shared server, not subagents.

Hand work to a cloud agent

Partly

Subagents always run locally; the main agent cannot spawn a cloud subagent. You can hand work to Codex Cloud yourself with codex cloud exec --env <ENV_ID> "<task>", check it with codex cloud status/codex cloud list, and pull the result in with codex cloud apply. In the desktop app, /cloud moves the whole chat to the cloud.

codex cloud is marked experimental in codex --help and needs a configured cloud environment.

Notes and sources

Codex CLI, 14 sources
  • Subagents inherit the parent sandbox and permission mode unless a custom agent overrides supported session settings.
  • The orchestrating turn waits for requested results, but users can switch to, steer, stop, and close subagent threads; no detached-dispatch flag is documented.
  • Custom sandbox policy is execution containment, not checkout isolation.
  • Concurrency is bounded by agents.max_concurrent_threads_per_session, and parallel write-heavy work can conflict in the shared checkout.
Is there one, and how does it start, 2
Built-in subagents, 2
Define your own, 3
What a definition can set, 2
What it sees, and what comes back, 2
Several at once, 3
Keep working while it runs, 3
Your checkout or its own copy, 4
Its permissions, 1
Subagents of subagents, 4
Watch, steer or stop one, 4
Hand work to a cloud agent, 3

Subagent lifecycle hooks

Recorded start and stop events, with their control semantics and availability caveats. A dash means no event is recorded here. General session or tool events do not establish a dedicated subagent hook.

Which moments a hook can attach to, and what it can do there. Event names link to each harness’s documentation. “Block”, “deny” and “modify” change what the agent does; “observe only” can watch but not intervene. Where hook files live is on the Locations page.

MomentCodex CLIHook commands
Hook types
  • command
  • mcp_tool
  • prompt (accepted but skipped)
  • agent (accepted but skipped)
Subagents
Subagent starts
SubagentStart

add context

Subagent finishes
SubagentStop

queue follow-up, stop

Notes and sources

Codex CLI
  • Matching hooks are launched concurrently, so one hook cannot stop another from starting.
  • Project hooks load only in a trusted project, and every non-managed hook must also be reviewed and trusted by its hash.
  • Background (async) hooks cannot block, approve or rewrite the triggering operation.
  • OpenAI describes tool hooks as a guardrail, not a complete enforcement boundary.
  • Since 0.165.0 an execution environment can bring its own managed hooks from its requirements; they are always required, run on that environment's executor and appear as <environment:ID>/requirements.toml. In 0.166.0, App Server hooks/list with a threadId includes them and marks each with environmentId. The App Server's own environment selection supplies none, so these come only from an environment owner that provides its configuration.
  • 0.167.0 managed prompt-user checkpoint, traced at 0.167.2: requirements.toml prefix rules can require fresh human approval for every execution attempt. Hooks and automatic review cannot satisfy it; approval cache/rule amendments do not replace it. A never/rejecting approval policy or enforced automatic-only review rejects the command instead. This is a managed-rule decision, not a fourth approval_policy mode. No runtime probe.
  • November 16 plugin-format audit at Codex 0.169.0: the local loader parses OpenAI overlay hooks but explicitly skips hook sources for Agent Plugins packages; legacy compatibility packages use the hook loader. Executor-owned inline hooks have a separate cleanup admission policy. This updates the package-loading boundary without redating the older event/handler traces; no runtime probe ran.

Subagent transcripts

Child storage and parent links are described separately from the harness’s general session format. Internal and source-observed formats can change between versions; these records do not promise a stable external schema.

QuestionCodex CLIsource-observed; checked at 0.169.0
Child transcripts and parent links

Each subagent gets its own rollout file in the same ~/.codex/sessions/YYYY/MM/DD/ tree. Its session_meta.source records subagent.thread_spawn with parent_thread_id, depth, agent_role and agent_nickname, and the parent-child link is also kept in the thread_spawn_edges table in state_5.sqlite. Forks are new files with forked_from_id set. At 0.164.0, non-ephemeral Auto-review (Guardian) reviewer sessions can also be saved in sessions/, but are internal reviewer sessions, not ordinary spawned subagents; temporary review forks are ephemeral. Archiving or deleting a parent also archives or deletes its spawned descendants. Use /subagents to open a child thread.

Ephemeral subagents are unsaved. Side-chat persistence is separate: temporary versus persisted attached chat depends on workspace, parent history and server capability.

Session file format

Partly

LocalThreadStore persists JSONL with timestamp, optional ordinal, type, payload and optional response metadata. The wire includes dynamic_tools_updated as well as session_meta, response_item, event_msg, turn_context, compacted, token_usage_record, retained_context and other families. history_mode distinguishes legacy and paginated persistence. This internal artifact has no published compatibility promise; App Server protocol generation describes a separate wire interface.

Cold files may be stored as .jsonl.zst when the under-development local_thread_store_compression feature is enabled. It is off by default, and Codex reads both forms.

What is recorded

The local rollout preserves selected model items and display events, settings, compaction and lineage. Persistence depends on legacy/paginated mode; it is not a complete record of all runtime events. Paginated display command/MCP output can be truncated to 64 KiB. Dynamic-tool updates, file-backed audio references, retained evidence and moderation metadata are covered by the 0.169.0 detailed format audit. File IDs retain identities, not the referenced bytes or their future availability.

Reasoning is stored as the model returns it, usually a summary plus encrypted content rather than raw chain of thought.

Since 0.162.0, paginated history caps persisted command output at 64 KiB and truncates oversized MCP results.

2026-11-13 supplement, Codex rust-v0.167.2 at ce21072c90d32c40af7a55b60b2fb35c84a43a6a: assistant text can contain :codex-file-citation{path="…" purpose="source"}. This is inline message markup, not a new JSONL record or memory_citation field. The TUI assistant renderer interprets it; external transcript/App Server consumers need their own rendering. HTTPS paths are live-observed; the inspected TUI treats non-local paths as relative, so its destination logic is not a web-link contract. See docs/research/codex-file-citations.md and docs/research/evidence/codex-file-citations-2026-11-13.json. The original supplement did not refresh the full schema; the 2026-11-15 audit supplies the current local format pin.

Read transcripts from code

The supported interface is codex app-server (JSON-RPC). thread/list, thread/read, thread/turns/list and thread/items/list read stored threads without resuming them; thread/resume, thread/fork, thread/archive and thread/delete manage them. codex exec --json streams JSONL events (thread.started with thread_id, item.*, turn.completed) for a live run. The TypeScript and Python SDKs can resume a thread by id, for example codex.resumeThread(threadId). You can also parse the rollout JSONL files directly, but they have no published schema.

codex app-server generate-json-schema and generate-ts (both experimental) emit the protocol types.

Session record structureCodex CLI
Envelope fieldstimestamp, ordinal, type, payload, metadata
Record discriminatortype
Identifiers and lineagesession_meta.payload.id (thread id), session_meta.payload.session_id, rollout_id (filename suffix), forked_from_id, forked_from_ordinal_exclusive, parent_thread_id, history_base, source.subagent.thread_spawn.parent_thread_id, agent_role, agent_nickname, agent_path, turn_id, response_id
Orderingfile-order-or-ordinal

Notes and sources

Codex CLI, 38 sources
  • Rollout JSONL is a harness-owned durable artifact, not a published compatibility API.
  • Prompt history.jsonl is a different artifact; history.persistence controls only that file.
  • 0.164.0 source refresh: resume lookup visits plain/compressed rollout filenames, and App Server restores persisted thread settings from turn context/settings events. Older format and storage claims retain their original source pins.
  • Automatic-approval findings specifically audited at rust-v0.164.0 / 6aaac694803004a63c6f393d153c96d22521a6b9 (2026-10-26); that historical baseline is retained in the 2026-11-15 evidence manifest, which separately refreshes the current local format.
  • 0.164.0 parent turn_context records preserve approval_policy and approvals_reviewer; the current writer fills approvals_reviewer, and persisted thread_settings_applied snapshots also carry it. This establishes the selected reviewer, not a per-action review outcome.
  • GuardianAssessment and GuardianWarning are transient and excluded from local rollout persistence. Do not treat missing guardian_assessment records in the parent transcript as evidence that no review occurred.
  • The registered reviewer creates sessions with session_meta.source = {internal: guardian} and thread_source = guardian_review. Non-ephemeral reviewer trunks use normal session persistence and can contain the reviewed action/context plus final JSON outcome, risk_level, user_authorization and rationale. Low-risk output can contain only outcome = allow; the parser supplies defaults.
  • A reviewer session can serve several reviews. Busy/incompatible reviews use ephemeral forks; an ephemeral parent also propagates its setting. Thus not every review has a saved reviewer transcript. These are internal sessions, distinct from ordinary subagent.thread_spawn lineage.
  • For live reviews capture App Server item/autoApprovalReview/started and item/autoApprovalReview/completed, correlating threadId, turnId, reviewId and targetItemId when present. They contain action and review status/risk/authorization/rationale, but are notifications, not durable transcript items; payload is marked unstable. codex exec --json drops unmatched notifications and is not this audit stream. See docs/research/automatic-approval.md.
  • Persistence conclusions apply to the ordinary local rollout store; desktop presentation, custom/cloud stores and hosted retention are not established by this source audit. No live classifier or transcript-production probe was run.
  • 2026-11-13 supplement, Codex rust-v0.167.2 at ce21072c90d32c40af7a55b60b2fb35c84a43a6a: assistant text can contain :codex-file-citation{path="…" purpose="source"}. This is inline message markup, not a new JSONL record or memory_citation field. The TUI assistant renderer interprets it; external transcript/App Server consumers need their own rendering. HTTPS paths are live-observed; the inspected TUI treats non-local paths as relative, so its destination logic is not a web-link contract. See docs/research/codex-file-citations.md and docs/research/evidence/codex-file-citations-2026-11-13.json. The original supplement did not refresh the full schema; the 2026-11-15 audit supplies the current local format pin.
  • 2026-11-15 source refresh: rust-v0.169.0 at d32063f96c2dff1dc96af839b3952abb6acfeda4. Source inspection, not a harness runtime probe. Historical supplements keep their independent evidence and dates.
  • Older user-facing resume/export/history instructions retain their dated documentation evidence; the 0.169.0 refresh audits the local storage writer, parser, reconstruction and host/provider boundary. It does not establish proprietary desktop behavior.
  • At 0.169.0 the opt-in terminal workspace can persist attached side chats; temporary chats remain ephemeral. The same /side UI action does not imply one storage policy across configurations.
Child transcripts and parent links, 8
Session file format, 5
What is recorded, 15
Read transcripts from code, 14