Run tool calls from code with Code Mode changedcode-mode
Nearest release: v2.1.329, published under an hour before upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 19 Nov 2026 19:00 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 19 Nov 2026 19:07 UTC.
Upstream edited
Recorded here
Lines+59added
Lines−6removed
From line
38
where the diff opens
First seen
13 Nov 2026
this site's first read of the page
Recorded edits8to this page, all time
### Check code output with a hook
The whole hunk
from line 38, old and new numbered
/
from line 38
3838* **Resuming**: you can resume a Code Mode session only in the terminal, with Code Mode on
3939* **Auto mode**: auto mode's classifier [reviews the code, not each tool call](#permission-checks)
4040* **Long-running code**: unless [code can run in the background](#long-running-code), you wait for it to finish, and it stops after ten minutes
41* **Hooks**: you can see [tool calls refused](#tool-call-refused-by-a-hook) when a `PreToolUse` hook can't run or times out, and [code output blocked](#code-output-withheld-by-a-hook) by a `UserPromptSubmit` hook
41* **Hooks**: you can see [tool calls refused](#tool-call-refused-by-a-hook) when a `PreToolUse` hook can't run or times out
4242* **Unavailable features**: you can't use [Remote Control](https://code.claude.com/docs/en/remote-control.md), [Claude in Chrome](https://code.claude.com/docs/en/chrome.md), or [computer use](https://code.claude.com/docs/en/computer-use.md)
4343* **Moving the session**: you can't move the session to the Desktop app or turn it into a [background session](https://code.claude.com/docs/en/agent-view.md), and `/fork` can't start a background copy
4444
from line 151
151151
152152If 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`.
153153
154To 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`.
154To 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](#check-code-output-with-a-hook).
155155
156156> [!WARNING]
157157>
from line 161
161161
162162While code runs a long build or test, Claude either waits for it or lets it continue in the background:
163163
164* **Waiting**: Claude answers after the code finishes, and the code stops after ten minutes, including time you spend at permission prompts
164* **Waiting**: Claude answers after the code finishes, and the code stops after ten minutes. In Manual and `acceptEdits` [modes](https://code.claude.com/docs/en/permission-modes.md#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.
165165* **Background**: you can keep talking to Claude, and the code can run for up to two hours
166166
167167For background code, start your session in auto or `bypassPermissions` mode. If Claude still waits, check your current mode and how you started the session:
168168
169169* **You switched to another mode**: press `Shift+Tab` until you're back in the mode you started in
170* **You started in another mode, or picked the session from the `claude --resume` list**: if [auto mode is available](https://code.claude.com/docs/en/permission-modes.md#eliminate-prompts-with-auto-mode) to you, exit, then run `claude --continue --permission-mode auto` with Code Mode on
170* **You started in another mode**: if [auto mode is available](https://code.claude.com/docs/en/permission-modes.md#eliminate-prompts-with-auto-mode) to you, exit, then run `claude --continue --permission-mode auto` with Code Mode on
171* **You're on a version before v2.1.328 and picked the session from the `claude --resume` list**: exit, [update Claude Code](https://code.claude.com/docs/en/setup.md#update-claude-code), then run the same `claude --resume` command with Code Mode on. To stay on your version, replace `--resume` with `--continue`
171172* **You passed tool names to `--tools`**: start again in auto mode without that flag
172173
174### Check code output with a hook
175
176To 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:
177
178```json theme={null}
179{
180 "code": "(await $`cat notes.txt`.text())",
181 "result": "deploy token: abc123",
182 "stdout": "",
183 "stderr": "",
184 "toolsUsed": ["Bash"]
185}
186```
187
188To 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:
189
190* **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
191* **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
192* **Remove images and PDFs**: if the copy has `images` or `documents` to hide, set that field to `[]`
193
194To hide the deploy token in the `notes.txt` result, print this JSON:
195
196```json theme={null}
197{
198 "hookSpecificOutput": {
199 "hookEventName": "PostToolUse",
200 "updatedToolOutput": {
201 "code": "(await $`cat notes.txt`.text())",
202 "result": "deploy token: REDACTED",
203 "stdout": "",
204 "stderr": "",
205 "toolsUsed": ["Bash"]
206 }
207 }
208}
209```
210
211To 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.
212
213Before you rely on the hook, plan for these cases:
214
215* **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
216* **Blocking**: return `updatedToolOutput` even when your hook blocks. Without it, Claude still reads the output
217* **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
218* **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
219* **`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)
220
173221## Troubleshooting
174222
175223### Code Mode doesn't start
from line 263
215263
216264### Code output withheld by a hook
217265
218If Claude reports a hook's block reason where you expected output from code, check your [`UserPromptSubmit`](https://code.claude.com/docs/en/hooks#userpromptsubmit) hooks. When [code can run in the background](#long-running-code), `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`.
266`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.
219267
268On 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:
269
270* **Update**: if you rely on the hook to check code output, first [move the check to a `PostToolUse` hook](#check-code-output-with-a-hook). Then [update Claude Code](https://code.claude.com/docs/en/setup.md#update-claude-code) to v2.1.328 or later
271* **Stay on your version**: change the hook so that it doesn't block when `source` in its input is `poll_event`
272
220273## Related resources
221274
222275* [Permission modes](https://code.claude.com/docs/en/permission-modes.md): compare auto mode with the modes that prompt you
223* [Hooks reference](https://code.claude.com/docs/en/hooks.md): write `PreToolUse` and `UserPromptSubmit` hooks
276* [Hooks reference](https://code.claude.com/docs/en/hooks.md): write `PreToolUse` and `PostToolUse` hooks
224277* [Managed settings](https://code.claude.com/docs/en/managed-settings.md): apply one configuration across an organization
225278
No line in this hunk matches that.