Claude Code CLI Cheat Sheet
Complete command reference organized by skill level.
Level 1: Beginner Commands
Terminal Commands (Starting Claude)
| Command |
When to Use |
Explanation |
claude |
Starting a new coding session |
Launches Claude Code CLI in interactive mode in the current directory |
claude "prompt" |
Quick start with a specific task |
Starts interactive session with an initial prompt, e.g., claude "explain this project" |
claude --version |
Checking installation |
Displays the installed Claude Code CLI version |
claude --help |
Learning available options |
Shows all command-line flags and usage information |
Session Commands (Inside Claude)
| Command |
When to Use |
Explanation |
/help |
Need to see available commands |
Lists all slash commands and their descriptions |
/exit |
Ending your session |
Cleanly exits Claude Code CLI and saves session |
Ctrl+C |
Canceling current operation |
Interrupts Claude's current response; press twice to exit |
Ctrl+C Ctrl+C |
Force exit |
Immediately exits Claude Code CLI |
Keyboard Shortcuts
| Shortcut |
When to Use |
Explanation |
Enter |
Sending a message |
Submits your prompt to Claude |
Shift+Enter |
Writing multi-line prompts |
Adds a new line without sending the message |
Up Arrow |
Recalling previous prompts |
Navigates backward through your prompt history |
Down Arrow |
Navigating prompt history |
Navigates forward through your prompt history |
Ctrl+L |
Cleaning up terminal |
Clears the terminal screen but keeps conversation |
Session Management
| Command |
When to Use |
Explanation |
claude -c |
Resuming previous work |
Continues your last conversation with full context |
claude --continue |
Same as above (long form) |
Full flag name for continuing previous session |
/clear |
Starting fresh in same session |
Clears conversation history while staying in session |
/compact |
Long conversations |
Summarizes conversation to reduce token usage while preserving key context |
/status |
Checking session info |
Shows current working directory, session length, and status |
Directory Control
| Command |
When to Use |
Explanation |
claude --cwd /path |
Working in different project |
Starts Claude in specified directory without cd-ing |
claude --cwd ~/project |
Shorthand path |
Works with home directory shorthand |
Git Integration
| Command |
When to Use |
Explanation |
> git status (in session) |
Checking changes |
Ask Claude to run git status and explain results |
> commit my changes |
Creating commits |
Claude stages, commits with appropriate message |
> create a PR |
Pull request creation |
Claude creates PR with summary using gh CLI |
> review the diff |
Code review |
Claude analyzes git diff for issues |
Level 3: Advanced Commands
Non-Interactive Mode
| Command |
When to Use |
Explanation |
claude -p "prompt" |
Scripting and automation |
Runs single prompt, prints response, exits (no session) |
claude --print "prompt" |
Same as above (long form) |
Full flag name for non-interactive mode |
claude -p "query" > file.md |
Saving output |
Redirects Claude's response to a file |
cat file \| claude -p "analyze" |
Processing file content |
Pipes file content to Claude for analysis |
$(claude -p "query") |
Capturing output |
Stores Claude's response in a shell variable |
Configuration
| Command |
When to Use |
Explanation |
/config |
Viewing/editing settings |
Opens configuration for model, permissions, etc. |
/docs |
Accessing documentation |
Opens official Claude Code documentation |
Custom Slash Commands
| Command |
When to Use |
Explanation |
/commandname |
Running custom commands |
Executes custom command from .claude/commands/commandname.md |
/review |
Code review (if configured) |
Example custom command for reviewing code |
/test |
Running tests (if configured) |
Example custom command for test workflows |
Model Selection
| Command |
When to Use |
Explanation |
claude --model claude-haiku |
Quick, simple tasks |
Uses faster, cheaper Haiku model |
claude --model claude-sonnet |
Balanced tasks |
Uses Sonnet for good balance of speed/capability |
claude --model claude-opus |
Complex analysis |
Uses most capable Opus model |
Level 4: Expert Commands
Advanced CLI Flags
| Command |
When to Use |
Explanation |
claude --max-tokens 100 |
Limiting response length |
Caps response to specified token count |
claude --system "prompt" |
Custom system behavior |
Sets custom system prompt for the session |
claude --allowedTools "Read,Edit" |
Restricting capabilities |
Limits which tools Claude can use |
Scripting Patterns
| Command |
When to Use |
Explanation |
claude -p "q" && echo "done" |
Conditional execution |
Runs next command only if Claude succeeds |
claude -p "q" \|\| echo "failed" |
Error handling |
Runs fallback if Claude fails |
claude -p "q" 2>&1 \| tee log |
Logging output |
Captures output while displaying it |
timeout 60 claude -p "q" |
Preventing hangs |
Kills Claude if it takes too long |
Shell Aliases (Add to ~/.zshrc)
| Alias |
When to Use |
Explanation |
alias cc="claude" |
Daily use |
Short alias for claude command |
alias ccc="claude -c" |
Continuing work |
Short alias for continue mode |
alias ccp="claude -p" |
Quick questions |
Short alias for non-interactive mode |
alias ccw="claude --cwd" |
Multi-project work |
Short alias for directory specification |
Shell Functions
| Function |
When to Use |
Explanation |
cc-ask() { claude -p "$*"; } |
Quick questions |
Function for one-off questions |
cc-review() { claude "review $1"; } |
File review |
Function to review specific file |
cc-debug() { claude "debug: $*"; } |
Debugging help |
Function for debugging assistance |
cc-explain() { cat $1 \| claude -p "explain"; } |
Understanding code |
Function to explain file contents |
MCP & Integration Commands
| Tool Pattern |
When to Use |
Explanation |
mcp__postgres__query |
Database queries |
Executes SQL queries via PostgreSQL MCP |
mcp__github__list_issues |
GitHub integration |
Lists issues from configured repository |
mcp__github__create_pr |
PR creation |
Creates pull request via GitHub MCP |
mcp__n8n__execute_workflow |
Workflow automation |
Triggers n8n workflow execution |
mcp__filesystem__read |
External file access |
Reads files outside working directory |
mcp__browser__fetch |
Web content |
Fetches and processes web pages |
Environment Variables
| Variable |
When to Use |
Explanation |
ANTHROPIC_API_KEY |
API authentication |
Your Anthropic API key for authentication |
MCP_DEBUG=1 |
Debugging MCP servers |
Enables verbose MCP server logging |
CLAUDE_PROJECT_CONTEXT |
Project identification |
Custom variable for project-specific settings |
Configuration Files
File Locations
| File |
When to Use |
Explanation |
~/.claude/settings.json |
Personal settings |
User-wide configuration (model, preferences) |
.claude/settings.json |
Project settings |
Project-specific settings (shared with team) |
~/.claude/commands/*.md |
Personal commands |
User's custom slash commands |
.claude/commands/*.md |
Project commands |
Project's custom slash commands (version controlled) |
CLAUDE.md |
Project context |
Instructions for Claude about the project |
Settings Structure
{
"model": "claude-sonnet-4-20250514",
"mcpServers": { },
"permissions": {
"allowedTools": [],
"deniedPaths": []
},
"hooks": {
"pre-tool-use": [],
"post-tool-use": []
}
}
Quick Reference Card
┌─────────────────────────────────────────────────────────────────────┐
│ CLAUDE CODE CLI CHEAT SHEET │
├─────────────────────────────────────────────────────────────────────┤
│ STARTING │
│ claude Interactive session │
│ claude "prompt" Start with prompt │
│ claude -c Continue last session │
│ claude -p "prompt" Non-interactive (scripts) │
│ claude --cwd DIR Different directory │
├─────────────────────────────────────────────────────────────────────┤
│ IN SESSION │
│ /help Show commands │
│ /exit Exit session │
│ /clear Clear history │
│ /compact Summarize conversation │
│ /config Settings │
├─────────────────────────────────────────────────────────────────────┤
│ KEYBOARD │
│ Enter Send message │
│ Shift+Enter New line │
│ Ctrl+C Cancel (2x to exit) │
│ Up/Down History │
│ Ctrl+L Clear screen │
├─────────────────────────────────────────────────────────────────────┤
│ SCRIPTING │
│ claude -p "q" > file Save output │
│ cat f | claude -p "q" Pipe input │
│ $(claude -p "q") Capture output │
├─────────────────────────────────────────────────────────────────────┤
│ ALIASES (add to ~/.zshrc) │
│ alias cc="claude" │
│ alias ccc="claude -c" │
│ alias ccp="claude -p" │
└─────────────────────────────────────────────────────────────────────┘
Common Workflows
Daily Development
# Start day - continue yesterday's work
claude -c
# Quick question without session
claude -p "what's the project structure?"
# Review changes before commit
claude "review my git changes"
# Create commit with message
claude "commit these changes"
Debugging
# Start debugging session
claude "I have an error: [paste error]"
# Analyze logs
cat error.log | claude -p "analyze these errors"
# Quick error lookup
claude -p "explain: TypeError: Cannot read property 'x' of undefined"
Code Review
# Review specific file
claude "review src/auth.ts for security issues"
# Review all changes
claude "review git diff for bugs and issues"
# Generate PR description
claude "create PR description for these changes"
Automation
# In CI/CD
claude -p "check for issues in this diff: $(git diff)"
# Scheduled task
0 9 * * * claude -p "daily code health check" >> /var/log/claude.log
# Git hook
claude -p "pre-commit check for issues" || exit 1
Troubleshooting Commands
| Issue |
Command |
Explanation |
| Check installation |
claude --version |
Verify Claude CLI is installed |
| Reset configuration |
rm -rf ~/.claude |
Remove all user settings (start fresh) |
| Debug MCP |
MCP_DEBUG=1 claude |
Start with verbose MCP logging |
| Check PATH |
which claude |
Verify claude is in PATH |
| NPM global path |
npm config get prefix |
Find npm global installation directory |
| Reinstall |
npm install -g @anthropic-ai/claude-code |
Fresh installation |
See Also