8 ファイル変更 +27 -21

この更新の概要

allowedToolsの設定に関する説明が更新され、特定のツールやサブエージェントの使用をプロンプトなしで自動承認するための設定であることが明示されました。スラッシュコマンドの定義において、コマンド名の先頭の「/」が削除され、新たにclearコマンドが追加されました。サブエージェントをワークツリーで実行する際、デフォルトで親セッションのHEADではなくリポジトリのデフォルトブランチから分岐する仕様が補足されています。

agent-sdk/mcp +3 -3

allowedToolsの役割が、MCPツールをプロンプトなしで利用するための「自動承認」設定であることを明記するように修正されました。

@@ -143,9 +143,9 @@ MCP tools require explicit permission before Claude can use them. Without permis
MCP 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`.
### Grant access with allowedTools
### Auto-approve with allowedTools
Use `allowedTools` to specify which MCP tools Claude can use:
Use `allowedTools` to auto-approve specific MCP tools so Claude can use them without a permission prompt:
```typescript hidelines={1,-1} theme={null}
const _ = {
@@ -693,7 +693,7 @@ const _ = {
mcpServers: {
// your servers
},
allowedTools: ["mcp__servername__*"] // Required for Claude to use the tools
allowedTools: ["mcp__servername__*"] // Auto-approve calls from this server
}
};
```
agent-sdk/overview +1 -1

サブエージェントの呼び出しを自動承認するために、allowedToolsにAgentツールを含める必要がある旨が追記されました。

@@ -210,7 +210,7 @@ for await (const message of query({
Spawn specialized agents to handle focused subtasks. Your main agent delegates work, and subagents report back with results.
Define custom agents with specialized instructions. Include `Agent` in `allowedTools` since subagents are invoked via the Agent tool:
Define custom agents with specialized instructions. Subagents are invoked via the Agent tool, so include `Agent` in `allowedTools` to auto-approve those invocations:
```python Python theme={null}
import asyncio
agent-sdk/plugins +2 -2

プラグインのカスタムコマンド例から「/」が削除され、最新のコマンド形式に合わせた記述に変更されました。

