Claude Code guide in three levels, Beginner to Advanced: hands-on lessons with checked exercises, every volatile fact cited to its source. Independent community guide.
JavaScript agent-skillsagentic-codingai-agentsanthropicanthropic-claudebest-practicesclaudeclaude-aiclaude-codeclaude-code-guideclaude-code-hooksclaude-code-pluginsclaude-code-skillsclaude-code-tutorialclaude-code-workflowsguidelearn-claude-codemcpsubagentstutorial
docs: copy the Intermediate and Advanced README sections into labelled previous-edition pages (#68)
Wesam Abousaid8b8e26bcac94
diff --git a/docs/legacy/fast-mode.md b/docs/legacy/fast-mode.mdnew file mode 100644index 0000000..4cb2f20--- /dev/null+++ b/docs/legacy/fast-mode.md@@ -0,0 +1,28 @@+<a id="fast-mode"></a>+<a id="fast-mode-"></a>+# Fast mode++> [!NOTE]+> From the previous edition, not yet re-verified. The guide is being rebuilt as lessons; this page keeps the earlier material reachable until they land.++`/fast` toggles fast mode, a [research preview](https://code.claude.com/docs/en/fast-mode): up to **2.5× faster output at 2× the price**. Since v2.1.280 it runs on **Opus 5.5** by default; Opus 5 and Opus 4.8 also support it ($10/$50 per MTok in fast mode), Sonnet and Haiku don't. It isn't CLI-only: the VS Code extension has a **Toggle fast mode** command, and claude.ai/code has a toggle in the model menu. The **↯** indicator confirms it's on. On subscription plans, fast mode draws from usage credits rather than plan limits.++| | Standard Opus 5.5 | Fast Mode (Opus 5.5) |+|---|---|---|+| Input (per MTok) | $4 | $8 (2×) |+| Output (per MTok) | $20 | $40 (2×) |++> [!WARNING]+> **Fast mode on older Opus models is gone.** Opus 4.7 fast was deprecated on June 25, 2026 and **removed on July 24, 2026** (v2.1.219), and Opus 4.6 doesn't support fast mode either.++```bash+/fast # toggle on (↯ appears)+> fix the auth bug in src/login.ts # faster output+/fast # toggle off when done+```++**Decision rule:** use it when latency matters (live debugging, demo prep, time-pressured fixes). At 2× cost it's a much easier call than the old 6×, but background work still doesn't need it. Use `/usage` to monitor.++---++<sub>From the previous edition of [Claude Code: Everything You Need to Know](../../README.md).</sub>diff --git a/docs/legacy/hooks.md b/docs/legacy/hooks.mdnew file mode 100644index 0000000..d0a9d67--- /dev/null+++ b/docs/legacy/hooks.md@@ -0,0 +1,118 @@+# Hooks++> [!NOTE]+> From the previous edition, not yet re-verified. The guide is being rebuilt as lessons; this page keeps the earlier material reachable until they land.++> **Mental model:** Hooks are programmable checkpoints on Claude Code's lifecycle (before/after a tool call, session start, prompt submit, etc.). Your script inspects the proposed action and returns *allow* / *deny* / *modify*.++**Three cases that win most teams over:**++| Use case | What the hook does |+|---|---|+| Auto-format on save | Runs `prettier` / `ruff` / `gofmt` after every Edit so Claude's output matches your style |+| Block sensitive paths | Refuses changes to `.env`, `secrets/`, `infra/prod/` regardless of what Claude tries |+| Action audit log | Records every tool call to a file: a paper trail of what Claude did and when |++If none of those resonate, skip ahead.++<a id="setting-up-claude-hooks"></a>+## Setting up hooks++Hooks live in settings files at four scopes (later overrides earlier):++| Scope | Path |+|---|---|+| User-wide | `~/.claude/settings.json` |+| Project (committed) | `.claude/settings.json` |+| Project (local, gitignored) | `.claude/settings.local.json` |+| Enterprise managed policy | platform-specific |++**Quickest setup**: use the interactive menu:++```bash+/hooks # browse, enable, configure hooks without touching JSON+```++## Hook Events++Hooks run in response to various events within Claude Code's lifecycle:+[examples](https://github.com/disler/claude-code-hooks-mastery)+- **`PreToolUse`**: Runs **after Claude creates tool parameters but before processing the tool call**.+- **`PostToolUse`**: Runs **immediately after a tool completes successfully**.+- **`Notification`**: Runs when Claude Code sends notifications, such as when permission is needed to use a tool or when prompt input has been idle.+- **`UserPromptSubmit`**: Runs when the user submits a prompt, **before Claude processes it**.+- **`Stop`**: Runs when the main Claude Code agent has finished responding (does not run if stopped by user interrupt).+- **`SubagentStop`**: Runs when a Claude Code subagent (Task tool call) has finished responding.+- **`SessionEnd`**: Runs when a Claude Code session ends.+- **`PreCompact`**: Runs before Claude Code is about to run a compact operation.+- **`SessionStart`**: Runs when Claude Code starts a new session or resumes an existing session.+- **`TeammateIdle`**: Runs when an agent teammate becomes idle (Agent Teams); exit code 2 sends the teammate back to work.+- **`TaskCompleted`**: Runs when a task is marked as completed; exit code 2 blocks the completion.++> These are the most-used events. The full catalog is **33 events** as of October 4, 2026 (SubagentStart, PermissionRequest, FileChanged, WorktreeCreate, PostCompact, …); see the [official hooks reference](https://code.claude.com/docs/en/hooks).++## Hook input++Hooks receive **JSON via stdin**. Every event includes `session_id`, `transcript_path`, and `cwd`. Event-specific fields:++| Hook Event | Event-specific fields |+|---|---|+| `PreToolUse` | `tool_name`, `tool_input` |+| `PostToolUse` | `tool_name`, `tool_input`, `tool_response` |+| `Notification` | `message` |+| `UserPromptSubmit` | `prompt` |+| `Stop` / `SubagentStop` | `stop_hook_active` |+| `PreCompact` | `trigger`, `custom_instructions` |+| `SessionStart` | `source` |+| `SessionEnd` | `reason` |+| `TeammateIdle` | `teammate_id`, `last_activity` |+| `TaskCompleted` | `task_id`, `task_name`, `completion_time` |++> [!NOTE]+> The `team_name` field in `TaskCreated` / `TaskCompleted` / `TeammateIdle` payloads is deprecated since v2.1.178 (one implicit team per session).++## Hook output++Two ways to communicate back: **exit codes** for simple control, **JSON in stdout** for fine-grained behavior.++| Exit code | Effect |+|---|---|+| `0` (success) | `stdout` shown in transcript mode (CTRL-R). For `UserPromptSubmit` / `SessionStart`, `stdout` is added to Claude's context. |+| `2` (blocking) | `stderr` fed back to Claude (or shown to user) to block the action. Stops tool calls in `PreToolUse`; stops prompt processing in `UserPromptSubmit`. |+| Other | `stderr` shown; execution continues. |++**Advanced: structured JSON in stdout.** Per-event decision fields:++| Event | JSON output |+|---|---|+| `PreToolUse` | `permissionDecision`: `"allow"` / `"deny"` / `"ask"`; `updatedInput` to modify tool parameters |+| `PostToolUse` | `decision`: `"block"` or `undefined`; `additionalContext` can be returned |+| `UserPromptSubmit` | `decision`: `"block"` or `undefined`; `additionalContext` can be returned |+| `Stop` / `SubagentStop` | `decision`: `"block"` or `undefined` |+| `SessionStart` | `additionalContext` |++## Security considerations++Hooks run **arbitrary shell commands automatically** with your user permissions: they can read, modify, or delete any file you can. Anthropic provides no warranty for what your hooks do.++**Best practices:**++- Validate and sanitize all inputs from stdin JSON+- Quote shell variables (`"$var"`, not `$var`)+- Block path traversal (`..`, absolute paths outside the project)+- Use absolute paths for invoked scripts so PATH attacks don't redirect+- Explicitly skip sensitive files (`.env`, `.git/`, `secrets/`)++Claude Code snapshots your hook configuration at session start and warns if hooks change mid-session; review before applying.++<a id="hook-execution-details-and-debugging"></a>+## Execution & debugging++- **Timeout**: defaults vary by hook type: 600s for `command`/`http`/`mcp_tool` hooks, 30s for `prompt` hooks, 60s for `agent` hooks (some events lower these, e.g. `UserPromptSubmit` command hooks get 30s). Configurable per hook.+- **Parallelization**: all matching hooks run in parallel; identical handlers are deduplicated automatically.+- **Environment**: hooks run in the current dir with Claude Code's env; `CLAUDE_PROJECT_DIR` is available.+- **Debug**: `/hooks` shows current config; `claude --debug` shows hook execution logs; test scripts manually with the JSON payload piped to stdin.++---++<sub>From the previous edition of [Claude Code: Everything You Need to Know](../../README.md).</sub>diff --git a/docs/legacy/mcp.md b/docs/legacy/mcp.mdnew file mode 100644index 0000000..6123080--- /dev/null+++ b/docs/legacy/mcp.md@@ -0,0 +1,30 @@+# Model Context Protocol (MCP)++> [!NOTE]+> From the previous edition, not yet re-verified. The guide is being rebuilt as lessons; this page keeps the earlier material reachable until they land.++> **Mental model:** MCP is a universal translator that lets any AI tool talk to any data source through one open protocol: USB-C for AI integrations.++## The N×M problem MCP solves++Before MCP, every AI app needed a custom integration for every tool: `n` apps × `m` tools = `n × m` brittle one-off connections. Teams inside the same company would reinvent the same Slack/GitHub/Postgres integration over and over.++MCP collapses this to **N + M**: each app implements MCP once, each tool exposes MCP once, and any combination works together. Same pattern Web APIs gave us for app-to-server and LSP gave us for editor-to-language tooling.++## Three pillars++Each pillar makes ownership explicit, so it's always clear who's driving:++| Pillar | Controlled by | Purpose |+|---|---|---|+| **Tools** | The model | Lets the AI take actions: query a DB, call an API, write a file |+| **Resources** | The application | Feeds the AI structured context: files, error logs, JSON objects |+| **Prompts** | The user | Slash-command shortcuts that kick off multi-step workflows |++## The MCP Registry & self-discovering agents++The [official MCP Registry](https://registry.modelcontextprotocol.io/) (public preview since September 2025) is the app-store-equivalent for MCP servers. An agent that needs to check Grafana logs but doesn't have a Grafana tool wired up can ping the registry, find the verified server, install it, and continue, teaching itself a new capability on the fly.++---++<sub>From the previous edition of [Claude Code: Everything You Need to Know](../../README.md).</sub>diff --git a/docs/legacy/skills.md b/docs/legacy/skills.mdnew file mode 100644index 0000000..9205dda--- /dev/null+++ b/docs/legacy/skills.md@@ -0,0 +1,67 @@+<a id="claude-skills"></a>+# Claude Skills++> [!NOTE]+> From the previous edition, not yet re-verified. The guide is being rebuilt as lessons; this page keeps the earlier material reachable until they land.++*~3 min read · [Full guide in `docs/skills.md` →](../../docs/skills.md)*++> **Mental model:** Skills package a workflow into a markdown file. Two equivalent formats, officially one system now:+> - **Slash skills**: `.claude/commands/<name>.md`, you invoke them with `/<name>`+> - **Agent Skills**: `.claude/skills/<name>/SKILL.md` with YAML frontmatter; Claude can also auto-invoke these when the description matches the task+>+> `.claude/commands/deploy.md` and `.claude/skills/deploy/SKILL.md` both create `/deploy`. Skills follow the open [agentskills.io](https://agentskills.io) standard, adopted by ~40 products beyond Claude Code (Codex, Copilot, Cursor, Gemini CLI, …).++> [!WARNING]+> **Security:** Skills are executable instructions running with your shell permissions. Read every third-party skill before adding it, exactly like reviewing a shell script before sourcing it.++On a name clash, enterprise beats personal (`~/.claude/`) and personal beats project (`.claude/`); a local skill replaces a bundled skill of the same name, or (in a local terminal session) a built-in command, but not its aliases; plugin skills are namespaced as `/plugin-name:skill-name`, so both load ([official rules](https://code.claude.com/docs/en/skills#resolve-skills-that-share-a-name)). Slash skills load on `/` autocomplete; Agent Skills preload only their metadata and read the body on demand. [Full lookup table →](../../docs/skills.md#where-claude-looks)++## Your first skill in 3 minutes++```bash+mkdir -p .claude/commands++cat > .claude/commands/analyze.md << 'EOF'+# Code Analysis++Analyze the current code for:+- Potential bugs and edge cases+- Performance optimizations+- Code quality improvements+- Security vulnerabilities++Provide specific, actionable recommendations.+EOF++claude # then type: /analyze+```++That's it: a working slash skill. Promote it to an Agent Skill later by moving it to `.claude/skills/analyze/SKILL.md` and adding `name`/`description` frontmatter.++## Want more depth?++The [full Skills guide in `docs/skills.md`](../../docs/skills.md) covers:++- The Agent Skill shipped here, [`/claude-md-review`](../../.claude/skills/claude-md-review/SKILL.md)+- Bundled built-in skills (e.g. `/dataviz`, `/debug`, `/keybindings-help`)+- Slash skills vs Agent Skills, and the [full frontmatter reference](../../docs/skills.md#frontmatter-reference), including why `allowed-tools` **grants** permission rather than restricting it+- How to write your own skills (file format, scope, examples)+- Skills FAQ, troubleshooting, and best practices++## Custom slash commands++Define a frequently-used prompt once as a markdown file, invoke it forever with `/skill-name`:++```bash+mkdir -p .claude/commands+echo "Analyze this code for performance issues and suggest optimizations:" \+ > .claude/commands/optimize.md+```++> [!TIP]+> **Next level:** custom slash commands and Skills are the same thing. Head to [Claude Skills](#claude-skills) for the deep dive: built-in skills, the Agent Skill in this repo, and how to write your own.++---++<sub>From the previous edition of [Claude Code: Everything You Need to Know](../../README.md).</sub>diff --git a/docs/legacy/subagents-and-parallel-work.md b/docs/legacy/subagents-and-parallel-work.mdnew file mode 100644index 0000000..84ad219--- /dev/null+++ b/docs/legacy/subagents-and-parallel-work.md@@ -0,0 +1,57 @@+<a id="ai-agents"></a>+<a id="running-agents-in-parallel"></a>+<a id="subagents--running-agents-in-parallel"></a>+# Subagents and running agents in parallel++> [!NOTE]+> From the previous edition, not yet re-verified. The guide is being rebuilt as lessons; this page keeps the earlier material reachable until they land.++Claude Code has **four** ways to run agents at once. They're easy to confuse, so start here: the question that separates them is **who coordinates the work**:++| Surface | Who coordinates | Reach for it when… |+|---|---|---|+| **Subagents** *(below)* | Claude, turn by turn, inside one session | A side task would flood your main conversation with search results, logs, or file contents you'll never reference again |+| **Agent view**: `claude agents` *(research preview)* | **You**: hand off, check back later | You have several independent tasks and want to dispatch them, glance at status, and step in only when one needs you. Each dispatched session gets **its own worktree automatically** |+| **[Agent Teams](../../README.md#agent-teams-experimental)** *(experimental)* | A lead agent supervising peer sessions | Workers need to **talk to each other**: share findings, challenge each other, self-claim from a shared task list |+| **[Dynamic Workflows](../../README.md#dynamic-workflows)** | **A script**, not Claude's judgement | The job outgrows a handful of subagents, or you want findings cross-checked against each other: codebase-wide audits, 500-file migrations |++Two supporting tools that aren't a coordination style of their own:++- **[Git worktrees](#1-git-worktrees--parallel-branches-parallel-sessions)**: separate checkouts so parallel sessions never touch the same files.+- **`/batch`**: a bundled skill that researches the codebase, splits one large change into **5–30 independent units**, and spawns a background subagent per unit **in its own worktree, each opening a PR**. It's a packaged use of subagents + worktrees, and the fastest way to feel this whole category.++> [!TIP]+> **Checking on running work** depends on what you started: `/tasks` for anything backgrounded in the current session, `claude agents` for background sessions, `/workflows` for workflow runs. Note `/agents` (removed as a wizard in v2.1.198) is a different thing entirely from `claude agents`.++<a id="1-git-worktrees--parallel-branches-parallel-sessions"></a>+## 1. Git worktrees: parallel branches, parallel sessions++[Git worktrees](https://git-scm.com/docs/git-worktree) let one repo have multiple branches checked out at the same time, each in its own folder. Pair them with one Claude Code session per worktree to run independent streams of work.++```bash+git worktree add -b feature-a ../feature-a # create the worktree+cd ../feature-a && claude # start Claude in it+# Repeat in another terminal for feature-b. Each session is independent.+git worktree remove ../feature-a # clean up when done+```++> [!TIP]+> Use [tmux](https://github.com/tmux/tmux/wiki/Installing) to keep each worktree's session attached even when you close the terminal.+>+> [!TIP]+> Prefer not to manage them by hand? `claude agents` (agent view) puts **each dispatched session in its own worktree automatically**, and `/batch` does the same per unit of work.++<a id="2-general-purpose-subagents--when-one-claude-isnt-enough"></a>+## 2. General-purpose subagents: when one Claude isn't enough++From your main session, ask Claude to spawn subagents for a parallel sub-task. Each subagent runs in its own context window and reports a summary back, so the main session stays focused.++```markdown+Analyze the implementation of the payment feature.+Spawn 5 subagents to accelerate the work.+Ultrathink.+```++---++<sub>From the previous edition of [Claude Code: Everything You Need to Know](../../README.md).</sub>