Dev Encyclopedia
ArticlesTools

Get notified when new content drops

No spam. Just new articles, tools, and updates — straight to your inbox.

Dev Encyclopedia

A reference for builders

Content

  • Articles
  • Tools
  • Contact

Connect

  • support@devencyclopedia.com
  • RSS Feed

© 2026 Dev Encyclopedia

Privacy PolicyTermsDisclaimer
  1. Home
  2. /Blog
  3. /Claude Code Cheatsheet: Commands, Hooks & Subagents
ai tools10 min read

Claude Code Cheatsheet: Commands, Hooks & Subagents

The complete Claude Code reference: every slash command, keyboard shortcut, hook, subagent, and CLAUDE.md tip — with real examples for developers.

By Dev EncyclopediaPublished June 6, 2026
On this page

On this page

  • What Is Claude Code and How Do You Start It
  • Slash Commands: The Full Reference
  • Keyboard Shortcuts Worth Memorizing
  • CLAUDE.md: The File That Tells Claude Who It Is
  • Hooks: Rules Claude Cannot Ignore
  • Custom Slash Commands vs. Skills
  • Subagents: Why Parallel Workers Change Everything
  • PR Review Setup
  • Quick Reference Card
  • Frequently Asked Questions

Most developers use Claude Code like a fancy autocomplete. They type a request, read the answer, and move on. That's maybe 20% of what the tool can do.

Claude Code is a terminal agent with full project access. It reads files, runs shell commands, commits to git, delegates work to parallel subagents, and enforces rules through lifecycle hooks. Once you know the full feature set, the way you work changes. This cheatsheet covers everything: every slash command, every shortcut, CLAUDE.md, hooks, subagents, and PR review — with working examples throughout.

💡 Quick start

npm install -g @anthropic-ai/claude-code, then cd into your project and type claude. On the first run, type /init to generate your CLAUDE.md and .claude/ folder.

What Is Claude Code and How Do You Start It

Claude Code is Anthropic's official CLI AI assistant. Unlike IDE-embedded tools, it runs in your terminal with full access to your project: it reads and writes files, executes shell commands, interacts with git, and connects to external services through MCP servers.

Installing it takes one command.

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

# Navigate to your project
cd my-project

# Start a session
claude

# On first run, generate project config
/init

/init reads your project structure and generates a CLAUDE.md file plus a .claude/ directory. That CLAUDE.md becomes Claude's instruction manual for every future session in that project. Get that file right and the rest of your sessions will be significantly more consistent.

Slash Commands: The Full Reference

Type / on an empty prompt and press Tab to see all available commands, including any custom ones you have defined. Here is the full built-in set.

Built-in Claude Code slash commands. Custom commands you define in .claude/commands/ also appear here.
CommandWhat it doesWhen to use it
/initGenerates CLAUDE.md and the .claude/ folderFirst run in a new project
/compactCompresses conversation history to a short summaryContext window above 80% full
/rewindRolls back Claude's last changeClaude broke something, fast undo
/planClaude thinks through a plan without making changesBefore large refactors or risky edits
/goalSet a finish condition — Claude works autonomously until metLong tasks you want to walk away from
/contextShows current context usage as a percentageCheck memory pressure mid-session
/hooksInteractive setup for lifecycle hooksConfigure enforcement rules without editing JSON manually
/agentsManage subagents for parallel task delegationSplit a large task across multiple Claude instances
/code-reviewReview code at a specified effort levelBefore merges, with effort: low | medium | high | max
/install-github-appConnect Claude to GitHub for PR integrationOne-time setup for PR review workflow
/clearClear conversation history entirelyFresh start with no carry-over context
/helpShow available commands and usageGetting oriented or checking syntax

Four of these commands deserve a bit more explanation because they change how you run longer sessions.

  • /compact — Claude's context window has a fixed limit. When you hit 80%, older parts of your conversation get fuzzy. /compact replaces the full history with a dense summary so you can keep working without starting over. Use it proactively — don't wait until Claude starts forgetting things.
  • /rewind — Esc Esc does the same thing interactively, but /rewind is useful in scripts or when you want to be deliberate. It rolls back the last file write or shell command Claude executed.
  • /plan — Makes Claude reason through a multi-step problem and show you the plan before touching anything. Essential before any refactor that spans more than two files.
  • /goal — Sets an autonomous objective. Claude works through the task step by step and stops when the goal condition is met. Pair this with hooks (covered below) to enforce safe execution boundaries.

