CloudCodeTree LogoCloudCodeTree
AI NewsTutorialsAbout
CloudCodeTree Logo
CloudCodeTree
  • AI News
  • Tutorials
  • About
← Back to AI News
Run a Command in Your Claude Code Session and Skip the Copy-Paste Step: The `!` Prefix

Run a Command in Your Claude Code Session and Skip the Copy-Paste Step: The `!` Prefix

Chris Harper

2 min read

Aug 31, 2026 · 12:07 UTC

AI
Workflow
Claude Code
Best Practices

TL;DR: In an interactive Claude Code session, prefix any command with ! and Claude automatically explains its output — no second prompt, no copy-pasting. The explanation has full conversation context.

When you're debugging inside a Claude Code session, the usual loop is: run a command in your terminal, copy the output, paste it back into Claude, ask "what's wrong?" The ! prefix collapses that into one step.

How it works

Type ! npm test at the Claude Code prompt. The command runs in the session's shell, the output lands in the transcript, and Claude explains it immediately — as if you had pasted the log and asked "diagnose this." No second prompt. The response inherits everything in your current conversation: the file you're working on, the change you just made, the error you mentioned three turns ago.

Practical patterns

> ! npm test
> ! cargo build --release
> ! git diff --stat
> ! python -m pytest tests/auth.py -v
> ! docker logs --tail 50 api-container

Each one runs, and Claude explains the result in context. "Why is this build failing?" becomes implicit — Claude already knows what you were building.

The key difference from claude -p "explain this" < output.txt: the ! variant runs inside a live session, so Claude's answer can reference earlier decisions, the files it has already read, and the specific changes that might have caused the failure. The -p pattern is for scripts and pipelines with no conversation history.

Turn it off if you don't want it

Set respondToBashCommands: false in settings.json to restore the old behavior where ! commands add output to context without triggering a response. Useful in a long diagnostic loop where you want to run several commands before asking Claude to synthesize the results.

Real limit: Each ! response is billed the same as a normal turn — a token cost against your session budget. Running many commands in quick succession (a debug loop of twenty ! pytest runs) can eat through your context budget faster than typed turns alone. If you're in a tight session, run the commands together and ask once rather than triggering a response on each.

Sources: Shell mode with the ! prefix — Claude Code docs · Week 26 What's New — code.claude.com