Stop Copy-Pasting Output Into Claude Code: Use the ! Shell Mode
Claude Code's bang prefix runs shell commands right in the session and adds the output to the conversation, so the agent can see what happened without you switching tabs or copying and pasting. It's a small habit to pick up, and it saves a lot of fiddling about.
There's a small annoyance in AI coding sessions that adds up over a day. Claude asks you to run a command (refresh an SSO token, check a database, pull the latest from main), so you flip to another terminal, run it, then copy the output back into the chat so the agent can see what happened. Do that twenty times a day and it starts to wear you down.
Claude Code has a fix for this that's barely documented and easy to miss: the ! prefix. If you type ! at the start of the input, the rest of the line runs in your shell, and both the command and its full output go into the conversation. You don't need to copy and paste or switch tabs, and there's no permission prompt either.
Once you know about it, you'll probably wonder how you managed without it.
What Shell Mode Actually Does
If you press ! as the first character of an empty prompt, Claude Code switches to shell mode. Anything you type after the bang runs as a normal shell command, using your own shell, working directory and environment variables. The official docs describe it in one short line:
Run shell commands directly without going through Claude by prefixing your input with
!
That line skips over the second half of the feature, though. Shell mode does three things at once:
- Executes the command in your local shell, exactly as if you had typed it in a normal terminal.
- Streams real-time output to the Claude Code interface so you can watch progress.
- Adds the command and its full output to the conversation context, where Claude can read and reason about it on the next turn.
The third point is the really useful one, because the agent sees the output as well as you. If you run ! git status and see three modified files, Claude sees those same three files in its next response. If you run ! npm test and a test fails, Claude reads the failure and can suggest a fix, so the chat turns into a place you both work from.
Shell mode also skips Claude's tool approval system. The command comes from you, so there's no permission prompt to click through, and Claude Code just records what happened.
A Real Example: SSO Tokens Mid-Session
Here's an example from a recent session. Claude was halfway through a CDK migration when an AWS API call failed because the SSO session had expired. Rather than asking you to "run the login command and paste the output", it offered the command with the ! prefix already on it:
SSO token's expired. Run this in your terminal to refresh, then I'll proceed:
! aws sso login --sso-session studia
(Pasting with the ! prefix runs it in this session so I see the result.)
Once that's done I'll verify state, then run the migration steps.
Pressing the up arrow in shell mode and accepting the suggestion ran the command right there in the session:
! aws sso login --sso-session studia
⎿ Attempting to open your default browser. If the browser does not open, open the following URL.
If you are unable to open the URL on this device, run this command again with the '--use-device-code' option.
https://oidc.eu-north-1.amazonaws.com/authorize?response_type=code&...
Successfully logged into Start URL: https://studia.awsapps.com/start
The browser opened, the OAuth round trip finished, and Claude saw "Successfully logged into Start URL" in the next turn. It picked up straight away where it had left off and carried on with the migration, without a second terminal, any copying and pasting, or a "what was the output?" message.
The old way would be to switch to another terminal, log in, copy the success message, switch back, paste it into the chat and type "done, you can continue now". That's four context switches, and shell mode turns them into one keystroke.
Where It Earns Its Keep
The bang prefix is most useful for commands that really belong to you, the ones the agent shouldn't or can't run itself:
- Authentication flows. SSO logins,
gcloud auth login,gh auth login,vault login. These usually involve a browser or device code that has to come from the human. - Sensitive checks. Reading production credentials, querying a customer database, anything where you want eyes on the command before it fires.
- Quick verification.
! git status,! docker ps,! kubectl get pods. Quick checks where it helps the agent to see the result without having to ask. - Environment manipulation.
! source .envrc,! nvm use 20,! direnv allow. Shell state changes that need to live in your interactive shell. - Long-form output you would otherwise paraphrase. Logs, stack traces, build errors. Pipe them in once with
!instead of typing "the test failed with a timeout error, here's the trace."
In each case you run the command and Claude reads the result, so you don't have to stop and "explain to the agent what I just saw".
Productivity Mechanics: Autocomplete, History, Backgrounding
Shell mode also borrows a few handy features from a normal terminal:
- Tab-completion of past
!commands. Type! npm teand press Tab and Claude Code will offer to complete it from your previous shell-mode invocations in this project. This helps with the test, lint, build and deploy commands you run dozens of times a day. Ctrl+Bbackgrounding. Long-running commands like dev servers can be sent to the background withCtrl+B(twice if you're inside tmux). The output streams to a file Claude can read with its Read tool, and you keep working.- Easy exit. Pressing
Escape,Backspace, orCtrl+Uon an empty shell-mode prompt drops you back to the regular Claude prompt, and you don't have to retype anything. - Paste-to-enter. Pasting text that starts with
!into an empty prompt automatically enters shell mode, which is handy when you copy a one-liner from a runbook or another agent's response.
It also works nicely with Claude's prompt suggestions. When Claude proposes a ! command in its response (as in the SSO example above), pressing Tab on the greyed-out suggestion picks it up directly into shell mode, ready to run.
Caveats Worth Knowing
Shell mode is simple on purpose, so there are a few things it doesn't handle well:
- Interactive prompts can be awkward. Commands that wait on stdin (
vim,less, anything with an interactive REPL) don't always behave well in shell mode. For those, drop out and use a regular terminal. - No permission prompt. Because the command is yours, Claude Code's permission rules don't apply. So take care with what you run, especially when
!autocomplete pulls in older commands, because a! rm -rfthat was safe in one project might not be in another. - History expansion is disabled. The classic shell
!!and!$history expansions are off by default in Claude Code, so you can't use bash-style history shortcuts inside a shell-mode line. Use Tab autocomplete orCtrl+Rreverse search instead. - Working directory matters. Shell mode runs in your current working directory. If Claude is operating on a subdirectory, you may need to
cdfirst or use absolute paths. - It's per session. Output captured in shell mode lives in that conversation. Start a fresh session and Claude won't remember what you ran earlier.
The Cousins: /, @, and #
The ! prefix is one of a small family of single-character entry points in Claude Code, each doing something different at the start of an input:
/is for slash commands, which covers built-in actions, custom skills and plugin commands. Type/on its own to see the menu.@is a file path mention. It triggers autocomplete over files in the project, so you can drop a precise path into your prompt without typing it.#is a memory reference. It pulls fromCLAUDE.mdand other memory files into the conversation.!is shell mode, the subject of this article.
Between them they cover most of the small annoyances in an AI coding session: running saved workflows (/), pointing at code (@), recalling saved context (#) and running commands in the session (!). It's worth learning all four, as they pay you back faster than any single power user keybinding.
A Small Habit Change
On its own, the bang prefix won't change the way anyone works. It's a one character shortcut that removes one specific annoyance, the moment when the agent needs information from your shell and you have to go and fetch it yourself.
Still, small fixes like this are how AI coding sessions get faster. Most of the time lost in an agentic workflow goes on you passing things back and forth between the agent and the rest of the system, and ! takes one of those steps away completely.
So next time Claude Code asks you to run a command and report back, try putting ! in front of it before you reach for another terminal. Once you're used to it, you'll likely find the old way feels a bit slow.
References
Related insights
View allTeaching Claude Code Your House Style with Agent Skills
Agent Skills let you put your team's conventions, workflows and checklists into a SKILL.md file that Claude Code loads when it needs it. Here's how skills differ from CLAUDE.md, why the description field matters so much, and the real skill we use to run this blog.
Website Accessibility: What the Equality Act Actually Requires
Your website counts as a service under the Equality Act 2010, and you have to make it accessible before anyone complains. UK enforcement is rare, but the lost customers are real, so we cover the £274bn Purple Pound, the four failures behind most broken sites, and a free ten-minute self-check.