Harness Notes

Subagents

Updated 2026-11-22,

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

QuestionClaude Codechecked at 2.1.299
Is there one, and how does it start

Yes. Claude delegates on its own when a task matches a subagent's description; you can also name the subagent in your prompt, @-mention it (@"code-reviewer (agent)" or @agent-<name>) to guarantee it runs, run /subtask <task> to fork the current conversation, or start the whole session as that agent with claude --agent <name> or the agent setting.

Add a phrase like "use proactively" to a description to encourage automatic delegation.

Built-in subagents

Explore is a fast read-only agent for searching code, Plan does read-only research while you're in plan mode, and general-purpose handles multi-step tasks with every tool. Helper agents also ship: claude (catch-all, and the default for background sessions), statusline-setup (used by /statusline) and claude-code-guide (answers questions about Claude Code). Claude can also spawn a fork, which inherits the whole conversation. In 2.1.302, fork subagents are enabled by default in the terminal, claude -p, Agent SDK, desktop app and VS Code; CLAUDE_CODE_FORK_SUBAGENT=0 disables them, and claude mcp serve never offers them.

Explore and Plan skip your CLAUDE.md files and git status, and can't be resumed.

Turn off Explore and Plan with CLAUDE_CODE_DISABLE_EXPLORE_PLAN_AGENTS=1, or block any type with a permissions.deny rule such as Agent(Explore).

Define your own

Write a Markdown file with YAML frontmatter (name and description are required) and put the system prompt in the body. Save it in .claude/agents/ for one project or ~/.claude/agents/ for all your projects, or pass JSON with claude --agents. When names clash, managed settings win first, then --agents, then project, then user, then plugin agents/ directories.

Both folders are scanned recursively, and the nested .claude/agents/ closest to your working directory wins. Edits are picked up without a restart, except when the agents folder didn't exist at startup.

A plugin agent is addressed by its scoped name, such as my-plugin:reviewer.

What a definition can set

Frontmatter can set name, description, tools, disallowedTools, model (an alias, a full ID or inherit), permissionMode, maxTurns, autoCompactWindow, skills (preloaded in full), mcpServers (by name or defined inline), hooks, memory (user, project or local), background, omitClaudeMd, effort, isolation: worktree, color, initialPrompt and experimental.cacheTtl. The Markdown body is the system prompt.

Plugin agents ignore hooks, mcpServers and permissionMode.

Claude Code silently ignores a misspelled field; claude --debug names it.

While it runs

QuestionClaude Codechecked at 2.1.299
What it sees, and what comes back

A subagent doesn't see your conversation. It starts with its own system prompt, the task message Claude writes, your CLAUDE.md files, a git status snapshot and any skills listed in skills, and only its final report comes back to the main conversation. A fork (/subtask) is the exception: it inherits the whole conversation, though still only its result returns.

Explore, Plan and agents with omitClaudeMd: true start without your CLAUDE.md files.

Your output style and auto memory don't reach a non-fork subagent.

2.1.307 improves parallel fork-subagent self-identification; 2.1.305 fixes reporting the model after a subagent fallback. Neither release establishes a new delegation protocol.

Several at once

Yes. Claude can run several subagents at once, for example when you ask it to research modules in parallel. By default a session allows 20 at a time, and the next spawn fails with Concurrent subagent limit reached; change the cap with CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS. There is no limit on the total over a session.

Every result comes back into the main context, so many detailed reports can use a lot of it.

Keep working while it runs

Yes. In interactive sessions subagents run in the background by default while you keep talking, and you can press Ctrl+B to send a running task there. When one finishes, its report arrives in the main conversation as a completion notification, and /tasks lists background work, including finished subagents for a short time. Set background: true to keep a subagent in the background, or CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 to keep all of them in the foreground.

Background subagents get a smaller set of built-in tools than foreground ones.

With -p and in the Agent SDK, Claude chooses the foreground when it needs the result before continuing.

2.1.302 published changes: desktop and VS Code always run the main conversation's subagents in the background, as the terminal does. A subagent's own Agent calls default to foreground in -p, Agent SDK, desktop and VS Code.

Your checkout or its own copy

By default a subagent works directly in your checkout, starting in the main conversation's working directory. With isolation: worktree, or when you ask Claude to "use worktrees for your agents", each subagent gets a temporary git worktree branched from your default branch (or from HEAD when worktree.baseRef is "head"). Nothing is merged automatically: a worktree with no changes is deleted when the subagent finishes, and one with changes stays on its branch for you to review and merge.

A worktree subagent can't edit files in your main checkout or point git at it.

Kept worktrees are swept after cleanupPeriodDays once they hold no changed files or unpushed commits.