Keyboard Shortcuts Worth Memorizing

Core keyboard shortcuts and inline syntax for Claude Code sessions.
ShortcutWhat It Does
Esc EscUndo Claude's last change — fastest way to recover from a bad edit
Ctrl+BSend the current task to background and free your terminal for other work
Ctrl+VPaste a screenshot directly into chat — Claude reads the image and responds
Ctrl+CCancel what Claude is doing right now — stops mid-execution
# textAdd a note to Claude's memory without sending a message to the model
@ pathAutocomplete a file path inline — quicker than typing full paths
! commandRun a shell command and include its output in context automatically

The ! prefix is underused. Typing !npm test pulls the test output directly into context so Claude can reason about failures without you copy-pasting. Ctrl+V for screenshots works especially well for sharing browser error states or design references.

CLAUDE.md: The File That Tells Claude Who It Is

CLAUDE.md is a Markdown file at the root of your project (or in .claude/) that Claude reads at the start of every session. It's your project's standing instructions: stack details, naming conventions, commands to run, rules to follow.

Here is a practical example for an API project.

markdown — CLAUDE.md
# My API Project

## Stack
Node.js 22, Express, PostgreSQL, Drizzle ORM. No TypeScript.

## Commands
- Start: npm run dev
- Test: npm test
- Lint: npm run lint

## Rules
- Never commit .env files
- Ask before deleting any file
- Write JSDoc comments on all exported functions

Keep CLAUDE.md under 500 lines. When rule sets grow large, split them into separate files under .claude/rules/ and reference them from the main CLAUDE.md — Claude follows imported files too.

The Commands section matters most. Claude references it every time it needs to run a linter or test suite. If your project has non-standard script names, see our guide to npm scripts — consistent naming makes Claude significantly more reliable without extra instruction.

CLAUDE.md instructions are advisory. In practice, Claude follows them roughly 80% of the time. For rules that must never be broken — blocking dangerous shell commands, enforcing formatting — use hooks instead. CLAUDE.md is for preferences and context; hooks are for enforcement.

ℹ Info

If you use this project with teammates, commit CLAUDE.md to version control. Every developer who opens a session gets the same base instructions automatically.

Hooks: Rules Claude Cannot Ignore

Hooks are shell scripts that run at fixed points in Claude's execution lifecycle. Unlike CLAUDE.md instructions, hooks are deterministic. If a hook exits with a non-zero status code, Claude stops and surfaces the error. There is no workaround.

There are five hook types.

  • PreToolUse — runs before Claude executes a tool. Use it to block dangerous commands before they happen.
  • PostToolUse — runs after Claude executes a tool. Use it to trigger formatters, linters, or logging.
  • SessionStart — runs when a session opens. Use it to load environment variables or run setup checks.
  • SessionEnd — runs when a session closes. Use it for cleanup or summaries.
  • Notification — runs when Claude is waiting for user input. Use it to ping a Slack channel or send a desktop notification.

Hooks live in .claude/settings.json. Here is a PostToolUse hook that runs Prettier automatically every time Claude writes a file.

json — .claude/settings.json
{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Write",
      "hooks": [{
        "type": "command",
        "command": "npx prettier --write $CLAUDE_TOOL_INPUT_FILE_PATH"
      }]
    }]
  }
}

The matcher field targets a specific tool — Write in this case. $CLAUDE_TOOL_INPUT_FILE_PATH is an environment variable Claude populates with the file path being written.

For safety-critical enforcement, PreToolUse is the right hook. This example blocks any rm -rf command before it executes.

json
{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "hooks": [{
        "type": "command",
        "command": "echo $CLAUDE_TOOL_INPUT_COMMAND | grep -q 'rm -rf' && exit 1 || exit 0"
      }]
    }]
  }
}

When the hook exits with code 1, Claude halts and reports the failure. The file system stays untouched.

PostToolUse hooks complement Git commit hooks rather than replacing them. If your project already uses Husky and lint-staged for pre-commit enforcement, Claude Code hooks catch format issues at the AI write layer before code ever reaches a commit.

⚠ Hooks vs. CLAUDE.md

