Quick reference guide for Claude Code CLI commands, shortcuts, and workflows.
npm install -g @anthropic-ai/claude-code
claude # Launch interactive REPL
claude --version # Check version
claude update # Update to latest
| Command | Description |
|---|---|
/help |
Display available commands |
/exit |
Terminate REPL |
/clear |
Reset conversation history |
/config |
Access configuration panel |
/doctor |
Verify installation status |
/cos |
Display session costs and duration |
/compact |
Summarize conversation to save context |
| Shortcut | Action |
|---|---|
Ctrl+C |
Cancel current operation |
Ctrl+D |
Exit application |
Tab |
Auto-complete |
Up/Down |
Navigate command history |
claude # Start REPL
claude "explain this codebase" # REPL with initial prompt
claude -p "explain this function" # Single query, output to stdout
cat logs.txt | claude -p "explain errors" # Pipe content for analysis
claude -c # Continue last conversation
claude --continue # Same as -c
claude -r "session-id" "query" # Resume specific session by ID
claude --model sonnet # Use Sonnet (faster, cheaper)
claude --model opus # Use Opus (most capable)
claude --model claude-sonnet-4-20250514 # Specific version
claude --add-dir ../apps ../lib # Add multiple working directories
claude -p "query" --output-format text # Plain text (default)
claude -p "query" --output-format json # JSON output for scripting
claude -p "query" --output-format stream-json # Streaming JSON
claude --allowedTools "Bash(git:*)" "Write" "Read"
claude --allowedTools "Bash(git log:*)" "Bash(git status:*)"
claude --disallowedTools "Bash(rm:*)" "Bash(sudo:*)"
claude --dangerously-skip-permissions
claude --allowedTools "Bash(git:*)" "Write" "Read" \
--disallowedTools "Bash(rm:*)" "Bash(sudo:*)"
claude -p --max-turns 3 "focused query" # Limit iterations
claude --verbose # Enable detailed logging
# Analyze git history
git log --oneline -10 | claude -p "summarize these commits"
# Error analysis
cat error.log | claude -p "find the root cause"
# Code review
git diff HEAD~1 | claude -p "review for security issues" > review.md
# Generate changelog
git log --oneline -20 | claude -p "create changelog" > CHANGELOG.md
# Analyze multiple files
find . -name "*.js" -exec claude -p "analyze: {}" \; > report.txt
# Generate documentation
for file in src/*.py; do
claude -p "generate docstring for $file" >> docs.md
done
# Save analysis as JSON
claude -p "analyze codebase" --output-format json > analysis.json
# Parse with jq
SESSION_ID=$(claude -p "task" --output-format json | jq -r '.session_id')
Create custom commands in .claude/commands/ directory:
mkdir -p .claude/commands
Example: .claude/commands/review.md
Review this code for:
1. Security vulnerabilities
2. Performance issues
3. Best practice violations
Use with: /project:review
claude --mcp # Configure MCP servers
/mcp # Access MCP in REPL
/ide vscode # Configure VS Code integration
/ide configure # General IDE setup
/clear to reset context--max-turns for focused queries/compact for long sessions/cos to monitor usage# Quick, focused analysis
claude -p --max-turns 1 "quick code review"
# Compact long conversation
/compact "keep architecture decisions only"
# Parallel processing
claude -p "task 1" & claude -p "task 2" & wait
claude --version # Check installation
claude /doctor # Run diagnostics
npm reinstall -g @anthropic-ai/claude-code # Reinstall
/clear # Reset conversation
/compact "keep essentials" # Reduce context
claude -p --max-turns 3 "query" # Limit iterations
claude --allowedTools "Bash(git:*)" # Grant specific permissions
claude --disallowedTools "Bash(rm:*)" # Restrict dangerous commands
# Security review
git diff main | claude -p "review for security vulnerabilities"
# Performance review
git diff main | claude -p "identify performance issues"
# Style review
git diff main | claude -p "check code style and best practices"
# Generate README
claude -p "generate README for this project" > README.md
# API documentation
claude -p "document all public functions" > API.md
# Changelog
git log --oneline v1.0..HEAD | claude -p "create changelog" > CHANGELOG.md
# Analyze error logs
cat error.log | claude -p "identify root cause and suggest fixes"
# Debug specific file
claude -p "find bugs in src/auth.js"
# Stack trace analysis
cat stacktrace.txt | claude -p "explain this error and how to fix it"
--dangerously-skip-permissions in production--disallowedToolsclaude update regularly/cos for unexpected activityBash(git log:*) over Bash(git:*)| Task | Command |
|---|---|
| Start REPL | claude |
| Quick query | claude -p "query" |
| Continue session | claude -c |
| Resume by ID | claude -r "id" "query" |
| Check costs | /cos |
| Clear history | /clear |
| Compact context | /compact |
| Use Opus model | claude --model opus |
| JSON output | --output-format json |
| Limit turns | --max-turns N |
| Add directories | --add-dir path1 path2 |
| Allow tools | --allowedTools "Tool" |
| Block tools | --disallowedTools "Tool" |