Claude Code CLI: Comprehensive Reference Guide
Overview
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands. It maintains awareness of your entire project structure, can find up-to-date information from the web, and with MCP (Model Context Protocol) can pull from external datasources like Google Drive, Figma, and Slack.
1. Installation Instructions
Prerequisites
- Node.js 18 or higher is required
- Git for Windows (if on Windows)
- npm package manager
Installation Methods
NPM (Recommended)
npm install -g @anthropic-ai/claude-codePlatform-Specific Instructions
macOS with Homebrew:
brew install node
npm install -g @anthropic-ai/claude-codeUbuntu/Linux:
# Install Node.js 20.x (LTS as of 2025)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# Verify installation
node --version # Should show v20.x.x
npm --version # Should show 10.x.x or higher
# Install Claude Code
npm install -g @anthropic-ai/claude-codeArch Linux (AUR):
yay -S claude-codeWindows:
- Recommended: Use WSL (Windows Subsystem for Linux) and follow Linux instructions
- Native Windows support requires Git for Windows
Getting Started
# Navigate to your project
cd your-awesome-project
# Start coding with Claude
claude2. Available Commands and Usage
Basic Commands
claude- Start a new session with clean contextclaude --continue- Resume your last session with all context preservedclaude --resume- See list of past sessions and jump back into any projectclaude -p "prompt"- Print mode for non-interactive outputclaude --help- Show all available options
Slash Commands (In Session)
Core Commands
/help- Lists all slash commands and their functions/clear- Reset the current session’s context/compact- Summarize conversation to manage context limits/status- Show system and account status/model- Switch between Claude models (Opus, Sonnet, etc.)
Project Management
/init- Initialize CLAUDE.md in project root for project memory/overview- Get high-level overview of repository/tree- Display project directory structure/add-dir- Specify additional working directories
Code Operations
/review- Review PR, file, or code block/find- Hunt down code for any feature/export- Export conversation for sharing
Configuration
/config- Manage configuration settings/permissions- Manage tool permissions/doctor- Identify and fix invalid setting files/mcp- Display MCP server information
Utilities
/bug- Report issues directly within Claude Code/release-notes- View release notes/upgrade- Switch to Claude Max plans/vim- Enable Vim bindings for text input
Command Line Options
claude [options]
Options:
-p, --print <prompt> Non-interactive output mode
--continue Resume previous conversation
--resume Switch between conversation contexts
--output-format=stream-json JSON streaming output (with -p)
--append-system-prompt Append system prompt (with -p)
--mcp-config <path> Run one-off MCP servers
--mcp-debug Show MCP server errors
--disallowedTools Specify tools not to use
--dangerously-skip-permissions Skip permission prompts3. Configuration Options
Configuration Hierarchy
- Environment variables (highest priority)
~/.config/claude-code/settings.json.claude/settings.json(project-specific).claude.json(deprecated but supported)
Environment Variables
# Authentication
export ANTHROPIC_API_KEY="your-api-key"
export AWS_BEARER_TOKEN_BEDROCK="bedrock-key"
# Configuration
export CLAUDE_CONFIG_DIR="/custom/config/path"
export CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=true
export CLAUDE_CODE_API_KEY_HELPER_TTL_MS=3600000
# MCP Configuration
export MCP_TIMEOUT=30000
export MCP_TOOL_TIMEOUT=60000
# Bash Tool Configuration
export BASH_DEFAULT_TIMEOUT_MS=120000
export BASH_MAX_TIMEOUT_MS=600000
# Features
export DISABLE_INTERLEAVED_THINKING=false
# Debugging
export ANTHROPIC_LOG=debugSettings.json Configuration
Location: ~/.config/claude-code/settings.json
{
"cleanupPeriodDays": 30,
"forceLoginMethod": "oauth",
"allowedTools": ["bash", "read", "write"],
"ignorePatterns": ["node_modules", ".git"],
"preferredNotifChannel": "terminal_bell"
}Project-Specific Configuration
Create .claude/settings.json in your project root:
{
"allowedTools": ["bash", "read", "write", "review"],
"ignorePatterns": ["dist", "build", "coverage"]
}CLAUDE.md File
Create a CLAUDE.md file in your project root to store:
- Architecture documentation
- Dependencies and conventions
- Project-specific instructions
- Repository etiquette
- Developer environment setup
Claude automatically pulls this file into context when starting conversations.
4. Common Workflows
The Four-Step Workflow (Best Practice)
- Read and Understand: Ask Claude to read relevant files, images, or URLs without writing code yet
- Plan: Have Claude create a document or GitHub issue with its plan
- Implement: Ask Claude to implement the solution in code
- Commit: Ask Claude to commit and create a pull request
Git Workflows
# Search git history
claude -p "What changes made it into v1.2.3?"
# Create commits
claude -p "Create a commit for these changes"
# Handle complex operations
claude -p "Help me resolve these rebase conflicts"
# Create pull requests
claude -p "Create a PR for this feature"Custom Slash Commands
Create custom commands in .claude/commands/:
- Create file:
.claude/commands/fix-github-issue.md - Add content with
$ARGUMENTSplaceholder - Use as:
/project:fix-github-issue 1234
Automated Workflows
# CI/CD automation
claude -p "Run tests and deploy if passing"
# Log monitoring
tail -f app.log | claude -p "Slack me if you see any anomalies"
# Translation workflow
claude -p "If there are new text strings, translate them into French and raise a PR"Multi-Instance Workflows
Use git worktrees for parallel Claude instances:
# Create worktree
git worktree add ../feature-branch feature-branch
# Run Claude in each worktree
cd ../feature-branch && claude5. Troubleshooting Tips
Common Issues and Solutions
Installation Problems
Node.js Version Error:
# Check version
node --version
# If < 18, update Node.js
# Ubuntu/Debian:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejsNPM Permission Issues:
# Fix npm permissions
sudo chown -R $(whoami) ~/.npm
# Or use npm prefix
npm config set prefix ~/.npm
export PATH=$HOME/.npm/bin:$PATHConfiguration Issues
Invalid Settings File:
# Use doctor command to fix
claude
/doctorAPI Key Not Working:
# Check environment variable
echo $ANTHROPIC_API_KEY
# Set if missing
export ANTHROPIC_API_KEY="your-key-here"Windows-Specific Issues
PATH Not Configured:
- Add npm global directory to PATH
- Use WSL for better compatibility
- Ensure Git for Windows is installed
Terminal Issues:
- Use
/terminal-setupto fix Shift+Enter for new lines - Use Escape to stop Claude (not Control+C)
Performance Issues
Context Limit Reached:
- Use
/compactto summarize conversation - Use
/clearwhen starting new tasks - Monitor with context indicator in UI
High Token Usage:
- Use
/costto monitor usage - Optimize prompts for efficiency
- Use appropriate model for task complexity
Advanced Troubleshooting
MCP Server Issues:
# Debug MCP servers
claude --mcp-debug
# Check MCP configuration
claude
/mcpBash Tool Timeouts:
# Increase timeout
export BASH_MAX_TIMEOUT_MS=600000File Permission Issues:
# Skip permissions (use carefully)
claude --dangerously-skip-permissions6. Best Practices
Project Setup
- Initialize with
/initto create CLAUDE.md - Document architecture and conventions
- Set up project-specific
.claude/settings.json - Create custom commands for repeated tasks
Context Management
- Use
/clearwhen switching tasks - Monitor context usage indicator
- Use
/compactproactively - Keep conversations focused
Git Integration
- Make smaller, focused commits
- Use consistent commit message conventions
- Let Claude handle complex git operations
- Review Claude’s suggestions before executing
Security
- Review file changes before accepting
- Use project-specific permission settings
- Be cautious with
--dangerously-skip-permissions - Keep API keys secure
Performance Optimization
- Use appropriate model for task complexity
- Run multiple instances for parallel work
- Use custom commands for repeated workflows
- Leverage MCP for external data sources
Additional Resources
Official Resources
Community Resources
Getting Help
- Use
/bugcommand to report issues - File GitHub issues at the official repository
- Check release notes with
/release-notes - Join community discussions
Quick Reference Card
Essential Commands
claude # Start new session
claude --continue # Resume last session
claude -p "prompt" # Non-interactive mode
/help # Show all commands
/clear # Reset context
/compact # Summarize conversation
/init # Initialize project
/review # Code review
/bug # Report issuesKey Shortcuts
- Escape: Stop Claude (not Ctrl+C)
- Shift+Enter: New line in input
- Ctrl+V: Paste images (not Cmd+V on Mac)
- Shift+Drag: Reference files
Configuration Files
~/.config/claude-code/settings.json- Global settings.claude/settings.json- Project settingsCLAUDE.md- Project documentation.claude/commands/- Custom commands
See Also
- Quickstart Guide - Get started in 5 minutes
- Configuration Guide - Detailed configuration options
- TypeScript SDK - For programmatic access
- Workshops - Hands-on tutorials