Nadhebe
Tutorials

Claude Code Cheat Sheet 2026: Commands, Keyboard Shortcuts, CLI Flags & Custom Skills

The definitive 2026 Claude Code CLI cheat sheet. Includes every keyboard shortcut, slash command, CLI automation flag, CLAUDE.md config, MCP server setup, and background agent workflow.

Nadhebe Editorial Team Nadhebe Editorial Team
· · 14 min read
Minimalist technical cheat sheet schematic showing terminal execution shortcuts and slash commands
On this page

Anthropic’s Claude Code CLI is an autonomous, agentic coding tool that reads your local repository codebase, edits multi-file project structures, runs shell terminal commands, and manages git workflows directly from your terminal. Powered by Claude 3.7 Sonnet, Claude Opus 4.8, and Claude Fable 5, it operates as an interactive pair-programmer—interpreting natural language goals into precise file reads, AST searches, and code modifications.

This Claude Code Cheat Sheet serves as the definitive reference manual for developers, DevOps engineers, and technical architects. Bookmark this page for quick access to every keyboard shortcut, slash command, CLI flag, configuration schema, and Unix piping script.


⚡ 1. Quick Installation & Setup

Claude Code runs natively across macOS, Linux, and Windows PowerShell/WSL2 environments.

# macOS & Linux (Native POSIX Shell Script - Recommended)
curl -fsSL https://claude.ai/install.sh | bash

# macOS via Homebrew Cask
brew install --cask claude-code

# Windows Native PowerShell 7+ (Requires Git for Windows)
irm https://claude.ai/install.ps1 | iex

# Verify Binary & Authenticate
claude --version
claude login

[!WARNING] Deprecated Installation Notice: Anthropic has officially deprecated npm install -g @anthropic-ai/claude-code for general usage because npm global installations cannot support background self-updates. Always use native OS scripts.


⌨️ 2. Essential Keyboard Shortcuts Matrix

These keyboard shortcuts operate inside interactive Claude Code terminal sessions.

Keyboard ShortcutPrimary ActionUse Case & Context
Ctrl + CInterrupt / CancelFirst press interrupts active tool execution. Second press exits the CLI session.
EscStop GenerationInterrupts model output mid-turn while preserving all file modifications completed so far.
Esc + EscOpen Rewind MenuOpens interactive checkpoint menu. Select Restore code and conversation to roll back.
Ctrl + DExit SessionCleanly closes active Claude Code terminal process.
Ctrl + LRedraw Terminal ScreenClears screen artifacts and recovers garbled TUI displays.
Ctrl + RReverse History SearchSearches through previous session prompt input history.
Shift + TabCycle Permission ModesCycles between manual, plan, acceptEdits, auto, and bypassPermissions.
Ctrl + GOpen External EditorOpens your active prompt draft inside $EDITOR (Neovim/Vim/VS Code).
Ctrl + OToggle Transcript ViewerDisplays raw tool call JSON payloads, API token counts, and expanded MCP calls.
Ctrl + TToggle Task ManagerDisplays live list of running background subagents and shell commands.
Ctrl + BDetach to BackgroundDetaches current long-running operation into a background agent task.
Ctrl + X Ctrl + KEmergency Subagent KillKills all active background subagents (press twice within 3 seconds).

Input Formatting & Line Editing

Keyboard ShortcutPrimary ActionPlatform Availability
\ + EnterMultiline New LineUniversal (Works across all terminals)
Ctrl + JMultiline New LineUniversal fallback for unconfigured shells
Option + EnterNew LinemacOS default shortcut
Alt + EnterNew LineLinux & Windows Terminal default shortcut
Shift + EnterNew LineiTerm2, Ghostty, Kitty, Warp, Windows Terminal
Ctrl + A / Ctrl + EStart / End of LineJumps cursor to absolute start or end of active input line
Ctrl + KDelete to EOLDeletes all text from active cursor position to end of line
Ctrl + UDelete to Line StartDeletes all text from active cursor position back to line start
Ctrl + WDelete Previous WordDeletes word immediately preceding the cursor
Ctrl + YPaste Killed TextPastes buffer text deleted via Ctrl+K, Ctrl+U, or Ctrl+W
Cmd + V / Ctrl + VPaste Image AssetPastes clipboard image directly into CLI prompt for visual analysis

Model & Reasoning Toggles

Keyboard ShortcutPrimary ActionOperational Description
Option + P / Alt + PSwitch ModelInteractively cycles active model (Sonnet 5, Opus 4.8, Haiku 4.5, Fable 5)
Option + T / Alt + TToggle Extended ThinkingEnables or disables <thinking> reasoning budget for active turn
Option + O / Alt + OToggle Fast ModeToggles high-speed output mode for rapid response generation

