Claude Code background subagents: waiting, permissions and completion
Separate running state from completion notification, and inspect fork mode, background tools and session-wide grants.
Waiting behavior depends on the surface · Background tools and grants are not local guarantees · Completion notification provides the result evidence
At a glance
The goal is to avoid reporting a background task result before completion. The official sub-agents page was checked. No subagent was created, launch environment changed or background command run; only synthetic state decisions were inspected. Running in the background differs from having its result.
Runtime and applicability
- Article type
- Spec file
- Verified
- Applies to
- Claude Code Applies to Claude Code as documented; environment prerequisites appear in the body.
- Tools
File locations
| Path | Scope | How it is read |
|---|---|---|
启动环境 CLAUDE_CODE_FORK_SUBAGENT 与主会话后台任务通知 | Subagent launch, waiting and result delivery. | A new session reads fork-mode environment; completion notification arrives in a later turn. |
When to use
- When a background result has not arrived, or a dependent step must wait for its report.
When not to use
- When operations must be isolated or grants contained, inspect permissions and sandboxing separately.
Waiting behavior depends on the surface
The docs say subagents spawned from the main conversation start in the background by default. claude -p and Agent SDK can wait by judgment or request. Local interactive terminal, VS Code and desktop sessions need default fork mode off before waiting. The documented steps set CLAUDE_CODE_FORK_SUBAGENT to 0, relaunch from the shell or open a new VS Code conversation, then request waiting. Editing a value in an existing session does not establish changed behavior.
Background tools and grants are not local guarantees
Background subagents have a smaller built-in toolset than foreground ones, except conversation forks and resumed foreground tasks. Permission prompts appear in the main session. A grant lasting beyond one call, such as a session grant, applies to the whole session including the main conversation. A prompt originating in a background task is not necessarily a background-only grant. Inspect actual scope and do not assume a custom tools field supplies every background tool.
Completion notification provides the result evidence
Background results arrive as a completion notification in a later turn; Claude waits for it before reporting results and reports still running if asked earlier. A background command can outlive the subagent turn and later notify that subagent, so turn completion does not establish completion of every command. Inspect the task or command producing the required artifact rather than treating a disappearing panel row as proof of success.
Preserve failure and incomplete states
The fixture maps running, completed_with_report and failed to wait, inspect report and preserve failure. It does not reproduce notifications. The docs say background API failure reports the error and last output; partial output is not completion. Inspect notification, artifact identity and outstanding commands before dependent work. Stop dependency steps on missing notification, failure or unclear grant scope without guessing results or widening permissions.
Sources
All links are official pages; verification dates are listed per source, and links point to the version checked.