Its permissions

A subagent inherits your permission rules and permission mode. A definition can set permissionMode (default, acceptEdits, auto, dontAsk, bypassPermissions or plan), but this only applies when the main conversation is in default, dontAsk or plan. When the main session is in bypassPermissions, acceptEdits or auto mode, the subagent uses that same mode, and bypassPermissions only applies if the main session already uses it.

Permission prompts from background subagents appear in your main session, labeled with the subagent's name. Press Esc to deny one tool call without stopping the subagent.

Use tools, disallowedTools and PreToolUse hooks in the definition to narrow what a subagent can do.

2.1.309 fixes split-pane teammates not inheriting leader CLI tool denies and --tools restrictions. Teammates and ordinary subagents remain distinct surfaces; publisher report, not a runtime permissions probe.

Subagents of subagents

Yes. Subagents can spawn their own subagents, up to three layers below the main conversation by default. At the limit the Agent tool is withheld. Change the depth with CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH (1 turns nesting off), or remove Agent from one subagent's tools.

A fork can't spawn another fork, and agent-team teammates can't spawn teammates.

Watching and handing off

QuestionClaude Codechecked at 2.1.299
Watch, steer or stop one

Running subagents appear in a panel below the prompt. Use ↑/↓ to pick one, Enter to open its transcript and type follow-up messages to it, and x to stop it. /tasks lists background work and the model each subagent runs on, and Ctrl+X Ctrl+K stops every background subagent. A finished subagent can be resumed, with its history intact, when Claude messages it with SendMessage.

Subagent transcripts are saved to ~/.claude/projects/{project}/{sessionId}/subagents/agent-{agentId}.jsonl.

SubagentStart and SubagentStop hooks fire when subagents start and stop.

Hand work to a cloud agent

Yes, as a separate cloud session rather than a subagent. claude --cloud "<task>" starts a cloud session on claude.ai that clones your repository's GitHub remote at the current branch. /autofix-pr starts a cloud session that watches your PR, and /code-review ultra runs a multi-agent review in the cloud. Use claude --teleport or /teleport to bring a cloud session back into your terminal.

The CLI can't push an existing terminal session to the cloud; the Desktop app can, from its Open in menu.

Requires a claude.ai account; cloud sessions aren't available through Bedrock, Google Cloud or Foundry.

--remote still works as a deprecated alias of --cloud; /remote-control is different and lets you steer a local session from another device.

Notes and sources

Claude Code, 9 sources
  • Background subagents use a reduced built-in tool set and surface permission prompts in the main session.
  • isolation: worktree creates an isolated checkout from the default branch, not necessarily the parent's HEAD.
  • Managed settings, session-only --agents JSON, and plugin-provided agents are documented sources that are not represented by the current user/project location vocabulary.
  • A remote isolation value appears in the Agent tool schema, but no first-party documentation establishes subagent cloud handoff, so cloudHandoff remains unknown.
  • 2.1.304 fixes plugins extending headless runs past --max-turns, Stop or ended input by spawning/resuming subagents, and subagents forgetting recent work when messaged/resumed immediately after completion.
  • 2.1.304 fixes agent-team shutdown approval from the main session exiting the entire CLI. VS Code background subagents now display a single status line; the full transcript stays in /tasks.
  • 2.1.311 publisher fixes access to MCP tools whose servers connect after a subagent starts, isolated-worktree cleanup while nested background work remains, and duplicate execution of finished subagent skills after a cloud/background restart. Ordinary subagents, teams and hosted sessions retain separate scopes.
  • 2.1.312 publisher notes: frontmatter autoCompactWindow can lower the window set by CLAUDE_CODE_AUTO_COMPACT_WINDOW, never raise it. Prompt and agent hooks now share a per-session concurrency limit that includes subagents.
  • Publisher updates: 2.1.316 adds CLAUDE_CODE_SUBAGENT_EFFORT fallback; 2.1.317 uses a different subagent/teammate model's saved/default effort rather than main-session effort, and SendMessage can background a running shell without stopping it. 2.1.318 backgrounds background-subagent shell commands after 3 minutes on all providers. 2.1.319 /tasks can reopen finished subagents after restart. No delegation probe.
Is there one, and how does it start, 2
Built-in subagents, 2
Define your own, 1
What a definition can set, 1
What it sees, and what comes back, 3
Several at once, 1
Keep working while it runs, 3
Your checkout or its own copy, 2
Its permissions, 2
Subagents of subagents, 1
Watch, steer or stop one, 2
Hand work to a cloud agent, 2

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.

