Skip to main content
Tips

beginner tip

Run Shell Commands Without Leaving Claude Code

AIErudit angle: Bash mode collapses the constant tab-switching that fragments an AI session — prefix any command with ! and it runs in your shell while the output lands back in Claude's context. Keeping the loop of run, observe, and ask in one place is a small delivery habit that compounds across a debugging session.

bash-modeshellclaude-codetips
Tip visual

Published: Feb 11, 2026 Updated: 2026-05-30

Original: https://wmedia.es/en/tips/claude-code-bash-mode-run-shell-commands

Claude Code has a built-in bash mode: type ! followed by any command and it runs directly in your shell, without Claude interpreting or approving it. Output appears in real time and gets added to the conversation context — Claude sees the result and can act on it.

This is one of those features you don't discover by reading the docs — you see someone use it. You're debugging, need a quick git log or a cat of a file, and instead of jumping to another tab you just type ! git log --oneline -5. Seems minor, but it eliminates the constant context switching.

It's not an obvious feature, but once you discover it, it changes how you work. No need to open another terminal or split pane. You type, it runs, you keep talking.

TL;DR Prefix any command with ! to run it directly. Use Ctrl+B to send long-running processes to the background. Claude sees the output from both.

Result:

> ! git status

On branch feature/auth
Changes not staged for commit:
  modified:   src/auth/login.ts
  modified:   src/auth/session.ts

How to use it

1. Run a quick command

Type ! followed by the command:

! npm test
! git diff --stat
! ls -la src/

Claude doesn't intervene — the command goes straight to your shell. But the output is added to the conversation, so you can ask "what failed?" right after.

2. Send a long process to the background

If a command takes too long (builds, tests, dev servers), press Ctrl+B while it's running:

! npm run build
# taking too long → press Ctrl+B
# Claude is available again while the build finishes in background

You can also ask Claude directly to run something in the background.

3. History-based autocomplete

Type ! followed by the first few letters and press Tab. Claude Code autocompletes from previous ! commands in the current project.

! np  → Tab → ! npm test

And to search your previous prompts, not just ! commands? Press Ctrl+R for reverse search over your prompt history — across every project, too.

Reference

AspectDetail
Prefix! at the start of input
ExecutionDirectly in your shell, no Claude interpretation
OutputShown in real time and added to conversation context
BackgroundCtrl+B during execution (tmux: press twice)
AutocompleteTab completes from project's ! command history
PermissionsNo approval needed — it's your terminal

Official docs: Interactive mode — Bash mode