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 install -g @anthropic-ai/claude-code

Platform-Specific Instructions

macOS with Homebrew:

brew install node
npm install -g @anthropic-ai/claude-code

Ubuntu/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-code

Arch Linux (AUR):

yay -S claude-code

Windows:

  • 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
claude

2. Available Commands and Usage

Basic Commands

  • claude - Start a new session with clean context
  • claude --continue - Resume your last session with all context preserved
  • claude --resume - See list of past sessions and jump back into any project
  • claude -p "prompt" - Print mode for non-interactive output
  • claude --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 prompts

3. Configuration Options

Configuration Hierarchy

  1. Environment variables (highest priority)
  2. ~/.config/claude-code/settings.json
  3. .claude/settings.json (project-specific)
  4. .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=debug

Settings.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)

  1. Read and Understand: Ask Claude to read relevant files, images, or URLs without writing code yet
  2. Plan: Have Claude create a document or GitHub issue with its plan
  3. Implement: Ask Claude to implement the solution in code
  4. 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/:

  1. Create file: .claude/commands/fix-github-issue.md
  2. Add content with $ARGUMENTS placeholder
  3. 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 && claude

5. 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 nodejs

NPM Permission Issues:

# Fix npm permissions
sudo chown -R $(whoami) ~/.npm
 
# Or use npm prefix
npm config set prefix ~/.npm
export PATH=$HOME/.npm/bin:$PATH

Configuration Issues

Invalid Settings File:

# Use doctor command to fix
claude
/doctor

API 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:

  1. Add npm global directory to PATH
  2. Use WSL for better compatibility
  3. Ensure Git for Windows is installed

Terminal Issues:

  • Use /terminal-setup to fix Shift+Enter for new lines
  • Use Escape to stop Claude (not Control+C)

Performance Issues

Context Limit Reached:

  • Use /compact to summarize conversation
  • Use /clear when starting new tasks
  • Monitor with context indicator in UI

High Token Usage:

  • Use /cost to 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
/mcp

Bash Tool Timeouts:

# Increase timeout
export BASH_MAX_TIMEOUT_MS=600000

File Permission Issues:

# Skip permissions (use carefully)
claude --dangerously-skip-permissions

6. Best Practices

Project Setup

  1. Initialize with /init to create CLAUDE.md
  2. Document architecture and conventions
  3. Set up project-specific .claude/settings.json
  4. Create custom commands for repeated tasks

Context Management

  1. Use /clear when switching tasks
  2. Monitor context usage indicator
  3. Use /compact proactively
  4. Keep conversations focused

Git Integration

  1. Make smaller, focused commits
  2. Use consistent commit message conventions
  3. Let Claude handle complex git operations
  4. Review Claude’s suggestions before executing

Security

  1. Review file changes before accepting
  2. Use project-specific permission settings
  3. Be cautious with --dangerously-skip-permissions
  4. Keep API keys secure

Performance Optimization

  1. Use appropriate model for task complexity
  2. Run multiple instances for parallel work
  3. Use custom commands for repeated workflows
  4. Leverage MCP for external data sources

Additional Resources

Official Resources

Community Resources

Getting Help

  • Use /bug command 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 issues

Key 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 settings
  • CLAUDE.md - Project documentation
  • .claude/commands/ - Custom commands

See Also