Subagents are in-process — no forking, no subprocess. The parent's conversation context is cloned, tools are resolved per-agent, and results return inline. Fork subagents go further: byte-identical message history ensures prompt cache hits across all children.
What happens when AgentTool.call({ prompt, subagent_type }) is invoked.
isForkSubagentEnabled(). Routes to FORK_AGENT or resolves named agent from registry (Explore, Plan, general-purpose, etc.). Validates agent exists and passes permission rules.resolveAgentTools() applies 3 filtering layers: (a) remove ALL_AGENT_DISALLOWED_TOOLS, (b) remove CUSTOM_AGENT_DISALLOWED_TOOLS for custom agents, (c) filter non-async tools if async agent. Wildcard ['*'] means all filtered tools. Fork path sets useExactTools: true for byte-identical API prefix.renderedSystemPrompt (cached bytes) to prevent GrowthBook divergence that would bust prompt cache. Normal path: calls selectedAgent.getSystemPrompt() for agent-specific instructions.cloneFileStateCache() gives the agent its own read cache (LRU). Parent's cached file reads are inherited — prevents redundant disk I/O.runWithAgentContext() for analytics attribution. Executes runAgent() inline, blocks until completion. Async: registers via registerAsyncAgent(), spawns in detached closure, returns async_launched immediately..claude/sessions/<id>/sidechain/<agentId>/. Invoked skills and dump state cleared. Analytics event logged (tengu_agent_tool_completed). Result text extracted and returned to parent.buildForkedMessages() creates messages where every fork shares an identical byte prefix — only the final directive differs. This maximizes prompt cache hits.
"Fork started — processing in background"FORK_BOILERPLATE_TAG prevents recursive forking.| Agent | Tools | Max Turns | Model | Use Case |
|---|---|---|---|---|
| General Purpose | All (*) | 200 | Inherited | Complex multi-step tasks |
| Explore | Read-only (no Edit/Write/Agent) | 50 | Configurable | Codebase research |
| Plan | Read-only (no Edit/Write/Agent) | 50 | Configurable | Architecture design |
| Claude Code Guide | Glob, Grep, Read, WebFetch, WebSearch | 30 | Inherited | Documentation Q&A |
| Statusline Setup | Read, Edit | 10 | Inherited | Status line config |
| Verification | Configurable | 20 | Inherited | Result verification |
Leader + multiple teammates. File-based mailbox communication. Permissions routed through leader's UI.
Leader creates team via TeamCreateTool, spawns teammates, approves permissions, receives idle notifications. Deterministic agent ID: formatAgentId("lead", teamName).
Teammates get assigned names, colors, prompts. Run in-process (AsyncLocalStorage), tmux panes, or iTerm tabs. File at ~/.claude/teams/<name>/team.json.
Teammate writes SwarmPermissionRequest to permissions/pending/. Leader polls every 500ms, shows UI dialog. Response moved to resolved/. "Always allow" rules propagate to teammate's context.
Idle notification: On Stop hook, teammate marks itself as idle in team config, sends idle notification to leader's mailbox with last peer DM summary.
| Backend | Availability | Isolation | Termination | Overhead |
|---|---|---|---|---|
| In-Process | Always (default) | AsyncLocalStorage | AbortController | Zero fork |
| Tmux | If installed | Separate pane (30/70 split) | Kill pane | Shell init 200ms |
| iTerm2 | If in iTerm + it2 CLI | Separate tab (vertical split) | Kill pane | Process fork |
Three scopes for agent-specific persistent knowledge.
| Scope | Path | VCS |
|---|---|---|
| User | ~/.claude/agent-memory/<type>/ | Not committed |
| Project | .claude/agent-memory/<type>/ | Committable |
| Local | .claude/agent-memory-local/<type>/ | Not committed |
| Remote | $CLAUDE_CODE_REMOTE_MEMORY_DIR/<project>/<type>/ | Remote mount |
checkAgentMemorySnapshot() checks if a newer snapshot exists. If so, pulls fresh context before the agent starts — ensures agents don't work with stale knowledge.