---
title: "Claude Code Coding Cheat Sheet — Beginner → Advanced"
category: "notes"
summary: "this is a cheatsheet which i am using for claude code Edited by Aayush Ate"
date: "2026-06-17"
---

this is a cheatsheet which i am using for claude code 
***Edited by Aayush Ate***

----

https://code.claude.com/docs/en/overview
https://platform.claude.com/cookbook/

----
# Claude Code Coding Cheat Sheet — Beginner → Advanced

**Scope:** This is a practical, copy/paste-friendly guide for using Claude Code for real coding work: install, daily commands, project analysis, sessions, multi-directory work, model/permission tuning, automation, custom skills/commands, subagents, hooks, MCP, PR review, and newer 2026 features. Claude Code is an agentic coding tool that can read codebases, edit files, run commands, and integrate with developer tools across terminal, IDE, desktop, browser, Slack, and CI/CD. [1](https://code.claude.com/docs/en/overview)

---

## 0. Mental model

Think of Claude Code as a **terminal-native coding agent**:

- You give it goals in natural language.
- It explores files, searches code, proposes edits, runs tests, and summarizes results.
- It asks permission depending on your permission mode.
- You can steer it with `CLAUDE.md`, settings, skills, hooks, MCP servers, and subagents.
- Use **plan mode** for “think first,” **accept edits / auto mode** for speed, and **hooks/permissions** for guardrails. [2](https://code.claude.com/docs/en/permission-modes)

---

# 1. Install and verify

## macOS, Linux, WSL — recommended native install

Bash

```
curl -fsSL https://claude.ai/install.sh | bash
```

Native installs auto-update in the background. [3](https://code.claude.com/docs/en/quickstart)

## Windows PowerShell

PowerShell

```
irm https://claude.ai/install.ps1 | iex
```

## Windows CMD

cmd

```
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
```

On native Windows, Git for Windows is recommended so Claude Code can use Bash; without it, Claude Code falls back to PowerShell. WSL setups do not need Git for Windows. [3](https://code.claude.com/docs/en/quickstart)

## Homebrew

Bash

```
brew install --cask claude-code
```

Homebrew’s `claude-code` cask tracks stable, while `claude-code@latest` tracks the latest channel; Homebrew installs do **not** auto-update, so run `brew upgrade claude-code` or `brew upgrade claude-code@latest`. [3](https://code.claude.com/docs/en/quickstart)

## WinGet

PowerShell

```
winget install Anthropic.ClaudeCode
winget upgrade Anthropic.ClaudeCode
```

WinGet installs do not auto-update automatically. [3](https://code.claude.com/docs/en/quickstart)

## Verify

Bash

```
claude --version
claude doctor
```

`claude doctor` checks installation and configuration health. [4](https://code.claude.com/docs/en/setup)

## Update

Bash

```
claude update
```

For native installs, updates download in the background and apply the next time Claude Code starts; you can also configure the update channel as `latest` or `stable`. [4](https://code.claude.com/docs/en/setup)

---

# 2. First session

Bash

```
cd /path/to/your/project
claude
```

Then try:

text

```
what does this project do?
```

text

```
explain the folder structure
```

text

```
where is the main entry point?
```

text

```
what technologies does this project use?
```

Claude Code reads project files as needed; you usually do **not** need to manually paste files into the chat. [3](https://code.claude.com/docs/en/quickstart)

---

# 3. Essential CLI commands

|Command|What it does|
|---|---|
|`claude`|Start interactive mode|
|`claude "explain this project"`|Start interactive mode with an initial prompt|
|`claude -p "explain this function"`|Print-mode one-off query, then exit|
|`cat logs.txt \| claude -p "explain"`|Process piped input|
|`claude -c`|Continue the most recent conversation in the current directory|
|`claude -r`|Resume from a picker|
|`claude -r "session-name"`|Resume a named session|
|`claude --name "auth-refactor"`|Start a named session|
|`claude --add-dir ../shared ../docs`|Add extra directories Claude can read/edit|
|`claude --model opus`|Start with a specific model alias|
|`claude --effort high`|Start with a higher reasoning effort|
|`claude --permission-mode plan`|Start in plan mode|
|`claude update`|Update Claude Code|
|`claude project purge ~/work/repo --dry-run`|Preview deletion of local Claude Code state for a repo|

Claude Code supports interactive sessions, print-mode automation, piped input, named sessions, session resume, multi-directory access, model selection, permission modes, and local state cleanup from the CLI. [5](https://code.claude.com/docs/en/cli-reference)

---

# 4. Interactive-mode power keys

|Shortcut / prefix|Use|
|---|---|
|`/`|Open commands and skills menu|
|`@`|Mention files, directories, MCP resources, or agents|
|`!`|Run shell commands directly and add output to context|
|`Shift+Tab`|Cycle permission modes|
|`Ctrl+O`|Toggle transcript/tool viewer|
|`Ctrl+B`|Background a running Bash command or agent|
|`Ctrl+R`|Reverse-search prompt history|
|`Ctrl+T`|Toggle task list|
|`Esc Esc`|Rewind or summarize from a previous point|
|`Ctrl+G` or `Ctrl+X Ctrl+E`|Open prompt in your editor|
|`?`|Show available shortcuts|

Use `! npm test` or `! git status` when you want a command’s output in the conversation but do not need Claude to decide how to run it. Shell mode shows real-time output, supports backgrounding, and adds the command/output to context. [6](https://code.claude.com/docs/en/interactive-mode)

---

# 5. The fastest useful prompts

## Understand a project

text

```
Give me a concise but thorough map of this codebase:
- main purpose
- entry points
- core modules
- data flow
- build/test commands
- risky or complex areas
- files I should read first
```

## Summarize a file

text

```
Explain @src/auth/session.ts:
- what it does
- key functions/classes
- dependencies
- edge cases
- possible bugs
- how to test it
```

`@file` includes the file in the conversation; `@directory` provides directory information. [7](https://docs.anthropic.com/en/docs/claude-code/tutorials)

## Summarize a directory

text

```
Analyze @src/components and summarize:
- component groups
- shared patterns
- duplicated logic
- files that look deprecated
- refactor opportunities
```

## Find where behavior lives

text

```
Trace how login works from the UI to the backend.
List every important file and function in order.
Do not edit anything yet.
```

## Debug a failure

text

```
The test `UserSession.refresh` is failing.
Investigate root cause, explain it, propose a minimal fix, then wait for my approval before editing.
```

## Implement safely

text

```
Add input validation to the registration form.

Process:
1. Explore the relevant files.
2. Explain the current flow.
3. Propose a plan.
4. Make the smallest safe change.
5. Add or update tests.
6. Run the relevant tests.
7. Summarize the diff.
```

## Review your changes

text

```
Review my uncommitted changes.
Focus on correctness, security, edge cases, test coverage, and accidental API changes.
Do not edit files unless I ask.
```

---

# 6. Project setup: make Claude smarter with `CLAUDE.md`

Run:

text

```
/init
```

`/init` creates or improves a project `CLAUDE.md` with discovered build commands, test instructions, and conventions; an interactive init flow can also help set up skills and hooks. [8](https://code.claude.com/docs/en/memory)

## Starter `CLAUDE.md`

Create `CLAUDE.md` or `.claude/CLAUDE.md`:

Markdown

```
# Project instructions for Claude Code

## Commands
- Install deps: `pnpm install`
- Typecheck: `pnpm typecheck`
- Lint: `pnpm lint`
- Unit tests: `pnpm test`
- Run one test: `pnpm test -- <file-or-pattern>`

## Code style
- Use TypeScript.
- Prefer small, focused functions.
- Keep public APIs backward compatible unless explicitly requested.
- Do not introduce new dependencies without explaining why.

## Workflow
- Before editing, briefly explain the plan for non-trivial changes.
- After editing, run the smallest relevant test set first.
- Before committing, run lint and typecheck if changes affect source code.
- Summaries should include files changed, tests run, and follow-up risks.

## Safety
- Never read or modify `.env`, `.env.*`, `secrets/**`, or credential files.
- Do not run destructive git commands unless explicitly requested.
```

`CLAUDE.md` is persistent context loaded into sessions. Keep it concise and concrete; Anthropic recommends targeting under about 200 lines per `CLAUDE.md` because large instruction files consume context and can reduce adherence. [8](https://code.claude.com/docs/en/memory)

## Personal preferences

Global personal instructions:

Bash

```
mkdir -p ~/.claude
cat > ~/.claude/CLAUDE.md <<'EOF'
# My personal Claude Code preferences

- Prefer concise explanations unless I ask for detail.
- Use bullet lists for plans.
- Ask before large rewrites.
- When debugging, identify the smallest reproducible failing command first.
EOF
```

User-level `~/.claude/CLAUDE.md` applies across projects, while project `CLAUDE.md` or `.claude/CLAUDE.md` is shareable with the repo. [8](https://code.claude.com/docs/en/memory)

## Path-specific rules

Use `.claude/rules/` for scoped instructions:

Bash

```
mkdir -p .claude/rules
cat > .claude/rules/api.md <<'EOF'
---
paths:
  - "src/api/**/*.ts"
---

# API rules

- Validate all inputs.
- Return the standard error shape.
- Include tests for 400/401/500 paths.
EOF
```

Rules can load globally or only when Claude works with matching paths, which keeps the always-loaded context smaller. [8](https://code.claude.com/docs/en/memory)

---

# 7. Permissions: move faster without losing control

## Permission modes

|Mode|Best for|Behavior|
|---|---|---|
|`default`|Starting out, sensitive work|Reads without asking; asks for edits/commands|
|`acceptEdits`|Fast coding with review|Auto-approves reads, file edits, common filesystem commands|
|`plan`|Exploration before changes|Read-only planning|
|`auto`|Long hands-off tasks|Runs more autonomously with background safety checks|
|`dontAsk`|Locked-down scripts/CI|Only pre-approved tools run|
|`bypassPermissions`|Isolated containers/VMs only|Skips permission layer|

In every mode except `bypassPermissions`, protected paths are not auto-approved; `bypassPermissions` should be reserved for isolated environments. [2](https://code.claude.com/docs/en/permission-modes)

## Start in plan mode

Bash

```
claude --permission-mode plan
```

Or inside Claude:

text

```
/plan refactor the auth module to separate token parsing from session storage
```

## Start with auto mode

Bash

```
claude --permission-mode auto
```

## Default to accept edits for a project

Create `.claude/settings.json`:

JSON

```
{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "permissions": {
    "defaultMode": "acceptEdits"
  }
}
```

Settings can be user, project, local, or managed; higher-precedence scopes and CLI flags override lower scopes. [9](https://code.claude.com/docs/en/settings)

## Deny sensitive files

JSON

```
{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "permissions": {
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)",
      "Read(./config/credentials.json)",
      "Bash(curl *)"
    ],
    "allow": [
      "Bash(git status *)",
      "Bash(git diff *)",
      "Bash(pnpm test *)",
      "Bash(pnpm lint)"
    ]
  }
}
```

Permission rules support `allow`, `ask`, and `deny`; deny rules are useful for excluding secrets and risky commands. [9](https://code.claude.com/docs/en/settings)

---

# 8. Model and effort settings

## Quick choices

|Need|Use|
|---|---|
|Daily coding|`sonnet`|
|Hard architecture/debugging/reasoning|`opus`|
|Cheap/fast simple tasks|`haiku`|
|Plan with Opus, execute with Sonnet|`opusplan`|
|Huge-context sessions|`sonnet[1m]` or `opus[1m]`|

Claude Code supports aliases such as `sonnet`, `opus`, `haiku`, `best`, `sonnet[1m]`, `opus[1m]`, and `opusplan`; aliases point to recommended versions and can change over time. In the current docs, Anthropic API aliases resolve `opus` to Opus 4.7 and `sonnet` to Sonnet 4.6. [10](https://code.claude.com/docs/en/model-config)

## Set model at startup

Bash

```
claude --model sonnet
claude --model opus
claude --model opusplan
```

## Switch inside a session

text

```
/model opus
/model sonnet
```

## Persist in settings

JSON

```
{
  "model": "opusplan"
}
```

Model priority is: in-session `/model`, startup `--model`, `ANTHROPIC_MODEL`, then settings. [10](https://code.claude.com/docs/en/model-config)

## Effort level

Bash

```
claude --effort high
```

Inside a session:

text

```
/effort high
/effort xhigh
/effort auto
```

Effort levels include `low`, `medium`, `high`, `xhigh`, and `max`, with availability depending on the model. [5](https://code.claude.com/docs/en/cli-reference)

## Fast mode

text

```
/fast on
/fast off
```

Fast mode is useful when you want quicker responses and can tolerate less exhaustive reasoning. The current docs list fast mode as a dedicated Claude Code feature. [11](https://code.claude.com/docs/en/commands)

---

# 9. Session management

## Resume / continue

Bash

```
claude -c
claude --continue
claude -r
claude --resume auth-refactor
```

Inside a session:

text

```
/rename auth-refactor
/resume
/clear
/compact focus on decisions, files changed, and remaining TODOs
/export session-notes.txt
```

`--continue` loads the most recent conversation in the current directory; `--resume` resumes by ID/name or opens a picker; `/compact` summarizes context while continuing the same conversation; `/clear` starts a new conversation while leaving the old one resumable. [5](https://code.claude.com/docs/en/cli-reference)

## Branch a conversation

text

```
/branch try-alternative-cache-design
```

`/branch`, also aliased as `/fork` in some configurations, creates a branch of the current conversation so you can explore an alternative while preserving the original. [11](https://code.claude.com/docs/en/commands)

## Rewind code/conversation

text

```
/rewind
```

Use this when Claude went down the wrong path and you want to restore code and/or conversation state to an earlier point. [11](https://code.claude.com/docs/en/commands)

## Resume sessions linked to PRs

Bash

```
claude --from-pr 123
```

This resumes sessions linked to a pull request when Claude created or linked that PR. [5](https://code.claude.com/docs/en/cli-reference)

## Clean old local project state

Preview:

Bash

```
claude project purge ~/work/my-repo --dry-run
```

Delete after confirmation:

Bash

```
claude project purge ~/work/my-repo
```

Claude Code stores local transcripts, file snapshots, prompt history, caches, and logs under `~/.claude`; `claude project purge` removes project-specific state after showing a deletion plan. [12](https://code.claude.com/docs/en/claude-directory)

---

# 10. Work with multiple directories

## Add directories for one session

Bash

```
claude --add-dir ../shared-lib ../docs ../infra
```

Then prompt:

text

```
Analyze how this app uses ../shared-lib.
Look for duplicated types between this repo and the shared library.
Do not edit anything yet.
```

`--add-dir` grants file access to additional working directories, but most `.claude/`configuration from those directories is not discovered automatically. [5](https://code.claude.com/docs/en/cli-reference)

## Persist additional directories

`.claude/settings.local.json`:

JSON

```
{
  "permissions": {
    "additionalDirectories": [
      "../shared-lib",
      "../docs"
    ]
  }
}
```

`settings.local.json` is useful for personal project-specific overrides that should not be committed. [9](https://code.claude.com/docs/en/settings)

## Load `CLAUDE.md` from additional directories

Bash

```
CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 claude --add-dir ../shared-config
```

By default, `CLAUDE.md` from `--add-dir` directories is not loaded; this environment variable opts in. [8](https://code.claude.com/docs/en/memory)

---

# 11. Copy/paste workflows

## A. Codebase onboarding

Bash

```
cd /path/to/repo
claude --permission-mode plan --model sonnet
```

Prompt:

text

```
Onboard me to this repository.

Produce:
1. one-paragraph purpose
2. architecture diagram in ASCII
3. top 10 files/directories to understand
4. build/test/dev commands
5. major data models
6. request/data flow
7. risky areas
8. open questions I should ask the team

Do not edit files.
```

## B. Summarize every important file

text

```
Find the main source files for this project.
For each important file, summarize:
- responsibility
- public exports/classes/functions
- dependencies
- tests
- risk level

Put the result in a table.
Do not edit files.
```

## C. Generate a project map file

text

```
Create docs/codebase-map.md with:
- overview
- architecture
- module map
- key workflows
- testing strategy
- glossary
- known risks

Read the repo first, then write the file.
```

## D. Fix a bug with strict control

Bash

```
claude --permission-mode plan
```

Prompt:

text

```
Bug: users can submit the registration form with an empty email.

First, investigate and identify the exact code path.
Then propose a minimal fix and tests.
Wait for my approval before editing.
```

After the plan:

text

```
Proceed with the minimal fix and tests.
Run only the relevant tests first.
```

## E. Safe refactor

text

```
Refactor the auth token parsing code to make it easier to test.

Constraints:
- no behavior changes
- keep public API stable
- add tests before or alongside changes
- run relevant tests
- show a before/after summary
```

## F. Test generation

text

```
Find untested edge cases in @src/auth/session.ts.
Add focused unit tests for the highest-risk cases.
Do not rewrite production code unless tests reveal a real bug.
```

## G. Commit helper

text

```
Review my diff, split it into logical commits if needed, and propose commit messages.
Do not commit until I confirm.
```

Then:

text

```
Commit the current changes with the best message.
```

Claude Code can do conversational Git tasks such as showing changed files, creating branches, committing with messages, showing recent commits, and helping resolve conflicts. [3](https://code.claude.com/docs/en/quickstart)

---

# 12. Automation with print mode

Print mode is ideal for scripts because Claude answers and exits. [5](https://code.claude.com/docs/en/cli-reference)

## Summarize a file

Bash

```
claude -p "Summarize @src/index.ts in 10 bullets"
```

## Explain logs

Bash

```
cat test-output.log | claude -p "Find the root cause and the first failing test"
```

## Review staged diff

Bash

```
git diff --staged | claude -p "
Review this staged diff for correctness, security, and missing tests.
Return:
- critical issues
- minor issues
- suggested tests
- final merge readiness
"
```

## JSON output

Bash

```
claude -p "Analyze this repo and output JSON with keys: summary, languages, test_commands, risks" \
  --output-format json
```

## Limit cost/turns for automation

Bash

```
claude -p "Review this diff" \
  --max-turns 3 \
  --max-budget-usd 2.00
```

`--max-turns`, `--max-budget-usd`, `--output-format`, and `--json-schema` are useful for non-interactive automation. [5](https://code.claude.com/docs/en/cli-reference)

---

# 13. Automate reviews

## Local review commands

Inside Claude:

text

```
/review
```

text

```
/security-review
```

text

```
/ultrareview
```

`/review` reviews a PR locally, `/security-review` analyzes pending branch changes for vulnerabilities, and `/ultrareview` runs a deeper multi-agent cloud review. [11](https://code.claude.com/docs/en/commands)

## Managed PR Code Review

Claude Code’s managed Code Review is in research preview for Team and Enterprise subscriptions and posts GitHub PR findings as inline comments; it uses multiple specialized agents, verifies candidate findings, deduplicates them, and tags severity. [13](https://code.claude.com/docs/en/code-review)

Manual triggers:

text

```
@claude review
```

text

```
@claude review once
```

Use `CLAUDE.md` and/or `REVIEW.md` to tune what the reviewer flags. [13](https://code.claude.com/docs/en/code-review)

## Quick local PR review with GitHub CLI

Bash

```
gh pr diff | claude -p "
Review this PR diff.
Focus on:
- correctness
- security
- edge cases
- tests
- backwards compatibility

Return findings grouped by severity.
"
```

## Create a reusable PR summary skill

Bash

```
mkdir -p .claude/skills/pr-summary
cat > .claude/skills/pr-summary/SKILL.md <<'EOF'
---
name: pr-summary
description: Summarize the current GitHub pull request using gh CLI data
context: fork
agent: Explore
allowed-tools: Bash(gh *)
disable-model-invocation: true
---

## Pull request context

- PR diff: !`gh pr diff`
- PR comments: !`gh pr view --comments`
- Changed files: !`gh pr diff --name-only`

## Task

Summarize this PR:
1. What changed
2. Why it likely changed
3. Risky areas
4. Missing tests
5. Review checklist
EOF
```

Run it:

text

```
/pr-summary
```

Skills can inject dynamic command output with `!command`, and `context: fork` runs the skill in an isolated subagent context. [14](https://code.claude.com/docs/en/skills)

---

# 14. Custom commands are now skills

Claude Code skills are reusable prompts/workflows invoked with `/skill-name`. Custom command files under `.claude/commands/*.md` still work, but custom commands have been merged into the skills mechanism, and skills are recommended because they support directories, supporting files, frontmatter, tool pre-approval, subagent execution, and automatic invocation. [14](https://code.claude.com/docs/en/skills)

## Create a simple skill

Bash

```
mkdir -p .claude/skills/explain-code
cat > .claude/skills/explain-code/SKILL.md <<'EOF'
---
name: explain-code
description: Explain code using analogies, diagrams, and step-by-step reasoning. Use when the user asks how a file or system works.
---

When explaining code:
1. Start with a one-sentence summary.
2. Use an analogy.
3. Draw an ASCII diagram if useful.
4. Walk through the important functions/classes.
5. Highlight gotchas and edge cases.
6. Suggest the best tests to read or add.

Target: $ARGUMENTS
EOF
```

Use it:

text

```
/explain-code src/auth/session.ts
```

## Create a manual-only deploy checklist

Bash

```
mkdir -p .claude/skills/deploy
cat > .claude/skills/deploy/SKILL.md <<'EOF'
---
name: deploy
description: Deploy the application using the release checklist
disable-model-invocation: true
allowed-tools: Bash(git status *) Bash(pnpm test *) Bash(pnpm build *)
---

Deploy target: $ARGUMENTS

Checklist:
1. Confirm working tree status.
2. Confirm branch and latest commit.
3. Run tests.
4. Run build.
5. Summarize release risk.
6. Ask for explicit approval before any deployment command.
EOF
```

`disable-model-invocation: true` prevents Claude from invoking the skill automatically, which is important for workflows with side effects. [14](https://code.claude.com/docs/en/skills)

## Create a deep research skill

Bash

```
mkdir -p .claude/skills/deep-research
cat > .claude/skills/deep-research/SKILL.md <<'EOF'
---
name: deep-research
description: Research a codebase topic thoroughly in an isolated context
context: fork
agent: Explore
---

Research $ARGUMENTS thoroughly:
1. Find relevant files with Glob/Grep.
2. Read the key files.
3. Identify important functions/classes.
4. Explain the current design.
5. List risks, edge cases, and tests.
6. Return specific file references.
EOF
```

Run:

text

```
/deep-research how billing invoices are generated
```

`context: fork` creates isolated context and returns a summary to your main conversation, which helps keep the main context clean. [14](https://code.claude.com/docs/en/skills)

---

# 15. Hooks: deterministic automation

Hooks run shell commands, prompts, HTTP calls, or agents at lifecycle events. Use them when something must happen every time, such as formatting after edits, blocking unsafe commands, or notifying you when Claude needs input. [15](https://code.claude.com/docs/en/hooks-guide)

## Desktop notification when Claude needs attention

`~/.claude/settings.json` on macOS:

JSON

```
{
  "hooks": {
    "Notification": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "osascript -e 'display notification \"Claude Code needs your attention\" with title \"Claude Code\"'"
          }
        ]
      }
    ]
  }
}
```

Verify:

text

```
/hooks
```

`/hooks` opens a read-only browser showing configured hooks and their sources. [15](https://code.claude.com/docs/en/hooks-guide)

## Auto-format after edits

JSON

```
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write"
          }
        ]
      }
    ]
  }
}
```

This runs after file edits and formats the edited file. [15](https://code.claude.com/docs/en/hooks-guide)

## Block edits to generated files

JSON

```
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "./scripts/block-generated-edits.sh"
          }
        ]
      }
    ]
  }
}
```

Example script:

Bash

```
#!/usr/bin/env bash
set -euo pipefail

INPUT="$(cat)"
FILE="$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')"

case "$FILE" in
  *generated*|*.lock)
    echo "Blocked: do not edit generated or lock files directly." >&2
    exit 2
    ;;
esac

exit 0
```

A `PreToolUse` hook can block operations by exiting with a blocking status, making it a better enforcement layer than a plain instruction in `CLAUDE.md`. [16](https://code.claude.com/docs/en/sub-agents)

---

# 16. Subagents: isolate specialized work

Use subagents when exploration, review, or logs would flood your main conversation. A subagent has its own context window, system prompt, tools, model, permissions, and optional memory; it returns a summary to the main session. [16](https://code.claude.com/docs/en/sub-agents)

## Built-in subagents

|Subagent|Best for|
|---|---|
|`Explore`|Fast read-only code search and codebase exploration|
|`Plan`|Read-only research during plan mode|
|`general-purpose`|Complex multi-step tasks that may need edits|

The built-in `Explore` agent uses a fast read-only setup for search and codebase exploration. [16](https://code.claude.com/docs/en/sub-agents)

## Create a code reviewer subagent

Bash

```
mkdir -p .claude/agents
cat > .claude/agents/code-reviewer.md <<'EOF'
---
name: code-reviewer
description: Reviews code for correctness, security, maintainability, and tests. Use proactively after code changes.
tools: Read, Glob, Grep, Bash
model: sonnet
effort: high
---

You are a senior code reviewer.

When invoked:
1. Inspect the relevant diff and surrounding code.
2. Look for correctness bugs, security issues, edge cases, and missing tests.
3. Do not edit files.
4. Return findings grouped by severity:
   - Critical
   - Important
   - Minor
   - Questions
5. Include file paths and line references when possible.
EOF
```

Use it:

text

```
Use the code-reviewer agent to review my uncommitted changes.
```

Or explicitly mention it via the agent picker using `@`. Subagents can also be launched session-wide with `claude --agent code-reviewer`. [16](https://code.claude.com/docs/en/sub-agents)

## Run a whole session as a subagent

Bash

```
claude --agent code-reviewer
```

This makes the main session use that subagent’s system prompt, tool restrictions, and model. [16](https://code.claude.com/docs/en/sub-agents)

## Temporary CLI-defined subagents

Bash

```
claude --agents '{
  "debugger": {
    "description": "Debugging specialist for test failures and runtime errors.",
    "prompt": "You are an expert debugger. Identify root causes, propose minimal fixes, and verify with tests.",
    "tools": ["Read", "Grep", "Glob", "Bash"],
    "model": "sonnet"
  }
}'
```

`--agents` defines session-only subagents and accepts fields similar to file-based subagent frontmatter. [16](https://code.claude.com/docs/en/sub-agents)

---

# 17. MCP: connect Claude to external tools

MCP servers let Claude Code access external services, databases, APIs, and developer tools instead of requiring you to copy/paste data. Anthropic warns to use third-party MCP servers only if you trust them, because untrusted tool outputs can introduce prompt-injection risk. [17](https://docs.anthropic.com/en/docs/claude-code/mcp)

## Add a local stdio MCP server

Bash

```
claude mcp add --transport stdio my-tool -- /path/to/my-tool-server
```

## Add a JSON-defined MCP server

Bash

```
claude mcp add-json weather-api '{
  "type": "stdio",
  "command": "/path/to/weather-cli",
  "args": ["--api-key", "abc123"],
  "env": {
    "CACHE_DIR": "/tmp"
  }
}'
```

Claude Code supports local stdio MCP servers and JSON MCP configuration for custom integrations. [17](https://docs.anthropic.com/en/docs/claude-code/mcp)

## Good MCP use cases

text

```
Show me the open GitHub issues related to authentication, then map them to files in this repo.
```

text

```
Query the staging database schema and compare it to the ORM models.
```

text

```
Read the Jira ticket for this branch and verify the implementation covers acceptance criteria.
```

MCP is best when Claude needs live external data or needs to act in another system. [17](https://docs.anthropic.com/en/docs/claude-code/mcp)

---

# 18. Dev tool integration

## VS Code / JetBrains

Use:

text

```
/ide
```

Or start with:

Bash

```
claude --ide
```

Claude Code supports VS Code and JetBrains integrations, and the same settings hierarchy applies across CLI and IDE surfaces. [5](https://code.claude.com/docs/en/cli-reference)

## Web / remote sessions

Start a cloud session from terminal:

Bash

```
claude --remote "Fix the login bug and open a PR"
```

Pull a web session into local terminal:

Bash

```
claude --teleport
```

Enable remote control for a local session:

Bash

```
claude --remote-control "My Project"
```

Claude Code supports web sessions, teleporting sessions between web and terminal, and Remote Control so you can control a local session from a browser or mobile app. [5](https://code.claude.com/docs/en/cli-reference)

## Desktop

Inside a terminal session:

text

```
/desktop
```

This continues the current session in the Claude Code Desktop app on supported platforms. [11](https://code.claude.com/docs/en/commands)

---

# 19. Advanced automation patterns

## A. Auto-fix PR comments and CI

text

```
/autofix-pr only fix lint and type errors
```

`/autofix-pr` starts a Claude Code on the web session that watches the current branch’s PR and pushes fixes when CI fails or reviewers leave comments; it requires the GitHub CLI and access to Claude Code on the web. [11](https://code.claude.com/docs/en/commands)

## B. Repeated checks with `/loop`

text

```
/loop 5m check if the deploy finished; if it failed, summarize the failure and suggest next steps
```

`/loop` runs a prompt repeatedly while the session stays open; omitting the interval lets Claude self-pace. [11](https://code.claude.com/docs/en/commands)

## C. Scheduled routines

text

```
/schedule every weekday at 9am summarize open PRs and failing CI for this repo
```

`/schedule`, also aliased as `/routines`, creates or manages recurring Claude Code tasks. [11](https://code.claude.com/docs/en/commands)

## D. Large-scale parallel change

text

```
/batch migrate src/ from Moment.js to date-fns
```

`/batch` researches the codebase, decomposes work into independent units, and spawns background agents in isolated git worktrees. [11](https://code.claude.com/docs/en/commands)

## E. Simplify recent changes

text

```
/simplify focus on readability and memory efficiency
```

`/simplify` reviews recently changed files using parallel review agents, aggregates findings, and applies fixes. [11](https://code.claude.com/docs/en/commands)

## F. Cloud planning

text

```
/ultraplan design a migration from REST endpoints to GraphQL without breaking clients
```

`/ultraplan` drafts a plan in a cloud planning session, lets you review it in the browser, then execute remotely or send it back to the terminal. [11](https://code.claude.com/docs/en/commands)

---

# 20. Recommended `.claude/` layout

text

```
your-repo/
 CLAUDE.md
 .claude/
    settings.json
    settings.local.json        # personal, gitignored
    rules/
       api.md
       frontend.md
    skills/
       deep-research/
          SKILL.md
       pr-summary/
          SKILL.md
       deploy/
           SKILL.md
    agents/
        code-reviewer.md
        debugger.md
 .mcp.json
```

Use `CLAUDE.md` for always-on project context, `settings.json` for permissions/hooks/env/model defaults, `skills/<name>/SKILL.md` for reusable workflows, `agents/*.md` for specialized subagents, `.mcp.json` for project MCP servers, and `settings.local.json` for personal non-committed overrides. [12](https://code.claude.com/docs/en/claude-directory)

---

# 21. Speed and quality tips

## Use this workflow for complex changes

text

```
Think through the task first.
Use plan mode.
Identify affected files.
Propose a minimal plan.
Wait for approval.
Then implement in small steps and test each step.
```

## Ask for file references

text

```
Explain your answer with file paths and function names.
```

## Keep tasks narrow

Better:

text

```
Fix the failing password reset tests in auth/session only.
```

Worse:

text

```
Fix auth.
```

## Prefer “investigate first” for unfamiliar code

text

```
Investigate how checkout totals are calculated.
Do not edit files.
Return the exact files and functions involved.
```

## Use subagents for noisy work

text

```
Use Explore to find all call sites of createSession, then summarize only the important ones.
```

## Compact before context gets messy

text

```
/compact focus on current goal, decisions made, files changed, tests run, and remaining TODOs
```

## Name long sessions

text

```
/rename checkout-tax-refactor
```

## Use `CLAUDE.md` when you correct Claude twice

If you repeatedly say “use pnpm, not npm,” put it in `CLAUDE.md` or ask:

text

```
Remember for this project: use pnpm, not npm.
```

Auto memory is on by default and lets Claude store project-specific learnings locally; `/memory` lets you browse/edit loaded memory files and auto-memory entries. [8](https://code.claude.com/docs/en/memory)

---

# 22. Latest / newer features found in official docs

As of the official docs index I checked, the newest “What’s New” entries listed go through **Week 17, April 20–24, 2026**. Recent 2026 additions include auto mode, built-in/computer-use improvements, PR auto-fix, transcript search, PowerShell tool support, `/powerup` lessons, fullscreen rendering, `/ultraplan`, self-paced `/loop`, `/team-onboarding`, `/autofix-pr`, Opus 4.7, `xhigh` effort, web routines, `/ultrareview`, `/usage` breakdowns, native binaries, automatic session recaps, custom color themes, and a redesigned Claude Code on the web. [18](https://code.claude.com/docs/llms.txt)

Useful commands to stay current:

text

```
/release-notes
```

text

```
/powerup
```

Bash

```
claude update
claude --version
```

---

# 23. “Do this now” starter kit

Run these in a repo:

Bash

```
mkdir -p .claude/rules .claude/skills/deep-research .claude/agents
```

Create `.claude/settings.json`:

JSON

```bash
{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "permissions": {
    "defaultMode": "default",
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)",
      "Bash(rm -rf *)"
    ],
    "allow": [
      "Bash(git status *)",
      "Bash(git diff *)",
      "Bash(git log *)"
    ]
  },
  "model": "sonnet"
}
```

Create `CLAUDE.md`:

Markdown

```bash
# Claude Code project guide

## Commands
- Install: `pnpm install`
- Lint: `pnpm lint`
- Typecheck: `pnpm typecheck`
- Test: `pnpm test`

## Workflow
- For non-trivial changes, plan before editing.
- Keep changes minimal and well-tested.
- Summarize files changed and tests run.
- Ask before adding dependencies.

## Safety
- Never read `.env`, `.env.*`, or `secrets/**`.
- Do not run destructive git commands unless explicitly requested.
```

Create `.claude/skills/deep-research/SKILL.md`:

Markdown

```bash
---
name: deep-research
description: Research a codebase topic in isolated context and return concise findings with file references
context: fork
agent: Explore
---

Research $ARGUMENTS.

Return:
1. Summary
2. Important files/functions
3. Current behavior
4. Risks and edge cases
5. Suggested tests
6. Recommended next steps
```

Create `.claude/agents/code-reviewer.md`:

Markdown

```bash
---
name: code-reviewer
description: Reviews code for correctness, security, maintainability, and tests. Use proactively after code changes.
tools: Read, Glob, Grep, Bash
model: sonnet
effort: high
---

You are a senior code reviewer. Do not edit files.

Review for:
- correctness
- security
- edge cases
- maintainability
- performance
- missing tests

Return findings by severity with file references.
```

Then start:

Bash

```
claude --permission-mode plan --name repo-onboarding
```

Prompt:

text

```
Onboard me to this repo. Use deep-research for architecture, then produce a codebase map and a prioritized list of safe first improvements. Do not edit files.
```