Skip to content

Claude Code CLI Cheatsheet

Claude Code CLI Cheatsheet

Overview

Claude Code is an agentic coding assistant from Anthropic that lives in your terminal. It can understand entire codebases, build features from natural language descriptions, fix bugs, and automate tedious development tasks. This cheatsheet focuses on the command-line interface (CLI) usage.

Installation

# Install Claude Code globally using npm
npm install -g @anthropic-ai/claude-code

Getting Started

# Navigate to your project directory
cd your-project

# Start an interactive session with Claude Code
claude

Core Commands

# Ask a question about your codebase
claude "How does the authentication middleware work?"

# Build a new feature
claude -p "Create a new API endpoint for user profiles"

# Fix a bug from an error message
claude -p "Fix this error: 'TypeError: Cannot read property 'id' of undefined'"

# Run a command and pipe the output to Claude
tail -f server.log | claude -p "Alert me if you see any critical errors"

Key Features

  • Codebase Awareness: Understands your entire project structure.
  • Agentic Capabilities: Can read files, run commands, and create commits.
  • Natural Language Interface: Interact with your codebase using plain English.
  • Terminal Integration: Works seamlessly within your existing terminal workflow.
  • MCP Integration: Connects to external tools like Google Drive, Figma, and Jira.

Common Workflows

  • Feature Development: Describe a feature, and Claude Code will plan and implement it.
  • Debugging: Paste an error message, and Claude will find and fix the root cause.
  • Code Refactoring: Ask Claude to refactor a file or function for better readability.
  • Documentation: Generate documentation for a specific part of your codebase.
  • CI/CD Automation: Automate tasks like linting, testing, and release notes.

Advanced Usage

# Use a specific model for a task
claude --model claude-3-opus -p "Analyze the performance of this function"

# Set a custom prompt for a session
claude --prompt "You are a senior security engineer. Review this code for vulnerabilities."

# Integrate with other tools
claude -p "Read the design doc from Google Drive and implement the new UI"

Additional Resources