from line 148
148148
149149Each tool call in the code goes through your `deny` and `ask` [permission rules](https://code.claude.com/docs/en/permissions.md) and [`PreToolUse` hooks](https://code.claude.com/docs/en/hooks#pretooluse) under the tool's usual name, such as `Bash` or an [MCP tool's name](https://code.claude.com/docs/en/permissions.md#mcp). Beyond rules and hooks, a classifier reviews the code in auto mode, and you answer prompts in the modes that ask:
150150
151* **[Auto mode](https://code.claude.com/docs/en/permission-modes.md#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](#permission-prompt-with-a-countdown)
151* **[Auto mode](https://code.claude.com/docs/en/permission-modes.md#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](#permission-prompt-with-a-countdown), such as calls in code that you approved yourself after repeated classifier blocks
152152* **Other [permission modes](https://code.claude.com/docs/en/permission-modes.md)**: you're prompted for each tool call that would prompt you in that mode
153153
154154If you have a `PreToolUse` hook that allows or blocks shell commands, make it check each part of a command, as [Bash rules do](https://code.claude.com/docs/en/permissions.md#compound-commands). In Code Mode, a `git push` in a folder named `app` can reach your hook as `cd 'app' && git push`.
from line 196
196196* **No, or `Esc`**: the code stops, and changes from calls that already finished stay in place
197197* **No, with a [comment](https://code.claude.com/docs/en/permissions.md#add-a-comment-when-you-answer-a-permission-prompt)**: the call is refused, and the code can continue with its other calls
198198
199### Limit shell commands with the sandbox
200
201Your [sandbox](https://code.claude.com/docs/en/sandboxing.md) settings apply to the shell commands that code runs. The JavaScript itself and its file, web, and MCP tool calls run [outside the sandbox](https://code.claude.com/docs/en/sandboxing.md#what-runs-outside-the-sandbox). To isolate the JavaScript and those calls too, run Claude Code in a [container or virtual machine](https://code.claude.com/docs/en/sandbox-environments.md).
202
203To keep commands in the sandbox when code requests to run them unsandboxed, turn on [strict sandbox mode](https://code.claude.com/docs/en/sandboxing.md#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.
204
199205### Long-running code
200206
201207While code runs a long build or test, Claude either waits for it or lets it continue in the background:
from line 224
218224
219225### Check code output with a hook
220226
221To check or redact what the code returns before Claude reads it, write a [`PostToolUse` hook](https://code.claude.com/docs/en/hooks#posttooluse) that matches `REPL`, the tool that runs the code. Read the output from `tool_response`, which has fields such as these:
227To check or redact what the code returns before Claude reads it, write a [`PostToolUse` hook](https://code.claude.com/docs/en/hooks#posttooluse) that matches `REPL`, the tool that runs the code. The same hook runs when [background code](#long-running-code) finishes and when code throws an error.
222228
229#### Read code output in the hook
230
231In your `PostToolUse` hook, read the output from `tool_response`, which has fields such as these:
232
223233```json theme={null}
224234{
225235 "code": "(await $`cat notes.txt`.text())",
from line 240
230240}
231241```
232242
243#### Redact code output
244
233245To hide part of the output, return a changed copy of `tool_response` as [`updatedToolOutput`](https://code.claude.com/docs/en/hooks#posttooluse-decision-control), and build the copy this way:
234246
235247* **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
from line 265
253265}
254266```
255267
256To test the hook, put a value that it should hide into a file, and ask Claude to read and quote the file. Type the path without `@`, and check that Claude's reply shows your replacement text.
268To 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.
257269
258Before you rely on the hook, plan for these cases:
270> [!WARNING]
271>
272> 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.
259273
260* **Background and failed code**: use the same `PostToolUse` hook for both. It runs when [background code](#long-running-code) finishes and when code throws an error
261* **Blocking**: return `updatedToolOutput` even when your hook blocks. Without it, Claude still reads the output
262* **Hook failures**: when your check hits an error, return 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
263* **Refused calls**: 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
264* **`UserPromptSubmit` checks**: if you check code output in a [`UserPromptSubmit` hook](https://code.claude.com/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](https://code.claude.com/docs/en/managed-settings.md)
274#### Redact when your hook blocks or hits an error
265275
276Return a changed copy of `tool_response` as `updatedToolOutput` even when your hook blocks or hits an error:
277
278* **Your hook blocks**: print the [redacted copy](#redact-code-output) in the same JSON as [`"decision": "block"`](https://code.claude.com/docs/en/hooks#posttooluse-decision-control). Without the copy, Claude still reads the original output
279* **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
280
281#### Move a check from a `UserPromptSubmit` hook
282
283If you check code output in a [`UserPromptSubmit` hook](https://code.claude.com/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](https://code.claude.com/docs/en/managed-settings.md).
284
266285## Troubleshooting
267286
268287### Code Mode doesn't start
from line 308
289308
290309### Permission prompt with a countdown
291310
292When 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:
311In auto mode, if you approve code yourself after [repeated classifier blocks](https://code.claude.com/docs/en/permission-modes.md#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:
293312
294313```text theme={null}
295314Claude Code will automatically block this request in 1:59, to avoid holding up an unattended session
from line 316
297316
298317Answer 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.
299318
319Before 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](https://code.claude.com/docs/en/setup.md#update-claude-code) to v2.1.327 or later.
320
300321### Tool call refused by a hook
301322
302323If 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`](https://code.claude.com/docs/en/hooks#block-the-action-when-a-hook-fails) is unset:
from line 329
308329
309330### Code output withheld by a hook
310331
311`UserPromptSubmit operation blocked by hook` in place of output from code means that your [`UserPromptSubmit`](https://code.claude.com/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.
332If you expected output from code and see `UserPromptSubmit operation blocked by hook` in Claude's reply, your [`UserPromptSubmit`](https://code.claude.com/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.
312333
313334On 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:
314335
No line in this hunk matches that.