SpyBara
Go Premium

Documentation 2026-05-22 06:33 UTC to 2026-05-23 06:18 UTC

8 files changed +29 −21. View all changes and history on the product overview
2026
Sun 31 06:39 Sat 30 06:23 Fri 29 06:38 Thu 28 06:37 Wed 27 06:42 Tue 26 06:33 Sun 24 06:25 Sat 23 06:18 Fri 22 06:33 Thu 21 06:36 Wed 20 06:35 Tue 19 06:34 Mon 18 23:59 Sun 17 01:01 Fri 15 22:58 Thu 14 17:02 Wed 13 23:01 Tue 12 22:57 Mon 11 23:00 Sun 10 23:03 Sat 9 04:57 Fri 8 22:00 Thu 7 22:59 Tue 5 23:00 Mon 4 22:58 Sat 2 18:14 Fri 1 18:19
Details

152 152 

153MCP tools follow the naming pattern `mcp__<server-name>__<tool-name>`. For example, a GitHub server named `"github"` with a `list_issues` tool becomes `mcp__github__list_issues`.153MCP tools follow the naming pattern `mcp__<server-name>__<tool-name>`. For example, a GitHub server named `"github"` with a `list_issues` tool becomes `mcp__github__list_issues`.

154 154 

155### Grant access with allowedTools155### Auto-approve with allowedTools

156 156 

157Use `allowedTools` to specify which MCP tools Claude can use:157Use `allowedTools` to auto-approve specific MCP tools so Claude can use them without a permission prompt:

158 158 

159```typescript hidelines={1,-1} theme={null}159```typescript hidelines={1,-1} theme={null}

160const _ = {160const _ = {


750 mcpServers: {750 mcpServers: {

751 // your servers751 // your servers

752 },752 },

753 allowedTools: ["mcp__servername__*"] // Required for Claude to use the tools753 allowedTools: ["mcp__servername__*"] // Auto-approve calls from this server

754 }754 }

755};755};

756```756```

Details

258 <Tab title="Subagents">258 <Tab title="Subagents">

259 Spawn specialized agents to handle focused subtasks. Your main agent delegates work, and subagents report back with results.259 Spawn specialized agents to handle focused subtasks. Your main agent delegates work, and subagents report back with results.

260 260 

261 Define custom agents with specialized instructions. Include `Agent` in `allowedTools` since subagents are invoked via the Agent tool:261 Define custom agents with specialized instructions. Subagents are invoked via the Agent tool, so include `Agent` in `allowedTools` to auto-approve those invocations:

262 262 

263 <CodeGroup>263 <CodeGroup>

264 ```python Python theme={null}264 ```python Python theme={null}

Details

99 99 

100 // Check available commands from plugins100 // Check available commands from plugins

101 console.log("Commands:", message.slash_commands);101 console.log("Commands:", message.slash_commands);

102 // Example: ["/help", "/compact", "my-plugin:custom-command"]102 // Example: ["compact", "context", "my-plugin:custom-command"]

103 }103 }

104 }104 }

105 ```105 ```


123 123 

124 # Check available commands from plugins124 # Check available commands from plugins

125 print("Commands:", message.data.get("slash_commands"))125 print("Commands:", message.data.get("slash_commands"))

126 # Example: ["/help", "/compact", "my-plugin:custom-command"]126 # Example: ["compact", "context", "my-plugin:custom-command"]

127 127 

128 128 

129 asyncio.run(main())129 asyncio.run(main())

Details

123 async for message in query(123 async for message in query(

124 prompt="Review utils.py for bugs that would cause crashes. Fix any issues you find.",124 prompt="Review utils.py for bugs that would cause crashes. Fix any issues you find.",

125 options=ClaudeAgentOptions(125 options=ClaudeAgentOptions(

126 allowed_tools=["Read", "Edit", "Glob"], # Tools Claude can use126 allowed_tools=["Read", "Edit", "Glob"], # Auto-approve these tools

127 permission_mode="acceptEdits", # Auto-approve file edits127 permission_mode="acceptEdits", # Auto-approve file edits

128 ),128 ),

129 ):129 ):


