1231 words Slides

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

  1. The ! Prefix: Direct Shell Access
  2. Any command starting with ! runs in your shell
  3. Results appear in the conversation immediately
  4. Claude sees the output and can respond intelligently
  5. Example: !npm test runs tests, Claude analyzes failures

  6. Why This Matters

  7. No context-switching between terminal and Claude Code
  8. Claude can see test failures and fix them
  9. Feedback loop is instant: code → test → fix → re-test
  10. Everything in one conversation

  11. Common Use Cases

  12. Build commands: !npm run build, !cargo build
  13. Tests: !npm test, !python -m pytest
  14. File listing: !ls -la src/, !find . -name "*.todo"
  15. Git status: !git status, !git log --oneline
  16. Environment checks: !node --version, !python3 --version

  17. Safety by Default

  18. Bash commands require explicit approval (unless you allow all)
  19. Destructive commands (rm -rf /) prompt for confirmation
  20. You remain in control of what executes
  21. Commands are logged and reviewable

  22. Feedback Loop: The Real Power

  23. Ask Claude to write code
  24. !npm test to see if it works
  25. Claude sees test output and improves
  26. No manual running tests, copying errors, pasting them back

  27. Permissions

  28. Default mode: asks for each bash command
  29. /permissions shows what's pre-approved
  30. Can pre-approve common commands: npm run *, git *, etc.
  31. Check mode with /config before big automation runs

Demo Plan

Live Session Walkthrough (3-5 minutes):

  1. Setup bash cd /path/to/project claude

  2. Simple List Command (45 seconds)

  3. Say: "Let me see what files are in this project"
  4. Type: !ls -la src/
  5. Show output appears in conversation
  6. Say: "Claude sees the file structure instantly"

  7. Check Version (30 seconds)

  8. Type: !node --version
  9. Show output
  10. Say: "This confirms our Node version"

  11. Run Tests (1 minute)

  12. Say: "Now the real power—let Claude see test results"
  13. Type: !npm test (or project's test command)
  14. Show test output in session
  15. Ask Claude: "Why is this test failing?"
  16. Claude analyzes failure, suggests fix

  17. Fix + Re-test (1 minute)

  18. Claude proposes a fix
  19. You approve it (Claude edits file)
  20. Type: !npm test again
  21. Show tests passing
  22. Say: "That's the feedback loop—instant verification"

  23. Git Status (30 seconds)

  24. Type: !git status
  25. Show changed files
  26. Ask Claude: "Create a commit for these changes"
  27. Claude uses git info in its response

  28. Show Permission Prompt (30 seconds)

  29. If using default mode, show the "approve this command?" prompt
  30. Click "Approve once" or "Approve for session"
  31. 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

  1. Gotcha: Commands must start with ! at the beginning
  2. Good: !npm test
  3. Bad: run !npm test
  4. The ! tells Claude Code this is a shell command, not a question

  5. Gotcha: Output shows in chat, not in separate terminal

  6. This is intentional—Claude sees the output
  7. Long outputs scroll in the conversation
  8. If output is huge (10,000+ lines), it gets truncated

  9. Tip: Use ! for fast feedback loops

  10. Code → Test → Debug → Fix cycle
  11. All in one session, no context switching
  12. Much faster than manual terminal use

  13. Tip: Check !git status before asking for commits

  14. !git status shows what changed
  15. Claude can see exactly what it's committing
  16. Prevents "did I commit the right files?" uncertainty

  17. Gotcha: Permissions may block commands

  18. Default mode asks for permission on first bash command
  19. Check /permissions to see pre-allowed commands
  20. Some corporate setups deny dangerous commands (rm, curl, etc.)

  21. Tip: Use !npm test as your verification

  22. Every code change → immediate test feedback
  23. Claude sees failures and adapts
  24. Much more reliable than manual testing

  25. Gotcha: Long-running commands time out

  26. Bash commands have timeout (typically 30-60 seconds)
  27. Use for quick checks, builds, tests
  28. Not ideal for server startups or infinite loops

  29. Tip: Combine with custom commands

  30. Custom command /test-and-refactor can include !npm test
  31. Command body: "Run !npm test and refactor any failures"
  32. Next level of automation

  33. Gotcha: Environment is isolated per session

  34. !export MY_VAR=value doesn't persist across commands
  35. Each ! command starts fresh shell context
  36. Workaround: set env via Claude Code settings

  37. Tip: Use !git commands to inform commits

    • !git diff shows exactly what changed
    • !git log --oneline -5 shows 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