CLAUDE.md says "never commit .env files" and Claude will comply most of the time. A PreToolUse hook that exits 1 when it detects a .env path in a git commit will comply every time. Use hooks for anything where "most of the time" is not good enough.

Custom Slash Commands vs. Skills: Which to Use

Claude Code lets you extend the slash command system in two ways. Custom commands are simple Markdown prompt files. Skills are structured, multi-file workflows that Claude can invoke automatically when the situation calls for them.

Custom CommandSkill
File location.claude/commands/name.md.claude/skills/name/SKILL.md
Supporting filesNo — single file onlyYes — can include templates, examples, sub-prompts
Auto-triggered by ClaudeNo — you invoke it manuallyYes — Claude recognizes when to apply it
Best forSimple one-off prompts: /standup, /pr-summaryComplex reusable workflows with multiple steps or files

A custom command for a standup summary is just a Markdown file with a prompt. It shows up as /standup in the command list and runs that prompt verbatim when invoked. Create it by adding .claude/commands/standup.md with your prompt text inside.

A skill makes sense when your workflow has branching logic, depends on supporting templates, or is something Claude should recognize and apply on its own without you typing a command. The complexity threshold is real: if you find yourself maintaining a multi-paragraph custom command with conditional instructions, it belongs in a skill.

Subagents: Why Parallel Workers Change Everything

Context windows fill up. In a long session, the earlier parts of your conversation fade from Claude's working memory, and output quality drops. Subagents solve this by offloading work to separate Claude instances with clean, empty context.

Your main session delegates a task to a subagent. The subagent works in isolation, completes the task, and returns a summary. The main session only sees the summary — not the thousands of lines of intermediate output the subagent generated.

The bigger win is parallelism. Claude can run three subagents simultaneously. You can review the auth module, run API integration tests, and check a DB migration at the same time rather than sequentially. On tasks that would take 20 minutes in a single session, parallel subagents regularly cut that to 7.

💡 When to reach for subagents

Use subagents when a task produces a lot of output that would pollute main context (test logs, large file listings), or when you have genuinely independent tasks that can run in parallel. Not every task needs a subagent — short contained questions are faster in the main session.

Custom subagents let you pre-configure a Claude instance for a specific role. Define one in .claude/agents/name.md with its own model choice, allowed tools, and standing instructions. A dedicated test-runner subagent configured to only use lightweight models and only run read commands is cheaper and safer than an unconfigured general-purpose instance.

markdown — .claude/agents/test-runner.md
---
model: claude-haiku-3-5
tools: Bash, Read
---

# Test Runner Agent

You run tests and report results. Do not modify any files.
Always run: npm test -- --reporter=verbose
Summarize failures concisely — file name, test name, error message only.

PR Review Setup

Claude Code integrates with GitHub for pull request review. Set it up once and you can run reviews directly from the terminal with findings posted as inline GitHub comments.

  1. 1

    Install the GitHub app

    Run /install-github-app inside a Claude session and follow the prompts. This authorizes Claude to read PR diffs and post review comments on your behalf.

  2. 2

    Open a session linked to a PR

    bash
    claude --from-pr 42

    Replace 42 with your PR number. Claude loads the diff and PR context into its working memory automatically.

  3. 3

    Run the review and post findings

    bash
    /code-review high --comment

    The --comment flag posts findings as inline GitHub comments on the PR. Without it, results print to your terminal only. The effort level controls depth: low is fast and high-confidence-only, max is the deepest analysis and best reserved for pre-release reviews.

For CI integration, /autofix-pr triggers an automated fix attempt when CI fails. Claude reads the failure logs, patches the issue, and pushes a follow-up commit to the same branch.

/code-review effort levels and when to use each.
Effort levelSpeedBest for
lowFast (~30 sec)Quick sanity check, low-stakes changes
mediumModerate (~90 sec)Regular feature PRs
highSlower (~3 min)Sensitive logic, auth, payments
maxSlowest (~5+ min)Pre-release, security-critical changes

Quick Reference Card

