modified How the agent loop works View current →
--- a/agent-loop.md +++ b/agent-loop.md @@ -206,7 +206,7 @@ `"acceptEdits"`| Auto-approves file edits and common filesystem commands (`mkdir`, `touch`, `mv`, `cp`, etc.); other Bash commands follow default rules `"plan"`| Claude explores and plans without editing your source files; file edits are never auto-approved and prompt through your `canUseTool` callback `"dontAsk"`| Never prompts. Tools pre-approved by [permission rules](</docs/en/settings#permission-settings>) run, everything else is denied -`"auto"` (TypeScript only)| Uses a model classifier to approve or deny each tool call. See [Auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) for availability and behavior +`"auto"`| Uses a model classifier to approve or deny each tool call. See [Auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) for availability and behavior `"bypassPermissions"`| Runs all allowed tools without asking, unless an explicit [`ask` rule](</docs/en/settings#permission-settings>) matches; see [How permissions are evaluated](</docs/en/agent-sdk/permissions#how-permissions-are-evaluated>) for where ask rules sit in the precedence order. Cannot be used when running as root on Unix. Use only in isolated environments where the agent’s actions cannot affect systems you care about For interactive applications, use `"default"` with a tool approval callback to surface approval prompts. For autonomous agents on a dev machine, `"acceptEdits"` auto-approves file edits and common filesystem commands (`mkdir`, `touch`, `mv`, `cp`, etc.) while still gating other `Bash` commands behind allow rules. Reserve `"bypassPermissions"` for CI, containers, or other isolated environments. See [Permissions](</docs/en/agent-sdk/permissions>) for full details.
modified Claude Code changelog View current →
--- a/changelog.md +++ b/changelog.md @@ -1,4 +1,56 @@ This page is generated from the [CHANGELOG.md on GitHub](<https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md>). Run `claude --version` to check your installed version. + +​ + +2.1.204 + +July 8, 2026 + + * Fixed hook events not streaming during SessionStart hooks in headless sessions, which could cause remote workers to be idle-reaped mid-hook + +​ + +2.1.203 + +July 7, 2026 + + * Added a warning when your login is about to expire, so you can re-authenticate before background sessions are interrupted + * Added a grey ⏸ badge to the footer when in manual permission mode, making the active mode always visible + * Added the session’s additional working directories to MCP `roots/list`, with `notifications/roots/list_changed` sent when the set changes + * Fixed opening or switching background agent sessions on macOS stalling for 15–20 seconds due to a false low-memory detection (regression in 2.1.196) + * Fixed background sessions becoming permanently unresponsive to attach, replies, and stop when the daemon’s session token went stale — the session now recovers automatically + * Fixed returning to `claude agents` silently stopping running subagents and re-running the prompt from scratch — their work now carries over + * Fixed a memory and per-turn CPU regression in interactive sessions: the context-usage indicator no longer re-analyzes the entire transcript after every turn + * Fixed background agents inheriting a stale `PATH` from the daemon instead of the dispatching shell, causing missing tools on Windows + * Fixed background and agent-view sessions dropping a shell-exported `ANTHROPIC_BASE_URL`, which sent API keys to the default endpoint and failed with 401 + * Fixed Bash failing with “argument list too long” in repos with many git worktrees + * Fixed worktree-isolated subagents sometimes running shell commands in the parent checkout instead of their own worktree + * Fixed worktree creation rejecting nested repositories in multi-repo workspaces, leaving background sessions unable to isolate and edit + * Fixed background agents crash-looping when their working directory was deleted, replaced by a file, or became an invalid path — they now fail once with a clear error + * Fixed a background daemon auto-upgrade failure silently killing all running background sessions + * Fixed `TaskStop` and `TaskOutput` failing to find background agents spawned by another agent — errors now list running agents by id and description + * Fixed the `claude agents` composer discarding your typed message when a slash command isn’t available there + * Fixed the agent list crashing when opening a stopped session whose conversation was already open in another session + * Fixed background sessions showing “Needs input” in the agent list after the question was already answered + * Fixed background agent startup failures showing only “exit_with_message” instead of the actual error + * Fixed background sessions ignoring `effortLevel` changes in settings.json when forked through the daemon + * Fixed attached background sessions ignoring `CLAUDE_CODE_DISABLE_MOUSE` and `CLAUDE_CODE_DISABLE_MOUSE_CLICKS` opt-outs + * Fixed `/exit` incorrectly warning about running background agents after all named agents had completed + * Fixed background sessions started from a non-git directory unable to edit files when a `WorktreeCreate` hook was configured + * Fixed the `@` directory picker in `claude agents` not showing registered git worktrees + * Fixed background task output on Windows being permanently replaced by an empty file after `/clear` + * Fixed content jumping when scrolling up through long transcript history + * Fixed the terminal flickering and jumping while typing in bash mode when a shell-history suggestion was shown + * Fixed literal `^[[I` / `^[[O` escape codes being printed when reattaching to a background session + * Fixed LSP-only plugins being incorrectly flagged for disuse when their language servers deliver diagnostics or answer navigation requests + * Improved responsiveness while long responses stream: live-preview updates no longer re-render the whole screen + * Improved subagent behavior: agents are now less likely to re-delegate their entire task to another subagent + * Reduced binary size by ~7 MB and startup memory by ~7 MB by loading a large bundled dependency lazily instead of inlining it + * Changed left arrow to no longer close the background tasks, diff, and workflow detail views — press Esc instead + * Changed the empty `claude agents` view to always show the organized sections (Needs input / Working / Completed) with descriptions + * Removed the startup “claude command missing or broken” warnings — they now appear in `/doctor` and `/status` instead + * Removed a redundant navigation hint from the `claude agents` footer + * [VSCode] Added a Settings toggle for “Enable Remote Control for all sessions” ​
modified Give Claude custom tools View current →
--- a/custom-tools.md +++ b/custom-tools.md @@ -13,7 +13,7 @@ Pre-approve a tool| Add to your allowed tools. See Configure allowed tools. Remove a built-in tool from Claude’s context| Pass a `tools` array listing only the built-ins you want. See Configure allowed tools. Let Claude call tools in parallel| Set `readOnlyHint: true` on tools with no side effects. See Add tool annotations. -Handle errors without stopping the loop| Return `isError: true` instead of throwing. See Handle errors. +Control the error message Claude reads| Return `isError: true` to compose the message instead of surfacing the raw exception. See Handle errors. Return images or files| Use `image` or `resource` blocks in the content array. See Return images and resources. Return a machine-readable JSON result| Set `structuredContent` on the result. See Return structured data. Scale to many tools| Use [tool search](</docs/en/agent-sdk/tool-search>) to load tools on demand. @@ -254,14 +254,14 @@ Handle errors -How your handler reports errors determines whether the agent loop continues or stops: +A handler error doesn’t stop the agent loop. The SDK’s in-process MCP server catches uncaught exceptions and returns them as error results, so how you report an error determines what Claude reads, not whether the query fails: What happens| Result ---|--- -Handler throws an uncaught exception| Agent loop stops. Claude never sees the error, and the `query` call fails. -Handler catches the error and returns `isError: true` (TS) / `"is_error": True` (Python)| Agent loop continues. Claude sees the error as data and can retry, try a different tool, or explain the failure. - -The example below catches two kinds of failures inside the handler instead of letting them throw. A non-200 HTTP status is caught from the response and returned as an error result. A network error or invalid JSON is caught by the surrounding `try/except` (Python) or `try/catch` (TypeScript) and also returned as an error result. In both cases the handler returns normally and the agent loop continues. +Handler throws an uncaught exception| The MCP server converts it to an error result carrying the raw exception message. Claude sees that message, and the agent loop continues. +Handler catches the error and returns `isError: true` (TS) / `"is_error": True` (Python)| Claude sees the message you compose. You can add context the raw exception lacks, such as which request failed or what to try instead. + +In both cases Claude can retry, try a different tool, or explain the failure. Catch errors yourself when the raw exception message isn’t enough for Claude to act on. The example below catches two kinds of failures inside the handler and composes the error message Claude reads. A non-200 HTTP status is caught from the response and returned as an error result. A network error or invalid JSON is caught by the surrounding `try/except` (Python) or `try/catch` (TypeScript) and also returned as an error result. In both cases Claude receives a message that describes the failure instead of a bare exception string. Python @@ -296,8 +296,8 @@ data = response.json() return {"content": [{"type": "text", "text": json.dumps(data, indent=2)}]} except Exception as e: - # Catching here keeps the agent loop alive. An uncaught exception - # would end the whole query() call. + # Composes the message Claude reads. An uncaught exception would + # reach Claude as the raw str(e) with no context. return { "content": [{"type": "text", "text": f"Failed to fetch data: {str(e)}"}], "is_error": True, @@ -309,7 +309,7 @@ Return images and resources -The `content` array in a tool result accepts `text`, `image`, `audio`, `resource`, and `resource_link` blocks. You can mix them in the same response. Audio blocks are saved to disk and Claude receives a text block with the saved file path. Resource link blocks are converted to a text block containing the link’s name, URI, and description. +The `content` array in a tool result accepts `text`, `image`, `audio`, `resource`, and `resource_link` blocks. You can mix them in the same response. In TypeScript, audio blocks are saved to disk and Claude receives a text block with the saved file path; in Python, the SDK drops audio blocks from the tool result and logs a warning. Resource link blocks are converted to a text block containing the link’s name, URI, and description. ### @@ -365,7 +365,7 @@ `type`| `"resource"`| `resource.uri`| `string`| Identifier for the content. Any URI scheme `resource.text`| `string`| The content, if it’s text. Provide this or `blob`, not both -`resource.blob`| `string`| The content base64-encoded, if it’s binary +`resource.blob`| `string`| The content base64-encoded, if it’s binary. TypeScript only: the Python SDK drops binary resources from the tool result and logs a warning `resource.mimeType`| `string`| Optional This example shows a resource block returned from inside a tool handler. The URI `file:///tmp/report.md` is a label that Claude can reference later; the SDK does not read from that path.
modified Hooks reference View current →
--- a/hooks.md +++ b/hooks.md @@ -248,7 +248,7 @@ * `mcp__brave-search__.*` matches all tools from a server whose name contains a hyphen * `mcp__.*__write.*` matches any tool whose name starts with `write` from any server -Hyphens in the exact-match set require Claude Code v2.1.195 or later. On earlier versions a bare hyphenated prefix like `mcp__brave-search` is evaluated as an unanchored regular expression and matches every tool from that server. The `mcp__brave-search__.*` form works on every version. This example logs all memory server operations and validates write operations from any MCP server: +Hyphens in the exact-match set require Claude Code v2.1.195 or later. On earlier versions a bare hyphenated prefix like `mcp__brave-search` is evaluated as an unanchored regular expression and matches every tool from that server. The `mcp__brave-search__.*` form works on every version. Tools from a [plugin-bundled MCP server](</docs/en/mcp#plugin-provided-mcp-servers>) use a scoped server segment that includes the plugin name: `mcp__plugin_<plugin-name>_<server-name>__<tool>`. A matcher written against the bare server key never fires for these tools. For a plugin named `my-plugin` that bundles a server under the key `db`, a `query` tool appears as `mcp__plugin_my-plugin_db__query`, so the matcher for every tool from that server is `mcp__plugin_my-plugin_db__.*`. Use the same scoped tool name in a handler’s `if` field. See [Plugin-provided MCP servers](</docs/en/mcp#plugin-provided-mcp-servers>) for how the scoped name is built. This example logs all memory server operations and validates write operations from any MCP server: { "hooks": { @@ -407,7 +407,7 @@ Field| Required| Description ---|---|--- -`server`| yes| Name of a configured MCP server. The server must already be connected; the hook never triggers an OAuth or connection flow +`server`| yes| Name of a configured MCP server. For a [plugin-bundled server](</docs/en/mcp#plugin-provided-mcp-servers>), this is the scoped name `plugin:<plugin-name>:<server-name>`, such as `plugin:my-plugin:db`, not the bare server key. The server must already be connected; the hook never triggers an OAuth or connection flow `tool`| yes| Name of the tool to call on that server `input`| no| Arguments passed to the tool. String values support `${path}` substitution from the hook’s JSON input, such as `"${tool_input.file_path}"` @@ -570,7 +570,7 @@ ---|--- `session_id`| Current session identifier `prompt_id`| UUID identifying the user prompt currently being processed. Matches the [`prompt.id` attribute on OpenTelemetry events](</docs/en/monitoring-usage#event-correlation-attributes>), so you can correlate hook output with telemetry for a single prompt. Absent until the first user input. Requires Claude Code v2.1.196 or later -`transcript_path`| Path to conversation JSON +`transcript_path`| Path to conversation JSON. The transcript file is written asynchronously and may lag the in-memory conversation, so it may not yet include the current turn’s most recent messages when a hook fires. Hooks that need the final assistant text of the current turn should use `last_assistant_message` on Stop and SubagentStop instead of reading the transcript `cwd`| Current working directory when the hook is invoked `permission_mode`| Current [permission mode](</docs/en/permissions#permission-modes>): `"default"`, `"plan"`, `"acceptEdits"`, `"auto"`, `"dontAsk"`, or `"bypassPermissions"`. The mode labeled **Manual** arrives as `"default"`, never as `"manual"`, so scripts that match `"default"` keep working. Not all events receive this field. Check the JSON example in each hook event section `effort`| Object with a `level` field holding the active [effort level](</docs/en/model-config#adjust-effort-level>) for the turn: `"low"`, `"medium"`, `"high"`, `"xhigh"`, or `"max"`. If the requested model effort exceeds what the current model supports, this is the downgraded level the model actually used. Ultracode is not a distinct level and reports as `"xhigh"`. The object matches the [status line](</docs/en/statusline#available-data>) `effort` field. Present for events that fire within a tool-use context, such as `PreToolUse`, `PostToolUse`, `Stop`, and `SubagentStop`, when the current model supports the effort parameter. The level is also available to hook commands and the Bash tool as the `$CLAUDE_EFFORT` environment variable. @@ -2114,7 +2114,7 @@ Stop input -In addition to the common input fields, Stop hooks receive `stop_hook_active`, `last_assistant_message`, `background_tasks`, and `session_crons`. The `stop_hook_active` field is `true` when Claude Code is already continuing as a result of a stop hook. Check this value or process the transcript to avoid blocking on a condition that will never resolve. Claude Code overrides the hook and ends the turn after 8 consecutive blocks. The `last_assistant_message` field contains the text content of Claude’s final response, so hooks can access it without parsing the transcript file. The `background_tasks` and `session_crons` arrays, available in Claude Code v2.1.145 or later, let hooks distinguish “session is done” from “session is paused waiting for background work to wake it back up”. Both arrays are present when the task registry is reachable and are empty when nothing is in flight or scheduled. Each entry in `background_tasks` describes one in-flight task and uses these fields: +In addition to the common input fields, Stop hooks receive `stop_hook_active`, `last_assistant_message`, `background_tasks`, and `session_crons`. The `stop_hook_active` field is `true` when Claude Code is already continuing as a result of a stop hook. Check this value or process the transcript to avoid blocking on a condition that will never resolve. Claude Code overrides the hook and ends the turn after 8 consecutive blocks. The `last_assistant_message` field contains the text content of Claude’s final response, so hooks can access it without parsing the transcript file. For hooks that act on the just-completed turn, such as read-aloud or notification hooks, use this field rather than reading `transcript_path`: the transcript file isn’t guaranteed to include the final message at Stop time on all versions. The `background_tasks` and `session_crons` arrays, available in Claude Code v2.1.145 or later, let hooks distinguish “session is done” from “session is paused waiting for background work to wake it back up”. Both arrays are present when the task registry is reachable and are empty when nothing is in flight or scheduled. Each entry in `background_tasks` describes one in-flight task and uses these fields: Field| Description ---|---
modified Automate actions with hooks View current →
--- a/hooks-guide.md +++ b/hooks-guide.md @@ -629,7 +629,7 @@ } } -MCP tools use a different naming convention than built-in tools: `mcp__<server>__<tool>`, where `<server>` is the MCP server name and `<tool>` is the tool it provides. For example, `mcp__github__search_repositories` or `mcp__filesystem__read_file`. Use a regex matcher to target all tools from a specific server, or match across servers with a pattern like `mcp__.*__write.*`. See [Match MCP tools](</docs/en/hooks#match-mcp-tools>) in the reference for the full list of examples.The command below extracts the tool name from the hook’s JSON input with `jq` and writes it to stderr. Writing to stderr keeps stdout clean for JSON output and sends the message to the [debug log](</docs/en/hooks#debug-hooks>): +MCP tools use a different naming convention than built-in tools: `mcp__<server>__<tool>`, where `<server>` is the MCP server name and `<tool>` is the tool it provides. For example, `mcp__github__search_repositories` or `mcp__filesystem__read_file`. Tools from a [plugin-bundled server](</docs/en/mcp#plugin-provided-mcp-servers>) use a scoped server segment instead, such as `mcp__plugin_my-plugin_db__query`. Use a regex matcher to target all tools from a specific server, or match across servers with a pattern like `mcp__.*__write.*`. See [Match MCP tools](</docs/en/hooks#match-mcp-tools>) in the reference for the full list of examples.The command below extracts the tool name from the hook’s JSON input with `jq` and writes it to stderr. Writing to stderr keeps stdout clean for JSON output and sends the message to the [debug log](</docs/en/hooks#debug-hooks>): { "hooks": {
modified Connect Claude Code to tools via MCP View current →
--- a/mcp.md +++ b/mcp.md @@ -181,11 +181,12 @@ Tips: - * Use the `--scope` flag to specify where the configuration is stored: + * Use the `-s` or `--scope` flag to specify where the configuration is stored: * `local` (default): available only to you in the current project. Older versions called this scope `project` * `project`: shared with everyone in the project via the `.mcp.json` file * `user`: available to you across all projects. Older versions called this scope `global` - * Set environment variables with `--env` flags (for example, `--env KEY=value`) + * Set environment variables with `-e` or `--env` flags (for example, `-e KEY=value`) + * The `--transport` and `--header` flags also accept `-t` and `-H` short forms * Configure MCP server startup timeout using the `MCP_TIMEOUT` environment variable (for example, `MCP_TIMEOUT=10000 claude` sets a 10-second timeout) * Set a per-server tool execution timeout by adding a `timeout` field in milliseconds to that server’s `.mcp.json` entry, for example `"timeout": 600000` for ten minutes. This overrides the `MCP_TOOL_TIMEOUT` environment variable for that server only * Claude Code displays a warning when MCP tool output exceeds 10,000 tokens. To increase this limit, set the `MAX_MCP_OUTPUT_TOKENS` environment variable (for example, `MAX_MCP_OUTPUT_TOKENS=50000`) @@ -248,7 +249,7 @@ mcp__plugin_my-plugin_database-tools__query -Use this full name when referencing the tool in [permission rules](</docs/en/permissions>), a skill’s `allowed-tools` list, or a [subagent’s `tools` field](</docs/en/sub-agents#available-tools>). **Benefits of plugin MCP servers** : +Use this full name when referencing the tool in [permission rules](</docs/en/permissions>), a skill’s `allowed-tools` list, a [subagent’s `tools` field](</docs/en/sub-agents#available-tools>), or a [hook matcher](</docs/en/hooks#match-mcp-tools>). A hook matcher written against the bare server key, such as `mcp__database-tools__.*`, never fires for a plugin-bundled server. The server itself registers under the scoped name `plugin:<plugin-name>:<server-name>`, such as `plugin:my-plugin:database-tools`. Use that name where a configured server name is expected, such as an [`mcp_tool` hook’s `server` field](</docs/en/hooks#mcp-tool-hook-fields>). **Benefits of plugin MCP servers** : * **Bundled distribution** : tools and servers packaged together * **Automatic setup** : no manual MCP configuration needed
modified Plugins reference View current →
--- a/plugins-reference.md +++ b/plugins-reference.md @@ -126,6 +126,8 @@ * `mcp_tool`: call a tool on a configured [MCP server](</docs/en/mcp>) * `prompt`: evaluate a prompt with an LLM (uses `$ARGUMENTS` placeholder for context) * `agent`: run an agentic verifier with tools for complex verification tasks + +Hooks that target the plugin’s own bundled MCP server must use its scoped names. Tool matchers and `if` fields take the scoped tool name `mcp__plugin_<plugin-name>_<server-name>__<tool>`, and an `mcp_tool` hook’s `server` field takes `plugin:<plugin-name>:<server-name>`. A matcher written against the bare server key never fires. See [Match MCP tools](</docs/en/hooks#match-mcp-tools>) and [Plugin-provided MCP servers](</docs/en/mcp#plugin-provided-mcp-servers>). ###
modified Agent SDK reference - Python View current →
--- a/python.md +++ b/python.md @@ -1194,6 +1194,7 @@ "plan", # Planning mode - explore without editing "dontAsk", # Deny anything not pre-approved instead of prompting "bypassPermissions", # Bypass permission checks; explicit ask rules still prompt (use with caution) + "auto", # A model classifier approves or denies each tool call ] ### @@ -2384,6 +2385,8 @@ tool_name: str tool_input: dict[str, Any] permission_suggestions: NotRequired[list[Any]] + agent_id: NotRequired[str] + agent_type: NotRequired[str] Field| Type| Description ---|---|--- @@ -2391,6 +2394,8 @@ `tool_name`| `str`| Name of the tool requesting permission `tool_input`| `dict[str, Any]`| Input parameters for the tool `permission_suggestions`| `list[Any]` (optional)| Suggested permission updates from the CLI +`agent_id`| `str` (optional)| Subagent identifier, present when the hook fires inside a subagent +`agent_type`| `str` (optional)| Subagent type, present when the hook fires inside a subagent ###
modified Handle approvals and user input View current →
--- a/user-input.md +++ b/user-input.md @@ -115,7 +115,7 @@ asyncio.run(main()) -In Python, `can_use_tool` requires [streaming mode](</docs/en/agent-sdk/streaming-vs-single-mode>) and a `PreToolUse` hook that returns `{"continue_": True}` to keep the stream open. Without this hook, the stream closes before the permission callback can be invoked. +In Python, `can_use_tool` requires [streaming mode](</docs/en/agent-sdk/streaming-vs-single-mode>). When you pass a finite message stream through `query(prompt=generator)` or `ClaudeSDKClient.connect(prompt=async_iterable)`, the SDK closes the input stream after the last message, before the permission callback can be invoked, unless a registered hook or in-process MCP server is keeping it open. The example above keeps it open with a `PreToolUse` hook that returns `{"continue_": True}`. Connecting with no prompt and sending messages through `ClaudeSDKClient.query()` keeps the stream open on its own and needs no hook. This example uses a `y/n` flow where any input other than `y` is treated as a denial. In practice, you might build a richer UI that lets users modify the request, provide feedback, or redirect Claude entirely. See Respond to tool requests for all the ways you can respond.