Claude Code Cheatsheet

LLM
CLI
Productivity
Quick reference for Claude Code CLI commands, shortcuts, and configuration
Author

Kedar Dabhadkar

Published

January 4, 2026

Claude Code is Anthropic’s official CLI tool for interacting with Claude directly from your terminal. This cheatsheet covers the essential commands, shortcuts, and configuration options.

Installation & Setup

# Install via npm
npm install -g @anthropic-ai/claude-code

# Launch Claude Code
claude

# First run will prompt for Anthropic API key or OAuth login

Essential Keyboard Shortcuts

Shortcut Action
Enter Send message
Shift+Enter New line in input
Ctrl+C Cancel current operation
Ctrl+L Clear screen
Esc Interrupt Claude / Exit input mode
Up/Down Navigate command history
Tab Autocomplete file paths

Slash Commands

Type these directly in the chat:

Command Description
/help Show help and available commands
/clear Clear conversation history
/compact Condense conversation to save context
/config Open configuration settings
/cost Show token usage and cost for session
/doctor Diagnose installation issues
/init Initialize Claude Code in current project
/login Switch accounts or re-authenticate
/logout Log out of current account
/memory View/edit persistent memory (CLAUDE.md)
/model Switch between available models
/permissions Manage tool permissions
/review Request code review
/status Show current session status
/tasks View running background tasks
/vim Toggle vim keybindings

CLI Flags

# Start with a specific prompt
claude "explain this codebase"

# Continue last conversation
claude --continue
claude -c

# Resume specific conversation
claude --resume <conversation_id>

# Print output only (no interactive mode)
claude --print "what does main.py do?"
claude -p "what does main.py do?"

# Use specific model
claude --model claude-sonnet-4-20250514

# Pipe input to Claude
cat error.log | claude "explain this error"

# Run in headless/non-interactive mode
claude --headless "fix the bug in auth.py"

# Output JSON format
claude --output-format json -p "list files"

# Set max turns for agentic loops
claude --max-turns 10 "refactor this module"

# Allow specific tools without prompting
claude --allowedTools "Bash(npm:*),Read,Write"

# Disable specific tools
claude --disallowedTools "Bash(rm:*)"

Configuration Files

CLAUDE.md (Project Memory)

Create CLAUDE.md in your project root to give Claude persistent context:

# Project: MyApp

## Tech Stack
- Python 3.11, FastAPI, PostgreSQL
- Frontend: React + TypeScript

## Conventions
- Use snake_case for Python, camelCase for JS
- All API endpoints go in `src/api/`
- Tests mirror source structure in `tests/`

## Common Commands
- `make dev` - Start development server
- `make test` - Run test suite

Settings Location

# Global settings
~/.claude/settings.json

# Project-level settings
.claude/settings.json

# Project-level settings (local, not committed)
.claude/settings.local.json

Permission Modes

Control how Claude asks for permission:

Mode Behavior
default Ask before file writes and shell commands
plan Research only, no code changes
trust-tools Allow all tools without asking
# Set via flag
claude --permission-mode trust-tools

# Or in settings.json
{
  "permissions": {
    "defaultMode": "default"
  }
}

MCP Servers

Model Context Protocol (MCP) servers extend Claude’s capabilities:

// ~/.claude/settings.json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "your-token"
      }
    }
  }
}

Popular MCP servers: - @modelcontextprotocol/server-filesystem - Enhanced file operations - @modelcontextprotocol/server-github - GitHub API integration - @modelcontextprotocol/server-postgres - Database queries - @modelcontextprotocol/server-brave-search - Web search

Hooks

Run custom scripts on Claude events:

// .claude/settings.json
{
  "hooks": {
    "onFileWrite": [
      {
        "command": "prettier --write",
        "match": "*.{js,ts,json}"
      }
    ],
    "onSessionStart": [
      {
        "command": "echo 'Session started'"
      }
    ]
  }
}

Available hooks: - onFileWrite - After file is written - onFileRead - After file is read - onSessionStart - When session begins - onSessionEnd - When session ends - onPromptSubmit - Before prompt is sent

Pro Tips

  1. Use /compact liberally - Keeps context window efficient for long sessions

  2. Create project-specific CLAUDE.md - Claude reads this automatically and follows your conventions

  3. Pipe content directly - git diff | claude "review these changes" is powerful

  4. Use --print for scripts - Get clean output for automation

  5. Check /cost periodically - Monitor your API usage

  6. Run /doctor - When things aren’t working right

  7. Use background tasks - Claude can run long operations without blocking

  8. Trust but verify - Always review code changes before committing

Useful Patterns

# Quick code explanation
claude -p "explain src/auth/" | less

# Debug with error logs
tail -100 app.log | claude "what's causing these errors?"

# Code review workflow
git diff main | claude "review this PR"

# Generate commit message
git diff --staged | claude -p "write a commit message"

# Explore unfamiliar codebase
claude "give me an overview of this project's architecture"

# Fix failing tests
npm test 2>&1 | claude "fix these test failures"

Resources