Claude Code Cheat Sheet

The essential commands, shortcuts, and patterns — organised for quick lookup.


Getting Started

Install

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

Requires Node.js 18+. After install, run claude in any project directory.

First run

claude

You’ll be prompted to authenticate via browser. After that, you’re in. Claude reads your current directory automatically.

Get help

/help

Lists all slash commands. Run it any time you forget something.


Essential Slash Commands

CommandWhat it does
/helpList all commands
/clearClear conversation and context
/compactSummarise history to free context window
/configView and edit settings
/costShow token usage and estimated cost for the session
/doctorCheck Claude Code installation and API health
/initGenerate a CLAUDE.md for your current project
/quit or /exitExit Claude Code

When to use /compact: Long sessions accumulate context. When responses start getting slower or less accurate, /compact compresses the history into a summary without losing the thread.


Tab Completion

Claude Code supports tab completion for slash commands. Type / and press Tab to cycle through options.


Working With Files

Claude Code reads, edits, and writes files directly — you don’t copy and paste content in. Just tell it what you need:

Read src/config/products.ts and tell me what products are defined.
Edit src/pages/index.astro — add a new ProductCard after the last one.

Tools Claude uses internally:

ToolDoes
ReadReads a file, returns contents with line numbers
EditMakes precise string replacements in a file
WriteCreates or overwrites a file
GlobFinds files matching a pattern (e.g. **/*.astro)
GrepSearches file contents with regex
BashRuns shell commands

You don’t invoke these directly — Claude chooses the right tool. But knowing they exist helps you ask better questions.

Useful asks:

Find all .astro files that import ProductCard.
Search for any file containing the string "kitTag".

Configuration

Project instructions — CLAUDE.md

Create a CLAUDE.md in your project root. Claude reads it at the start of every session. Use it for:

  • Project-specific conventions (naming, file structure, stack)
  • Commands Claude should always know (npm run dev, deployment steps)
  • Rules Claude should follow (British spelling, no emojis, etc.)

Generate a starter with:

/init

Global instructions — ~/.claude/CLAUDE.md

Same format, but applies to every project. Good for:

  • Your writing voice and tone
  • Tools and CLIs available on your machine
  • Preferred commit message format
  • Platform-specific knowledge (which VPS hosts what, etc.)

Settings — ~/.claude/settings.json

Controls permissions, allowed tools, and approved bash commands. Claude Code updates this automatically when you approve a new command. You can edit it directly if you need to revoke or pre-approve something.


Skills and Agents

Skills are slash commands with instructions. They live as markdown files and give Claude a defined task to run.

~/.claude/skills/my-skill.md

Invoke with:

/my-skill

Or pass arguments:

/my-skill --target src/pages/index.astro

Skills work best for: repeatable tasks you’d otherwise retype (commit messages, PR descriptions, code reviews, content audits).

Agents are autonomous subprocesses that run independently of the current conversation. You start them with the Agent tool inside a session, or Claude Code can spawn them during complex tasks.

Key difference: a skill is a prompt with instructions. An agent is a separate Claude Code process that can use all the same tools, run its own commands, and report back.


MCP Servers

MCP (Model Context Protocol) servers extend Claude Code with external tools — calendar access, database queries, API calls, custom data sources.

Where to configure them:

~/.claude/settings.json

Under the mcpServers key. Each server needs a command to start it and optional args/env vars.

Verify they’re working:

/doctor

Lists loaded MCP servers and flags any that failed to start.

In-session check:

Ask Claude: “What MCP tools do you have available?” — it will list everything it can see.


Power User Patterns

Free up context with /compact

Claude Code has a context window limit. For long sessions — large refactors, multi-file work — run /compact periodically. It compresses history into a summary so you can keep going without starting over.

Background agents with run_in_background

When you use the Agent tool (or Claude spawns one), you can flag it to run in the background. This lets you continue the main conversation while the agent works. Useful for: long-running audits, batch operations, content generation across many files.

Note: background agents don’t inherit the parent session’s permissions — they run as separate processes with their own permission context.

Git worktrees for isolation

Running multiple Claude Code sessions on the same repo can cause conflicts. Git worktrees let each session work in its own directory on the same underlying repo:

git worktree add ../my-project-feature feature-branch
cd ../my-project-feature
claude

Each worktree gets its own working directory, so sessions can’t step on each other.

Hooks for automation

Claude Code supports hooks — scripts that run before or after certain events (file save, bash command, session end). Configure in settings.json under the hooks key. Useful for: auto-formatting, commit prep, logging.


Keyboard Shortcuts

ShortcutDoes
EscCancel current operation
Shift + TabInsert a literal newline (for multi-line input)
(up arrow)Cycle through previous messages
Ctrl + CExit Claude Code (same as /quit)

Quick Reference: What Goes Where

FilePurpose
CLAUDE.md (project root)Project-specific instructions
~/.claude/CLAUDE.mdGlobal instructions for all projects
~/.claude/settings.jsonPermissions, tools, MCP servers, hooks
~/.claude/skills/Custom slash commands
~/.claude/agents/Agent definitions and prompts

Common Mistakes

Forgetting /compact — Long sessions degrade. Run /compact before quality drops, not after.

Global vs project CLAUDE.md confusion — Project CLAUDE.md overrides nothing in the global one. Both are read. Put project-specific things in the project file, universal things in the global file.

Background agents and permissions — A background agent that needs to write files must have those permissions set in its own context. It doesn’t inherit your session’s approvals.

Skipping /doctor — If an MCP server isn’t responding, /doctor will tell you immediately. Don’t spend time debugging in session before running it.