Claude Code is Anthropic’s AI-powered CLI tool that reads your codebase, edits files, runs commands, and manages git workflows directly from the terminal. It operates as an agentic coding assistant – you describe what you want in plain English, and it figures out which files to read, what commands to run, and what changes to make. This cheat sheet covers every command, shortcut, configuration option, and workflow pattern you need to be productive with Claude Code.
Installation
Install Claude Code on macOS, Linux, or Windows (WSL):
curl -fsSL https://claude.ai/install.sh | bash
On macOS via Homebrew:
brew install --cask claude-code
On Windows (PowerShell):
irm https://claude.ai/install.ps1 | iex
Verify and authenticate:
claude --version
claude auth login
Keyboard Shortcuts
These work in the interactive Claude Code terminal. This is the most-referenced section – bookmark it.
Essential Shortcuts
| Shortcut | Action |
|---|---|
Ctrl+C | Cancel current generation or input |
Ctrl+D | Exit Claude Code |
Ctrl+L | Clear terminal screen |
Ctrl+R | Reverse search command history |
Esc + Esc | Rewind to previous checkpoint (undo) |
Shift+Tab | Cycle permission modes (default/plan/yolo) |
Ctrl+G | Open input in external editor (vim, etc.) |
Ctrl+O | Toggle verbose output |
Ctrl+T | Toggle task list |
Ctrl+F | Kill all background agents (press twice) |
Input and Editing
| Shortcut | Action |
|---|---|
\ + Enter | New line (multiline input) – works everywhere |
Option+Enter (Mac) | New line (macOS default) |
Shift+Enter | New line (iTerm2, WezTerm, Ghostty, Kitty) |
Ctrl+K | Delete to end of line |
Ctrl+U | Delete entire line |
Ctrl+Y | Paste deleted text |
Alt+B / Alt+F | Move cursor back/forward one word |
Ctrl+V / Cmd+V | Paste image from clipboard |
Up/Down | Navigate command history |
Model and Mode Switching
| Shortcut | Action |
|---|---|
Option+P (Mac) / Alt+P | Switch model (Sonnet/Opus/Haiku) |
Option+T (Mac) / Alt+T | Toggle extended thinking |
Shift+Tab | Cycle permission mode |
? | Show all available shortcuts |
Quick Prefixes
| Prefix | Action |
|---|---|
/ | Open slash command menu |
! | Run bash command directly |
@ | Autocomplete file path mention |
Slash Commands Reference
Session and Context Management
| Command | What It Does |
|---|---|
/clear | Wipe conversation history and free context window |
/compact [focus] | Summarize conversation to free context – optionally focus on specific topic |
/cost | Show token usage and API cost for current session |
/context | Visualize what is consuming your context window |
/resume | Pick and resume a previous session |
/rename [name] | Name current session for easy resuming later |
/rewind | Rewind to a previous checkpoint |
/diff | View interactive diff of all changes made |
/copy | Copy last response to clipboard |
/export [file] | Export conversation as text file |
Configuration and Model
| Command | What It Does |
|---|---|
/model [name] | Switch model (sonnet, opus, haiku) |
/effort [level] | Set reasoning effort (low, medium, high, max) |
/config | Open settings interface |
/permissions | View and manage tool permissions |
/mcp | Manage MCP server connections |
/terminal-setup | Configure terminal keybindings for your shell |
/theme | Change color theme |
/vim | Toggle vim keybinding mode |
Project and Code Tools
| Command | What It Does |
|---|---|
/init | Initialize project – generates CLAUDE.md with project context |
/memory | View and edit CLAUDE.md files and auto-memory |
/security-review | Scan pending changes for security vulnerabilities |
/simplify | Review changed code for quality issues and suggest improvements |
/pr-comments [PR] | Fetch and address GitHub PR review comments |
/add-dir [path] | Add another directory to the working context |
/plan | Enter plan mode – read-only exploration before making changes |
/batch [task] | Run large-scale changes across 5-30 parallel git worktrees |
System and Account
| Command | What It Does |
|---|---|
/help | Show all available commands |
/doctor | Diagnose installation and configuration issues |
/status | Show version, model, and account info |
/login / /logout | Sign in or out |
/bug | Submit a bug report |
/stats | View usage patterns and daily stats |
/usage | Show plan usage and rate limits |
/release-notes | View changelog |
CLI Flags – Non-Interactive and Automation
Starting Sessions
# Start interactive session
claude
# Start with initial prompt
claude "refactor the auth module"
# Continue most recent session
claude -c
# Resume specific session by name
claude -r "auth-refactor"
# Name a session for later
claude -n "feature-payments"
# Run in isolated git worktree
claude -w feature-branch
Print Mode (Non-Interactive / Piping)
The -p flag runs Claude Code non-interactively – it processes the prompt and exits. This is the key to integrating Claude Code into scripts, CI/CD pipelines, and Unix pipes:
# Simple query
claude -p "explain this error in server.log"
# Pipe input
cat error.log | claude -p "what caused this crash?"
# Git diff review
git diff main | claude -p "review for security issues"
# JSON output for scripting
claude -p "list all TODO comments" --output-format json
# Structured output with schema validation
claude -p "extract function names from auth.py" \
--output-format json \
--json-schema '{"type":"object","properties":{"functions":{"type":"array","items":{"type":"string"}}}}'
# Auto-approve tools (careful with this)
claude -p "run tests and fix failures" --allowedTools "Bash,Read,Edit"
# Set spending limit
claude -p "refactor the API layer" --max-budget-usd 5.00
# Limit turns
claude -p "fix the bug" --max-turns 3
Model and Effort Flags
# Use specific model
claude --model opus
claude --model sonnet
claude --model haiku
# Set reasoning effort
claude --effort high # More thorough (costs more)
claude --effort low # Faster, cheaper
# Custom system prompt
claude --append-system-prompt "Always use TypeScript. Never use any."
# Load system prompt from file
claude --append-system-prompt-file ./coding-rules.txt
CLAUDE.md – Project Instructions
CLAUDE.md is the single most important file for customizing Claude Code behavior on a per-project basis. It is loaded automatically at the start of every session.
File Locations and Scope
| Location | Scope | Shared with Team? |
|---|---|---|
./CLAUDE.md | This project only | Yes (commit to git) |
./.claude/CLAUDE.md | This project only | Yes (commit to git) |
~/.claude/CLAUDE.md | All your projects | No (personal) |
.claude/rules/*.md | Path-specific rules | Yes (commit to git) |
Example CLAUDE.md
vi CLAUDE.md
Add your project instructions:
# My Project
## Build and Test
- Run tests: `npm test`
- Build: `npm run build`
- Lint: `npm run lint`
## Code Style
- Use TypeScript strict mode
- Prefer functional components in React
- All API responses must include error handling
- Never commit .env files
## Architecture
- Backend: Express.js + PostgreSQL
- Frontend: React + TailwindCSS
- Auth: JWT tokens stored in httpOnly cookies
See @README.md for project overview.
See @package.json for available scripts.
The @filename syntax imports content from other files – Claude reads them automatically.
Path-Specific Rules
Rules that only apply to certain files. Create .claude/rules/api.md:
vi .claude/rules/api.md
Add frontmatter with path patterns:
---
paths:
- "src/api/**/*.ts"
---
# API Rules
- All endpoints must validate input with Zod
- Return proper HTTP status codes
- Include rate limiting on public endpoints
Generate a CLAUDE.md automatically for any project with /init.
Permission Modes
Claude Code asks permission before running commands or editing files. Toggle between modes with Shift+Tab:
| Mode | Behavior | Use Case |
|---|---|---|
| default | Prompts on first use of each tool | Normal interactive work |
| plan | Read-only – no edits, no commands | Safe exploration and planning |
| acceptEdits | Auto-approves file edits, prompts for commands | Trusted editing sessions |
| dontAsk | Auto-denies unless pre-approved | Strict control |
| bypassPermissions | Skips all prompts (dangerous) | Containers/sandboxes only |
Pre-Approve Specific Tools
In .claude/settings.json or via the CLI:
# Allow git commands and file reads without prompting
claude --allowedTools "Read,Bash(git *)"
Or in settings:
vi .claude/settings.json
Add permission rules:
{
"permissions": {
"allow": [
"Read",
"Bash(git *)",
"Bash(npm run *)",
"Bash(docker compose *)"
],
"deny": [
"Bash(rm -rf *)"
]
}
}
Models and Effort Levels
| Model | Best For | Speed |
|---|---|---|
| sonnet (Claude Sonnet 4.6) | Daily coding – edits, refactors, tests | Fast |
| opus (Claude Opus 4.6) | Complex architecture, debugging, multi-file changes | Slower |
| haiku (Claude Haiku 4.5) | Simple tasks, quick questions | Fastest |
Switch models mid-session with /model opus or Option+P (Mac) / Alt+P.
Effort levels control how much reasoning Claude applies:
| Level | Use Case |
|---|---|
/effort low | Simple questions, quick lookups |
/effort medium | Default – balanced speed and quality |
/effort high | Complex debugging, architecture decisions |
/effort max | Hardest problems (Opus only, unlimited thinking budget) |
MCP Servers – Extend Claude Code
MCP (Model Context Protocol) lets Claude Code connect to external tools and data sources. Configure servers in .mcp.json at the project root or ~/.claude/.mcp.json for all projects.
vi .mcp.json
Example configuration with GitHub and PostgreSQL servers:
{
"mcpServers": {
"github": {
"type": "stdio",
"command": "npx",
"args": ["@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_TOKEN"
}
},
"postgres": {
"type": "stdio",
"command": "npx",
"args": ["@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb"
}
}
}
}
Manage MCP connections with /mcp in the interactive session.
Custom Skills – Your Own Slash Commands
Skills are reusable prompts that show up as slash commands. Create them at .claude/skills/ (project) or ~/.claude/skills/ (personal).
Example – create a deploy skill:
mkdir -p .claude/skills/deploy
vi .claude/skills/deploy/SKILL.md
Add the skill definition:
---
name: deploy
description: Deploy the application to production
argument-hint: "[environment]"
user-invocable: true
---
Deploy the application to the $0 environment (default: staging).
Steps:
1. Run the test suite
2. Build the production bundle
3. Deploy using the deploy script
4. Verify the deployment health check
Now use it: /deploy production
Custom Subagents
Subagents are specialized AI agents that Claude can delegate tasks to. Create them at .claude/agents/:
mkdir -p .claude/agents/code-reviewer
vi .claude/agents/code-reviewer/AGENT.md
Define the agent:
---
name: code-reviewer
description: Expert code reviewer. Use proactively after code changes.
tools: Read, Grep, Glob, Bash
model: sonnet
---
You are a senior code reviewer. When reviewing code:
- Check for security vulnerabilities (SQL injection, XSS, etc.)
- Verify error handling is complete
- Flag any hardcoded secrets or credentials
- Suggest performance improvements
- Check for proper input validation
Claude automatically delegates code review tasks to this agent, or you can invoke it directly with @code-reviewer check my latest changes.
Hooks – Automation Triggers
Hooks run shell commands automatically in response to Claude Code events. Configure in .claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "npx prettier --write $(jq -r '.tool_input.file_path')"
}
]
}
],
"Notification": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "osascript -e 'display notification \"Claude needs input\" with title \"Claude Code\"'"
}
]
}
]
}
}
Common hook events: SessionStart, PreToolUse, PostToolUse, Stop, Notification, UserPromptSubmit.
Context Window Management
Claude Code has a finite context window. Managing it well is the difference between a productive session and hitting walls.
Key Commands
| Command | When to Use |
|---|---|
/compact | Summarize conversation to free space mid-task |
/compact Focus on auth module | Summarize but keep specific context intact |
/clear | Complete reset between unrelated tasks |
/context | See what is consuming your context |
Tips for Long Sessions
- Use
/clearbetween unrelated tasks – do not carry old context into new work - Run
/compactproactively when you notice slowdowns - Use subagents for verbose operations (test runs, log analysis) – their output stays in the subagent context
- Move detailed instructions to skills instead of typing them every time
- Keep CLAUDE.md under 200 lines – move details to separate files and import with
@filename
Git Worktrees – Parallel Work
Work on multiple tasks simultaneously without branch switching conflicts:
# Start Claude in a new worktree
claude -w feature-auth
# Batch changes across many files in parallel
/batch migrate all components from class-based to functional
The -w flag creates an isolated git worktree. Changes happen in the worktree without affecting your main working directory. When the agent finishes, merge the worktree branch back.
Settings File Reference
| File | Scope |
|---|---|
.claude/settings.json | Project (shared via git) |
.claude/settings.local.json | Project (gitignored, personal) |
~/.claude/settings.json | All projects (personal) |
Common settings:
{
"model": "sonnet",
"effortLevel": "medium",
"defaultMode": "default",
"autoMemoryEnabled": true,
"permissions": {
"allow": ["Read", "Bash(git *)"],
"deny": ["Bash(rm -rf *)"]
}
}
Environment Variables
| Variable | Purpose |
|---|---|
ANTHROPIC_MODEL | Default model (e.g., opus) |
ANTHROPIC_API_KEY | API key for direct API access |
CLAUDE_CODE_EFFORT_LEVEL | Default effort (low/medium/high/max) |
CLAUDE_CODE_DISABLE_AUTO_MEMORY | Set to 1 to disable auto-memory |
CLAUDE_CODE_DISABLE_1M_CONTEXT | Set to 1 to disable 1M token context |
MAX_THINKING_TOKENS | Custom thinking budget (default varies) |
HTTPS_PROXY | HTTP proxy for corporate networks |
File Structure Reference
# User-level (personal, all projects)
~/.claude/
settings.json # Global settings
keybindings.json # Custom keyboard shortcuts
CLAUDE.md # Personal instructions
rules/ # Personal rules
agents/ # Personal subagents
skills/ # Personal skills
.mcp.json # Global MCP servers
# Project-level (shared with team)
.claude/
settings.json # Project settings (git tracked)
settings.local.json # Local overrides (gitignored)
CLAUDE.md # Project instructions
rules/ # Path-specific rules
agents/ # Project subagents
skills/ # Project skills
.mcp.json # Project MCP servers
CLAUDE.md # Project instructions (alternative location)
Practical Workflow Tips
Start Every Project Right
# In your project root
claude
/init
This scans your project and generates a CLAUDE.md with build commands, test instructions, and code conventions. Review and edit it – this file shapes every future interaction.
Plan Before You Build
Press Shift+Tab to enter plan mode before asking Claude to make changes. In plan mode, Claude reads and analyzes but cannot edit anything. Once you approve the plan, switch back to default mode and say “implement the plan”.
Undo Mistakes Instantly
Press Esc + Esc to open the rewind menu. Choose “Restore code and conversation” to undo both the code changes and the conversation that led to them. This is faster than git stash for quick experiments.
Pipe Everything
# Analyze logs
tail -500 /var/log/app.log | claude -p "find the root cause of errors"
# Review a PR
gh pr diff 42 | claude -p "security review this PR"
# Generate commit message
git diff --staged | claude -p "write a conventional commit message" --model haiku
# Translate
cat README.md | claude -p "translate to Japanese" > README.ja.md
Side Questions with /btw
Need to ask something without derailing the current task? Use /btw:
/btw what was the name of that config file we edited earlier?
The response is ephemeral (not saved to context), low-cost (uses cache), and does not use any tools.
Cost Control
- Use
/costto check spend at any time - Use Sonnet for most work, Opus only for complex problems
- Use
/effort lowfor simple tasks - Run
/compactto reduce context size (fewer tokens per request) - Be specific in prompts – vague requests cause more back-and-forth
- Use
--max-budget-usd 5.00in CI/CD to prevent runaway costs
IDE Integrations
Claude Code integrates with VS Code and JetBrains IDEs for inline diffs, context sharing, and side-by-side conversations.
VS Code
- Install the “Claude Code” extension from the VS Code marketplace
- Open Command Palette (
Cmd+Shift+P/Ctrl+Shift+P) and search “Claude Code” - Works with Cursor editor too
JetBrains (IntelliJ, PyCharm, WebStorm, etc.)
- Install “Claude Code” from the JetBrains Marketplace
- Works across all JetBrains IDEs
- Supports interactive diffs and context sharing
Start Claude with IDE auto-detection:
claude --ide
Quick Reference Card
The 20 commands and shortcuts you will use every day:
| Action | How |
|---|---|
| Start new session | claude |
| Continue last session | claude -c |
| Initialize project | /init |
| Switch to plan mode | Shift+Tab |
| Switch model | /model opus or Option+P |
| Undo changes | Esc + Esc |
| Free context space | /compact |
| Start fresh | /clear |
| Check costs | /cost |
| Review changes | /diff |
| Security scan | /security-review |
| Name session | /rename my-feature |
| Resume session | /resume or claude -r |
| Mention a file | @path/to/file |
| Run bash directly | !ls -la |
| Multiline input | \ + Enter |
| Cancel generation | Ctrl+C |
| Exit | Ctrl+D |
| Non-interactive | claude -p "query" |
| Show all commands | /help |
Conclusion
Claude Code replaces a large part of the manual terminal workflow for developers and sysadmins. The key to getting the most out of it: set up CLAUDE.md for every project, use plan mode before making changes, keep context clean with /compact and /clear, and use print mode (-p) to integrate it into your existing scripts and CI/CD pipelines. For the latest features and documentation, visit the official Claude Code docs.
Related guides:
- SSH Commands Cheat Sheet for Linux SysAdmins
- rsync Command on Linux – Usage Guide with Examples
- Basic Linux Terminal Shortcuts Cheat Sheet
- Install and Use lazygit – Terminal UI for Git

























