148 for await (const message of query({148 for await (const message of query({

149 prompt: "Review utils.py for bugs that would cause crashes. Fix any issues you find.",149 prompt: "Review utils.py for bugs that would cause crashes. Fix any issues you find.",

150 options: {150 options: {

151 allowedTools: ["Read", "Edit", "Glob"], // Tools Claude can use151 allowedTools: ["Read", "Edit", "Glob"], // Auto-approve these tools

152 permissionMode: "acceptEdits" // Auto-approve file edits152 permissionMode: "acceptEdits" // Auto-approve file edits

153 }153 }

154 })) {154 })) {

Details

22 })) {22 })) {

23 if (message.type === "system" && message.subtype === "init") {23 if (message.type === "system" && message.subtype === "init") {

24 console.log("Available slash commands:", message.slash_commands);24 console.log("Available slash commands:", message.slash_commands);

25 // Example output: ["/compact", "/context", "/usage"]25 // Example output: ["clear", "compact", "context", "usage"]

26 }26 }

27 }27 }

28 ```28 ```


36 async for message in query(prompt="Hello Claude", options=ClaudeAgentOptions(max_turns=1)):36 async for message in query(prompt="Hello Claude", options=ClaudeAgentOptions(max_turns=1)):

37 if isinstance(message, SystemMessage) and message.subtype == "init":37 if isinstance(message, SystemMessage) and message.subtype == "init":

38 print("Available slash commands:", message.data["slash_commands"])38 print("Available slash commands:", message.data["slash_commands"])

39 # Example output: ["/compact", "/context", "/usage"]39 # Example output: ["clear", "compact", "context", "usage"]

40 40 

41 41 

42 asyncio.run(main())42 asyncio.run(main())


80 80 

81## Common Slash Commands81## Common Slash Commands

82 82 

83### `/compact` - Compact Conversation History83### `/compact` - Compact conversation history

84 84 

85The `/compact` command reduces the size of your conversation history by summarizing older messages while preserving important context:85The `/compact` command reduces the size of your conversation history by summarizing older messages while preserving important context:

86 86 


117 ```117 ```

118</CodeGroup>118</CodeGroup>

119 119 

120### Clearing the conversation120### `/clear` - Reset conversation context

121 121 

122The interactive `/clear` command is not available in the SDK. Each `query()` call already starts a fresh conversation, so to clear context, end the current `query()` and start a new one. The previous conversation stays on disk and can be returned to by passing its session ID to the [`resume` option](/en/agent-sdk/sessions#resume-by-id).122The `/clear` command resets the conversation to an empty context, so subsequent prompts start with no prior conversation history. The previous conversation remains on disk and can be returned to by passing its session ID to the [`resume` option](/en/agent-sdk/sessions#resume-by-id).

123 

124This is useful in [streaming input mode](/en/agent-sdk/streaming-vs-single-mode), where you send multiple prompts over a single connection. For one-shot `query()` calls, each call already starts with empty context, so sending `/clear` has no practical effect; start a new `query()` instead.

125 

126<Note>

127 `/clear` in the SDK requires Claude Code v2.1.117 or later. In earlier versions it is omitted from `slash_commands`.

128</Note>

123 129 

124## Creating Custom Slash Commands130## Creating Custom Slash Commands

125 131 


199 if (message.type === "system" && message.subtype === "init") {205 if (message.type === "system" && message.subtype === "init") {

200 // Will include both built-in and custom commands206 // Will include both built-in and custom commands

201 console.log("Available commands:", message.slash_commands);207 console.log("Available commands:", message.slash_commands);

202 // Example: ["/compact", "/context", "/usage", "/refactor", "/security-check"]208 // Example: ["clear", "compact", "context", "usage", "refactor", "security-check"]

203 }209 }

204 }210 }