@@ -91,7 +91,7 @@ for await (const message of query({
// Check available commands from plugins
console.log("Commands:", message.slash_commands);
// Example: ["/help", "/compact", "my-plugin:custom-command"]
// Example: ["compact", "context", "my-plugin:custom-command"]
}
}
```
@@ -114,7 +114,7 @@ async def main():
# Check available commands from plugins
print("Commands:", message.data.get("slash_commands"))
# Example: ["/help", "/compact", "my-plugin:custom-command"]
# Example: ["compact", "context", "my-plugin:custom-command"]
asyncio.run(main())
```
agent-sdk/quickstart +2 -2

コード例内のコメントにおいて、allowed_toolsがツールの自動承認を意味するものであることが明確化されました。

@@ -101,7 +101,7 @@ async def main():
async for message in query(
prompt="Review utils.py for bugs that would cause crashes. Fix any issues you find.",
options=ClaudeAgentOptions(
allowed_tools=["Read", "Edit", "Glob"], # Tools Claude can use
allowed_tools=["Read", "Edit", "Glob"], # Auto-approve these tools
permission_mode="acceptEdits", # Auto-approve file edits
),
):
@@ -125,7 +125,7 @@ import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Review utils.py for bugs that would cause crashes. Fix any issues you find.",
options: {
allowedTools: ["Read", "Edit", "Glob"], // Tools Claude can use
allowedTools: ["Read", "Edit", "Glob"], // Auto-approve these tools
permissionMode: "acceptEdits" // Auto-approve file edits
}
})) {
agent-sdk/slash-commands +11 -7

コンテキストをリセットするclearコマンドの説明が追加され、各コマンド名から先頭の「/」記号が削除されました。

@@ -22,7 +22,7 @@ for await (const message of query({
})) {
if (message.type === "system" && message.subtype === "init") {
console.log("Available slash commands:", message.slash_commands);
// Example output: ["/compact", "/context", "/usage"]
// Example output: ["clear", "compact", "context", "usage"]
}
}
```
@@ -35,7 +35,7 @@ async def main():
async for message in query(prompt="Hello Claude", options=ClaudeAgentOptions(max_turns=1)):
if isinstance(message, SystemMessage) and message.subtype == "init":
print("Available slash commands:", message.data["slash_commands"])
# Example output: ["/compact", "/context", "/usage"]
# Example output: ["clear", "compact", "context", "usage"]
asyncio.run(main())
```
@@ -73,7 +73,7 @@ asyncio.run(main())
## Common Slash Commands
### `/compact` - Compact Conversation History
### `/compact` - Compact conversation history
The `/compact` command reduces the size of your conversation history by summarizing older messages while preserving important context:
@@ -106,9 +106,13 @@ async def main():
asyncio.run(main())
```
### Clearing the conversation
### `/clear` - Reset conversation context
The 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).
The `/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).
This 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.
`/clear` in the SDK requires Claude Code v2.1.117 or later. In earlier versions it is omitted from `slash_commands`.
## Creating Custom Slash Commands
@@ -185,7 +189,7 @@ for await (const message of query({
if (message.type === "system" && message.subtype === "init") {
// Will include both built-in and custom commands
console.log("Available commands:", message.slash_commands);
// Example: ["/compact", "/context", "/usage", "/refactor", "/security-check"]
// Example: ["clear", "compact", "context", "usage", "refactor", "security-check"]
}
}
```
@@ -209,7 +213,7 @@ async def main():
if isinstance(message, SystemMessage) and message.subtype == "init":
# Will include both built-in and custom commands
print("Available commands:", message.data["slash_commands"])
# Example: ["/compact", "/context", "/usage", "/refactor", "/security-check"]
# Example: ["clear", "compact", "context", "usage", "refactor", "security-check"]
asyncio.run(main())
```
agent-sdk/subagents +5 -5

サブエージェント実行時の自動承認フローと、allowedToolsにAgentを登録しなかった場合の挙動に関する詳細が追加されました。

@@ -54,7 +54,7 @@ Subagents can be limited to specific tools, reducing the risk of unintended acti
### Programmatic definition (recommended)
Define 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.
Define 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.
```python Python theme={null}
import asyncio
@@ -64,7 +64,7 @@ async def main():
async for message in query(
prompt="Review the authentication module for security issues",
options=ClaudeAgentOptions(
# Agent tool is required for subagent invocation
# Auto-approve these tools, including Agent for subagent invocation
allowed_tools=["Read", "Grep", "Glob", "Agent"],
agents={
"code-reviewer": AgentDefinition(
@@ -112,7 +112,7 @@ import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Review the authentication module for security issues",
options: {
// Agent tool is required for subagent invocation
// Auto-approve these tools, including Agent for subagent invocation
allowedTools: ["Read", "Grep", "Glob", "Agent"],
agents: {
"code-reviewer": {
@@ -179,7 +179,7 @@ Subagents cannot spawn their own subagents. Don't include `Agent` in a subagent'
You 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.
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.
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.
## What subagents inherit
@@ -550,7 +550,7 @@ identify patterns, and suggest improvements without making changes.`,
If Claude completes tasks directly instead of delegating to your subagent:
1. **Include the Agent tool**: subagents are invoked via the Agent tool, so it must be in `allowedTools`
1. **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
2. **Use explicit prompting**: mention the subagent by name in your prompt (for example, "Use the code-reviewer agent to...")
3. **Write a clear description**: explain exactly when the subagent should be used so Claude can match tasks appropriately
sub-agents +1 -1

隔離環境(isolation: worktree)で実行されるサブエージェントが、デフォルトでリポジトリのデフォルトブランチから分岐する仕様が追記されました。

@@ -238,7 +238,7 @@ The following fields can be used in the YAML frontmatter. Only `name` and `descr
| `memory` | No | [Persistent memory scope](#enable-persistent-memory): `user`, `project`, or `local`. Enables cross-session learning |
| `background` | No | Set to `true` to always run this subagent as a [background task](#run-subagents-in-foreground-or-background). Default: `false` |
| `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 |
| `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 |
| `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 |
| `color` | No | Display color for the subagent in the task list and transcript. Accepts `red`, `blue`, `green`, `yellow`, `purple`, `orange`, `pink`, or `cyan` |
| `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 |
worktrees +2 -0

サブエージェントのワークツリー作成時のベースブランチが、コマンドライン引数の--worktreeと同じルールに従うことが説明されました。

@@ -79,6 +79,8 @@ This applies to worktrees created with `--worktree`, [subagent worktrees](#isola
Subagents 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.
Subagent 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"`.
## Clean up worktrees
When you exit a worktree session, cleanup depends on whether you made changes: