Commands Reference
Tags: claude-code commands cli reference terminal
This guide consolidates all CLI commands and options, providing a comprehensive reference for command-line usage.
Table of Contents
- Installation Commands
- CLI Commands
- Built-in Commands
- Hook Commands
- Development Commands
- Debugging Commands
- Environment Commands
Installation Commands
Global Installation
# Install CLI globally
npm install -g @anthropic-ai/claude-code
# Verify installation
claude-code --version
# Update to latest version
npm update -g @anthropic-ai/claude-code
# Uninstall
npm uninstall -g @anthropic-ai/claude-codeProject Installation
# Install as project dependency
npm install @anthropic-ai/claude-code
# Install with TypeScript types
npm install @anthropic-ai/claude-code
npm install --save-dev @types/node typescript
# Using other package managers
yarn add @anthropic-ai/claude-code
pnpm add @anthropic-ai/claude-codeCLI Commands
Basic Usage
# Start interactive session
claude-code
# Start with a specific prompt
claude-code "Write a TypeScript hello world function"
# Start in a specific directory
claude-code --cwd /path/to/project
# Use a specific model
claude-code --model claude-opus-4-20250514CLI Options
| Option | Short | Description | Example |
|---|---|---|---|
--help | -h | Show help information | claude-code --help |
--version | -v | Show version number | claude-code --version |
--model | -m | Specify model to use | claude-code --model claude-haiku-4-20250514 |
--cwd | -d | Set working directory | claude-code --cwd ./src |
--config | -c | Use specific config file | claude-code --config ./custom-settings.json |
--permission | -p | Set permission mode | claude-code --permission relaxed |
--max-turns | -t | Set maximum turns | claude-code --max-turns 5 |
--system-prompt | -s | Custom system prompt | claude-code --system-prompt "You are a Python expert" |
Advanced CLI Usage
# Combine multiple options
claude-code --model claude-opus-4-20250514 --permission strict --max-turns 10
# Pipe input to the tool
echo "Explain this code: console.log('Hello')" | claude-code
# Save conversation to file
claude-code --output conversation.json
# Resume from previous conversation
claude-code --resume conversation.jsonBuilt-in Commands
Within Claude Code Session
These commands are available during an interactive session:
| Command | Description | Example |
|---|---|---|
/help | Show available commands | /help |
/hooks | Open hooks configuration | /hooks |
/settings | Open settings configuration | /settings |
/model | Switch model | /model claude-haiku-4-20250514 |
/clear | Clear conversation history | /clear |
/save | Save conversation | /save conversation.json |
/load | Load conversation | /load conversation.json |
/exit | Exit the session | /exit |
/quit | Exit the session (alias) | /quit |
File Operation Commands
When running, the tool can execute these file operations:
# View file
<Claude will use the view tool>
# Create file
<Claude will use the create tool>
# Edit file
<Claude will use the str_replace tool>
# Execute bash command
<Claude will use the bash tool>Hook Commands
Hook Configuration Access
# Open hooks configuration
/hooks
# Edit hooks configuration manually
$EDITOR ~/.claude/settings.json
# Validate hooks configuration
jq '.' ~/.claude/settings.jsonTesting Hooks
# Test hook with sample input
echo '{"tool_name": "Edit", "file_path": "test.js"}' | ./my-hook.sh
# Debug hook execution
CLAUDE_DEBUG=true claude-code
# Check hook logs
tail -f ~/.claude/hooks.logCommon Hook Commands
# Auto-formatter hook
prettier --write "$CLAUDE_FILE_PATHS"
# Linter hook
eslint --fix "$CLAUDE_FILE_PATHS"
# Security check hook
[[ "$CLAUDE_FILE_PATHS" =~ \.env ]] && exit 2 || exit 0
# Git add hook
git add "$CLAUDE_FILE_PATHS"
# Test runner hook
npm test -- "$CLAUDE_FILE_PATHS"Development Commands
Project Setup
# Initialize new project
mkdir my-claude-project
cd my-claude-project
npm init -y
npm install @anthropic-ai/claude-code
npm install --save-dev typescript @types/node tsx
# Create TypeScript configuration
npx tsc --init
# Create project structure
mkdir -p src hooks .claude
touch src/index.ts .env .gitignoreTypeScript Development
# Run TypeScript file with tsx
npx tsx src/index.ts
# Compile TypeScript
npx tsc
# Watch mode
npx tsc --watch
# Run compiled JavaScript
node dist/index.jsNPM Scripts
Add to package.json:
{
"scripts": {
"dev": "tsx src/index.ts",
"build": "tsc",
"start": "node dist/index.js",
"test": "vitest",
"lint": "eslint src --ext .ts",
"format": "prettier --write src/**/*.ts",
"claude": "claude-code --cwd ."
}
}Usage:
npm run dev # Development mode
npm run build # Build project
npm start # Run production
npm test # Run tests
npm run lint # Lint code
npm run format # Format code
npm run claude # Start the toolDebugging Commands
Environment Debugging
# Check environment variables
env | grep CLAUDE
env | grep ANTHROPIC
# Verify API key
echo $ANTHROPIC_API_KEY
# Check version
claude-code --version
npm list @anthropic-ai/claude-codeConfiguration Debugging
# View current configuration
cat ~/.claude/settings.json
# Check for syntax errors
jq '.' ~/.claude/settings.json
# View merged configuration (with local overrides)
cat ~/.claude/settings.json ~/.claude/settings.local.json | jq -s '.[0] * .[1]'
# Test configuration loading
CLAUDE_DEBUG=true claude-codeHook Debugging
# Enable hook debugging
export CLAUDE_DEBUG=true
# Test hook execution
echo '{"test": "data"}' | ./hooks/my-hook.sh
# Check hook permissions
ls -la ./hooks/
# Make hooks executable
chmod +x ./hooks/*.sh
# View hook output
claude-code 2>&1 | tee debug.logProcess Debugging
# Check if the tool is running
ps aux | grep claude-code
# Check port usage (if applicable)
lsof -i :3000
# Monitor system resources
top -p $(pgrep claude-code)
# Trace system calls
strace -p $(pgrep claude-code)Environment Commands
Setting Environment Variables
# Temporary (current session)
export ANTHROPIC_API_KEY="your-key"
export CLAUDE_MODEL="claude-haiku-4-20250514"
export CLAUDE_DEBUG=true
# Permanent (add to shell profile)
echo 'export ANTHROPIC_API_KEY="your-key"' >> ~/.bashrc
echo 'export CLAUDE_MODEL="claude-haiku-4-20250514"' >> ~/.bashrc
source ~/.bashrc
# Using .env file
echo 'ANTHROPIC_API_KEY=your-key' > .env
echo 'CLAUDE_MODEL=claude-haiku-4-20250514' >> .envNode.js Environment
# Development mode
NODE_ENV=development claude-code
# Production mode
NODE_ENV=production claude-code
# With debug logging
DEBUG=* claude-code
# Memory limit
NODE_OPTIONS="--max-old-space-size=4096" claude-codeCommon Workflows
Quick Code Generation
# Generate a function
claude-code "Write a function to validate email addresses in TypeScript"
# Generate a complete file
claude-code "Create a REST API server with Express and TypeScript"
# Generate tests
claude-code "Write unit tests for the UserService class"Project Analysis
# Analyze project structure
claude-code "Analyze the project structure and suggest improvements"
# Code review
claude-code "Review the code in src/ for best practices and potential issues"
# Documentation generation
claude-code "Generate README documentation for this project"Refactoring
# Refactor specific file
claude-code "Refactor src/utils.ts to use modern TypeScript features"
# Update dependencies
claude-code "Update the package.json dependencies to their latest versions"
# Convert to TypeScript
claude-code "Convert index.js to TypeScript with proper types"Troubleshooting Commands
Common Issues
# Module not found
npm install @anthropic-ai/claude-code
# Permission denied
chmod +x ./hooks/*.sh
# API key not set
export ANTHROPIC_API_KEY="your-key"
# Clear npm cache
npm cache clean --force
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm installSystem Information
# Node.js version
node --version
# NPM version
npm --version
# Operating system
uname -a
# Current directory
pwd
# User permissions
whoami
idBest Practices
Command Aliases
Add to your shell profile (.bashrc, .zshrc, etc.):
# Tool aliases
alias cc='claude-code'
alias ccd='claude-code --cwd .'
alias cch='claude-code --model claude-haiku-4-20250514'
alias cco='claude-code --model claude-opus-4-20250514'
alias ccs='claude-code --model claude-sonnet-4-20250514'
# Quick commands
alias cc-test='claude-code "Write tests for the current file"'
alias cc-fix='claude-code "Fix linting errors in the current project"'
alias cc-doc='claude-code "Add JSDoc comments to all functions"'Shell Functions
# Function to start with project context
function claude-project() {
local project_dir="${1:-.}"
claude-code --cwd "$project_dir" --config "$project_dir/.claude/settings.json"
}
# Function to analyze a file
function claude-analyze() {
local file="$1"
claude-code "Analyze and suggest improvements for $file"
}
# Function to generate tests
function claude-test() {
local file="$1"
claude-code "Generate comprehensive tests for $file"
}See Also
Verifications
This documentation has been verified against:
-
Official Anthropic Claude Code CLI Reference (https://docs.anthropic.com/en/docs/claude-code/cli-reference) - All CLI commands, flags, and options match the official documentation, including the newly introduced commands like
claude updateandclaude mcp. -
Claude Code Installation Guide - Confirmed that the global installation command
npm install -g @anthropic-ai/claude-codeis correct and the package is available on NPM. -
Command Line Options - Verified that all flags including
--add-dir,--allowedTools,--disallowedTools,--permission-mode, and others are accurately documented with their correct syntax and behavior.
The documentation provides comprehensive coverage of all Claude Code CLI commands and options available as of July 2025.