3.4 Bash Mode
Course: Claude Code - Essentials Section: Basic Input & Interaction Video Length: 2-5 minutes Presenter: Daniel Treasure Next Video: Section 4 - Claude Desktop App
Opening Hook
So far you've given Claude context with @files, controlled behavior with /commands, and created custom shortcuts with skills. Now the final piece: run actual shell commands without leaving the session. Type !npm test and watch your tests run right there in the conversation.
Key Talking Points
- The ! Prefix: Direct Shell Access
- Any command starting with
!runs in your shell - Results appear in the conversation immediately
- Claude sees the output and can respond intelligently
-
Example:
!npm testruns tests, Claude analyzes failures -
Why This Matters
- No context-switching between terminal and Claude Code
- Claude can see test failures and fix them
- Feedback loop is instant: code → test → fix → re-test
-
Everything in one conversation
-
Common Use Cases
- Build commands:
!npm run build,!cargo build - Tests:
!npm test,!python -m pytest - File listing:
!ls -la src/,!find . -name "*.todo" - Git status:
!git status,!git log --oneline -
Environment checks:
!node --version,!python3 --version -
Safety by Default
- Bash commands require explicit approval (unless you allow all)
- Destructive commands (
rm -rf /) prompt for confirmation - You remain in control of what executes
-
Commands are logged and reviewable
-
Feedback Loop: The Real Power
- Ask Claude to write code
!npm testto see if it works- Claude sees test output and improves
-
No manual running tests, copying errors, pasting them back
-
Permissions
- Default mode: asks for each bash command
/permissionsshows what's pre-approved- Can pre-approve common commands:
npm run *,git *, etc. - Check mode with
/configbefore big automation runs
Demo Plan
Live Session Walkthrough (3-5 minutes):
-
Setup
bash cd /path/to/project claude -
Simple List Command (45 seconds)
- Say: "Let me see what files are in this project"
- Type:
!ls -la src/ - Show output appears in conversation
-
Say: "Claude sees the file structure instantly"
-
Check Version (30 seconds)
- Type:
!node --version - Show output
-
Say: "This confirms our Node version"
-
Run Tests (1 minute)
- Say: "Now the real power—let Claude see test results"
- Type:
!npm test(or project's test command) - Show test output in session
- Ask Claude: "Why is this test failing?"
-
Claude analyzes failure, suggests fix
-
Fix + Re-test (1 minute)
- Claude proposes a fix
- You approve it (Claude edits file)
- Type:
!npm testagain - Show tests passing
-
Say: "That's the feedback loop—instant verification"
-
Git Status (30 seconds)
- Type:
!git status - Show changed files
- Ask Claude: "Create a commit for these changes"
-
Claude uses git info in its response
-
Show Permission Prompt (30 seconds)
- If using default mode, show the "approve this command?" prompt
- Click "Approve once" or "Approve for session"
- Explain: "Safety first—you control what runs"
Code Examples & Commands
File & Directory Operations
# List files
!ls -la src/
# Find specific files
!find . -name "*.todo" -type f
# Count lines of code
!wc -l **/*.ts
# Show file content
!cat src/index.ts
Build & Test Operations
# Run tests (most projects)
!npm test
# Build project
!npm run build
# Specific test file
!npm test -- src/auth.test.ts
# Python projects
!python -m pytest tests/
# Rust projects
!cargo test
Git Operations
# Check status
!git status
# See recent commits
!git log --oneline -10
# Diff current changes
!git diff
# See uncommitted changes
!git diff --cached
Environment & Version Checks
# Node version
!node --version
# NPM version
!npm --version
# Python version
!python3 --version
# Environment variables
!echo $PATH
# System info
!uname -a
Real-World Workflows
# 1. Ask Claude to write code
# Claude: [writes authentication module]
# 2. Run tests immediately
!npm test
# Output: 5 tests passing, 2 failing
# 3. Claude sees output and fixes failures
# Claude: [updates code based on test failures]
# 4. Run tests again
!npm test
# Output: all 7 tests passing
# 5. Create commit
!git add .
!git status
# Claude: Commit message based on changes and test output
Gotchas & Tips
- Gotcha: Commands must start with ! at the beginning
- Good:
!npm test - Bad:
run !npm test -
The
!tells Claude Code this is a shell command, not a question -
Gotcha: Output shows in chat, not in separate terminal
- This is intentional—Claude sees the output
- Long outputs scroll in the conversation
-
If output is huge (10,000+ lines), it gets truncated
-
Tip: Use ! for fast feedback loops
- Code → Test → Debug → Fix cycle
- All in one session, no context switching
-
Much faster than manual terminal use
-
Tip: Check !git status before asking for commits
!git statusshows what changed- Claude can see exactly what it's committing
-
Prevents "did I commit the right files?" uncertainty
-
Gotcha: Permissions may block commands
- Default mode asks for permission on first bash command
- Check
/permissionsto see pre-allowed commands -
Some corporate setups deny dangerous commands (rm, curl, etc.)
-
Tip: Use !npm test as your verification
- Every code change → immediate test feedback
- Claude sees failures and adapts
-
Much more reliable than manual testing
-
Gotcha: Long-running commands time out
- Bash commands have timeout (typically 30-60 seconds)
- Use for quick checks, builds, tests
-
Not ideal for server startups or infinite loops
-
Tip: Combine with custom commands
- Custom command
/test-and-refactorcan include!npm test - Command body: "Run
!npm testand refactor any failures" -
Next level of automation
-
Gotcha: Environment is isolated per session
!export MY_VAR=valuedoesn't persist across commands- Each
!command starts fresh shell context -
Workaround: set env via Claude Code settings
-
Tip: Use !git commands to inform commits
!git diffshows exactly what changed!git log --oneline -5shows context- Claude creates better commit messages with this info
Lead-out
You've now mastered the core input methods: @ files for context, / commands for control, custom skills for automation, and ! bash for real-time feedback. These four tools are the foundation of being fast with Claude Code.
Now we move to the Claude Desktop App (Section 4). While the terminal is powerful, the desktop app brings visual workflows, session management, and file browsing that make handling large projects much easier. See you there.
Reference URLs
- Official Docs - Bash Integration: https://code.claude.com/docs/en/cli-reference (section: "Core CLI Commands")
- Official Docs - Permissions for Bash: https://code.claude.com/docs/en/permissions (section: "Permission Tiers" and "Tool-Specific Rules")
- Official Docs - Common Workflows: https://code.claude.com/docs/en/common-workflows (search: "testing" and "debugging")
Prep Reading
- Official: CLI Reference docs - shows bash command execution details
- Official: Permissions documentation - understand how bash commands are controlled
- Context: Common workflows article shows bash commands in real-world scenarios
- Recent Articles: Creator's workflow heavily uses bash commands for verification