The commands and patterns you will reach for every day.
CategoryDo ThisNotes
StartclaudeOpens a session in the current folder
First run/initGenerates CLAUDE.md and .claude/
Context full/compactCompresses history — use at >80% context
UndoEsc Esc or /rewindRolls back Claude's last change
Parallel work/agentsDelegate to parallel subagents
PR reviewclaude --from-pr 42, then /code-review high --commentPosts inline GitHub comments
Custom command.claude/commands/name.mdSimple reusable prompt — shows up as /name
Skill.claude/skills/name/SKILL.mdComplex reusable workflow with supporting files
HookAdd to .claude/settings.json hooks sectionDeterministic enforcement — cannot be overridden
Shell output in context! npm testRuns command and pulls output into Claude's context
Paste screenshotCtrl+VClaude reads the image and responds

Frequently Asked Questions

What is the difference between CLAUDE.md and hooks in Claude Code?

CLAUDE.md is advisory. Claude reads it at session start and follows its instructions roughly 80% of the time. It's the right place for style preferences, stack context, and reminders.

Hooks are deterministic shell scripts. When a PreToolUse hook exits with a non-zero code, Claude stops — no exceptions, no model judgment involved. Use CLAUDE.md for guidance; use hooks for anything that must be enforced.

How do I see all available slash commands in Claude Code?

Type / on an empty prompt and press Tab. Claude shows all built-in commands plus any custom commands you have defined in .claude/commands/. The autocomplete also shows a brief description of each command so you do not have to memorize the list.

When should I use a subagent instead of the main Claude session?

Two situations call for subagents. First, when a task generates a lot of output (test logs, large file trees, grep results) that would fill context and make Claude less useful for the rest of your session. The subagent absorbs that output and returns a summary.

Second, when you have independent tasks that can run simultaneously. Code review, test run, and DB migration check do not depend on each other — run them in parallel with subagents and finish in a third of the time.

What does /compact do and when should I use it?

/compact replaces your full conversation history with a short summary. Claude's context window has a fixed token limit. As history grows, earlier context fades and response quality drops.

Use /compact when context usage passes 80% (check with /context), or whenever you notice Claude starting to forget decisions made earlier in the session. Running it proactively is better than waiting for degraded responses.

Can Claude Code work offline?

No. Claude Code requires an internet connection to reach Anthropic's API. All AI inference runs on Anthropic's servers. Your code stays local — only the conversation text and any file contents you share in a session are sent to the API.

How is Claude Code different from GitHub Copilot?

GitHub Copilot is an IDE autocomplete that suggests code as you type. Claude Code is a terminal agent that reads your full project, executes commands, makes multi-file changes, runs tests, and reviews PRs autonomously. They solve different problems.

If you are evaluating both on cost, see our breakdown of how Claude Code compares to Copilot on cost — especially relevant now that Copilot has moved to per-token billing. Claude Code's flat-rate plan tends to favor heavy agentic users.

GitHub CopilotClaude Code
Primary interfaceIDE (VS Code, JetBrains, etc.)Terminal
Core strengthInline code completions as you typeMulti-file edits, shell commands, full project reasoning
Agentic capabilityAgent mode (per-token billing)Native — runs tools, subagents, hooks
Billing modelPer AI Credit (token-based, post June 2026)Flat-rate subscription
Project contextOpen files + configured workspaceFull project tree, git history, shell environment

Related Articles

tools

GitHub Copilot Token Billing: Real Cost by Workflow (2026)

GitHub Copilot switched to AI Credits billing June 1. Code completions stay free. Here's what chat, agent mode, and code review cost per workflow — and when to switch.

Jun 5, 2026·8 min read
nextjs

Husky + Prettier + lint-staged Setup for Next.js

Set up Husky v9, Prettier, and lint-staged in your Next.js project. Step-by-step guide covering pre-commit hooks with the correct 2026 config.

May 30, 2026·8 min read
security

How to Audit Your VS Code Extensions for Security

The GitHub breach happened through a VS Code extension. Here's how to check what you have installed and reduce your exposure in 10 minutes.

May 30, 2026·6 min read

On this page

  • What Is Claude Code and How Do You Start It
  • Slash Commands: The Full Reference
  • Keyboard Shortcuts Worth Memorizing
  • CLAUDE.md: The File That Tells Claude Who It Is
  • Hooks: Rules Claude Cannot Ignore
  • Custom Slash Commands vs. Skills
  • Subagents: Why Parallel Workers Change Everything
  • PR Review Setup
  • Quick Reference Card
  • Frequently Asked Questions