Claude Code CLI: Complete Commands Reference with Examples
Master every Claude Code CLI command, flag, and configuration option. Includes practical examples, common workflows, and power user tips.
Claude Code CLI: Complete Commands Reference with Examples
Claude Code's command-line interface is where the magic happens. Whether you're navigating projects, customizing behavior, or building complex workflows, understanding the CLI is essential. This reference covers every command, flag, and configuration option available.
Getting Started
Installation
# Install globally via npm
npm install -g @anthropic-ai/claude-code
# Or use npx for one-time usage
npx @anthropic-ai/claude-code
First Run
# Start Claude Code in current directory
claude
# Start in a specific directory
claude /path/to/project
# Start with a specific prompt
claude "Explain the architecture of this project"
Authentication
# Login to your Anthropic account
claude login
# Check authentication status
claude auth status
# Logout
claude logout
Core Commands
Starting Sessions
| Command | Description |
|---|---|
claude | Start interactive session |
claude <path> | Start in specific directory |
claude "<prompt>" | Start with initial prompt |
claude --resume | Resume last session |
claude --continue | Continue from last conversation |
Examples:
# Start fresh session
claude
# Start with context
claude "Review the authentication flow in this project"
# Resume where you left off
claude --resume
# Open specific project
claude ~/projects/my-app
Session Management
| Command | Description |
|---|---|
/clear | Clear current conversation |
/reset | Reset to fresh state |
/save <name> | Save current session |
/load <name> | Load saved session |
/history | Show conversation history |
/sessions | List all saved sessions |
Examples:
> /save feature-implementation
Session saved as "feature-implementation"
> /load feature-implementation
Session loaded. 24 messages restored.
> /sessions
Available sessions:
- feature-implementation (2 hours ago)
- bug-investigation (yesterday)
- refactoring-session (3 days ago)
> /history
Showing last 10 messages...
Built-in Slash Commands
File Operations
| Command | Description |
|---|---|
/read <file> | Read and display file contents |
/edit <file> | Open file for editing discussion |
/find <pattern> | Find files matching pattern |
/grep <pattern> | Search file contents |
/tree | Show directory structure |
Examples:
> /read src/components/Button.tsx
Reading Button.tsx...
[File contents displayed]
> /find "*.test.ts"
Found 47 test files:
- src/components/__tests__/Button.test.ts
- src/hooks/__tests__/useAuth.test.ts
...
> /grep "TODO:"
Found 12 TODO comments:
- src/api/users.ts:45 - TODO: Add validation
- src/utils/format.ts:23 - TODO: Handle edge case
...
> /tree src/components
src/components/
├── Button/
│ ├── Button.tsx
│ ├── Button.test.tsx
│ └── index.ts
├── Card/
│ ├── Card.tsx
│ └── index.ts
└── index.ts
Git Operations
| Command | Description |
|---|---|
/git status | Show git status |
/git diff | Show unstaged changes |
/git log | Show recent commits |
/commit | Create a commit (if skill installed) |
/pr | Create pull request (if skill installed) |
Examples:
> /git status
On branch feature/auth
Changes not staged for commit:
modified: src/auth/login.ts
modified: src/auth/register.ts
> /git diff src/auth/login.ts
Showing diff for login.ts...
[Diff output]
> /git log -5
Recent commits:
abc1234 - Add password validation (2 hours ago)
def5678 - Fix login redirect (yesterday)
...
Navigation
| Command | Description |
|---|---|
/cd <path> | Change working directory |
/pwd | Print working directory |
/ls | List directory contents |
/open <file> | Open file in default editor |
Examples:
> /pwd
/Users/dev/projects/my-app
> /cd src/components
Changed to /Users/dev/projects/my-app/src/components
> /ls
Button/
Card/
Form/
Modal/
index.ts
Help and Information
| Command | Description |
|---|---|
/help | Show all available commands |
/help <command> | Get help for specific command |
/version | Show Claude Code version |
/config | Show current configuration |
/tools | List available tools and MCP servers |
Examples:
> /help
Available commands:
/clear Clear conversation
/reset Reset session
/save Save session
/load Load session
...
> /help commit
/commit - Create a git commit
Usage: /commit [message]
Creates a conventional commit based on staged changes.
If no message provided, generates one automatically.
> /tools
Available tools:
- Bash: Execute shell commands
- Read: Read file contents
- Edit: Edit files
- Grep: Search file contents
- Glob: Find files by pattern
MCP Servers:
- postgres: Database operations
- github: GitHub API access
CLI Flags and Options
Startup Flags
| Flag | Description |
|---|---|
--help, -h | Show help message |
--version, -v | Show version number |
--resume, -r | Resume last session |
--continue, -c | Continue last conversation |
--model <model> | Specify model to use |
--no-context | Start without loading CLAUDE.md |
Examples:
# Use specific model
claude --model claude-3-opus
# Start fresh without project context
claude --no-context
# Show version
claude --version
Claude Code v1.0.45
Output Flags
| Flag | Description |
|---|---|
--print, -p | Print response and exit |
--json | Output as JSON |
--quiet, -q | Minimal output |
--verbose | Detailed output |
--no-color | Disable colored output |
Examples:
# One-shot query with output
claude -p "What's in package.json?" > analysis.txt
# JSON output for scripting
claude --json "List all dependencies" | jq '.dependencies'
# Verbose mode for debugging
claude --verbose "Debug this error"
Configuration Flags
| Flag | Description |
|---|---|
--config <file> | Use specific config file |
--project <path> | Set project root |
--claude-md <file> | Use specific CLAUDE.md |
--no-mcp | Disable MCP servers |
--allow <permissions> | Grant specific permissions |
Examples:
# Use custom config
claude --config ./custom-settings.json
# Override CLAUDE.md
claude --claude-md ./docs/AI_CONTEXT.md
# Disable MCP for testing
claude --no-mcp
# Pre-approve specific permissions
claude --allow bash --allow write
Configuration
Configuration Files
Claude Code reads configuration from multiple sources (in order of precedence):
- CLI flags
- Environment variables
- Project config (
.claude/settings.json) - User config (
~/.claude/settings.json) - Default values
Settings File Structure
{
"model": "claude-3-5-sonnet-20241022",
"maxTokens": 8192,
"temperature": 0.7,
"theme": "dark",
"editor": "vscode",
"shell": "/bin/zsh",
"autoSave": true,
"historyLength": 100,
"permissions": {
"bash": "ask",
"write": "ask",
"network": "deny"
},
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"]
}
}
}
Key Configuration Options
Model Settings:
| Option | Default | Description |
|---|---|---|
model | claude-3-5-sonnet | Model to use |
maxTokens | 8192 | Max response tokens |
temperature | 0.7 | Response creativity (0-1) |
Interface Settings:
| Option | Default | Description |
|---|---|---|
theme | auto | Color theme (dark/light/auto) |
editor | $EDITOR | Default editor for /open |
shell | $SHELL | Shell for Bash tool |
historyLength | 100 | Messages to keep in history |
Permission Settings:
| Option | Values | Description |
|---|---|---|
bash | ask/allow/deny | Shell command execution |
write | ask/allow/deny | File write operations |
network | ask/allow/deny | Network requests |
mcp | ask/allow/deny | MCP tool usage |
Environment Variables
# API Key (required)
export ANTHROPIC_API_KEY="sk-ant-..."
# Optional overrides
export CLAUDE_MODEL="claude-3-opus"
export CLAUDE_MAX_TOKENS="4096"
export CLAUDE_CONFIG="~/.claude/custom-settings.json"
# Debug mode
export CLAUDE_DEBUG="true"
Common Workflows
Code Review Workflow
# Start Claude Code
claude
# Review changes
> Review the changes in this PR for security issues and best practices.
> Focus on the authentication module.
# Get specific file review
> /read src/auth/middleware.ts
> What security vulnerabilities exist in this middleware?
# Commit the fixes
> /commit "Fix authentication vulnerabilities"
Bug Investigation Workflow
# Start with error context
claude "I'm seeing this error: 'Cannot read property of undefined'"
# Search for related code
> /grep "property of undefined"
# Investigate specific file
> /read src/utils/dataProcessor.ts
# Find all usages
> /find "**/dataProcessor*"
# Review related tests
> /read src/utils/__tests__/dataProcessor.test.ts
# Implement fix
> Fix the null check issue in dataProcessor.ts
Refactoring Workflow
# Start session
claude
# Understand current structure
> /tree src/components
# Analyze component
> /read src/components/UserProfile.tsx
> This component is too large. How should I split it?
# Plan the refactoring
> Create a refactoring plan for UserProfile.tsx
# Execute refactoring
> Implement step 1 of the refactoring plan
# Verify tests still pass
> Run the tests for UserProfile
Documentation Workflow
# Generate docs
claude "Generate API documentation for the auth module"
# Review generated docs
> /read docs/api/auth.md
# Update README
> Update README.md with setup instructions for the new auth system
# Create examples
> Add code examples for common authentication flows
Power User Tips
Command Chaining
Execute multiple operations in sequence:
# Multiple prompts in one session
claude << 'EOF'
First, review the authentication code.
Then, identify any security issues.
Finally, suggest fixes with code examples.
EOF
Scripting with Claude Code
Use Claude Code in shell scripts:
#!/bin/bash
# Generate commit message
MESSAGE=$(claude -p "Generate a commit message for these changes: $(git diff --staged)")
git commit -m "$MESSAGE"
# Analyze code changes
claude -p "Review this diff for issues: $(git diff HEAD~1)" > review.md
# Generate documentation
for file in src/api/*.ts; do
claude -p "Generate JSDoc for: $(cat $file)" > "docs/$(basename $file .ts).md"
done
Aliases for Common Operations
Add to your shell profile:
# ~/.zshrc or ~/.bashrc
# Quick Claude commands
alias c="claude"
alias cr="claude --resume"
alias cc="claude --continue"
# Code review
alias review="claude 'Review the staged changes for issues'"
# Quick documentation
alias doc="claude 'Generate documentation for this file'"
# Explain code
explain() {
claude -p "Explain this code: $(cat $1)"
}
# Fix linting errors
alias fixlint="claude 'Fix all linting errors in the project'"
Session Templates
Create reusable session starters:
# ~/.claude/templates/code-review.md
I'm doing a code review session. For each file I show you:
1. Check for security vulnerabilities
2. Identify performance issues
3. Suggest improvements
4. Note any anti-patterns
Be thorough but concise.
Use with:
claude "$(cat ~/.claude/templates/code-review.md)"
Advanced Grep Patterns
# Find all TODO comments with context
> /grep -C 3 "TODO:|FIXME:|HACK:"
# Find all exported functions
> /grep "^export (async )?function"
# Find all React components
> /grep "^export (default )?(function|const) [A-Z]"
# Find all API endpoints
> /grep "app\.(get|post|put|delete)\("
Custom File Patterns
# Find all config files
> /find "*.config.{js,ts,json}"
# Find all test files
> /find "**/*.{test,spec}.{ts,tsx}"
# Find all markdown docs
> /find "**/*.md" --ignore "node_modules"
# Find large files
> /find "**/*.ts" --size ">100k"
Troubleshooting
Common Issues
Claude Code won't start:
# Check installation
which claude
# Reinstall
npm uninstall -g @anthropic-ai/claude-code
npm install -g @anthropic-ai/claude-code
# Check API key
echo $ANTHROPIC_API_KEY
Session not loading:
# Clear cache
rm -rf ~/.claude/cache
# Reset configuration
mv ~/.claude/settings.json ~/.claude/settings.json.backup
# Check permissions
ls -la ~/.claude/
MCP servers not working:
# Check MCP configuration
> /config
# Test server manually
npx @modelcontextprotocol/server-postgres
# Check logs
> /tools
Slow performance:
# Reduce history length
# In settings.json:
{
"historyLength": 50
}
# Clear old sessions
rm ~/.claude/sessions/*.json
# Use smaller model
claude --model claude-3-haiku
Debug Mode
Enable debug output:
CLAUDE_DEBUG=true claude
# Or in session
> /debug on
Debug mode enabled. Showing tool calls and API requests.
Getting Help
# In-app help
> /help
# Command-specific help
> /help <command>
# Online documentation
claude docs
# Report issues
claude feedback
Quick Reference Card
Essential Commands
| Action | Command |
|---|---|
| Start session | claude |
| Resume session | claude --resume |
| Clear conversation | /clear |
| Save session | /save <name> |
| Get help | /help |
| Show tools | /tools |
Essential Flags
| Flag | Purpose |
|---|---|
-r, --resume | Resume last session |
-p, --print | Print and exit |
--model <m> | Use specific model |
-q, --quiet | Minimal output |
Essential Shortcuts
| Shortcut | Action |
|---|---|
Ctrl+C | Cancel current operation |
Ctrl+D | Exit Claude Code |
Ctrl+L | Clear screen |
Up/Down | Navigate history |
Tab | Autocomplete |
Conclusion
The Claude Code CLI is your gateway to AI-assisted development. Master these commands, and you'll find yourself navigating projects, debugging issues, and writing code faster than ever.
Start with the basics: /help, /read, /find. Then gradually incorporate more advanced workflows. Before long, Claude Code becomes an extension of your development environment—always ready, always helpful.
Ready to extend Claude Code further? Check out our Plugin Development Guide to build your own integrations.