🛠️ 3. Interactive Slash Commands Reference

Slash commands control session state, token usage, code review suites, and environment settings.

mindmap
  root((Claude Code Slash Commands))
    Session Management
      /clear
      /compact
      /cost
      /context
      /rewind
      /cd
    Project & Code Tools
      /init
      /code-review
      /simplify
      /verify
      /plan
      /branch
      /batch
    System & Diagnostics
      /doctor
      /checkup
      /insights
      /loop
      /teleport
      /remote-control

Context & Session Controls

Slash CommandUsage SyntaxOperational Purpose
/clear/clearWipes active conversation history completely and resets token context to zero.
/compact/compact [focus topic]Summarizes current chat history to free context window space while preserving key state.
/cost/costDisplays exact token consumption, cached token reads, and cumulative API USD cost.
/context/contextVisualizes exact token distribution across files, system prompts, and tool history.
/resume/resume [session-name]Displays interactive picker to resume prior conversation sessions.
/rename/rename <new-name>Assigns a custom identifier name to the current session for easy resuming.
/rewind/rewindOpens checkpoint menu to roll back both filesystem edits and conversation turns.
/diff/diffDisplays interactive git diff of all uncommitted modifications executed by Claude.
/cd/cd <path>Changes active working directory while retaining active prompt cache entries.
/background/background (or /bg)Detaches current interactive session into a background agent running in user space.

Code Analysis & Refactoring Tools

Slash CommandUsage SyntaxOperational Purpose
/init/initScans workspace and auto-generates a standardized CLAUDE.md context file.
/code-review/code-review [--fix] [--comment]Audits uncommitted git diff for security flaws and performance bottlenecks.
/simplify/simplify [target-file]Performs cleanup-only refactoring (simplifying code, removing boilerplate).
/verify/verifyCompiles, builds, and executes application tests to confirm code modifications work.
/plan/planEnters read-only planning mode to analyze repository state before editing.
/branch/branch <branch-name>Branches active conversation to explore alternative refactoring directions.
/fork/fork <directive>Copies current conversation into a new background session while keeping active context.
/subtask/subtask <directive>Spawns an in-session subagent that executes a sub-goal and returns findings.
/batch/batch <task-description>Decomposes massive changes into parallel units running across separate git worktrees.

System Diagnostics & Advanced Utilities

Slash CommandUsage SyntaxOperational Purpose
/doctor/doctor (or /checkup)Runs comprehensive diagnostic audit on auth, settings, MCP servers, and updater state. Press f to auto-fix issues.
/insights/insightsGenerates analytical report on developer prompting efficiency, waiting times, and token cost patterns.
/loop/loop <interval> <prompt>Schedules a prompt or slash command to run repeatedly on a timer (e.g., /loop 5m /verify).
/teleport/teleportPulls an active session from the Claude web interface (claude.ai) or iOS app into your terminal.
/remote-control/remote-controlAllows controlling your local terminal Claude session remotely from mobile or web interfaces.
/deep-research/deep-research <topic>Fans out web queries, cross-checks technical documentation, and synthesizes a cited report.
/btw/btw <question>Asks an ephemeral side question without writing to conversation context or using tokens.

🤖 4. Non-Interactive CLI Automation & Piping (claude -p)

The -p (print) flag runs Claude Code in headless, non-interactive mode. This enables integration into shell scripts, CI/CD runners, and git hooks.

Core Automation Flags

# Simple non-interactive query
claude -p "Explain the error handling strategy in src/server.ts"

# Read input from standard Unix pipe
cat error.log | claude -p "What is causing this database connection pool exhaustion?"

# Audit Git Diff non-interactively
git diff main | claude -p "Review for OWASP Top 10 security vulnerabilities"

# Enforce JSON output format for downstream shell processing
claude -p "Extract all API route definitions from src/routes/" --output-format json

# Restrict allowed tool calls (Auto-approve specific tools)
claude -p "Fix unit test failures in tests/auth.test.ts" --allowedTools "Read,Edit,Bash(npm test)"

# Explicitly block destructive commands
claude -p "Refactor API layer" --disallowedTools "Bash(rm:*),Bash(sudo:*)"

# Set strict spending and turn limits
claude -p "Refactor database migrations" --max-budget-usd 3.50 --max-turns 5

# Headless CI/CD container mode (Bypasses all confirmation prompts)
claude --dangerously-skip-permissions -p "Run linter and auto-fix formatting issues"