MomentClaude CodeHook commands
Hook types
  • command
  • http
  • mcp_tool
  • prompt
  • agent (experimental)
Subagents
Subagent starts
SubagentStart

add context

Subagent finishes
SubagentStop

block, add context

Notes and sources

Claude Code
  • onFailure: "block" on a command or HTTP hook makes a failed or timed-out hook block the action (2.1.295 and later).
  • Plugin mods are a separate JavaScript hook surface with their own events and are not recorded here.
  • 2.1.302 published changes: at most 12 prompt and agent hooks for one event run at once; remaining handlers wait. This is not the subagent concurrency limit or a stated cap on command/MCP hooks. Superseded by 2.1.312 below.
  • 2.1.304 caps skill hooks from each source (a repository, personal folder or plugin) at 1,024 hooks and 16,384 matcher characters per session; these are separate from the 12 prompt/agent-hook concurrency limit.
  • 2.1.304 fixes a skill once hook removing another skill’s identical hook, preserves a PreToolUse deny reason when an SDK callback hook times out, and excludes up to 10 minutes of SessionStart command-hook runtime from the VS Code subprocess initialization timeout.
  • 2.1.304 adds a transcript notice identifying the event and plugin when an earlier plugin skips a mod hook. Mod tool.check gains e.isReadOnly and decider: person; settings.read receives individual layers and can rewrite merged settings. Mods remain a separate JavaScript hook surface.
  • 2.1.309 publisher fixes PowerShell command hooks failing to block on exit code 2, including Windows PreToolUse/PermissionRequest fail-open behavior without Git for Windows. No hook-execution probe.
  • 2.1.307 added claude_code.safety_event OpenTelemetry instrumentation for permission/safety/hook/sandbox outcomes; 2.1.312 stops sending it. It was never a hook event or hook control authority.
  • 2.1.311 publisher fixes SubagentStop firing repeatedly while a subagent runs (about twice per minute); it should run once when the subagent finishes. 2.1.310 fixes Windows PreToolUse/PermissionRequest fail-open behavior with only quoted command strings when Git Bash is missing. No hook-execution probe.
  • 2.1.312 publisher notes: prompt and agent hooks run at most 24 at a time per session, subagents included, plus at most 12 that have waited longer than their event's timeout. A timeout under 1 second counts as 1 second. Command, HTTP and MCP-tool hooks are not covered by this limit. No hook-execution probe.
  • Publisher updates: 2.1.314 truncates each PreCompact hook output to 10,000 characters; 2.1.317 adds onFailure: block to Agent SDK callbacks; 2.1.319 runs PostToolUse (up to 10 seconds) for calls finishing after a new message interrupts the turn. 2.1.321 fixes competing PreToolUse ask/defer answers, refuses MCP tool calls on >16 MiB mcp_tool hook replies, and keeps original AskUserQuestion/ExitPlanMode results despite PostToolUse replacements in Cowork cloud. Separate hosts and handler types; no execution probe.
  • 2.1.328 publisher notes extend onFailure: block to mcp_tool hooks and add CLAUDE_CODE_DISABLE_DEFERRED_TOOL_RESUME to stop deferred tool execution on -p --resume/--continue. Code Mode script output no longer runs UserPromptSubmit hooks; use PostToolUse updatedToolOutput for redaction. Managed PostToolUse no longer fires for calls refused before execution; PostToolBatch receives most without a refused marker. No hook runtime probe.

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.

QuestionClaude Codedocumented-internal; checked at 2.1.299
Child transcripts and parent links

Subagent transcripts are written beside the parent at ~/.claude/projects/<project>/<session-id>/subagents/agent-<agentId>.jsonl (with an agent-<agentId>.meta.json sidecar) and are deleted together with the parent session. Forks made with /branch or --fork-session become ordinary top-level sessions with their own IDs, and SubagentStop hooks receive agent_transcript_path pointing at the subagent file.

Compacting the main conversation does not alter subagent transcripts; subagents log their own compact_boundary records.

Subagent transcripts written before 2.1.307 can show placeholder token usage and empty stop reasons.

Session file format

Partly

Transcripts are JSONL: one JSON object per line for a message, tool use, or metadata entry, each tagged with a type such as user, assistant, system, or attachment. Anthropic documents the entry format as internal and says it changes between versions, so for anything durable use /export, claude -p --output-format json/stream-json, or the Agent SDK session functions rather than parsing the files.

Each message record carries the writing Claude Code version, which is the only per-record version signal.

What is recorded

The transcript holds the full conversation: every prompt, response, tool call and tool result, plus thinking blocks, per-response token usage, compaction markers (compact_boundary with preTokens) and summaries, session titles, and other metadata. Large tool outputs and full-size MCP images spill into <session-id>/tool-results/, and pre-edit file snapshots for checkpoints live separately in ~/.claude/file-history/<session>/.