205 ```211 ```


224 if isinstance(message, SystemMessage) and message.subtype == "init":230 if isinstance(message, SystemMessage) and message.subtype == "init":

225 # Will include both built-in and custom commands231 # Will include both built-in and custom commands

226 print("Available commands:", message.data["slash_commands"])232 print("Available commands:", message.data["slash_commands"])

227 # Example: ["/compact", "/context", "/usage", "/refactor", "/security-check"]233 # Example: ["clear", "compact", "context", "usage", "refactor", "security-check"]

228 234 

229 235 

230 asyncio.run(main())236 asyncio.run(main())

Details

53 53 

54### Programmatic definition (recommended)54### Programmatic definition (recommended)

55 55 

56Define subagents directly in your code using the `agents` parameter. This example creates two subagents: a code reviewer with read-only access and a test runner that can execute commands. The `Agent` tool must be included in `allowedTools` since Claude invokes subagents through the Agent tool.56Define subagents directly in your code using the `agents` parameter. This example creates two subagents: a code reviewer with read-only access and a test runner that can execute commands. Claude invokes subagents through the `Agent` tool, so include `Agent` in `allowedTools` to auto-approve subagent invocations without a permission prompt.

57 57 

58<CodeGroup>58<CodeGroup>

59 ```python Python theme={null}59 ```python Python theme={null}


