In Claude Code, what does starting a prompt with `!` do, and how does it differ from asking Claude to run that command?
answer
- you run it, not the model
- output joins the conversation
- Claude replies to the output
- respondToBashCommands set to false
- no approval prompt, usually no sandbox
basics
~20 sA leading ! puts Claude Code in shell mode: the command runs directly with no approval prompt, its command and output are added to the conversation, and since v2.1.186 Claude replies to that output automatically.
solid answer
~40 sTyping `! npm test` runs the command yourself instead of asking the model to call its Bash tool. The command and its output are added to the conversation context, and since v2.1.186 Claude responds to the output on its own, at the cost of a normal prompt; setting `respondToBashCommands` to `false` brings back the older behaviour of adding output silently. Because you are the one running it, there is no permission prompt, and in most sessions the command runs outside the Bash sandbox, which applies to commands Claude runs. Asking Claude instead routes the command through the permission mode, your rules and the sandbox. Shell mode also supports `Ctrl+B` backgrounding and `Tab` completion from earlier `!` commands.
go deeper
Recall that ! runs a command yourself and that its output goes into the conversation, so Claude can explain a failing test run without a second prompt.
Explain the reply behaviour: Claude answers ! output by default since v2.1.186, it costs a normal prompt, and respondToBashCommands set to false makes the output land silently.
Show you know which layers a typed command skips: no approval prompt and, in most sessions, no sandbox. Choose ! for vetted commands and let Claude run unvetted ones through permissions.
Weigh the speed of ! against the guardrails it bypasses when standardising a team workflow, and decide whether background sessions or a scrubbed Linux environment are needed for typed commands to be contained.
## What shell mode is In Claude Code, a prompt that starts with `!` is not sent to the model as a request. It switches the input box into **shell mode**, and pressing Enter runs the rest of the line as a shell command on your machine, the same as typing it in a terminal: ```bash ! npm test ! git status ``` The point is speed and control: you already know the command, so there is no reason to describe it to Claude and wait for the model to decide to call its **Bash tool**. You run it yourself, directly. ## What enters the context, and what Claude does next Shell mode is not a side terminal. Its defining property is that **the command and its output are added to the conversation context**, so everything Claude does afterwards can use them. - **Default since v2.1.186:** once the output lands in the transcript, Claude **responds to it automatically**. `! npm test` followed by nothing else gets you an explanation of the failures. That reply is a model turn and **costs the same as sending a normal prompt**. - **Before v2.1.186:** the output was added to context silently and Claude waited for your next prompt. Anyone who learned the tool earlier may still expect that. - **The switch:** the `respondToBashCommands` setting (default `true`, valid in any settings file) set to `false` restores the silent behaviour, which suits running several diagnostic commands and then asking one question about all of them. ## How it differs from asking Claude to run the command | | `! cmd` typed by you | "please run cmd" | | :- | :- | :- | | Who decides to run it | You | The model, via the Bash tool | | Approval prompt | None: you are the one running it | Subject to the permission mode and allow/ask/deny rules | | Sandbox (when enabled) | Runs outside it in most sessions | Commands Claude runs are sandboxed | | Output in context | Yes | Yes, as a tool result | | Model call | Only for the reply (unless `respondToBashCommands` is `false`) | The request itself plus the reply | The sandbox row surprises people. The Bash sandbox applies to commands **Claude** runs; a command you type at the `!` prompt has the access you already have in any terminal. Strict sandbox mode covers shell-mode commands only in a background session and in a Linux session with `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB` set; before v2.1.260 it covered them in every session. How the sandbox is configured is a subject of its own. ## Shell-mode conveniences 1. **Backgrounding:** a long command started with `!` can be moved to the background with `Ctrl+B`, the same key used for Claude's own Bash calls. 2. **Completion:** `Tab` completes a partial command from your earlier `!` commands in this project, and a token containing `/` (such as `./src/`) opens a file path dropdown. 3. **Leaving the mode:** `Escape`, `Backspace` or `Ctrl+U` on an empty prompt returns to normal input. 4. **Pasting:** text that starts with `!` pasted into an empty prompt enters shell mode, just like typing it. 5. **Stash:** `Ctrl+S` stashes a `!` draft and restores it in shell mode. ## When to use which - Use `!` when **you know the exact command** and want its output in front of Claude: a failing test run, `git status`, a log tail. - Ask Claude when you want the model to **choose** the command, or when you want the permission and sandbox layers in the loop for a command you have not vetted. - Remember that output size matters: a huge `!` output fills the context window just as a huge tool result would.
- You want to run three diagnostic commands with `!` and then ask one question about all of them. How?Set `respondToBashCommands` to `false` in a settings file. Each `!` command's output is then added to context without Claude replying, so you avoid three separate model turns and their cost, and you ask your one question once all three outputs are in the conversation.
- Your organisation enabled the Bash sandbox in strict mode. Does a command typed after `!` run sandboxed?In most sessions, no. Strict sandbox mode applies to the commands Claude runs; a command you type at the `!` prompt runs with your own terminal access. The exceptions are a background session and a Linux session with `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB` set. Before v2.1.260 strict mode sandboxed typed commands in every session.
- The output of a ! command is shown to you, but Claude never sees it.
- A ! command waits on the same approval prompt as Claude's own Bash calls.
- Claude never reacts to ! output until you send another prompt.
- Enabling the Bash sandbox also sandboxes every command typed after ! in any session.
- Shell mode is free because it never triggers a model call.
Assumes Claude Code 2.1.286; Claude has replied to ! output by default since 2.1.186, and strict sandbox mode stopped covering typed commands in most sessions in 2.1.260.