JSON Schema Output Enforcement

To force Claude Code to return structured JSON adhering to a specific schema:

claude -p "Extract exported function signatures from src/utils.ts" \
  --output-format json \
  --json-schema '{
    "type": "object",
    "properties": {
      "functions": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "name": { "type": "string" },
            "returnType": { "type": "string" }
          },
          "required": ["name", "returnType"]
        }
      }
    },
    "required": ["functions"]
  }'

📄 5. CLAUDE.md Project Configuration Architecture

CLAUDE.md is the primary configuration file for establishing repository-level guidelines, build instructions, and coding standards. It is loaded automatically at the start of every session.

File Hierarchy & Resolution Order

Project Root Configuration:
├── ./CLAUDE.md                  # Project-specific rules (Committed to Git)
├── ./.claude/CLAUDE.md          # Alternative project path (Committed to Git)
├── ./.claude/rules/*.md         # Path-specific conditional rules
└── ~/.claude/CLAUDE.md          # Global user preferences (Personal - Not committed)

Production CLAUDE.md Template

Create CLAUDE.md at your repository root:

# Repository Technical Guidelines — Modern E-Commerce API

## Build, Test & Lint Commands
- Run Unit Tests: `npm test`
- Run Single Test File: `npx jest tests/auth.test.ts`
- Execute Production Build: `npm run build`
- Type Check & Lint: `npm run typecheck && npm run lint`

## Architecture & Framework Stack
- Runtime & Framework: Node.js v20 LTS + Express.js + TypeScript Strict
- Database Engine: PostgreSQL 16 managed via Prisma ORM (`prisma/schema.prisma`)
- Context & Cache Layer: Redis Enterprise (`src/lib/redis.ts`)

## Coding Standards & Conventions
- All database queries must use parameterized statements or Prisma client calls.
- Never write bare `any` types; define explicit Zod validation schemas for API inputs.
- All errors must be handled by `src/middleware/errorHandler.ts`.

## Environment Context References
- Import Database Schema: @prisma/schema.prisma
- Import API Package Manifest: @package.json

Path-Specific Rules (.claude/rules/*.md)

To enforce rules that only apply when Claude touches specific subdirectories, create path-targeted rule files under .claude/rules/.

Example: .claude/rules/api-routes.md:

---
paths:
  - "src/routes/**/*.ts"
  - "src/controllers/**/*.ts"
---

# REST API Security Guidelines
- Every endpoint MUST enforce JWT bearer token validation middleware.
- Input validation MUST be executed using Zod schemas before hitting business logic.
- API endpoints MUST return standard RFC 7807 problem details JSON on error.

🔌 6. MCP Servers Setup (.mcp.json)

Model Context Protocol (MCP) connects Claude Code to external tools, databases, issue trackers, and third-party APIs.

Project Configuration (.mcp.json)

Create .mcp.json at your repository root to share tool integrations across your engineering team:

{
  "mcpServers": {
    "github": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_TOKEN"
      }
    },
    "postgres": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "DATABASE_URL": "postgresql://postgres:secret@localhost:5432/production_db"
      }
    },
    "sentry": {
      "type": "http",
      "url": "https://mcp.sentry.io/query"
    }
  }
}

Managing MCP via CLI Subcommands

# Add a new stdio MCP server
claude mcp add github -e GITHUB_TOKEN=$GITHUB_TOKEN -- npx @modelcontextprotocol/server-github

# Add an HTTP transport MCP server
claude mcp add --transport http sentry https://mcp.sentry.io/query

# List all active MCP server connections
claude mcp list

# Authenticate OAuth MCP connections
claude mcp login github

🧠 7. Custom Skills & Subagents

Extend Claude Code by authoring reusable slash commands (Skills) and specialized subagents.

Authoring Custom Skills (.claude/skills/)

Create .claude/skills/deploy/SKILL.md:

---
name: deploy
description: Executing automated staging/production deployments
argument-hint: "[environment]"
user-invocable: true
---

Execute a verified deployment to the $0 environment (default: staging).

Execution Workflow:
1. Run `npm run typecheck` and `npm test` to verify codebase integrity.
2. Build static artifacts via `npm run build`.
3. Execute deployment script: `./scripts/deploy.sh $0`.
4. Trigger health check endpoint and verify HTTP 200 OK response.

Invoke your skill inside terminal sessions:

/deploy production

Authoring Custom Subagents (.claude/agents/)

Create .claude/agents/security-auditor/AGENT.md:

---
name: security-auditor
description: Specialized OWASP security auditing agent
tools: Read, Grep, Glob, Bash
model: sonnet
---

You are an expert Application Security Auditor. When invoked:
1. Audit all modified files for SQL injection, XSS, and unauthenticated endpoints.
2. Verify that secrets, private keys, and API tokens are NOT committed.
3. Validate CORS origins and JWT verification middleware.

Invoke your agent in interactive or headless modes:

# Interactive call
@security-auditor Perform security audit on latest changes

# Headless CLI call
claude --agent security-auditor -p "Audit src/auth/ for vulnerabilities"

⚡ 8. Background Agents & Dynamic Workflows

Claude Code supports running full autonomous agent sessions detached in the background.

# Launch a background agent session
claude --bg "Investigate flaky test failures in tests/integration/"

# Launch a background shell command
claude --bg --exec "npm run test:e2e"

# Open interactive TUI background agent manager
claude agents

# Manage background sessions by ID
claude attach 7c5dcf5d    # Attach to terminal
claude logs 7c5dcf5d      # Tail live log output
claude stop 7c5dcf5d      # Stop running background session

Dynamic Multi-Agent Workflows

When handling large tasks under high reasoning effort (/effort max or ultracode), Claude Code automatically spawns parallel subagents:

  • /subtask <directive>: Spawns an in-session subagent that executes an isolated task and reports back.
  • /batch <task>: Decomposes repository-wide refactoring into 5–30 units running in parallel git worktrees.

⚙️ 9. Environment Variables & TUI Optimization

Fine-tune CLI performance, proxy configuration, and rendering settings via environment variables.

# Eliminate terminal screen flicker & enable mouse event support
export CLAUDE_CODE_NO_FLICKER=1

# Set default model & reasoning budget
export ANTHROPIC_MODEL="sonnet"
export CLAUDE_CODE_EFFORT_LEVEL="high"

# Configure corporate HTTP proxy
export HTTPS_PROXY="http://proxy.enterprise.com:8080"

# Safety caps: Limit subagent spawns per session (Default: 200)
export CLAUDE_CODE_MAX_SUBAGENTS_PER_SESSION=100

🧪 10. Real-World Shell Piping Examples

Claude Code integrates into Unix pipeline chains.

1. Automated Git Commit Message Generator

git diff --staged | claude -p "Generate a concise Conventional Commit message based on these changes" --model haiku

2. Live Log Error Root Cause Analysis

tail -n 500 /var/log/nginx/error.log | claude -p "Analyze these Nginx log errors and output root cause troubleshooting steps"

3. Kubernetes Pod Failure Audit

kubectl logs deployment/payment-service --tail=200 | claude -p "Identify exception stack traces and suggest fixes"

4. Docker Container Resource Inspection

docker stats --no-stream | claude -p "Which containers are exceeding memory thresholds?"

📊 Summary Quick Reference Card

================================================================================
CLAUDE CODE QUICK REFERENCE CARD
================================================================================
Launch Interactive Session:    claude
Resume Last Session:           claude -c
Initialize CLAUDE.md:          /init
Switch Permission Mode:        Shift + Tab
Rewind Code & History:         Esc + Esc
Compact Context Window:        /compact
Check Token Cost:              /cost
Run Setup Health Check:        /doctor  (press 'f' to auto-fix)
Headless Non-Interactive Run:  claude -p "prompt" --output-format json
Flicker-Free TUI Mode:         export CLAUDE_CODE_NO_FLICKER=1
================================================================================

Frequently asked questions

How do I interrupt or stop Claude Code mid-turn?

Press 'Esc' once to stop generation while preserving changes made so far. Press 'Ctrl+C' to cancel a running operation or exit.

How do I rewind code changes and conversation state in Claude Code?

Press 'Esc + Esc' to open the interactive rewind menu, then select 'Restore code and conversation' to revert to a prior checkpoint.

What is the non-interactive CLI flag for headless automation?

Use 'claude -p "your prompt"' along with '--output-format json' and '--allowedTools' for CI/CD pipeline automation.

How do I eliminate terminal rendering screen flicker in Claude Code?

Set the environment variable 'export CLAUDE_CODE_NO_FLICKER=1' in your shell profile or use 'tui: "fullscreen"' in settings.json.

Sources & references

  1. [1]Official Claude Code CLI Documentation
  2. [2]Anthropic Claude Code GitHub Repository
Nadhebe Editorial Team

Nadhebe Editorial Team

Technical research and documentation published by the Nadhebe editorial team.

Get the next issue

One focused essay a week. No noise, unsubscribe anytime.