65 async for message in query(65 async for message in query(

66 prompt="Review the authentication module for security issues",66 prompt="Review the authentication module for security issues",

67 options=ClaudeAgentOptions(67 options=ClaudeAgentOptions(

68 # Agent tool is required for subagent invocation68 # Auto-approve these tools, including Agent for subagent invocation

69 allowed_tools=["Read", "Grep", "Glob", "Agent"],69 allowed_tools=["Read", "Grep", "Glob", "Agent"],

70 agents={70 agents={

71 "code-reviewer": AgentDefinition(71 "code-reviewer": AgentDefinition(


114 for await (const message of query({114 for await (const message of query({

115 prompt: "Review the authentication module for security issues",115 prompt: "Review the authentication module for security issues",

116 options: {116 options: {

117 // Agent tool is required for subagent invocation117 // Auto-approve these tools, including Agent for subagent invocation

118 allowedTools: ["Read", "Grep", "Glob", "Agent"],118 allowedTools: ["Read", "Grep", "Glob", "Agent"],

119 agents: {119 agents: {

120 "code-reviewer": {120 "code-reviewer": {


185You can also define subagents as markdown files in `.claude/agents/` directories. See the [Claude Code subagents documentation](/en/sub-agents) for details on this approach. Programmatically defined agents take precedence over filesystem-based agents with the same name.185You can also define subagents as markdown files in `.claude/agents/` directories. See the [Claude Code subagents documentation](/en/sub-agents) for details on this approach. Programmatically defined agents take precedence over filesystem-based agents with the same name.

186 186 

187<Note>187<Note>

188 Even without defining custom subagents, Claude can spawn the built-in `general-purpose` subagent when `Agent` is in your `allowedTools`. This is useful for delegating research or exploration tasks without creating specialized agents.188 Even without defining custom subagents, Claude can spawn the built-in `general-purpose` subagent. This is useful for delegating research or exploration tasks without creating specialized agents. Include `Agent` in `allowedTools` so these invocations auto-approve without a permission prompt.

189</Note>189</Note>

190 190 

191## What subagents inherit191## What subagents inherit


583 583 

584If Claude completes tasks directly instead of delegating to your subagent:584If Claude completes tasks directly instead of delegating to your subagent:

585 585 

5861. **Include the Agent tool**: subagents are invoked via the Agent tool, so it must be in `allowedTools`5861. **Check Agent invocations are approved**: include `Agent` in `allowedTools` to auto-approve subagent calls. Without it, Agent invocations fall through to your `canUseTool` callback or, in `dontAsk` mode, are denied

5872. **Use explicit prompting**: mention the subagent by name in your prompt (for example, "Use the code-reviewer agent to...")5872. **Use explicit prompting**: mention the subagent by name in your prompt (for example, "Use the code-reviewer agent to...")

5883. **Write a clear description**: explain exactly when the subagent should be used so Claude can match tasks appropriately5883. **Write a clear description**: explain exactly when the subagent should be used so Claude can match tasks appropriately

589 589 

Details

277| `memory` | No | [Persistent memory scope](#enable-persistent-memory): `user`, `project`, or `local`. Enables cross-session learning |277| `memory` | No | [Persistent memory scope](#enable-persistent-memory): `user`, `project`, or `local`. Enables cross-session learning |

278| `background` | No | Set to `true` to always run this subagent as a [background task](#run-subagents-in-foreground-or-background). Default: `false` |278| `background` | No | Set to `true` to always run this subagent as a [background task](#run-subagents-in-foreground-or-background). Default: `false` |

279| `effort` | No | Effort level when this subagent is active. Overrides the session effort level. Default: inherits from session. Options: `low`, `medium`, `high`, `xhigh`, `max`; available levels depend on the model |279| `effort` | No | Effort level when this subagent is active. Overrides the session effort level. Default: inherits from session. Options: `low`, `medium`, `high`, `xhigh`, `max`; available levels depend on the model |

280| `isolation` | No | Set to `worktree` to run the subagent in a temporary [git worktree](/en/worktrees), giving it an isolated copy of the repository. The worktree is automatically cleaned up if the subagent makes no changes |280| `isolation` | No | Set to `worktree` to run the subagent in a temporary [git worktree](/en/worktrees), giving it an isolated copy of the repository branched by default from your [default branch](/en/worktrees#choose-the-base-branch) rather than the parent session's `HEAD`. The worktree is automatically cleaned up if the subagent makes no changes |

281| `color` | No | Display color for the subagent in the task list and transcript. Accepts `red`, `blue`, `green`, `yellow`, `purple`, `orange`, `pink`, or `cyan` |281| `color` | No | Display color for the subagent in the task list and transcript. Accepts `red`, `blue`, `green`, `yellow`, `purple`, `orange`, `pink`, or `cyan` |

282| `initialPrompt` | No | Auto-submitted as the first user turn when this agent runs as the main session agent (via `--agent` or the `agent` setting). [Commands](/en/commands) and [skills](/en/skills) are processed. Prepended to any user-provided prompt |282| `initialPrompt` | No | Auto-submitted as the first user turn when this agent runs as the main session agent (via `--agent` or the `agent` setting). [Commands](/en/commands) and [skills](/en/skills) are processed. Prepended to any user-provided prompt |

283 283 

en/worktrees.md +2 −0

Details

80 80 

81Subagents can run in their own worktrees so parallel edits don't conflict. Ask Claude to "use worktrees for your agents", or set it permanently on a [custom subagent](/en/sub-agents#supported-frontmatter-fields) by adding `isolation: worktree` to the frontmatter. Each subagent gets a temporary worktree that is removed automatically when the subagent finishes without changes.81Subagents can run in their own worktrees so parallel edits don't conflict. Ask Claude to "use worktrees for your agents", or set it permanently on a [custom subagent](/en/sub-agents#supported-frontmatter-fields) by adding `isolation: worktree` to the frontmatter. Each subagent gets a temporary worktree that is removed automatically when the subagent finishes without changes.

82 82 

83Subagent worktrees use the same [base branch](#choose-the-base-branch) as `--worktree`, so they branch from your repository's default branch unless `worktree.baseRef` is set to `"head"`.

84 

83## Clean up worktrees85## Clean up worktrees

84 86 

85When you exit a worktree session, cleanup depends on whether you made changes:87When you exit a worktree session, cleanup depends on whether you made changes: