Computer screen displaying code and terminal output

Stop Copy-Pasting Output Into Claude Code: Use the ! Shell Mode

Claude Code's bang prefix runs shell commands inline and feeds the output straight back into the conversation, so the agent can see what just happened without you tab-switching or copy-pasting. A small habit change with an outsized payoff.

5 May 20265 min readBy LibraBit Team

There is a small friction in AI coding sessions that adds up. Claude asks you to run a command — refresh an SSO token, check a database, pull the latest from main — and you have to flip to another terminal, run it, then copy the output back into the chat so the agent can see what happened. Repeat that twenty times a day and it starts to bite.

Claude Code has a fix for this that is barely documented and easy to miss: the ! prefix. Type ! at the start of the input and the rest of the line runs in your shell, with both the command and its full output captured into the conversation. No copy-pasting. No tab-switching. No permission round-trip.

It is one of those features you learn about once and immediately wonder how you got by without it.

What Shell Mode Actually Does

Press ! as the first character of an empty prompt and Claude Code drops into shell mode. Anything you type after the bang runs as a regular shell command — your shell, your working directory, your environment variables. The official docs describe it tersely:

Run shell commands directly without going through Claude by prefixing your input with !

What that one line glosses over is the second half of the feature. Shell mode does three things at once:

  1. Executes the command in your local shell, exactly as if you had typed it in a normal terminal.
  2. Streams real-time output to the Claude Code interface so you can watch progress.
  3. Adds the command and its full output to the conversation context, where Claude can read and reason about it on the next turn.

That last point is the one that matters. The output is not just shown to you — it is shown to the agent. 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. The transcript becomes the shared workspace.

Critically, shell mode bypasses Claude's tool-approval system. The command is yours, not the agent's, so there is no permission prompt to click through. You ran it. You own it. Claude Code just records what happened.

A Real Example: SSO Tokens Mid-Session

Here is a concrete example from a recent session. Claude was halfway through a CDK migration when an AWS API call failed because the SSO session had expired. Instead of asking the user to "run the login command and paste the output," it offered the bang-prefixed version directly:

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 inline:

!  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 completed, and Claude saw "Successfully logged into Start URL" in the next turn. It immediately picked up where it had left off and continued the migration. There was no second terminal involved, no copy-paste, and no need for a "what was the output?" message.

Compare that with the alternative: switch to another terminal, log in, copy the success message, switch back, paste it into chat, type "done, you can continue now." That is four context switches replaced by one keystroke.

Where It Earns Its Keep

The bang prefix is most valuable for commands that are user-owned by nature — things the agent should not, or cannot, run directly:

  • 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 — sanity checks where the agent benefits from seeing 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."

The pattern is the same in every case: the user runs the command, Claude reads the result. The friction of "explain to the agent what I just saw" disappears.

Productivity Mechanics: Autocomplete, History, Backgrounding

Shell mode picks up a few quality-of-life features from the terminal proper:

  • Tab-completion of past ! commands. Type ! npm te and press Tab and Claude Code will offer to complete it from your previous shell-mode invocations in this project. Useful for the test, lint, build, and deploy commands you run dozens of times a day.
  • Ctrl+B backgrounding. Long-running commands like dev servers can be sent to the background with Ctrl+B (twice if you are inside tmux). The output streams to a file Claude can read with its Read tool, and you keep working.
  • Easy exit. Pressing Escape, Backspace, or Ctrl+U on an empty shell-mode prompt drops you back to the regular Claude prompt. No need to retype anything.
  • Paste-to-enter. Pasting text that starts with ! into an empty prompt automatically enters shell mode. Convenient when you copy a one-liner from a runbook or another agent's response.

There is also a useful interaction 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 intentionally simple, which means a few things are not handled:

  • Interactive prompts can be awkward. Commands that wait on stdin — vim, less, anything with an interactive REPL — do not always behave well in shell mode. For those, drop out and use a regular terminal.
  • No permission gate. Because the command is yours, Claude Code's permission rules do not apply. Be deliberate about what you run, especially with ! autocomplete pulling from previous commands. A ! rm -rf that looked 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 cannot use bash-style history shortcuts inside a shell-mode line. Use Tab autocomplete or Ctrl+R reverse search instead.
  • Working directory matters. Shell mode runs in your current working directory. If Claude is operating on a subdirectory, you may need to cd first or use absolute paths.
  • It is per-session. Output captured in shell mode lives in that conversation. Start a fresh session and Claude will not 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:

  • / — slash commands. Built-in actions, custom skills, and plugin commands. Type / alone to see the menu.
  • @ — file path mention. Triggers autocomplete over files in the project, so you can drop a precise path into your prompt without typing it.
  • # — memory reference. Pulls from CLAUDE.md and other memory files into the conversation.
  • ! — shell mode. The subject of this article.

Together they cover most of the friction points in an AI coding session: invoking saved workflows (/), pointing at code (@), recalling persistent context (#), and running commands inline (!). Learning all four pays back faster than learning any single power-user keybinding.

A Small Habit Change

The bang prefix is not going to transform anyone's workflow on its own. It is not a new agent or a new model or a new framework. It is a one-character shortcut that removes one specific kind of friction: the moment when the agent needs information from your shell and you have to fetch it manually.

But removing small frictions is exactly how AI coding sessions get faster. Most of the time lost in an agentic workflow is not in the model's thinking — it is in the human's plumbing between the agent and the rest of the system. ! collapses one of those plumbing steps to nothing.

The next time Claude Code asks you to run a command and report back, try prefixing it with ! instead of opening another terminal. Once it becomes muscle memory, the older way of doing it will feel quaintly slow.


References