Everything is plaintext and unencrypted; a secret printed by a tool ends up in the transcript.

Since v2.1.299 the bytes of @-mentioned PDFs are no longer kept in the transcript.

Read transcripts from code

The Agent SDK exposes listSessions(), getSessionMessages(), getSessionInfo(), renameSession(), tagSession() and forkSession() in TypeScript (list_sessions(), get_session_messages() and friends in Python), plus resume/forkSession options and a sessionStore adapter for mirroring transcripts to your own storage. From the CLI, claude -p --output-format json or stream-json returns the result, session ID, usage and cost, and hooks and status line commands receive the live transcript_path.

Session record structureClaude Code
Envelope fieldstype, uuid, parentUuid, sessionId, timestamp, version, cwd, gitBranch, entrypoint, isSidechain, userType, message
Record discriminatortype
Identifiers and lineagesessionId, uuid, parentUuid, logicalParentUuid, leafUuid, promptId, requestId, agentId, toolUseID, sourceToolAssistantUUID
Orderingfile append order; message records also chain via parentUuid

Notes and sources

Claude Code, 16 sources
  • Claude Code says the entry format is internal and can change between versions.
  • Prompt history (~/.claude/history.jsonl) is a different artifact.
  • 2.1.304 adds earlier tool names to compaction summaries in Ctrl+O, avoids storing auto-mode classifier context with every request, and fixes local transcript GC dropping messages when disk fills during trimming. Mods settings.read can impose a cleanupPeriodDays ceiling used by retention sweeps. These are publisher claims, not a new transcript schema audit.
  • 2026-10-26 automatic-approval audit: publisher docs show auto-mode denials and reasons alongside tool calls in the conversation/Ctrl+O viewer. This is not evidence for a stable JSONL classifier verdict record or a complete audit of approvals.
  • 2.1.304 publisher changelog says classifier context is no longer saved with every request. Older transcripts may therefore contain more classifier context. Remaining private metadata/decision fields are not exhaustively specified or claimed absent.
  • For documented machine-readable classifier decisions use separately configured OpenTelemetry tool_decision: classifier_verdict and permission_mode (2.1.301+), and optional classifier_category with OTEL_LOG_TOOL_DETAILS=1. safety_event (2.1.307–2.1.311; no longer sent from 2.1.312) recorded blocked/prompted checks, not every successful classifier allow. Telemetry is not the session transcript. See docs/research/automatic-approval.md.
  • 2.1.311 publisher fixes out-of-order or retracted messages retained by -p/SDK transcripts. JSON/stream-json now escape DEL, C1 controls and Unicode format characters as \uXXXX without changing parsed values. 2.1.310 fixes cleanup of recent files with very large cleanupPeriodDays; a large value does not disable retention.
  • 2.1.312 publisher fixes a rare case where the first reply after a terminal resume could be missing when the session was resumed again, and makes transcripts name the effort level in force rather than a newly picked level the model has not applied yet. Not a new JSONL schema audit.
  • Documentation checked 2026-11-15 against latest 2.1.325 / stable 2.1.311 release metadata. Detailed internal shapes remain the historical 2.1.310 survey (high-level observedVersion 2.1.299); readable implementation JavaScript has now been located in the installed native executable; the 2.1.325 source supplement traces selected fields and storage policies. The four-field implementation supplement is not a complete 2.1.325 schema or controlled runtime verification.
  • 2026-11-15 aggregate-only existing-record survey found 1,769 version-matched 2.1.325 records across five files. Ten record/subtype families and top-level/message field types were retained without content. Unversioned metadata in these mixed files is counted separately and cannot be attributed to 2.1.325. This supplements the 2.1.310 full survey; it is not a controlled writer/resume probe or an exhaustive current schema.
  • Installed 2.1.325 source correction: the native executable embeds readable JavaScript alongside bytecode/string tables. Static extraction recovered transcript constructors, write routing and GC policy tables plus four field definitions. See docs/research/evidence/claude-transcript-source-2.1.325.json and its partial JSON Schema. Keep the older full catalogue version pin; these are explicitly current source supplements.
  • Expanded 2.1.325 installed-source supplement: 46 write/read/GC policy registrations plus repl-mode special handling, six previously uncatalogued metadata families, and actual cost-state validator projection with eight passing isolated checks. Do not treat constructor candidates or normalized-reader shapes as complete runtime input schemas.
Child transcripts and parent links, 5
Session file format, 5
What is recorded, 3
Read transcripts from code, 8