modified
--- a/code-mode.md +++ b/code-mode.md @@ -41,7 +41,7 @@ * **Surface** : an interactive `claude` session in a terminal. Code Mode doesn’t work with the VS Code panel, the Desktop app, or cloud sessions * **Agent teams** : to use Code Mode with [agent teams](</docs/en/agent-teams>) on, you need v2.1.326 or later. Teammates run in Code Mode in the default [in-process display mode](</docs/en/agent-teams#choose-a-display-mode>), and start without it in split panes * **Mods** : to use Code Mode with a [mod](</docs/en/plugins/mods/overview>) that hooks tool calls, you need v2.1.327 or later. If you’re on the `stable` channel and an update doesn’t reach that version, [switch to `latest`](</docs/en/setup#configure-release-channel>) - * **Telemetry settings** : to use Code Mode with [feature-flag fetching off](</docs/en/env-vars#features-that-need-feature-flag-fetching>) or [OpenTelemetry](</docs/en/monitoring-usage>) events and metrics on, you need v2.1.329 or later. Keep [tracing](</docs/en/monitoring-usage#traces-beta>) off on any version + * **Telemetry settings** : to use Code Mode with [feature-flag fetching off](</docs/en/env-vars#features-that-need-feature-flag-fetching>) or [OpenTelemetry](</docs/en/monitoring-usage>) events and metrics on, you need v2.1.329 or later. With [tracing](</docs/en/monitoring-usage#traces-beta>) on, you need v2.1.333 or later * **Installation** : the [native build](</docs/en/setup>) of Claude Code * **Windows** : [Git for Windows](<https://git-scm.com/downloads/win>) is installed @@ -134,7 +134,9 @@ } } -If your users can connect through a cloud provider, deploy this setting through [MDM or a managed settings file](</docs/en/managed-settings#delivery-mechanisms>). A user who sets a provider variable such as `CLAUDE_CODE_USE_BEDROCK` in their shell or user settings can start Code Mode without receiving [server-managed settings](</docs/en/server-managed-settings#platform-availability>). Users who are in a Code Mode session stay in it until they exit or restart Claude Code. After that, your users start without Code Mode and can’t resume their Code Mode sessions while the `0` is in place. You can’t turn on Code Mode for your users from managed settings. +If you already deploy a policy through MDM or a managed settings file, add the variable to its `env` block, and to any [server-managed settings](</docs/en/server-managed-settings>) that already deliver a policy. If you put the variable in a new [higher-ranked source](</docs/en/managed-settings#how-claude-code-combines-managed-sources>), such as server-managed settings, Claude Code ignores your existing policy’s permission rules and most of its other settings [by default](</docs/en/managed-settings#compose-every-managed-source>).If your MDM policy or file sets a [policy helper](</docs/en/managed-settings#compute-the-policy-with-a-helper-program>), also add the variable to the `env` block of each [`managedSettings` object](</docs/en/settings-reference#write-the-helper-output>) that the helper already outputs. + +If your users can connect through a cloud provider, deploy the variable through [MDM or a managed settings file](</docs/en/managed-settings#delivery-mechanisms>). A user who sets a provider variable such as `CLAUDE_CODE_USE_BEDROCK` in their shell or user settings can start Code Mode without receiving [server-managed settings](</docs/en/server-managed-settings#platform-availability>). Users who are in a Code Mode session stay in it until they exit or restart Claude Code. After that, your users start without Code Mode and can’t resume their Code Mode sessions while the `0` is in place. You can’t turn on Code Mode for your users from managed settings. ### Monitor Code Mode with OpenTelemetry @@ -143,6 +145,13 @@ * **Find calls from code** : filter on `tool_use_id` values that start with `repl_` or `toolu_cc_`. The `REPL` tool, which runs the code, has events of its own without either prefix * **Read classifier verdicts** : in auto mode, a call that the classifier’s review of the code covers has no `classifier_verdict`. Look for the verdict on the `REPL` tool’s `tool_decision` events that have that call’s `request_id`. If you find more than one, the events don’t show which piece of code made the call * **Keep secrets out of your backend** : code can read a value, such as a token in a file, and pass it to another call. Leave `OTEL_LOG_TOOL_DETAILS` unset if your backend shouldn’t receive those values + +#### Trace calls from code + +On v2.1.333 or later, look for calls from code under the `claude_code.tool.execution` span of the `REPL` call that ran the code. Expect the same [span types](</docs/en/monitoring-usage#span-hierarchy>) as for a call that Claude makes directly. Before your users turn on Code Mode, decide what you export and what you audit from: + + * **Keep tool output out of your backend** : code can read far more than it shows Claude. Leave `OTEL_LOG_TOOL_CONTENT` unset if your backend shouldn’t receive what calls from code return. In that case, also leave `OTEL_LOG_TOOL_DETAILS`, `OTEL_LOG_RAW_API_BODIES`, `OTEL_LOG_ASSISTANT_RESPONSES`, and `OTEL_LOG_USER_PROMPTS` unset, because each can send parts of that output + * **Audit from events** : after code makes many calls, you can lose spans if Claude Code exits right away or your collector falls behind. Export [events](</docs/en/monitoring-usage#events>) too and audit from those. To avoid losing events as well, run a collector that responds quickly and accepts large requests ## Permissions and long-running code @@ -234,7 +243,7 @@ * **Change the text** : redact `result`, `stdout`, `stderr`, and `error`. Handle a `result` that’s missing or `null`, and expect `error` only when the code failed or was stopped * **Keep the shape** : return `code`, `stdout`, and `stderr` as strings, and return `error` as a string or leave it out. If you break this shape, Claude gets the original output - * **Remove images, PDFs, and page errors** : if the copy has `images`, `documents`, or `imagePagesFailed` to hide, set that field to `[]`. The `imagePagesFailed` field lists the file path and error for each PDF page that couldn’t be shown + * **Remove images, PDFs, and page errors** : to hide `images`, `documents`, or `imagePagesFailed`, set that field to `[]` and return the copy each time the hook runs. The `imagePagesFailed` field lists the file path and error for each PDF page that couldn’t be shown * **Remove the path to long output** : on v2.1.331 or later, omit `uncutOutputNote` from the copy. The field gives Claude a path to the uncut text To hide the deploy token in the `notes.txt` result, print this JSON: @@ -284,7 +293,7 @@ `it only works with Opus 5.5, Sonnet 5.5 and later models`| Pass the full name of a supported model that your account can use, for example `--model claude-opus-5-5`, or on Microsoft Foundry the name of your deployment of one. Avoid aliases such as `sonnet`, which [select older models on some providers](</docs/en/model-config#model-aliases>) `it doesn't work in background jobs`| Start in the foreground, without `--remote-control`. If the reason shows in a teammate’s split pane, use the [in-process display mode](</docs/en/agent-teams#choose-a-display-mode>) to run teammates in Code Mode `it needs settings that Claude Code downloads from Anthropic`| [Update Claude Code](</docs/en/setup#update-claude-code>) to meet the telemetry settings requirement. To stay on your version, unset the variable that [turns off feature-flag fetching](</docs/en/env-vars#features-that-need-feature-flag-fetching>), such as `DISABLE_TELEMETRY` -`OpenTelemetry tracing is on`| Unset `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA`, `ENABLE_ENHANCED_TELEMETRY_BETA`, and `ENABLE_BETA_TRACING_DETAILED` if you can work without [traces](</docs/en/monitoring-usage#traces-beta>) +`OpenTelemetry tracing is on`| To keep [traces](</docs/en/monitoring-usage#traces-beta>) on, [update Claude Code](</docs/en/setup#update-claude-code>) to meet the telemetry settings requirement. To stay on your version, unset `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA`, `ENABLE_ENHANCED_TELEMETRY_BETA`, and `ENABLE_BETA_TRACING_DETAILED` if you can work without traces `OpenTelemetry is on`| To keep events and metrics on, [update Claude Code](</docs/en/setup#update-claude-code>) and meet the telemetry settings requirement. To stay on your version, unset `CLAUDE_CODE_ENABLE_TELEMETRY` and `ENABLE_BETA_TRACING_DETAILED` if you can work without [OpenTelemetry export](</docs/en/monitoring-usage>) `it doesn't yet work with the plugin`| [Update Claude Code](</docs/en/setup#update-claude-code>) to meet the mods requirement. To stay on your version, run `/plugin` and disable each plugin that the reason names. If your organization turned one on, ask your administrator to turn it off `it doesn't yet work with an installed mod`| [Update Claude Code](</docs/en/setup#update-claude-code>) to meet the mods requirement. To stay on your version, run `/plugin` and disable each mod you installed
modified
--- a/code-mode.md +++ b/code-mode.md @@ -88,11 +88,15 @@ Confirm that you want Code Mode -Claude Code asks you to confirm before your first Code Mode session. Select **Yes, turn on Code Mode**. Claude Code restarts and shows this line near the top of the session: +Claude Code asks you to confirm before your first Code Mode session. Select **Yes, turn on Code Mode**.This line near the top of the session means that Code Mode is on: Code Mode (experimental) is on · this session can be resumed only with Code Mode on -If you see a different line or none, see Code Mode doesn’t start. +If you see this line instead, Code Mode is off in this session: + + Code Mode (experimental) will be on after you quit and start Claude Code again the same way. This session uses the ordinary tools. + +To turn on Code Mode, exit Claude Code and start it again as you did in the previous step. Then look for the `is on` line.If you see a different line or none, see Code Mode doesn’t start. 4
modified
--- a/code-mode.md +++ b/code-mode.md @@ -109,6 +109,12 @@ Press `Ctrl+O` and expand a **Code** row to see the JavaScript behind the tool calls. Press `Ctrl+O` again to return to the conversation. To resume a Code Mode session later, keep `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE` set to `1` when you run `claude --continue` or `claude --resume`. With Code Mode off, Claude Code refuses to resume the session. Sessions that you started without Code Mode resume without Code Mode, even with the variable set. + +### Use Code Mode in subagents + +If your [subagent](</docs/en/sub-agents>) has a `tools` list, add [`REPL`](</docs/en/tools-reference>) to the list so that the subagent uses Code Mode: + + tools: Read, Bash, REPL ### Turn off Code Mode
modified
Show diff (169 lines)
--- a/code-mode.md +++ b/code-mode.md @@ -25,26 +25,27 @@ Before you turn on Code Mode, check that you can accept these limits: - * **Resuming** : you can resume a Code Mode session only in the terminal, with Code Mode on + * **Resuming** : you can resume a Code Mode session only with Code Mode on. After a Code Mode session has run with a Claude subscription or a Console account, you can’t resume it on a cloud provider such as Amazon Bedrock * **Auto mode** : auto mode’s classifier reviews the code, not each tool call * **Long-running code** : unless code can run in the background, you wait for it to finish, and it stops after ten minutes - * **Hooks** : you can see tool calls refused when a `PreToolUse` hook doesn’t finish, for example after a timeout + * **Hooks** : by default, expect a refused tool call when a `PreToolUse` hook doesn’t finish, and a call that can still run when the hook fails another way * **Unavailable features** : you can’t use [Remote Control](</docs/en/remote-control>), [Claude in Chrome](</docs/en/chrome>), or [computer use](</docs/en/computer-use>) * **Moving the session** : you can’t move the session to the Desktop app or turn it into a [background session](</docs/en/agent-view>), and `/fork` can’t start a background copy ## Requirements * **Version** : Claude Code v2.1.323 or later, on either [release channel](</docs/en/setup#configure-release-channel>). An older version starts without Code Mode, with or without the reason `it isn't open to your account yet` - * **Account** : a Claude subscription or Console account. You can’t use Code Mode through a gateway, Amazon Bedrock, Claude Platform on AWS, Google Cloud’s Agent Platform, Microsoft Foundry, or [Claude Models on Google Cloud (Anthropic managed)](</docs/en/claude-models-on-google-cloud-anthropic-managed>) + * **Account or provider** : a Claude subscription, a Console account, or a [cloud provider](</docs/en/feature-availability#availability-by-model-provider>) such as Amazon Bedrock, Google Cloud’s Agent Platform, or Microsoft Foundry. With a cloud provider, you need v2.1.331 or later. You can’t use Code Mode through a [gateway](</docs/en/gateways>) or with Claude for Government. If you reach a cloud provider with an [Enterprise Admin Console sign-in](</docs/en/authentication#log-in-to-claude-code>), you need Agent Platform, or Amazon Bedrock without the [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>) * **Organization** : your organization doesn’t use the [HIPAA configuration](</docs/en/hipaa-setup>) or [zero data retention](</docs/en/zero-data-retention>) - * **Model** : Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, or Fable 5.2 + * **Model** : Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, or Fable 5.2. If you select the model by a deployment name or an application inference profile, ask whoever manages that name whether it points to one of these models * **Surface** : an interactive `claude` session in a terminal. Code Mode doesn’t work with the VS Code panel, the Desktop app, or cloud sessions * **Agent teams** : to use Code Mode with [agent teams](</docs/en/agent-teams>) on, you need v2.1.326 or later. Teammates run in Code Mode in the default [in-process display mode](</docs/en/agent-teams#choose-a-display-mode>), and start without it in split panes + * **Mods** : to use Code Mode with a [mod](</docs/en/plugins/mods/overview>) that hooks tool calls, you need v2.1.327 or later. If you’re on the `stable` channel and an update doesn’t reach that version, [switch to `latest`](</docs/en/setup#configure-release-channel>) * **Telemetry settings** : to use Code Mode with [feature-flag fetching off](</docs/en/env-vars#features-that-need-feature-flag-fetching>) or [OpenTelemetry](</docs/en/monitoring-usage>) events and metrics on, you need v2.1.329 or later. Keep [tracing](</docs/en/monitoring-usage#traces-beta>) off on any version * **Installation** : the [native build](</docs/en/setup>) of Claude Code * **Windows** : [Git for Windows](<https://git-scm.com/downloads/win>) is installed -You also can’t start Code Mode with some settings on, such as an API key helper. For the fix for each, see Code Mode doesn’t start. +You also can’t start Code Mode with some settings on, such as an API key helper on a direct connection to Anthropic. For the fix for each, see Code Mode doesn’t start. ## Try Code Mode @@ -54,7 +55,7 @@ Check your version -Run `claude --version`. If the version is older than v2.1.323, run `claude update`. If you’re on the `stable` channel and the update doesn’t reach v2.1.323, wait for `stable` to catch up or [switch to `latest`](</docs/en/setup#configure-release-channel>). +Run `claude --version`. If the version is older than the one you need for your setup, run `claude update`. If you’re on the `stable` channel and the update doesn’t reach that version, wait for `stable` to catch up or [switch to `latest`](</docs/en/setup#configure-release-channel>). 2 @@ -111,7 +112,7 @@ ### Turn off Code Mode -Remove `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE` from your shell and from `~/.claude/settings.json`, then start a new session. You can also keep the variable and change its value to `0` in either place. With a `0` in one place, Code Mode stays off even if you set `1` in the other. +Remove `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE` from your shell, `~/.claude/settings.json`, and any `--settings` file, then start a new session. You can also keep the variable and change its value to `0` in any of them. With a `0` in one place, Code Mode stays off even if you set `1` in another. ### Block Code Mode for your organization @@ -123,7 +124,7 @@ } } -Users who are in a Code Mode session stay in it until they exit or restart Claude Code. After that, your users start without Code Mode and can’t resume their Code Mode sessions while the `0` is in place. You can’t turn on Code Mode for your users from managed settings. +If your users can connect through a cloud provider, deploy this setting through [MDM or a managed settings file](</docs/en/managed-settings#delivery-mechanisms>). A user who sets a provider variable such as `CLAUDE_CODE_USE_BEDROCK` in their shell or user settings can start Code Mode without receiving [server-managed settings](</docs/en/server-managed-settings#platform-availability>). Users who are in a Code Mode session stay in it until they exit or restart Claude Code. After that, your users start without Code Mode and can’t resume their Code Mode sessions while the `0` is in place. You can’t turn on Code Mode for your users from managed settings. ### Monitor Code Mode with OpenTelemetry @@ -139,7 +140,7 @@ ### Permission checks -In auto and `bypassPermissions` modes, code can run from start to finish without a permission prompt. Some calls still prompt you, such as the [actions no mode auto-approves](</docs/en/permission-modes#actions-no-mode-auto-approves>). Each tool call in the code goes through your `deny` and `ask` [permission rules](</docs/en/permissions>) and [`PreToolUse` hooks](</docs/en/hooks#pretooluse>) under the tool’s usual name, such as `Bash` or an [MCP tool’s name](</docs/en/permissions#mcp>). Beyond rules and hooks, a classifier reviews the code in auto mode, and you answer prompts in the modes that ask: +In auto and `bypassPermissions` modes, code can run from start to finish without a permission prompt. Some calls still prompt you, such as the [actions no mode auto-approves](</docs/en/permission-modes#actions-no-mode-auto-approves>). To control tool calls in the code, write `deny` and `ask` [permission rules](</docs/en/permissions>) and [`PreToolUse` hooks](</docs/en/hooks#pretooluse>) under the tool’s usual name, such as `Bash` or an [MCP tool’s name](</docs/en/permissions#mcp>). Beyond rules and hooks, a classifier reviews the code in auto mode, and you answer prompts in the modes that ask: * **[Auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>)** : the classifier reviews each piece of code before it runs, not each tool call. It doesn’t see values computed at run time, such as a path taken from search output, so keep rules or hooks for calls you must control. You can still be prompted for some calls, such as calls in code that you approved yourself after repeated classifier blocks * **Other[permission modes](</docs/en/permission-modes>)**: you’re prompted for each tool call that would prompt you in that mode @@ -192,10 +193,10 @@ For background code, start your session in auto or `bypassPermissions` mode. If Claude still waits, check your current mode and how you started the session: - * **You switched to another mode** : press `Shift+Tab` until you’re back in the mode you started in - * **You started in another mode** : if [auto mode is available](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) to you, exit, then run `claude --continue --permission-mode auto` with Code Mode on - * **You’re on a version before v2.1.328 and picked the session from the`claude --resume` list**: exit, [update Claude Code](</docs/en/setup#update-claude-code>), then run the same `claude --resume` command with Code Mode on. To stay on your version, replace `--resume` with `--continue` - * **You passed tool names to`--tools`**: start again in auto mode without that flag + * **You’re on a version before v2.1.328 and picked the session from the`claude --resume` list**: exit, [update Claude Code](</docs/en/setup#update-claude-code>), then run the same `claude --resume` command with Code Mode on. To stay on your version, replace `--resume` with `--continue`. If Claude still waits after the update, start a new session in auto mode + * **You passed tool names to`--tools`**: start a new session in auto mode, with Code Mode on and without that flag + * **The session first started in auto or`bypassPermissions` mode**: press `Shift+Tab` until you’re back in that mode. If that doesn’t help, exit, then run `claude --continue --permission-mode auto` with Code Mode on + * **The session first started in another mode** : if [auto mode is available](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) to you, exit, then run `claude --permission-mode auto` with Code Mode on to start a new session. On v2.1.331 or later, expect Claude to keep waiting if you resume the old session instead ### Stop code in progress @@ -203,7 +204,7 @@ ### Check code output with a hook -To check or redact what the code returns before Claude reads it, write a [`PostToolUse` hook](</docs/en/hooks#posttooluse>) that matches `REPL`, the tool that runs the code. The same hook runs when background code finishes and when code throws an error. +To check or redact what the code returns, write a [`PostToolUse` hook](</docs/en/hooks#posttooluse>) that matches `REPL`, the tool that runs the code. The same hook runs when background code finishes and when code throws an error. #### Read code output in the hook @@ -223,7 +224,8 @@ * **Change the text** : redact `result`, `stdout`, `stderr`, and `error`. Handle a `result` that’s missing or `null`, and expect `error` only when the code failed or was stopped * **Keep the shape** : return `code`, `stdout`, and `stderr` as strings, and return `error` as a string or leave it out. If you break this shape, Claude gets the original output - * **Remove images and PDFs** : if the copy has `images` or `documents` to hide, set that field to `[]` + * **Remove images, PDFs, and page errors** : if the copy has `images`, `documents`, or `imagePagesFailed` to hide, set that field to `[]`. The `imagePagesFailed` field lists the file path and error for each PDF page that couldn’t be shown + * **Remove the path to long output** : on v2.1.331 or later, omit `uncutOutputNote` from the copy. The field gives Claude a path to the uncut text To hide the deploy token in the `notes.txt` result, print this JSON: @@ -265,17 +267,20 @@ ---|--- `it isn't open to your account in this version` or `it isn't open to your account yet`| If your version is older than v2.1.323, update. Otherwise, check your network connection and start again. If the reason stays, try again another day `Anthropic has turned it off for now`| [Update Claude Code](</docs/en/setup#update-claude-code>), or start again later -`it only works directly with the Anthropic API` or `it only works with the Anthropic API`| Remove the settings that route requests through a cloud provider, a gateway, or a custom `ANTHROPIC_BASE_URL` +`it only works directly with the Anthropic API` or `it only works with the Anthropic API`| If you use a cloud provider without a gateway, [update Claude Code](</docs/en/setup#update-claude-code>) to v2.1.331 or later. If you use a gateway, follow the next row +`it isn't offered yet through a gateway or proxy`| If your administrator set up the [gateway](</docs/en/gateways>), you need it, or you use Claude for Government, turn off Code Mode to stop seeing the line. Otherwise, remove [the gateway’s settings](</docs/en/llm-gateway-connect>) and key, and connect directly. You can keep `HTTPS_PROXY`. If you signed in to a Claude apps gateway, also remove [its entries from your user settings](</docs/en/claude-apps-gateway#set-the-gateway-url-in-user-settings>) and run `/logout`, which removes saved MCP server logins and plugin secrets too +`it isn't offered yet through a gateway or proxy`, with an [Enterprise Admin Console sign-in](</docs/en/authentication#log-in-to-claude-code>)| Run `/status`. If `API provider` shows a provider that the requirements rule out, such as `Microsoft Foundry` or `Amazon Bedrock (Mantle)`, turn off Code Mode to stop seeing the line. Otherwise, follow the previous row `it doesn't work with an API key helper`| Remove `apiKeyHelper`, `ANTHROPIC_AUTH_TOKEN`, and any `Authorization` or `X-Api-Key` header in `ANTHROPIC_CUSTOM_HEADERS`. Then sign in or set `ANTHROPIC_API_KEY` -`it only works with Opus 5.5, Sonnet 5.5 and later models`| Start with a supported model, for example with `--model opus`. Haiku 5.5 and Fable 5.2 also work +`it only works with Opus 5.5, Sonnet 5.5 and later models`| Pass the full name of a supported model that your account can use, for example `--model claude-opus-5-5`, or on Microsoft Foundry the name of your deployment of one. Avoid aliases such as `sonnet`, which [select older models on some providers](</docs/en/model-config#model-aliases>) `it doesn't work in background jobs`| Start in the foreground, without `--remote-control`. If the reason shows in a teammate’s split pane, use the [in-process display mode](</docs/en/agent-teams#choose-a-display-mode>) to run teammates in Code Mode `it needs settings that Claude Code downloads from Anthropic`| [Update Claude Code](</docs/en/setup#update-claude-code>) to meet the telemetry settings requirement. To stay on your version, unset the variable that [turns off feature-flag fetching](</docs/en/env-vars#features-that-need-feature-flag-fetching>), such as `DISABLE_TELEMETRY` `OpenTelemetry tracing is on`| Unset `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA`, `ENABLE_ENHANCED_TELEMETRY_BETA`, and `ENABLE_BETA_TRACING_DETAILED` if you can work without [traces](</docs/en/monitoring-usage#traces-beta>) `OpenTelemetry is on`| To keep events and metrics on, [update Claude Code](</docs/en/setup#update-claude-code>) and meet the telemetry settings requirement. To stay on your version, unset `CLAUDE_CODE_ENABLE_TELEMETRY` and `ENABLE_BETA_TRACING_DETAILED` if you can work without [OpenTelemetry export](</docs/en/monitoring-usage>) -`it doesn't yet work with the plugin`| In a session, run `/plugin` and disable each plugin that the reason names. If your organization turned one on, ask your administrator to turn it off -`it doesn't yet work with an installed mod`| Turn off the [mod](</docs/en/plugins/mods/overview>) that checks tool calls +`it doesn't yet work with the plugin`| [Update Claude Code](</docs/en/setup#update-claude-code>) to meet the mods requirement. To stay on your version, run `/plugin` and disable each plugin that the reason names. If your organization turned one on, ask your administrator to turn it off +`it doesn't yet work with an installed mod`| [Update Claude Code](</docs/en/setup#update-claude-code>) to meet the mods requirement. To stay on your version, run `/plugin` and disable each mod you installed `it can't be used together with agent teams yet`| To keep agent teams on, [update Claude Code](</docs/en/setup#update-claude-code>) to v2.1.326 or later. To stay on your version, unset `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` `this launch's tool options`| Start without `--restricted`, add `REPL` to `--tools`, and remove `REPL` from `--disallowedTools` and your `deny` rules +`couldn't read your organization's settings or policy`| Start again. If your Enterprise Admin Console sign-in ended, run `claude auth login` and select your organization. If the reason stays and your network blocks `api.anthropic.com`, ask your administrator to allow that host. If you use a cloud provider and not that sign-in, you can instead unset `ANTHROPIC_API_KEY` and run `claude auth logout`, which also removes saved MCP server logins and plugin secrets `couldn't save your answer`| Make `~/.claude.json` writable `your organization's settings don't allow it`| Ask your administrator about the managed setting @@ -283,7 +288,7 @@ ### Permission prompt with a countdown -In auto mode, if you approve code yourself after [repeated classifier blocks](</docs/en/permission-modes#when-auto-mode-falls-back>), you can be asked about tool calls in that code and in earlier code that’s still running. With no IDE connected, the prompt can show a countdown: +In auto mode, if you approve code yourself after [repeated classifier blocks](</docs/en/permission-modes#when-auto-mode-falls-back>), you can be asked about tool calls in that code and in earlier code that’s still running. Expect the same in auto mode after an `ask` rule or a `PreToolUse` hook on `REPL` has you approve the code. With no IDE connected, the prompt can show a countdown: Claude Code will automatically block this request in 1:59, to avoid holding up an unattended session @@ -291,15 +296,20 @@ ### Tool call refused by a hook -If Claude reports a refused tool call, ask it for the error text. These errors mean that your [`PreToolUse` hook](</docs/en/hooks#pretooluse>) didn’t give a decision: - - * **`the hook did not finish`** : your hook timed out, or your agent hook ended without a decision. After a timeout, raise the hook’s [`timeout`](</docs/en/hooks#common-fields>). For an agent hook that gives no decision, move the check to a `command` hook. You can see this error on calls from code, and on other tool calls after Claude runs code in the session - * **`the hook failed`** : on a call from code, your hook couldn’t start, was killed, exited with 126, 127, or a code above 128, or returned an HTTP error or invalid output. Fix the hook. You can see this error before v2.1.329. On later versions it’s rare: one cause is [feature-flag fetching](</docs/en/env-vars#features-that-need-feature-flag-fetching>) turning off during a session, after Claude has run code - -On v2.1.329 or later, expect a call from code to run by default after a hook failure other than `the hook did not finish`. To choose whether the call runs, use a `command` or `http` hook and set [`onFailure`](</docs/en/hooks#block-the-action-when-a-hook-fails>) on it: - - * **To stop the call after a timeout or failure** : set `"onFailure": "block"`. Do this for a hook that guards calls - * **To let the call run after a timeout or failure** : set `"onFailure": "continue"` +If Claude reports a refused call, ask it for the error text. These errors mean your [`PreToolUse` hook](</docs/en/hooks#pretooluse>) gave no decision: + + * **`the hook did not finish`** : your hook timed out, or your agent hook ended without a decision. Raise the hook’s [`timeout`](</docs/en/hooks#common-fields>), or set `"onFailure": "continue"` on a `command` or `http` hook. If an agent hook still gives this error, move the check to a `command` hook. After Claude runs code, you can see this error on calls outside code too + * **`the hook failed`** : your hook failed on a call from code, for example because it couldn’t start. Find the failure in the [debug log](</docs/en/hooks#debug-hooks>) and fix it. Expect this error before v2.1.329. On later versions, you can see it after you turn off [feature-flag fetching](</docs/en/env-vars#features-that-need-feature-flag-fetching>) during a session + +### Tool call ran after a hook failed + +To stop a call from code when its `PreToolUse` hook fails, use a `command` or `http` hook and set [`"onFailure": "block"`](</docs/en/hooks#block-the-action-when-a-hook-fails>). If several settings files have that hook, give it the same `onFailure` value in each. On v2.1.329 or later, expect these results for `command` and `http` hooks: + +`onFailure`| Hook times out| Hook fails another way, such as a missing script +---|---|--- +Not set| Refused| Goes on to permission checks, with rare exceptions +`"block"`| Refused| Refused +`"continue"`| Goes on to permission checks| Goes on to permission checks ### Code output withheld by a hook
modified
--- a/code-mode.md +++ b/code-mode.md @@ -40,10 +40,11 @@ * **Model** : Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, or Fable 5.2 * **Surface** : an interactive `claude` session in a terminal. Code Mode doesn’t work with the VS Code panel, the Desktop app, or cloud sessions * **Agent teams** : to use Code Mode with [agent teams](</docs/en/agent-teams>) on, you need v2.1.326 or later. Teammates run in Code Mode in the default [in-process display mode](</docs/en/agent-teams#choose-a-display-mode>), and start without it in split panes + * **Telemetry settings** : to use Code Mode with [feature-flag fetching off](</docs/en/env-vars#features-that-need-feature-flag-fetching>) or [OpenTelemetry](</docs/en/monitoring-usage>) events and metrics on, you need v2.1.329 or later. Keep [tracing](</docs/en/monitoring-usage#traces-beta>) off on any version * **Installation** : the [native build](</docs/en/setup>) of Claude Code * **Windows** : [Git for Windows](<https://git-scm.com/downloads/win>) is installed -You also can’t start Code Mode with some settings on, such as an API key helper, OpenTelemetry export, or `DISABLE_TELEMETRY`. For the fix for each, see Code Mode doesn’t start. +You also can’t start Code Mode with some settings on, such as an API key helper. For the fix for each, see Code Mode doesn’t start. ## Try Code Mode @@ -123,6 +124,14 @@ } Users who are in a Code Mode session stay in it until they exit or restart Claude Code. After that, your users start without Code Mode and can’t resume their Code Mode sessions while the `0` is in place. You can’t turn on Code Mode for your users from managed settings. + +### Monitor Code Mode with OpenTelemetry + +If you collect [OpenTelemetry events](</docs/en/monitoring-usage#events>), your backend receives `tool_decision` and `tool_result` events for the tool calls in the code that Claude writes, under each tool’s usual name, such as `Bash`. Update your queries and settings for these calls: + + * **Find calls from code** : filter on `tool_use_id` values that start with `repl_` or `toolu_cc_`. The `REPL` tool, which runs the code, has events of its own without either prefix + * **Read classifier verdicts** : in auto mode, a call that the classifier’s review of the code covers has no `classifier_verdict`. Look for the verdict on the `REPL` tool’s `tool_decision` events that have that call’s `request_id`. If you find more than one, the events don’t show which piece of code made the call + * **Keep secrets out of your backend** : code can read a value, such as a token in a file, and pass it to another call. Leave `OTEL_LOG_TOOL_DETAILS` unset if your backend shouldn’t receive those values ## Permissions and long-running code @@ -255,12 +264,14 @@ Reason includes| What to do ---|--- `it isn't open to your account in this version` or `it isn't open to your account yet`| If your version is older than v2.1.323, update. Otherwise, check your network connection and start again. If the reason stays, try again another day +`Anthropic has turned it off for now`| [Update Claude Code](</docs/en/setup#update-claude-code>), or start again later `it only works directly with the Anthropic API` or `it only works with the Anthropic API`| Remove the settings that route requests through a cloud provider, a gateway, or a custom `ANTHROPIC_BASE_URL` `it doesn't work with an API key helper`| Remove `apiKeyHelper`, `ANTHROPIC_AUTH_TOKEN`, and any `Authorization` or `X-Api-Key` header in `ANTHROPIC_CUSTOM_HEADERS`. Then sign in or set `ANTHROPIC_API_KEY` `it only works with Opus 5.5, Sonnet 5.5 and later models`| Start with a supported model, for example with `--model opus`. Haiku 5.5 and Fable 5.2 also work `it doesn't work in background jobs`| Start in the foreground, without `--remote-control`. If the reason shows in a teammate’s split pane, use the [in-process display mode](</docs/en/agent-teams#choose-a-display-mode>) to run teammates in Code Mode -`it needs settings that Claude Code downloads from Anthropic`| Unset the variable that [turns off feature-flag fetching](</docs/en/env-vars#features-that-need-feature-flag-fetching>), such as `DISABLE_TELEMETRY` -`OpenTelemetry is on`| Unset `CLAUDE_CODE_ENABLE_TELEMETRY` and `ENABLE_BETA_TRACING_DETAILED` if you can work without [OpenTelemetry export](</docs/en/monitoring-usage>) +`it needs settings that Claude Code downloads from Anthropic`| [Update Claude Code](</docs/en/setup#update-claude-code>) to meet the telemetry settings requirement. To stay on your version, unset the variable that [turns off feature-flag fetching](</docs/en/env-vars#features-that-need-feature-flag-fetching>), such as `DISABLE_TELEMETRY` +`OpenTelemetry tracing is on`| Unset `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA`, `ENABLE_ENHANCED_TELEMETRY_BETA`, and `ENABLE_BETA_TRACING_DETAILED` if you can work without [traces](</docs/en/monitoring-usage#traces-beta>) +`OpenTelemetry is on`| To keep events and metrics on, [update Claude Code](</docs/en/setup#update-claude-code>) and meet the telemetry settings requirement. To stay on your version, unset `CLAUDE_CODE_ENABLE_TELEMETRY` and `ENABLE_BETA_TRACING_DETAILED` if you can work without [OpenTelemetry export](</docs/en/monitoring-usage>) `it doesn't yet work with the plugin`| In a session, run `/plugin` and disable each plugin that the reason names. If your organization turned one on, ask your administrator to turn it off `it doesn't yet work with an installed mod`| Turn off the [mod](</docs/en/plugins/mods/overview>) that checks tool calls `it can't be used together with agent teams yet`| To keep agent teams on, [update Claude Code](</docs/en/setup#update-claude-code>) to v2.1.326 or later. To stay on your version, unset `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS`
modified
--- a/code-mode.md +++ b/code-mode.md @@ -28,7 +28,7 @@ * **Resuming** : you can resume a Code Mode session only in the terminal, with Code Mode on * **Auto mode** : auto mode’s classifier reviews the code, not each tool call * **Long-running code** : unless code can run in the background, you wait for it to finish, and it stops after ten minutes - * **Hooks** : you can see tool calls refused when a `PreToolUse` hook can’t run or times out + * **Hooks** : you can see tool calls refused when a `PreToolUse` hook doesn’t finish, for example after a timeout * **Unavailable features** : you can’t use [Remote Control](</docs/en/remote-control>), [Claude in Chrome](</docs/en/chrome>), or [computer use](</docs/en/computer-use>) * **Moving the session** : you can’t move the session to the Desktop app or turn it into a [background session](</docs/en/agent-view>), and `/fork` can’t start a background copy @@ -38,7 +38,7 @@ * **Account** : a Claude subscription or Console account. You can’t use Code Mode through a gateway, Amazon Bedrock, Claude Platform on AWS, Google Cloud’s Agent Platform, Microsoft Foundry, or [Claude Models on Google Cloud (Anthropic managed)](</docs/en/claude-models-on-google-cloud-anthropic-managed>) * **Organization** : your organization doesn’t use the [HIPAA configuration](</docs/en/hipaa-setup>) or [zero data retention](</docs/en/zero-data-retention>) * **Model** : Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, or Fable 5.2 - * **Surface** : an interactive `claude` session in a terminal. Code Mode doesn’t work with `-p`, the Agent SDK, the VS Code panel, the Desktop app, or cloud sessions + * **Surface** : an interactive `claude` session in a terminal. Code Mode doesn’t work with the VS Code panel, the Desktop app, or cloud sessions * **Agent teams** : to use Code Mode with [agent teams](</docs/en/agent-teams>) on, you need v2.1.326 or later. Teammates run in Code Mode in the default [in-process display mode](</docs/en/agent-teams#choose-a-display-mode>), and start without it in split panes * **Installation** : the [native build](</docs/en/setup>) of Claude Code * **Windows** : [Git for Windows](<https://git-scm.com/downloads/win>) is installed @@ -280,12 +280,15 @@ ### Tool call refused by a hook -If Claude reports a refused tool call, ask it for the error text. These errors mean that a `PreToolUse` hook didn’t give a decision, which refuses the call even when [`onFailure`](</docs/en/hooks#block-the-action-when-a-hook-fails>) is unset: - - * **`the hook failed`** : on a call from code, your hook couldn’t start, was killed, exited with 126, 127, or a code above 128, or returned an HTTP error or invalid output. Fix the hook - * **`the hook did not finish`** : your hook timed out on a call from code, or on any other tool call once Claude has run code in the session. Raise the hook’s [`timeout`](</docs/en/hooks#common-fields>) - -To let calls go ahead when a `command` or `http` hook fails or times out, set `"onFailure": "continue"` on it. If a `command` hook exits with an ordinary code such as 1, the call goes ahead unless you set `"onFailure": "block"`. +If Claude reports a refused tool call, ask it for the error text. These errors mean that your [`PreToolUse` hook](</docs/en/hooks#pretooluse>) didn’t give a decision: + + * **`the hook did not finish`** : your hook timed out, or your agent hook ended without a decision. After a timeout, raise the hook’s [`timeout`](</docs/en/hooks#common-fields>). For an agent hook that gives no decision, move the check to a `command` hook. You can see this error on calls from code, and on other tool calls after Claude runs code in the session + * **`the hook failed`** : on a call from code, your hook couldn’t start, was killed, exited with 126, 127, or a code above 128, or returned an HTTP error or invalid output. Fix the hook. You can see this error before v2.1.329. On later versions it’s rare: one cause is [feature-flag fetching](</docs/en/env-vars#features-that-need-feature-flag-fetching>) turning off during a session, after Claude has run code + +On v2.1.329 or later, expect a call from code to run by default after a hook failure other than `the hook did not finish`. To choose whether the call runs, use a `command` or `http` hook and set [`onFailure`](</docs/en/hooks#block-the-action-when-a-hook-fails>) on it: + + * **To stop the call after a timeout or failure** : set `"onFailure": "block"`. Do this for a hook that guards calls + * **To let the call run after a timeout or failure** : set `"onFailure": "continue"` ### Code output withheld by a hook
modified
Show diff (171 lines)
--- a/code-mode.md +++ b/code-mode.md @@ -28,7 +28,7 @@ * **Resuming** : you can resume a Code Mode session only in the terminal, with Code Mode on * **Auto mode** : auto mode’s classifier reviews the code, not each tool call * **Long-running code** : unless code can run in the background, you wait for it to finish, and it stops after ten minutes - * **Hooks** : you can see tool calls refused when a `PreToolUse` hook can’t run or times out, and code output blocked by a `UserPromptSubmit` hook + * **Hooks** : you can see tool calls refused when a `PreToolUse` hook can’t run or times out * **Unavailable features** : you can’t use [Remote Control](</docs/en/remote-control>), [Claude in Chrome](</docs/en/chrome>), or [computer use](</docs/en/computer-use>) * **Moving the session** : you can’t move the session to the Desktop app or turn it into a [background session](</docs/en/agent-view>), and `/fork` can’t start a background copy @@ -130,27 +130,121 @@ ### Permission checks -When Claude runs code, each tool call in it goes through your `deny` and `ask` [permission rules](</docs/en/permissions>) and your [`PreToolUse` hooks](</docs/en/hooks#pretooluse>) under the tool’s usual name, such as `Bash`. Beyond rules and hooks, a classifier reviews the code in auto mode, and you answer prompts in the modes that ask: - - * **[Auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>)** : the classifier reviews each piece of code before it runs, not each tool call. It doesn’t see values computed at run time, such as a path taken from search output, so keep rules or hooks for calls you must control. You can still be prompted when new code starts while earlier code runs - * **Other[permission modes](</docs/en/permission-modes>)**: the code starts without a review, and you’re prompted for each tool call that would prompt you in that mode - -If you have a `PreToolUse` hook that allows or blocks shell commands, make it check each part of a command, as [Bash rules do](</docs/en/permissions#compound-commands>). In Code Mode, a `git push` in a folder named `app` can reach your hook as `cd 'app' && git push`. To check the code itself, write a `PreToolUse` hook that matches `REPL`, the tool that runs the code, and read the JavaScript from `tool_input.code`. +In auto and `bypassPermissions` modes, code can run from start to finish without a permission prompt. Some calls still prompt you, such as the [actions no mode auto-approves](</docs/en/permission-modes#actions-no-mode-auto-approves>). Each tool call in the code goes through your `deny` and `ask` [permission rules](</docs/en/permissions>) and [`PreToolUse` hooks](</docs/en/hooks#pretooluse>) under the tool’s usual name, such as `Bash` or an [MCP tool’s name](</docs/en/permissions#mcp>). Beyond rules and hooks, a classifier reviews the code in auto mode, and you answer prompts in the modes that ask: + + * **[Auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>)** : the classifier reviews each piece of code before it runs, not each tool call. It doesn’t see values computed at run time, such as a path taken from search output, so keep rules or hooks for calls you must control. You can still be prompted for some calls, such as calls in code that you approved yourself after repeated classifier blocks + * **Other[permission modes](</docs/en/permission-modes>)**: you’re prompted for each tool call that would prompt you in that mode + +If you have a `PreToolUse` hook that allows or blocks shell commands, make it check each part of a command, as [Bash rules do](</docs/en/permissions#compound-commands>). In Code Mode, a `git push` in a folder named `app` can reach your hook as `cd 'app' && git push`. To check the code itself, write a `PreToolUse` hook that matches `REPL`, the tool that runs the code, and read the JavaScript from `tool_input.code`. To check what the code returns, see Check code output with a hook. Bash rules match command text, so Claude can run a denied command [in a form the rule doesn’t match](</docs/en/permissions#bash-rule-limits>), with or without Code Mode. For limits that don’t depend on command text, see [sandboxing](</docs/en/sandboxing>). +#### Require approval for a command + +To see a prompt for a specific command in auto or `bypassPermissions` mode, add an `ask` rule for it. You’re prompted for the [forms of the command that the rule matches](</docs/en/permissions#bash-rule-limits>). To be prompted for commands that start with `git push`, save this rule in `~/.claude/settings.json`: + + { + "permissions": { + "ask": ["Bash(git push *)"] + } + } + +To test the rule, start a new session in auto mode in a repository with no remote, and ask Claude to run `git push origin main`. You see a prompt for that command. + +#### Approve each piece of code first + +To read and approve code before it starts, add an `ask` rule for `REPL`, the tool that runs the code. Save this rule in `~/.claude/settings.json`: + + { + "permissions": { + "ask": ["REPL"] + } + } + +To test the rule, start a new session and give Claude a task. You see a prompt that doesn’t include the code. To read the code before you answer, press `Ctrl+O`, expand the **Code** row, and press `Ctrl+O` again to return. From the main conversation, you don’t see a [subagent](</docs/en/sub-agents>)’s code in that view. If you approve in auto mode, the code starts even when the classifier would have blocked it, and its project edits and read-only commands run without a prompt. If Claude reports that the code can’t start a subagent, remove the rule. + +#### Answer a permission prompt while code runs + +To stop the code at a prompt for one of its tool calls, answer **No** without a comment. These results apply to prompts that aren’t labeled as coming from a subagent: + + * **No, or`Esc`**: the code stops, and changes from calls that already finished stay in place + * **No, with a[comment](</docs/en/permissions#add-a-comment-when-you-answer-a-permission-prompt>)**: the call is refused, and the code can continue with its other calls + +### Limit shell commands with the sandbox + +Your [sandbox](</docs/en/sandboxing>) settings apply to the shell commands that code runs. The JavaScript itself and its file, web, and MCP tool calls run [outside the sandbox](</docs/en/sandboxing#what-runs-outside-the-sandbox>). To isolate the JavaScript and those calls too, run Claude Code in a [container or virtual machine](</docs/en/sandbox-environments>). To keep commands in the sandbox when code requests to run them unsandboxed, turn on [strict sandbox mode](</docs/en/sandboxing#turn-off-the-retry-with-strict-sandbox-mode>). In auto mode, the classifier reviews the code that makes the request, and the command has no separate review. + ### Long-running code While code runs a long build or test, Claude either waits for it or lets it continue in the background: - * **Waiting** : Claude answers after the code finishes, and the code stops after ten minutes, including time you spend at permission prompts + * **Waiting** : Claude answers after the code finishes, and the code stops after ten minutes. In Manual and `acceptEdits` [modes](</docs/en/permission-modes#available-modes>), time you spend at a tool’s permission prompt doesn’t count toward the ten minutes. Before v2.1.328, that time counted. * **Background** : you can keep talking to Claude, and the code can run for up to two hours For background code, start your session in auto or `bypassPermissions` mode. If Claude still waits, check your current mode and how you started the session: * **You switched to another mode** : press `Shift+Tab` until you’re back in the mode you started in - * **You started in another mode, or picked the session from the`claude --resume` list**: if [auto mode is available](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) to you, exit, then run `claude --continue --permission-mode auto` with Code Mode on + * **You started in another mode** : if [auto mode is available](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) to you, exit, then run `claude --continue --permission-mode auto` with Code Mode on + * **You’re on a version before v2.1.328 and picked the session from the`claude --resume` list**: exit, [update Claude Code](</docs/en/setup#update-claude-code>), then run the same `claude --resume` command with Code Mode on. To stay on your version, replace `--resume` with `--continue` * **You passed tool names to`--tools`**: start again in auto mode without that flag + +### Stop code in progress + +To stop code while Claude is responding or waiting for the code, press `Esc`. To stop background code after Claude finishes responding, run [`/tasks`](</docs/en/commands>) in the session, select the running task, and press `x`. After you stop the code, check `/tasks` for [subagents](</docs/en/sub-agents>), [shell commands](</docs/en/interactive-mode#background-bash-commands>), and [MCP calls](</docs/en/mcp#automatic-backgrounding-of-long-tool-calls>) that the code started and that are still running. To stop one, select it and press `x`. + +### Check code output with a hook + +To check or redact what the code returns before Claude reads it, write a [`PostToolUse` hook](</docs/en/hooks#posttooluse>) that matches `REPL`, the tool that runs the code. The same hook runs when background code finishes and when code throws an error. + +#### Read code output in the hook + +In your `PostToolUse` hook, read the output from `tool_response`, which has fields such as these: + + { + "code": "(await $`cat notes.txt`.text())", + "result": "deploy token: abc123", + "stdout": "", + "stderr": "", + "toolsUsed": ["Bash"] + } + +#### Redact code output + +To hide part of the output, return a changed copy of `tool_response` as [`updatedToolOutput`](</docs/en/hooks#posttooluse-decision-control>), and build the copy this way: + + * **Change the text** : redact `result`, `stdout`, `stderr`, and `error`. Handle a `result` that’s missing or `null`, and expect `error` only when the code failed or was stopped + * **Keep the shape** : return `code`, `stdout`, and `stderr` as strings, and return `error` as a string or leave it out. If you break this shape, Claude gets the original output + * **Remove images and PDFs** : if the copy has `images` or `documents` to hide, set that field to `[]` + +To hide the deploy token in the `notes.txt` result, print this JSON: + + { + "hookSpecificOutput": { + "hookEventName": "PostToolUse", + "updatedToolOutput": { + "code": "(await $`cat notes.txt`.text())", + "result": "deploy token: REDACTED", + "stdout": "", + "stderr": "", + "toolsUsed": ["Bash"] + } + } + } + +To test the hook, create a file that contains a value your hook redacts. Then start a Code Mode session, and ask Claude to read and quote the file. Type the path without `@`, and check that Claude’s reply shows your replacement text. + +Don’t rely on this hook to hide a value in a refused tool call’s input, such as a Bash command. The `refusedCalls` field can repeat that input, and Claude reads it unchanged. + +#### Redact when your hook blocks or hits an error + +Return a changed copy of `tool_response` as `updatedToolOutput` even when your hook blocks or hits an error: + + * **Your hook blocks** : print the redacted copy in the same JSON as [`"decision": "block"`](</docs/en/hooks#posttooluse-decision-control>). Without the copy, Claude still reads the original output + * **Your hook hits an error** : catch the error, and print a copy with placeholder text in the fields that you redact. If the hook crashes, times out, or prints invalid JSON, Claude gets the original output + +#### Move a check from a `UserPromptSubmit` hook + +If you check code output in a [`UserPromptSubmit` hook](</docs/en/hooks#userpromptsubmit>), move that check to your `PostToolUse` hook. On v2.1.328 or later, `UserPromptSubmit` hooks don’t receive code output, even when an administrator sets them in [managed settings](</docs/en/managed-settings>). ## Troubleshooting @@ -178,11 +272,11 @@ ### Permission prompt with a countdown -When Claude starts more code in auto mode while earlier code is still running, the earlier code loses its classifier review. Claude Code then asks you about the earlier code’s remaining calls that would need a review. With no IDE connected, the prompt shows a countdown: +In auto mode, if you approve code yourself after [repeated classifier blocks](</docs/en/permission-modes#when-auto-mode-falls-back>), you can be asked about tool calls in that code and in earlier code that’s still running. With no IDE connected, the prompt can show a countdown: Claude Code will automatically block this request in 1:59, to avoid holding up an unattended session -Answer before the countdown ends. Otherwise that call is refused, and later calls that would show a countdown are refused without a prompt. To see the prompts again, send Claude a message. +Answer before the countdown ends. Otherwise that call is refused, and later calls that would show a countdown are refused without a prompt. To see the prompts again, send Claude a message. Before v2.1.327, you could also be asked about the remaining calls in running code after Claude started new code, even if the classifier allowed the new code. To see fewer of these prompts, [update Claude Code](</docs/en/setup#update-claude-code>) to v2.1.327 or later. ### Tool call refused by a hook @@ -195,10 +289,13 @@ ### Code output withheld by a hook -If Claude reports a hook’s block reason where you expected output from code, check your [`UserPromptSubmit`](</docs/en/hooks#userpromptsubmit>) hooks. When code can run in the background, `command`, `http`, and `mcp_tool` hooks on that event also run on code output. To let the output through, change the hook so that it doesn’t block when `source` in its input is `poll_event`. +If you expected output from code and see `UserPromptSubmit operation blocked by hook` in Claude’s reply, your [`UserPromptSubmit`](</docs/en/hooks#userpromptsubmit>) hook received the output as a prompt and blocked it. If Claude reports only the hook’s reason, ask it to quote the message it received. On v2.1.328 or later, `UserPromptSubmit` hooks don’t receive code output. To let the output through on an earlier version, update Claude Code or change the hook: + + * **Update** : if you rely on the hook to check code output, first move the check to a `PostToolUse` hook. Then [update Claude Code](</docs/en/setup#update-claude-code>) to v2.1.328 or later + * **Stay on your version** : change the hook so that it doesn’t block when `source` in its input is `poll_event` ## Related resources * [Permission modes](</docs/en/permission-modes>): compare auto mode with the modes that prompt you - * [Hooks reference](</docs/en/hooks>): write `PreToolUse` and `UserPromptSubmit` hooks + * [Hooks reference](</docs/en/hooks>): write `PreToolUse` and `PostToolUse` hooks * [Managed settings](</docs/en/managed-settings>): apply one configuration across an organization
modified
--- a/code-mode.md +++ b/code-mode.md @@ -35,14 +35,15 @@ ## Requirements * **Version** : Claude Code v2.1.323 or later, on either [release channel](</docs/en/setup#configure-release-channel>). An older version starts without Code Mode, with or without the reason `it isn't open to your account yet` - * **Account** : a Claude subscription or Console account. You can’t use Code Mode through a gateway, Amazon Bedrock, Claude Platform on AWS, Google Cloud’s Agent Platform, or Microsoft Foundry + * **Account** : a Claude subscription or Console account. You can’t use Code Mode through a gateway, Amazon Bedrock, Claude Platform on AWS, Google Cloud’s Agent Platform, Microsoft Foundry, or [Claude Models on Google Cloud (Anthropic managed)](</docs/en/claude-models-on-google-cloud-anthropic-managed>) * **Organization** : your organization doesn’t use the [HIPAA configuration](</docs/en/hipaa-setup>) or [zero data retention](</docs/en/zero-data-retention>) * **Model** : Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, or Fable 5.2 * **Surface** : an interactive `claude` session in a terminal. Code Mode doesn’t work with `-p`, the Agent SDK, the VS Code panel, the Desktop app, or cloud sessions + * **Agent teams** : to use Code Mode with [agent teams](</docs/en/agent-teams>) on, you need v2.1.326 or later. Teammates run in Code Mode in the default [in-process display mode](</docs/en/agent-teams#choose-a-display-mode>), and start without it in split panes * **Installation** : the [native build](</docs/en/setup>) of Claude Code * **Windows** : [Git for Windows](<https://git-scm.com/downloads/win>) is installed -You also can’t start Code Mode with some settings on, such as an API key helper, agent teams, OpenTelemetry export, or `DISABLE_TELEMETRY`. For the fix for each, see Code Mode doesn’t start. +You also can’t start Code Mode with some settings on, such as an API key helper, OpenTelemetry export, or `DISABLE_TELEMETRY`. For the fix for each, see Code Mode doesn’t start. ## Try Code Mode @@ -125,16 +126,16 @@ ## Permissions and long-running code -Your permission mode decides how Claude’s code is checked and whether you can talk to Claude while the code runs. +Your permission mode decides how the code that Claude writes is checked and whether you can talk to Claude while the code runs. ### Permission checks -Each tool call that Claude’s code makes goes through your `deny` and `ask` [permission rules](</docs/en/permissions>) and your [`PreToolUse` hooks](</docs/en/hooks#pretooluse>). You don’t need to change a rule or matcher for a tool such as `Bash`. Beyond rules and hooks, a classifier reviews the code in auto mode, and you answer prompts in the modes that ask: +When Claude runs code, each tool call in it goes through your `deny` and `ask` [permission rules](</docs/en/permissions>) and your [`PreToolUse` hooks](</docs/en/hooks#pretooluse>) under the tool’s usual name, such as `Bash`. Beyond rules and hooks, a classifier reviews the code in auto mode, and you answer prompts in the modes that ask: * **[Auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>)** : the classifier reviews each piece of code before it runs, not each tool call. It doesn’t see values computed at run time, such as a path taken from search output, so keep rules or hooks for calls you must control. You can still be prompted when new code starts while earlier code runs * **Other[permission modes](</docs/en/permission-modes>)**: the code starts without a review, and you’re prompted for each tool call that would prompt you in that mode -To check the code itself, write a `PreToolUse` hook that matches `REPL`, the tool that runs Claude’s code, and read the JavaScript from `tool_input.code`. +If you have a `PreToolUse` hook that allows or blocks shell commands, make it check each part of a command, as [Bash rules do](</docs/en/permissions#compound-commands>). In Code Mode, a `git push` in a folder named `app` can reach your hook as `cd 'app' && git push`. To check the code itself, write a `PreToolUse` hook that matches `REPL`, the tool that runs the code, and read the JavaScript from `tool_input.code`. Bash rules match command text, so Claude can run a denied command [in a form the rule doesn’t match](</docs/en/permissions#bash-rule-limits>), with or without Code Mode. For limits that don’t depend on command text, see [sandboxing](</docs/en/sandboxing>). @@ -159,15 +160,16 @@ Reason includes| What to do ---|--- -`it isn't open to your account yet`| If your version is older than v2.1.323, update. Otherwise, check your network connection and start again. If the reason stays, try again another day -`it only works with the Anthropic API`| Remove the settings that route requests through a cloud provider, a gateway, or a custom `ANTHROPIC_BASE_URL` +`it isn't open to your account in this version` or `it isn't open to your account yet`| If your version is older than v2.1.323, update. Otherwise, check your network connection and start again. If the reason stays, try again another day +`it only works directly with the Anthropic API` or `it only works with the Anthropic API`| Remove the settings that route requests through a cloud provider, a gateway, or a custom `ANTHROPIC_BASE_URL` `it doesn't work with an API key helper`| Remove `apiKeyHelper`, `ANTHROPIC_AUTH_TOKEN`, and any `Authorization` or `X-Api-Key` header in `ANTHROPIC_CUSTOM_HEADERS`. Then sign in or set `ANTHROPIC_API_KEY` `it only works with Opus 5.5, Sonnet 5.5 and later models`| Start with a supported model, for example with `--model opus`. Haiku 5.5 and Fable 5.2 also work -`it doesn't work in background jobs`| Start in the foreground, without `--remote-control` +`it doesn't work in background jobs`| Start in the foreground, without `--remote-control`. If the reason shows in a teammate’s split pane, use the [in-process display mode](</docs/en/agent-teams#choose-a-display-mode>) to run teammates in Code Mode `it needs settings that Claude Code downloads from Anthropic`| Unset the variable that [turns off feature-flag fetching](</docs/en/env-vars#features-that-need-feature-flag-fetching>), such as `DISABLE_TELEMETRY` `OpenTelemetry is on`| Unset `CLAUDE_CODE_ENABLE_TELEMETRY` and `ENABLE_BETA_TRACING_DETAILED` if you can work without [OpenTelemetry export](</docs/en/monitoring-usage>) +`it doesn't yet work with the plugin`| In a session, run `/plugin` and disable each plugin that the reason names. If your organization turned one on, ask your administrator to turn it off `it doesn't yet work with an installed mod`| Turn off the [mod](</docs/en/plugins/mods/overview>) that checks tool calls -`it can't be used together with agent teams yet`| Unset `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` +`it can't be used together with agent teams yet`| To keep agent teams on, [update Claude Code](</docs/en/setup#update-claude-code>) to v2.1.326 or later. To stay on your version, unset `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` `this launch's tool options`| Start without `--restricted`, add `REPL` to `--tools`, and remove `REPL` from `--disallowedTools` and your `deny` rules `couldn't save your answer`| Make `~/.claude.json` writable `your organization's settings don't allow it`| Ask your administrator about the managed setting @@ -186,14 +188,14 @@ If Claude reports a refused tool call, ask it for the error text. These errors mean that a `PreToolUse` hook didn’t give a decision, which refuses the call even when [`onFailure`](</docs/en/hooks#block-the-action-when-a-hook-fails>) is unset: - * **`the hook failed`** : on a call from Claude’s code, your hook couldn’t start, was killed, exited with 126, 127, or a code above 128, or returned an HTTP error or invalid output. Fix the hook - * **`the hook did not finish`** : your hook timed out on a call from Claude’s code, or on any other tool call once Claude has run code in the session. Raise the hook’s [`timeout`](</docs/en/hooks#common-fields>) + * **`the hook failed`** : on a call from code, your hook couldn’t start, was killed, exited with 126, 127, or a code above 128, or returned an HTTP error or invalid output. Fix the hook + * **`the hook did not finish`** : your hook timed out on a call from code, or on any other tool call once Claude has run code in the session. Raise the hook’s [`timeout`](</docs/en/hooks#common-fields>) To let calls go ahead when a `command` or `http` hook fails or times out, set `"onFailure": "continue"` on it. If a `command` hook exits with an ordinary code such as 1, the call goes ahead unless you set `"onFailure": "block"`. ### Code output withheld by a hook -If Claude reports a hook’s block reason where you expected output from Claude’s code, check your [`UserPromptSubmit`](</docs/en/hooks#userpromptsubmit>) hooks. When code can run in the background, `command`, `http`, and `mcp_tool` hooks on that event also run on code output. To let the output through, change the hook so that it doesn’t block when `source` in its input is `poll_event`. +If Claude reports a hook’s block reason where you expected output from code, check your [`UserPromptSubmit`](</docs/en/hooks#userpromptsubmit>) hooks. When code can run in the background, `command`, `http`, and `mcp_tool` hooks on that event also run on code output. To let the output through, change the hook so that it doesn’t block when `source` in its input is `poll_event`. ## Related resources
added
Show diff (205 lines)
--- a/code-mode.md +++ b/code-mode.md @@ -0,0 +1,202 @@ +Code Mode changes how Claude uses its [tools](</docs/en/tools-reference>). Without Code Mode, Claude asks for tool calls such as Bash, Read, or Edit directly and reads each result before it decides what to do next. With Code Mode, Claude writes a piece of JavaScript that makes the tool calls, and Claude Code runs that code in your session. + +Code Mode is experimental and off by default. It may change or be removed in any release. To share feedback, run `/feedback`. + +## How Code Mode works + +In a Code Mode session, you still describe your task in a prompt, and Claude writes JavaScript to carry it out. One piece of code can run commands in parallel, use one result in the next call, and return the part of the output that Claude needs to read. For example, if you ask Claude to raise a retry limit, Claude might write this code to find the file, edit it, and run the tests. The last line returns the file’s path and the test output to Claude: + + const files = await $`rg -l "function retryPolicy" src`.text(); + const target = files.trim().split("\n")[0]; + await edit(target, "maxAttempts: 3", "maxAttempts: 5"); + ({ edited: target, tests: $`npm test -- retryPolicy`.nothrow() }); + +In the conversation, you see the tool calls, such as the edit’s diff, and not the code. To read the code, press `Ctrl+O` to open the [transcript viewer](</docs/en/interactive-mode#transcript-viewer>). Each piece of code appears there as a collapsed **Code** row, with a hint for how to expand it. + +### When to use Code Mode + +Try Code Mode on tasks that take many related tool calls, such as: + + * A change that repeats across many files + * A search whose results need filtering before Claude reads them + * Several independent commands that can run at the same time + +### Code Mode limitations + +Before you turn on Code Mode, check that you can accept these limits: + + * **Resuming** : you can resume a Code Mode session only in the terminal, with Code Mode on + * **Auto mode** : auto mode’s classifier reviews the code, not each tool call + * **Long-running code** : unless code can run in the background, you wait for it to finish, and it stops after ten minutes + * **Hooks** : you can see tool calls refused when a `PreToolUse` hook can’t run or times out, and code output blocked by a `UserPromptSubmit` hook + * **Unavailable features** : you can’t use [Remote Control](</docs/en/remote-control>), [Claude in Chrome](</docs/en/chrome>), or [computer use](</docs/en/computer-use>) + * **Moving the session** : you can’t move the session to the Desktop app or turn it into a [background session](</docs/en/agent-view>), and `/fork` can’t start a background copy + +## Requirements + + * **Version** : Claude Code v2.1.323 or later, on either [release channel](</docs/en/setup#configure-release-channel>). An older version starts without Code Mode, with or without the reason `it isn't open to your account yet` + * **Account** : a Claude subscription or Console account. You can’t use Code Mode through a gateway, Amazon Bedrock, Claude Platform on AWS, Google Cloud’s Agent Platform, or Microsoft Foundry + * **Organization** : your organization doesn’t use the [HIPAA configuration](</docs/en/hipaa-setup>) or [zero data retention](</docs/en/zero-data-retention>) + * **Model** : Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, or Fable 5.2 + * **Surface** : an interactive `claude` session in a terminal. Code Mode doesn’t work with `-p`, the Agent SDK, the VS Code panel, the Desktop app, or cloud sessions + * **Installation** : the [native build](</docs/en/setup>) of Claude Code + * **Windows** : [Git for Windows](<https://git-scm.com/downloads/win>) is installed + +You also can’t start Code Mode with some settings on, such as an API key helper, agent teams, OpenTelemetry export, or `DISABLE_TELEMETRY`. For the fix for each, see Code Mode doesn’t start. + +## Try Code Mode + +Turn on Code Mode, give Claude a task, and look at the code that Claude wrote. + +1 + +Check your version + +Run `claude --version`. If the version is older than v2.1.323, run `claude update`. If you’re on the `stable` channel and the update doesn’t reach v2.1.323, wait for `stable` to catch up or [switch to `latest`](</docs/en/setup#configure-release-channel>). + +2 + +Start Claude Code with Code Mode on + +Set the [`CLAUDE_CODE_EXPERIMENTAL_CODE_MODE`](</docs/en/env-vars#variables>) environment variable to `1`. To try Code Mode, set it in your shell. To turn on Code Mode for every new session, set it in your user settings. + + * macOS, Linux, WSL + + * Windows PowerShell + + * settings.json + + CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude + + $env:CLAUDE_CODE_EXPERIMENTAL_CODE_MODE = "1" + claude + +Save this `env` block in `~/.claude/settings.json` and start `claude`: + + { + "env": { + "CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "1" + } + } + +Claude Code [ignores this variable in a project’s settings files](</docs/en/settings-reference#variables-claude-code-ignores-in-env>), so a repository you clone can’t turn on Code Mode for you. + +3 + +Confirm that you want Code Mode + +Claude Code asks you to confirm before your first Code Mode session. Select **Yes, turn on Code Mode**. Claude Code restarts and shows this line near the top of the session: + + Code Mode (experimental) is on · this session can be resumed only with Code Mode on + +If you see a different line or none, see Code Mode doesn’t start. + +4 + +Give Claude a task with many tool calls + +In a project you know, send a prompt such as this one: + + Read every Markdown file in this project and list the links that point to local files that don't exist. + +5 + +Read the code Claude wrote + +Press `Ctrl+O` and expand a **Code** row to see the JavaScript behind the tool calls. Press `Ctrl+O` again to return to the conversation. + +To resume a Code Mode session later, keep `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE` set to `1` when you run `claude --continue` or `claude --resume`. With Code Mode off, Claude Code refuses to resume the session. Sessions that you started without Code Mode resume without Code Mode, even with the variable set. + +### Turn off Code Mode + +Remove `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE` from your shell and from `~/.claude/settings.json`, then start a new session. You can also keep the variable and change its value to `0` in either place. With a `0` in one place, Code Mode stays off even if you set `1` in the other. + +### Block Code Mode for your organization + +Add `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE` with the value `0` to your [managed settings](</docs/en/managed-settings>) so that nobody in your organization can use Code Mode: + + { + "env": { + "CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "0" + } + } + +Users who are in a Code Mode session stay in it until they exit or restart Claude Code. After that, your users start without Code Mode and can’t resume their Code Mode sessions while the `0` is in place. You can’t turn on Code Mode for your users from managed settings. + +## Permissions and long-running code + +Your permission mode decides how Claude’s code is checked and whether you can talk to Claude while the code runs. + +### Permission checks + +Each tool call that Claude’s code makes goes through your `deny` and `ask` [permission rules](</docs/en/permissions>) and your [`PreToolUse` hooks](</docs/en/hooks#pretooluse>). You don’t need to change a rule or matcher for a tool such as `Bash`. Beyond rules and hooks, a classifier reviews the code in auto mode, and you answer prompts in the modes that ask: + + * **[Auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>)** : the classifier reviews each piece of code before it runs, not each tool call. It doesn’t see values computed at run time, such as a path taken from search output, so keep rules or hooks for calls you must control. You can still be prompted when new code starts while earlier code runs + * **Other[permission modes](</docs/en/permission-modes>)**: the code starts without a review, and you’re prompted for each tool call that would prompt you in that mode + +To check the code itself, write a `PreToolUse` hook that matches `REPL`, the tool that runs Claude’s code, and read the JavaScript from `tool_input.code`. + +Bash rules match command text, so Claude can run a denied command [in a form the rule doesn’t match](</docs/en/permissions#bash-rule-limits>), with or without Code Mode. For limits that don’t depend on command text, see [sandboxing](</docs/en/sandboxing>). + +### Long-running code + +While code runs a long build or test, Claude either waits for it or lets it continue in the background: + + * **Waiting** : Claude answers after the code finishes, and the code stops after ten minutes, including time you spend at permission prompts + * **Background** : you can keep talking to Claude, and the code can run for up to two hours + +For background code, start your session in auto or `bypassPermissions` mode. If Claude still waits, check your current mode and how you started the session: + + * **You switched to another mode** : press `Shift+Tab` until you’re back in the mode you started in + * **You started in another mode, or picked the session from the`claude --resume` list**: if [auto mode is available](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) to you, exit, then run `claude --continue --permission-mode auto` with Code Mode on + * **You passed tool names to`--tools`**: start again in auto mode without that flag + +## Troubleshooting + +### Code Mode doesn’t start + +`Code Mode (experimental) isn't available` near the top of the session means that Claude Code started without Code Mode. The reason follows on the same line, and `/status` shows it too. Find the reason in this table, make the change, and start a new session. For a reason that isn’t listed, check the requirements. + +Reason includes| What to do +---|--- +`it isn't open to your account yet`| If your version is older than v2.1.323, update. Otherwise, check your network connection and start again. If the reason stays, try again another day +`it only works with the Anthropic API`| Remove the settings that route requests through a cloud provider, a gateway, or a custom `ANTHROPIC_BASE_URL` +`it doesn't work with an API key helper`| Remove `apiKeyHelper`, `ANTHROPIC_AUTH_TOKEN`, and any `Authorization` or `X-Api-Key` header in `ANTHROPIC_CUSTOM_HEADERS`. Then sign in or set `ANTHROPIC_API_KEY` +`it only works with Opus 5.5, Sonnet 5.5 and later models`| Start with a supported model, for example with `--model opus`. Haiku 5.5 and Fable 5.2 also work +`it doesn't work in background jobs`| Start in the foreground, without `--remote-control` +`it needs settings that Claude Code downloads from Anthropic`| Unset the variable that [turns off feature-flag fetching](</docs/en/env-vars#features-that-need-feature-flag-fetching>), such as `DISABLE_TELEMETRY` +`OpenTelemetry is on`| Unset `CLAUDE_CODE_ENABLE_TELEMETRY` and `ENABLE_BETA_TRACING_DETAILED` if you can work without [OpenTelemetry export](</docs/en/monitoring-usage>) +`it doesn't yet work with an installed mod`| Turn off the [mod](</docs/en/plugins/mods/overview>) that checks tool calls +`it can't be used together with agent teams yet`| Unset `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` +`this launch's tool options`| Start without `--restricted`, add `REPL` to `--tools`, and remove `REPL` from `--disallowedTools` and your `deny` rules +`couldn't save your answer`| Make `~/.claude.json` writable +`your organization's settings don't allow it`| Ask your administrator about the managed setting + +If you see no line about Code Mode, run `claude --version`. If your version is older than v2.1.323, update. Then check that `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE` is `1` in your shell or user settings, and remove any `0` from those and from any `--settings` file. + +### Permission prompt with a countdown + +When Claude starts more code in auto mode while earlier code is still running, the earlier code loses its classifier review. Claude Code then asks you about the earlier code’s remaining calls that would need a review. With no IDE connected, the prompt shows a countdown: + + Claude Code will automatically block this request in 1:59, to avoid holding up an unattended session + +Answer before the countdown ends. Otherwise that call is refused, and later calls that would show a countdown are refused without a prompt. To see the prompts again, send Claude a message. + +### Tool call refused by a hook + +If Claude reports a refused tool call, ask it for the error text. These errors mean that a `PreToolUse` hook didn’t give a decision, which refuses the call even when [`onFailure`](</docs/en/hooks#block-the-action-when-a-hook-fails>) is unset: + + * **`the hook failed`** : on a call from Claude’s code, your hook couldn’t start, was killed, exited with 126, 127, or a code above 128, or returned an HTTP error or invalid output. Fix the hook + * **`the hook did not finish`** : your hook timed out on a call from Claude’s code, or on any other tool call once Claude has run code in the session. Raise the hook’s [`timeout`](</docs/en/hooks#common-fields>) + +To let calls go ahead when a `command` or `http` hook fails or times out, set `"onFailure": "continue"` on it. If a `command` hook exits with an ordinary code such as 1, the call goes ahead unless you set `"onFailure": "block"`. + +### Code output withheld by a hook + +If Claude reports a hook’s block reason where you expected output from Claude’s code, check your [`UserPromptSubmit`](</docs/en/hooks#userpromptsubmit>) hooks. When code can run in the background, `command`, `http`, and `mcp_tool` hooks on that event also run on code output. To let the output through, change the hook so that it doesn’t block when `source` in its input is `poll_event`. + +## Related resources + + * [Permission modes](</docs/en/permission-modes>): compare auto mode with the modes that prompt you + * [Hooks reference](</docs/en/hooks>): write `PreToolUse` and `UserPromptSubmit` hooks + * [Managed settings](</docs/en/managed-settings>): apply one configuration across an organization