CLI Reference
Complete reference for Claude Code command-line interface.
Global Options
Options available for all commands:
Option | Description | Default |
---|---|---|
--version | Show version number | - |
--help | Show help | - |
--verbose | Enable verbose output | false |
--quiet | Suppress non-error output | false |
--no-color | Disable colored output | false |
--config <path> | Use custom config file | ~/.claude/settings.json |
Starting Claude
Basic Usage
claude [options]
Options
Option | Description | Example |
---|---|---|
-p, --prompt <text> | Start with a prompt | claude -p "Review this code" |
-m, --model <model> | Set model | claude -m opus |
--dangerously-skip-permissions | Skip all permission prompts | claude --dangerously-skip-permissions |
--allowed-tools <tools> | Pre-allow tools | claude --allowed-tools Edit,Bash |
--add-dir <path> | Add additional directory | claude --add-dir ../shared |
--no-cache | Disable context caching | claude --no-cache |
--output-format <format> | Set output format | claude --output-format json |
Examples
# Start with a specific model
claude --model sonnet
# Start with pre-allowed tools
claude --allowed-tools "Edit,Read,Bash(git:*)"
# Non-interactive mode
claude -p "Fix all ESLint errors" --output-format stream-json
Slash Commands
Commands available during a Claude session:
Session Management
Command | Description | Usage |
---|---|---|
/help | Show all commands | /help |
/clear | Clear conversation context | /clear |
/exit | Exit Claude Code | /exit |
/restart | Restart Claude session | /restart |
Model & Configuration
Command | Description | Usage |
---|---|---|
/model [model] | Show/change model | /model opus |
/models | List available models | /models |
/config | Show configuration | /config |
/settings | Edit settings | /settings |
Permissions
Command | Description | Usage |
---|---|---|
/permissions | Manage tool permissions | /permissions |
/allow <tool> | Allow a tool | /allow Edit |
/deny <tool> | Deny a tool | /deny Bash |
/reset-permissions | Reset all permissions | /reset-permissions |
Context Management
Command | Description | Usage |
---|---|---|
/context | Show context usage | /context |
/memory | Manage CLAUDE.md files | /memory |
/memory load | Reload memory files | /memory load |
/memory edit | Edit memory inline | /memory edit |
Directory Management
Command | Description | Usage |
---|---|---|
/add-dir <path> | Add directory | /add-dir ../lib |
/remove-dir <path> | Remove directory | /remove-dir ../lib |
/dirs | List directories | /dirs |
MCP Servers
Command | Description | Usage |
---|---|---|
/mcp list | List MCP servers | /mcp list |
/mcp add <name> | Add MCP server | /mcp add github |
/mcp remove <name> | Remove MCP server | /mcp remove github |
/mcp restart <name> | Restart MCP server | /mcp restart think-tool |
Advanced Commands
Command | Description | Usage |
---|---|---|
/install-github-app | Install GitHub integration | /install-github-app |
/export | Export conversation | /export conversation.md |
/import | Import conversation | /import saved-chat.json |
/stats | Show session statistics | /stats |
MCP Management
List Servers
claude mcp list
Output:
Available MCP servers:
✓ filesystem (local)
✓ github (http)
✗ think-tool (not installed)
Add Server
claude mcp add [options] <name> <command...>
Options:
--transport <type>
- Transport type (local/http)--env <key=value>
- Environment variables
Examples:
# Local server
claude mcp add sequential-thinking npx @modelcontextprotocol/server-sequential-thinking
# HTTP server
claude mcp add --transport http github https://api.githubcopilot.com/mcp/
# With environment variables
claude mcp add --env API_KEY=$SECRET_KEY custom-server ./server.js
Remove Server
claude mcp remove <name>
Configure Server
claude mcp config <name> [key] [value]
Examples:
# Show config
claude mcp config github
# Set value
claude mcp config github timeout 30000
Configuration Management
View Configuration
claude config show [key]
Examples:
# Show all config
claude config show
# Show specific key
claude config show defaultModel
Set Configuration
claude config set <key> <value>
Examples:
claude config set defaultModel opus
claude config set autoSave true
claude config set theme dark
Reset Configuration
claude config reset [key]
Tool Permission Syntax
Basic Syntax
ToolName
ToolName(command:pattern)
Examples
Permission | Description |
---|---|
Edit | Allow all file edits |
Read | Allow all file reads |
Bash | Allow all bash commands |
Bash(ls:*) | Allow only ls commands |
Bash(git:*) | Allow only git commands |
Bash(npm install:*) | Allow only npm install |
Write(*.md) | Allow writing markdown files |
Edit(src/*:*) | Allow editing files in src/ |
Complex Patterns
# Multiple patterns
claude --allowed-tools "Bash(ls:*),Bash(cat:*),Edit(*.js)"
# Glob patterns
claude --allowed-tools "Edit(src/**/*.ts)"
# Negation
claude --allowed-tools "Edit,!Edit(*.env)"
Environment Variables
Variable | Description | Default |
---|---|---|
ANTHROPIC_API_KEY | API key | Required |
CLAUDE_MODEL | Default model | sonnet |
CLAUDE_NO_COLOR | Disable colors | false |
CLAUDE_CACHE_DIR | Cache directory | ~/.claude/cache |
CLAUDE_LOG_LEVEL | Log level | info |
CLAUDE_TIMEOUT | Request timeout | 300000 |
HTTP_PROXY | HTTP proxy | - |
HTTPS_PROXY | HTTPS proxy | - |
Output Formats
Stream (Default)
Normal interactive output.
JSON
claude -p "List files" --output-format json
Output:
{
"messages": [...],
"tools_used": ["LS"],
"result": "success"
}
Stream JSON
claude -p "Write a function" --output-format stream-json
Outputs newline-delimited JSON events.
Error Codes
Code | Description | Solution |
---|---|---|
1 | General error | Check error message |
2 | Authentication failed | Verify API key |
3 | Network error | Check connection |
4 | Permission denied | Check file permissions |
5 | Tool blocked | Review permissions |
6 | Context overflow | Clear context |
7 | Model unavailable | Try different model |
Keyboard Shortcuts
Shortcut | Action |
---|---|
Tab | Autocomplete |
Shift+Tab | Toggle Plan Mode |
Ctrl+C | Cancel current operation |
Ctrl+D | Exit Claude |
Ctrl+L | Clear screen |
Ctrl+R | Search history |
Esc | Interrupt Claude |
Esc Esc | Edit last prompt |
↑/↓ | Navigate history |
Advanced Usage
Piping Input
# Pipe file content
cat script.js | claude -p "Explain this code"
# Pipe command output
git diff | claude -p "Summarize these changes"
Scripting
#!/bin/bash
# Automated code review
git diff main | claude -p "Review these changes for:
- Security issues
- Performance problems
- Best practices"
Headless Mode
# Run without interaction
claude -p "Generate README.md for this project" \
--dangerously-skip-permissions \
--output-format json \
> result.json
Next Steps
- Learn about Configuration Files
- Explore Workflows
- Master MCP Servers