SpyBara
Go Premium

Documentation 2026-01-21 21:05 UTC to 2026-01-22 21:03 UTC

16 files changed +790 −122. View all changes and history on the product overview
2026
Sat 31 03:42 Fri 30 18:07 Thu 29 21:03 Wed 28 15:06 Tue 27 21:01 Mon 26 21:03 Sun 25 03:34 Sat 24 03:29 Fri 23 21:01 Thu 22 21:03 Wed 21 21:05 Tue 20 21:03 Mon 19 21:01 Fri 16 21:01 Wed 14 06:02 Mon 12 21:02 Sun 11 18:02 Sat 10 21:01 Fri 9 21:01 Thu 8 21:02 Wed 7 21:01 Tue 6 21:01 Sat 3 18:02

best-practices.md +596 −0 created

Details

1# Best Practices for Claude Code

2 

3> Tips and patterns for getting the most out of Claude Code, from configuring your environment to scaling across parallel sessions.

4 

5Claude Code is an agentic coding environment. Unlike a chatbot that answers questions and waits, Claude Code can read your files, run commands, make changes, and autonomously work through problems while you watch, redirect, or step away entirely.

6 

7This changes how you work. Instead of writing code yourself and asking Claude to review it, you describe what you want and Claude figures out how to build it. Claude explores, plans, and implements.

8 

9But this autonomy still comes with a learning curve. Claude works within certain constraints you need to understand.

10 

11This guide covers patterns that have proven effective across Anthropic's internal teams and for engineers using Claude Code across various codebases, languages, and environments. For how the agentic loop works under the hood, see [How Claude Code works](/en/how-claude-code-works).

12 

13***

14 

15Most best practices are based on one constraint: Claude's context window fills up fast, and performance degrades as it fills.

16 

17Claude's context window holds your entire conversation, including every message, every file Claude reads, and every command output. However, this can fill up fast. A single debugging session or codebase exploration might generate and consume tens of thousands of tokens.

18 

19This matters since LLM performance degrades as context fills. When the context window is getting full, Claude may start "forgetting" earlier instructions or making more mistakes. The context window is the most important resource to manage. For detailed strategies on reducing token usage, see [Reduce token usage](/en/costs#reduce-token-usage).

20 

21***

22 

23## Give Claude a way to verify its work

24 

25<Tip>

26 Include tests, screenshots, or expected outputs so Claude can check itself. This is the single highest-leverage thing you can do.

27</Tip>

28 

29Claude performs dramatically better when it can verify its own work, like run tests, compare screenshots, and validate outputs.

30 

31Without clear success criteria, it might produce something that looks right but actually doesn't work. You become the only feedback loop, and every mistake requires your attention.

32 

33| Strategy | Before | After |

34| ------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

35| **Provide verification criteria** | *"implement a function that validates email addresses"* | *"write a validateEmail function. example test cases: [user@example.com](mailto:user@example.com) is true, invalid is false, [user@.com](mailto:user@.com) is false. run the tests after implementing"* |

36| **Verify UI changes visually** | *"make the dashboard look better"* | *"\[paste screenshot] implement this design. take a screenshot of the result and compare it to the original. list differences and fix them"* |

37| **Address root causes, not symptoms** | *"the build is failing"* | *"the build fails with this error: \[paste error]. fix it and verify the build succeeds. address the root cause, don't suppress the error"* |

38 

39UI changes can be verified using the [Claude in Chrome extension](/en/chrome). It opens a browser, tests the UI, and iterates until the code works.

40 

41Your verification can also be a test suite, a linter, or a Bash command that checks output. Invest in making your verification rock-solid.

42 

43***

44 

45## Explore first, then plan, then code

46 

47<Tip>

48 Separate research and planning from implementation to avoid solving the wrong problem.

49</Tip>

50 

51Letting Claude jump straight to coding can produce code that solves the wrong problem. Use [Plan Mode](/en/common-workflows#use-plan-mode-for-safe-code-analysis) to separate exploration from execution.

52 

53The recommended workflow has four phases:

54 

55<Steps>

56 <Step title="Explore">

57 Enter Plan Mode. Claude reads files and answers questions without making changes.

58 

59 ```txt claude (Plan Mode) theme={null}

60 read /src/auth and understand how we handle sessions and login.

61 also look at how we manage environment variables for secrets.

62 ```

63 </Step>

64 

65 <Step title="Plan">

66 Ask Claude to create a detailed implementation plan.

67 

68 ```txt claude (Plan Mode) theme={null}

69 I want to add Google OAuth. What files need to change?

70 What's the session flow? Create a plan.

71 ```

72 </Step>

73 

74 <Step title="Implement">

75 Switch back to Normal Mode and let Claude code, verifying against its plan.

76 

77 ```txt claude (Normal Mode) theme={null}

78 implement the OAuth flow from your plan. write tests for the

79 callback handler, run the test suite and fix any failures.

80 ```

81 </Step>

82 

83 <Step title="Commit">

84 Ask Claude to commit with a descriptive message and create a PR.

85 

86 ```txt claude (Normal Mode) theme={null}

87 commit with a descriptive message and open a PR

88 ```

89 </Step>

90</Steps>

91 

92<Callout>

93 Plan Mode is useful, but also adds overhead.

94 

95 For tasks where the scope is clear and the fix is small (like fixing a typo, adding a log line, or renaming a variable) ask Claude to do it directly.

96 

97 Planning is most useful when you're uncertain about the approach, when the change modifies multiple files, or when you're unfamiliar with the code being modified. If you could describe the diff in one sentence, skip the plan.

98</Callout>

99 

100***

101 

102## Provide specific context in your prompts

103 

104<Tip>

105 The more precise your instructions, the fewer corrections you'll need.

106</Tip>

107 

108Claude can infer intent, but it can't read your mind. Reference specific files, mention constraints, and point to example patterns.

109 

110| Strategy | Before | After |

111| ------------------------------------------------------------------------------------------------ | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

112| **Scope the task.** Specify which file, what scenario, and testing preferences. | *"add tests for foo.py"* | *"write a test for foo.py covering the edge case where the user is logged out. avoid mocks."* |

113| **Point to sources.** Direct Claude to the source that can answer a question. | *"why does ExecutionFactory have such a weird api?"* | *"look through ExecutionFactory's git history and summarize how its api came to be"* |

114| **Reference existing patterns.** Point Claude to patterns in your codebase. | *"add a calendar widget"* | *"look at how existing widgets are implemented on the home page to understand the patterns. HotDogWidget.php is a good example. follow the pattern to implement a new calendar widget that lets the user select a month and paginate forwards/backwards to pick a year. build from scratch without libraries other than the ones already used in the codebase."* |

115| **Describe the symptom.** Provide the symptom, the likely location, and what "fixed" looks like. | *"fix the login bug"* | *"users report that login fails after session timeout. check the auth flow in src/auth/, especially token refresh. write a failing test that reproduces the issue, then fix it"* |

116 

117Vague prompts can be useful when you're exploring and can afford to course-correct. A prompt like `"what would you improve in this file?"` can surface things you wouldn't have thought to ask about.

118 

119### Provide rich content

120 

121<Tip>

122 Use `@` to reference files, paste screenshots/images, or pipe data directly.

123</Tip>

124 

125You can provide rich data to Claude in several ways:

126 

127* **Reference files with `@`** instead of describing where code lives. Claude reads the file before responding.

128* **Paste images directly**. Copy/paste or drag and drop images into the prompt.

129* **Give URLs** for documentation and API references. Use `/permissions` to allowlist frequently-used domains.

130* **Pipe in data** by running `cat error.log | claude` to send file contents directly.

131* **Let Claude fetch what it needs**. Tell Claude to pull context itself using Bash commands, MCP tools, or by reading files.

132 

133***

134 

135## Configure your environment

136 

137A few setup steps make Claude Code significantly more effective across all your sessions. For a full overview of extension features and when to use each one, see [Extend Claude Code](/en/features-overview).

138 

139### Write an effective CLAUDE.md

140 

141<Tip>

142 Run `/init` to generate a starter CLAUDE.md file based on your current project structure, then refine over time.

143</Tip>

144 

145CLAUDE.md is a special file that Claude reads at the start of every conversation. Include Bash commands, code style, and workflow rules. This gives Claude persistent context **it can't infer from code alone**.

146 

147The `/init` command analyzes your codebase to detect build systems, test frameworks, and code patterns, giving you a solid foundation to refine.

148 

149There's no required format for CLAUDE.md files, but keep it short and human-readable. For example:

150 

151```markdown CLAUDE.md theme={null}

152# Code style

153- Use ES modules (import/export) syntax, not CommonJS (require)

154- Destructure imports when possible (eg. import { foo } from 'bar')

155 

156# Workflow

157- Be sure to typecheck when you're done making a series of code changes

158- Prefer running single tests, and not the whole test suite, for performance

159```

160 

161CLAUDE.md is loaded every session, so only include things that apply broadly. For domain knowledge or workflows that are only relevant sometimes, use [skills](/en/skills) instead. Claude loads them on demand without bloating every conversation.

162 

163Keep it concise. For each line, ask: *"Would removing this cause Claude to make mistakes?"* If not, cut it. Bloated CLAUDE.md files cause Claude to ignore your actual instructions!

164 

165| ✅ Include | ❌ Exclude |

166| ---------------------------------------------------- | -------------------------------------------------- |

167| Bash commands Claude can't guess | Anything Claude can figure out by reading code |

168| Code style rules that differ from defaults | Standard language conventions Claude already knows |

169| Testing instructions and preferred test runners | Detailed API documentation (link to docs instead) |

170| Repository etiquette (branch naming, PR conventions) | Information that changes frequently |

171| Architectural decisions specific to your project | Long explanations or tutorials |

172| Developer environment quirks (required env vars) | File-by-file descriptions of the codebase |

173| Common gotchas or non-obvious behaviors | Self-evident practices like "write clean code" |

174 

175If Claude keeps doing something you don't want despite having a rule against it, the file is probably too long and the rule is getting lost. If Claude asks you questions that are answered in CLAUDE.md, the phrasing might be ambiguous. Treat CLAUDE.md like code: review it when things go wrong, prune it regularly, and test changes by observing whether Claude's behavior actually shifts.

176 

177You can tune instructions by adding emphasis (e.g., "IMPORTANT" or "YOU MUST") to improve adherence. Check CLAUDE.md into git so your team can contribute. The file compounds in value over time.

178 

179CLAUDE.md files can import additional files using `@path/to/import` syntax:

180 

181```markdown CLAUDE.md theme={null}

182See @README.md for project overview and @package.json for available npm commands.

183 

184# Additional Instructions

185- Git workflow: @docs/git-instructions.md

186- Personal overrides: @~/.claude/my-project-instructions.md

187```

188 

189You can place CLAUDE.md files in several locations:

190 

191* **Home folder (`~/.claude/CLAUDE.md`)**: Applies to all Claude sessions

192* **Project root (`./CLAUDE.md`)**: Check into git to share with your team, or name it `CLAUDE.local.md` and `.gitignore` it

193* **Parent directories**: Useful for monorepos where both `root/CLAUDE.md` and `root/foo/CLAUDE.md` are pulled in automatically

194* **Child directories**: Claude pulls in child CLAUDE.md files on demand when working with files in those directories

195 

196### Configure permissions

197 

198<Tip>

199 Use `/permissions` to allowlist safe commands or `/sandbox` for OS-level isolation. This reduces interruptions while keeping you in control.

200</Tip>

201 

202By default, Claude Code requests permission for actions that might modify your system: file writes, Bash commands, MCP tools, etc. This is safe but tedious. After the tenth approval you're not really reviewing anymore, you're just clicking through. There are two ways to reduce these interruptions:

203 

204* **Permission allowlists**: Permit specific tools you know are safe (like `npm run lint` or `git commit`)

205* **Sandboxing**: Enable OS-level isolation that restricts filesystem and network access, allowing Claude to work more freely within defined boundaries

206 

207Alternatively, use `--dangerously-skip-permissions` to bypass all permission checks for contained workflows like fixing lint errors or generating boilerplate.

208 

209<Warning>

210 Letting Claude run arbitrary commands can result in data loss, system corruption, or data exfiltration via prompt injection. Only use `--dangerously-skip-permissions` in a sandbox without internet access.

211</Warning>

212 

213Read more about [configuring permissions](/en/settings) and [enabling sandboxing](/en/sandboxing#sandboxing).

214 

215### Use CLI tools

216 

217<Tip>

218 Tell Claude Code to use CLI tools like `gh`, `aws`, `gcloud`, and `sentry-cli` when interacting with external services.

219</Tip>

220 

221CLI tools are the most context-efficient way to interact with external services. If you use GitHub, install the `gh` CLI. Claude knows how to use it for creating issues, opening pull requests, and reading comments. Without `gh`, Claude can still use the GitHub API, but unauthenticated requests often hit rate limits.

222 

223Claude is also effective at learning CLI tools it doesn't already know. Try prompts like `Use 'foo-cli-tool --help' to learn about foo tool, then use it to solve A, B, C.`

224 

225### Connect MCP servers

226 

227<Tip>

228 Run `claude mcp add` to connect external tools like Notion, Figma, or your database.

229</Tip>

230 

231With [MCP servers](/en/mcp), you can ask Claude to implement features from issue trackers, query databases, analyze monitoring data, integrate designs from Figma, and automate workflows.

232 

233### Set up hooks

234 

235<Tip>

236 Use hooks for actions that must happen every time with zero exceptions.

237</Tip>

238 

239[Hooks](/en/hooks-guide) run scripts automatically at specific points in Claude's workflow. Unlike CLAUDE.md instructions which are advisory, hooks are deterministic and guarantee the action happens.

240 

241Claude can write hooks for you. Try prompts like *"Write a hook that runs eslint after every file edit"* or *"Write a hook that blocks writes to the migrations folder."* Run `/hooks` for interactive configuration, or edit `.claude/settings.json` directly.

242 

243### Create skills

244 

245<Tip>

246 Create `SKILL.md` files in `.claude/skills/` to give Claude domain knowledge and reusable workflows.

247</Tip>

248 

249[Skills](/en/skills) extend Claude's knowledge with information specific to your project, team, or domain. Claude applies them automatically when relevant, or you can invoke them directly with `/skill-name`.

250 

251Create a skill by adding a directory with a `SKILL.md` to `.claude/skills/`:

252 

253```markdown .claude/skills/api-conventions/SKILL.md theme={null}

254---

255name: api-conventions

256description: REST API design conventions for our services

257---

258# API Conventions

259- Use kebab-case for URL paths

260- Use camelCase for JSON properties

261- Always include pagination for list endpoints

262- Version APIs in the URL path (/v1/, /v2/)

263```

264 

265Skills can also define repeatable workflows you invoke directly:

266 

267```markdown .claude/skills/fix-issue/SKILL.md theme={null}

268---

269name: fix-issue

270description: Fix a GitHub issue

271disable-model-invocation: true

272---

273Analyze and fix the GitHub issue: $ARGUMENTS.

274 

2751. Use `gh issue view` to get the issue details

2762. Understand the problem described in the issue

2773. Search the codebase for relevant files

2784. Implement the necessary changes to fix the issue

2795. Write and run tests to verify the fix

2806. Ensure code passes linting and type checking

2817. Create a descriptive commit message

2828. Push and create a PR

283```

284 

285Run `/fix-issue 1234` to invoke it. Use `disable-model-invocation: true` for workflows with side effects that you want to trigger manually.

286 

287### Create custom subagents

288 

289<Tip>

290 Define specialized assistants in `.claude/agents/` that Claude can delegate to for isolated tasks.

291</Tip>

292 

293[Subagents](/en/sub-agents) run in their own context with their own set of allowed tools. They're useful for tasks that read many files or need specialized focus without cluttering your main conversation.

294 

295```markdown .claude/agents/security-reviewer.md theme={null}

296---

297name: security-reviewer

298description: Reviews code for security vulnerabilities

299tools: Read, Grep, Glob, Bash

300model: opus

301---

302You are a senior security engineer. Review code for:

303- Injection vulnerabilities (SQL, XSS, command injection)

304- Authentication and authorization flaws

305- Secrets or credentials in code

306- Insecure data handling

307 

308Provide specific line references and suggested fixes.

309```

310 

311Tell Claude to use subagents explicitly: *"Use a subagent to review this code for security issues."*

312 

313### Install plugins

314 

315<Tip>

316 Run `/plugin` to browse the marketplace. Plugins add skills, tools, and integrations without configuration.

317</Tip>

318 

319[Plugins](/en/plugins) bundle skills, hooks, subagents, and MCP servers into a single installable unit from the community and Anthropic.

320 

321For guidance on choosing between skills, subagents, hooks, and MCP, see [Extend Claude Code](/en/features-overview#match-features-to-your-goal).

322 

323***

324 

325## Communicate effectively

326 

327The way you communicate with Claude Code significantly impacts the quality of results.

328 

329### Ask codebase questions

330 

331<Tip>

332 Ask Claude questions you'd ask a senior engineer.

333</Tip>

334 

335When onboarding to a new codebase, use Claude Code for learning and exploration. You can ask Claude the same sorts of questions you would ask another engineer:

336 

337* How does logging work?

338* How do I make a new API endpoint?

339* What does `async move { ... }` do on line 134 of `foo.rs`?

340* What edge cases does `CustomerOnboardingFlowImpl` handle?

341* Why does this code call `foo()` instead of `bar()` on line 333?

342 

343Using Claude Code this way is an effective onboarding workflow, improving ramp-up time and reducing load on other engineers. No special prompting required: ask questions directly.

344 

345### Let Claude interview you

346 

347<Tip>

348 For larger features, have Claude interview you first. Start with a minimal prompt and ask Claude to interview you using the `AskUserQuestion` tool.

349</Tip>

350 

351Claude asks about things you might not have considered yet, including technical implementation, UI/UX, edge cases, and tradeoffs.

352 

353```

354I want to build [brief description]. Interview me in detail using the AskUserQuestion tool.

355 

356Ask about technical implementation, UI/UX, edge cases, concerns, and tradeoffs. Don't ask obvious questions, dig into the hard parts I might not have considered.

357 

358Keep interviewing until we've covered everything, then write a complete spec to SPEC.md.

359```

360 

361Once the spec is complete, start a fresh session to execute it. The new session has clean context focused entirely on implementation, and you have a written spec to reference.

362 

363***

364 

365## Manage your session

366 

367Conversations are persistent and reversible. Use this to your advantage!

368 

369### Course-correct early and often

370 

371<Tip>

372 Correct Claude as soon as you notice it going off track.

373</Tip>

374 

375The best results come from tight feedback loops. Though Claude occasionally solves problems perfectly on the first attempt, correcting it quickly generally produces better solutions faster.

376 

377* **`Esc`**: Stop Claude mid-action with the `Esc` key. Context is preserved, so you can redirect.

378* **`Esc + Esc` or `/rewind`**: Press `Esc` twice or run `/rewind` to open the rewind menu and restore previous conversation and code state.

379* **`"Undo that"`**: Have Claude revert its changes.

380* **`/clear`**: Reset context between unrelated tasks. Long sessions with irrelevant context can reduce performance.

381 

382If you've corrected Claude more than twice on the same issue in one session, the context is cluttered with failed approaches. Run `/clear` and start fresh with a more specific prompt that incorporates what you learned. A clean session with a better prompt almost always outperforms a long session with accumulated corrections.

383 

384### Manage context aggressively

385 

386<Tip>

387 Run `/clear` between unrelated tasks to reset context.

388</Tip>

389 

390Claude Code automatically compacts conversation history when you approach context limits, which preserves important code and decisions while freeing space.

391 

392During long sessions, Claude's context window can fill with irrelevant conversation, file contents, and commands. This can reduce performance and sometimes distract Claude.

393 

394* Use `/clear` frequently between tasks to reset the context window entirely

395* When auto compaction triggers, Claude summarizes what matters most, including code patterns, file states, and key decisions

396* For more control, run `/compact <instructions>`, like `/compact Focus on the API changes`

397* Customize compaction behavior in CLAUDE.md with instructions like `"When compacting, always preserve the full list of modified files and any test commands"` to ensure critical context survives summarization

398 

399### Use subagents for investigation

400 

401<Tip>

402 Delegate research with `"use subagents to investigate X"`. They explore in a separate context, keeping your main conversation clean for implementation.

403</Tip>

404 

405Since context is your fundamental constraint, subagents are one of the most powerful tools available. When Claude researches a codebase it reads lots of files, all of which consume your context. Subagents run in separate context windows and report back summaries:

406 

407```

408Use subagents to investigate how our authentication system handles token

409refresh, and whether we have any existing OAuth utilities I should reuse.

410```

411 

412The subagent explores the codebase, reads relevant files, and reports back with findings, all without cluttering your main conversation.

413 

414You can also use subagents for verification after Claude implements something:

415 

416```

417use a subagent to review this code for edge cases

418```

419 

420### Rewind with checkpoints

421 

422<Tip>

423 Every action Claude makes creates a checkpoint. You can restore conversation, code, or both to any previous checkpoint.

424</Tip>

425 

426Claude automatically checkpoints before changes. Double-tap `Escape` or run `/rewind` to open the checkpoint menu. You can restore conversation only (keep code changes), restore code only (keep conversation), or restore both.

427 

428Instead of carefully planning every move, you can tell Claude to try something risky. If it doesn't work, rewind and try a different approach. Checkpoints persist across sessions, so you can close your terminal and still rewind later.

429 

430<Warning>

431 Checkpoints only track changes made *by Claude*, not external processes. This isn't a replacement for git.

432</Warning>

433 

434### Resume conversations

435 

436<Tip>

437 Run `claude --continue` to pick up where you left off, or `--resume` to choose from recent sessions.

438</Tip>

439 

440Claude Code saves conversations locally. When a task spans multiple sessions (you start a feature, get interrupted, come back the next day) you don't have to re-explain the context:

441 

442```bash theme={null}

443claude --continue # Resume the most recent conversation

444claude --resume # Select from recent conversations

445```

446 

447Use `/rename` to give sessions descriptive names (`"oauth-migration"`, `"debugging-memory-leak"`) so you can find them later. Treat sessions like branches. Different workstreams can have separate, persistent contexts.

448 

449***

450 

451## Automate and scale

452 

453Once you're effective with one Claude, multiply your output with parallel sessions, headless mode, and fan-out patterns.

454 

455Everything so far assumes one human, one Claude, and one conversation. But Claude Code scales horizontally. The techniques in this section show how you can get more done.

456 

457### Run headless mode

458 

459<Tip>

460 Use `claude -p "prompt"` in CI, pre-commit hooks, or scripts. Add `--output-format stream-json` for streaming JSON output.

461</Tip>

462 

463With `claude -p "your prompt"`, you can run Claude headlessly, without an interactive session. Headless mode is how you integrate Claude into CI pipelines, pre-commit hooks, or any automated workflow. The output formats (plain text, JSON, streaming JSON) let you parse results programmatically.

464 

465```bash theme={null}

466# One-off queries

467claude -p "Explain what this project does"

468 

469# Structured output for scripts

470claude -p "List all API endpoints" --output-format json

471 

472# Streaming for real-time processing

473claude -p "Analyze this log file" --output-format stream-json

474```

475 

476### Run multiple Claude sessions

477 

478<Tip>

479 Run multiple Claude sessions in parallel to speed up development, run isolated experiments, or start complex workflows.

480</Tip>

481 

482There are two main ways to run parallel sessions:

483 

484* [Claude Desktop](/en/desktop): Manage multiple local sessions visually. Each session gets its own isolated worktree.

485* [Claude Code on the web](/en/claude-code-on-the-web): Run on Anthropic's secure cloud infrastructure in isolated VMs.

486 

487Beyond parallelizing work, multiple sessions enable quality-focused workflows. A fresh context improves code review since Claude won't be biased toward code it just wrote.

488 

489For example, use a Writer/Reviewer pattern:

490 

491| Session A (Writer) | Session B (Reviewer) |

492| ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |

493| `Implement a rate limiter for our API endpoints` | |

494| | `Review the rate limiter implementation in @src/middleware/rateLimiter.ts. Look for edge cases, race conditions, and consistency with our existing middleware patterns.` |

495| `Here's the review feedback: [Session B output]. Address these issues.` | |

496 

497You can do something similar with tests: have one Claude write tests, then another write code to pass them.

498 

499### Fan out across files

500 

501<Tip>

502 Loop through tasks calling `claude -p` for each. Use `--allowedTools` to scope permissions for batch operations.

503</Tip>

504 

505For large migrations or analyses, you can distribute work across many parallel Claude invocations:

506 

507<Steps>

508 <Step title="Generate a task list">

509 Have Claude list all files that need migrating (e.g., `list all 2,000 Python files that need migrating`)

510 </Step>

511 

512 <Step title="Write a script to loop through the list">

513 ```bash theme={null}

514 for file in $(cat files.txt); do

515 claude -p "Migrate $file from React to Vue. Return OK or FAIL." \

516 --allowedTools "Edit,Bash(git commit:*)"

517 done

518 ```

519 </Step>

520 

521 <Step title="Test on a few files, then run at scale">

522 Refine your prompt based on what goes wrong with the first 2-3 files, then run on the full set. The `--allowedTools` flag restricts what Claude can do, which matters when you're running unattended.

523 </Step>

524</Steps>

525 

526You can also integrate Claude into existing data/processing pipelines:

527 

528```bash theme={null}

529claude -p "<your prompt>" --output-format json | your_command

530```

531 

532Use `--verbose` for debugging during development, and turn it off in production.

533 

534### Safe Autonomous Mode

535 

536Use `claude --dangerously-skip-permissions` to bypass all permission checks and let Claude work uninterrupted. This works well for workflows like fixing lint errors or generating boilerplate code.

537 

538<Warning>

539 Letting Claude run arbitrary commands is risky and can result in data loss, system corruption, or data exfiltration (e.g., via prompt injection attacks). To minimize these risks, use `--dangerously-skip-permissions` in a container without internet access.

540 

541 With sandboxing enabled (`/sandbox`), you get similar autonomy with better security. Sandbox defines upfront boundaries rather than bypassing all checks.

542</Warning>

543 

544***

545 

546## Avoid common failure patterns

547 

548These are common mistakes. Recognizing them early saves time:

549 

550* **The kitchen sink session.** You start with one task, then ask Claude something unrelated, then go back to the first task. Context is full of irrelevant information.

551 > **Fix**: `/clear` between unrelated tasks.

552* **Correcting over and over.** Claude does something wrong, you correct it, it's still wrong, you correct again. Context is polluted with failed approaches.

553 > **Fix**: After two failed corrections, `/clear` and write a better initial prompt incorporating what you learned.

554* **The over-specified CLAUDE.md.** If your CLAUDE.md is too long, Claude ignores half of it because important rules get lost in the noise.

555 > **Fix**: Ruthlessly prune. If Claude already does something correctly without the instruction, delete it or convert it to a hook.

556* **The trust-then-verify gap.** Claude produces a plausible-looking implementation that doesn't handle edge cases.

557 > **Fix**: Always provide verification (tests, scripts, screenshots). If you can't verify it, don't ship it.

558* **The infinite exploration.** You ask Claude to "investigate" something without scoping it. Claude reads hundreds of files, filling the context.

559 > **Fix**: Scope investigations narrowly or use subagents so the exploration doesn't consume your main context.

560 

561***

562 

563## Develop your intuition

564 

565The patterns in this guide aren't set in stone. They're starting points that work well in general, but might not be optimal for every situation.

566 

567Sometimes you *should* let context accumulate because you're deep in one complex problem and the history is valuable. Sometimes you should skip planning and let Claude figure it out because the task is exploratory. Sometimes a vague prompt is exactly right because you want to see how Claude interprets the problem before constraining it.

568 

569Pay attention to what works. When Claude produces great output, notice what you did: the prompt structure, the context you provided, the mode you were in. When Claude struggles, ask why. Was the context too noisy? The prompt too vague? The task too big for one pass?

570 

571Over time, you'll develop intuition that no guide can capture. You'll know when to be specific and when to be open-ended, when to plan and when to explore, when to clear context and when to let it accumulate.

572 

573## Related resources

574 

575<CardGroup cols={2}>

576 <Card title="How Claude Code works" icon="gear" href="/en/how-claude-code-works">

577 Understand the agentic loop, tools, and context management

578 </Card>

579 

580 <Card title="Extend Claude Code" icon="puzzle-piece" href="/en/features-overview">

581 Choose between skills, hooks, MCP, subagents, and plugins

582 </Card>

583 

584 <Card title="Common workflows" icon="list-check" href="/en/common-workflows">

585 Step-by-step recipes for debugging, testing, PRs, and more

586 </Card>

587 

588 <Card title="CLAUDE.md" icon="file-lines" href="/en/memory">

589 Store project conventions and persistent context

590 </Card>

591</CardGroup>

592 

593 

594---

595 

596> To find navigation and other pages in this documentation, fetch the llms.txt file at: https://code.claude.com/docs/llms.txt

Details

363. Install the Claude GitHub app in your repositories363. Install the Claude GitHub app in your repositories

374. Select your default environment374. Select your default environment

385. Submit your coding task385. Submit your coding task

396. Review changes and create a pull request in GitHub396. Review changes in diff view, iterate with comments, then create a pull request

40 40 

41## How it works41## How it works

42 42 


495. **Completion**: You're notified when finished and can create a PR with the changes495. **Completion**: You're notified when finished and can create a PR with the changes

506. **Results**: Changes are pushed to a branch, ready for pull request creation506. **Results**: Changes are pushed to a branch, ready for pull request creation

51 51 

52## Review changes with diff view

53 

54Diff view lets you see exactly what Claude changed before creating a pull request. Instead of clicking "Create PR" to review changes in GitHub, view the diff directly in the app and iterate with Claude until the changes are ready.

55 

56When Claude makes changes to files, a diff stats indicator appears showing the number of lines added and removed (for example, `+12 -1`). Select this indicator to open the diff viewer, which displays a file list on the left and the changes for each file on the right.

57 

58From the diff view, you can:

59 

60* Review changes file by file

61* Comment on specific changes to request modifications

62* Continue iterating with Claude based on what you see

63 

64This lets you refine changes through multiple rounds of feedback without creating draft PRs or switching to GitHub.

65 

52## Moving tasks between web and terminal66## Moving tasks between web and terminal

53 67 

54You can start tasks on the web and continue them in your terminal, or send tasks from your terminal to run on the web. Web sessions persist even if you close your laptop, and you can monitor them from anywhere including the Claude iOS app.68You can start tasks on the web and continue them in your terminal, or send tasks from your terminal to run on the web. Web sessions persist even if you close your laptop, and you can monitor them from anywhere including the Claude iOS app.


283 297 

284* api.anthropic.com298* api.anthropic.com

285* statsig.anthropic.com299* statsig.anthropic.com

300* docs.claude.com

301* code.claude.com

286* claude.ai302* claude.ai

287 303 

288#### Version Control304#### Version Control


290* github.com306* github.com

291* [www.github.com](http://www.github.com)307* [www.github.com](http://www.github.com)

292* api.github.com308* api.github.com

309* npm.pkg.github.com

293* raw\.githubusercontent.com310* raw\.githubusercontent.com

311* pkg-npm.githubusercontent.com

294* objects.githubusercontent.com312* objects.githubusercontent.com

295* codeload.github.com313* codeload.github.com

296* avatars.githubusercontent.com314* avatars.githubusercontent.com


312* [www.docker.com](http://www.docker.com)330* [www.docker.com](http://www.docker.com)

313* production.cloudflare.docker.com331* production.cloudflare.docker.com

314* download.docker.com332* download.docker.com

333* gcr.io

315* \*.gcr.io334* \*.gcr.io

316* ghcr.io335* ghcr.io

317* mcr.microsoft.com336* mcr.microsoft.com


388 407 

389* crates.io408* crates.io

390* [www.crates.io](http://www.crates.io)409* [www.crates.io](http://www.crates.io)

410* index.crates.io

391* static.crates.io411* static.crates.io

392* rustup.rs412* rustup.rs

393* static.rust-lang.org413* static.rust-lang.org


486* statsig.com506* statsig.com

487* [www.statsig.com](http://www.statsig.com)507* [www.statsig.com](http://www.statsig.com)

488* api.statsig.com508* api.statsig.com

509* sentry.io

489* \*.sentry.io510* \*.sentry.io

511* http-intake.logs.datadoghq.com

512* \*.datadoghq.com

513* \*.datadoghq.eu

490 514 

491#### Content Delivery & Mirrors515#### Content Delivery & Mirrors

492 516 

517* sourceforge.net

493* \*.sourceforge.net518* \*.sourceforge.net

494* packagecloud.io519* packagecloud.io

495* \*.packagecloud.io520* \*.packagecloud.io


501* json.schemastore.org526* json.schemastore.org

502* [www.schemastore.org](http://www.schemastore.org)527* [www.schemastore.org](http://www.schemastore.org)

503 528 

529#### Model Context Protocol

530 

531* \*.modelcontextprotocol.io

532 

504<Note>533<Note>

505 Domains marked with `*` indicate wildcard subdomain matching. For example, `*.gcr.io` allows access to any subdomain of `gcr.io`.534 Domains marked with `*` indicate wildcard subdomain matching. For example, `*.gcr.io` allows access to any subdomain of `gcr.io`.

506</Note>535</Note>

Details

79The `--agents` flag accepts a JSON object that defines one or more custom subagents. Each subagent requires a unique name (as the key) and a definition object with the following fields:79The `--agents` flag accepts a JSON object that defines one or more custom subagents. Each subagent requires a unique name (as the key) and a definition object with the following fields:

80 80 

81| Field | Required | Description |81| Field | Required | Description |

82| :------------ | :------- | :--------------------------------------------------------------------------------------------------------------------- |82| :------------ | :------- | :---------------------------------------------------------------------------------------------------------------------------------- |

83| `description` | Yes | Natural language description of when the subagent should be invoked |83| `description` | Yes | Natural language description of when the subagent should be invoked |

84| `prompt` | Yes | The system prompt that guides the subagent's behavior |84| `prompt` | Yes | The system prompt that guides the subagent's behavior |

85| `tools` | No | Array of specific tools the subagent can use (for example, `["Read", "Edit", "Bash"]`). If omitted, inherits all tools |85| `tools` | No | Array of specific tools the subagent can use (for example, `["Read", "Edit", "Bash"]`). If omitted, inherits all tools |

86| `model` | No | Model alias to use: `sonnet`, `opus`, or `haiku`. If omitted, uses the default subagent model |86| `model` | No | Model alias to use: `sonnet`, `opus`, `haiku`, or `inherit`. If omitted, defaults to `inherit` (uses the main conversation's model) |

87 87 

88Example:88Example:

89 89 

common-workflows.md +18 −106

Details

2 2 

3> Step-by-step guides for exploring codebases, fixing bugs, refactoring, testing, and other everyday tasks with Claude Code.3> Step-by-step guides for exploring codebases, fixing bugs, refactoring, testing, and other everyday tasks with Claude Code.

4 4 

5This page covers practical workflows for everyday development: exploring unfamiliar code, debugging, refactoring, writing tests, creating PRs, and managing sessions. Each section includes example prompts you can adapt to your own projects.5This page covers practical workflows for everyday development: exploring unfamiliar code, debugging, refactoring, writing tests, creating PRs, and managing sessions. Each section includes example prompts you can adapt to your own projects. For higher-level patterns and tips, see [Best practices](/en/best-practices).

6 6 

7## Understand new codebases7## Understand new codebases

8 8 


219 219 

220***220***

221 221 

222## Create custom skills and commands

223 

224Skills extend Claude's capabilities with reusable prompts and workflows. Create a skill once, then invoke it with `/skill-name` or let Claude use it automatically when relevant.

225 

226For the full reference, see the [Skills documentation](/en/skills).

227 

228### Create a skill Claude can use automatically

229 

230This skill teaches Claude how to analyze code performance. Because it has a description and no restrictions, Claude can load it automatically when you ask about optimization.

231 

232<Steps>

233 <Step title="Create a skills directory in your project">

234 ```bash theme={null}

235 mkdir -p .claude/skills/optimize

236 ```

237 </Step>

238 

239 <Step title="Create a SKILL.md file with frontmatter and instructions">

240 Create `.claude/skills/optimize/SKILL.md` with the following content:

241 

242 ```markdown .claude/skills/optimize/SKILL.md theme={null}

243 ---

244 name: optimize

245 description: Analyze code performance and suggest optimizations

246 ---

247 

248 Analyze the performance of this code and suggest three specific optimizations.

249 ```

250 </Step>

251 

252 <Step title="Use your custom skill">

253 Claude uses it automatically when relevant, or you can invoke it directly:

254 

255 ```

256 /optimize src/utils/parser.js

257 ```

258 </Step>

259</Steps>

260 

261### Create a skill for manual invocation

262 

263This skill runs tests and shows coverage. The `disable-model-invocation: true` field means Claude can't invoke it automatically—only you can trigger it with `/test-coverage`.

264 

265<Steps>

266 <Step title="Create a skill file">

267 Create `.claude/commands/test-coverage.md` with the following content:

268 

269 ```markdown .claude/commands/test-coverage.md theme={null}

270 ---

271 description: Run tests with coverage report

272 disable-model-invocation: true

273 ---

274 

275 Run the test suite with coverage enabled and summarize the results.

276 ```

277 </Step>

278 

279 <Step title="Use your skill">

280 ```

281 /test-coverage

282 ```

283 </Step>

284</Steps>

285 

286<Tip>

287 Skills can be scoped to a project, personal directory, or organization. They can also accept arguments with `$ARGUMENTS`. See the [Skills documentation](/en/skills) for details.

288</Tip>

289 

290***

291 

292## Use Plan Mode for safe code analysis222## Use Plan Mode for safe code analysis

293 223 

294Plan Mode instructs Claude to create a plan by analyzing the codebase with read-only operations, perfect for exploring codebases, planning complex changes, or reviewing code safely. In Plan Mode, Claude uses [`AskUserQuestion`](/en/settings#tools-available-to-claude) to gather requirements and clarify your goals before proposing a plan.224Plan Mode instructs Claude to create a plan by analyzing the codebase with read-only operations, perfect for exploring codebases, planning complex changes, or reviewing code safely. In Plan Mode, Claude uses [`AskUserQuestion`](/en/settings#tools-available-to-claude) to gather requirements and clarify your goals before proposing a plan.


353 283 

354See [settings documentation](/en/settings#available-settings) for more configuration options.284See [settings documentation](/en/settings#available-settings) for more configuration options.

355 285 

356## Let Claude interview you

357 

358For large features, start with a minimal spec and let Claude interview you to fill in the details:

359 

360```

361> Interview me about this feature before you start: user notification system

362```

363 

364```

365> Help me think through the requirements for authentication by asking questions

366```

367 

368```

369> Ask me clarifying questions to build out this spec: payment processing

370```

371 

372Claude uses the [`AskUserQuestion`](/en/settings#tools-available-to-claude) tool to ask you multiple-choice questions for gathering requirements, clarifying ambiguity, and understanding your preferences before writing any code. This collaborative approach produces better specs than trying to anticipate every requirement upfront.

373 

374<Tip>

375 When you select "Type something" to provide a custom answer, press **Ctrl+G** to open your default text editor for longer responses.

376</Tip>

377 

378This behavior is most active in Plan Mode. To encourage it in other modes, add guidance to your `CLAUDE.md` file:

379 

380```markdown theme={null}

381Always ask clarifying questions when there are multiple valid approaches to a task.

382```

383 

384<Note>

385 If you're building applications with the Agent SDK and want to surface clarifying questions to your users programmatically, see [Handle approvals and user input](https://platform.claude.com/docs/en/agent-sdk/user-input#handle-clarifying-questions).

386</Note>

387 

388***286***

389 287 

390## Work with tests288## Work with tests


942 840 

943## Next steps841## Next steps

944 842 

945<Card title="Claude Code reference implementation" icon="code" href="https://github.com/anthropics/claude-code/tree/main/.devcontainer">843<CardGroup cols={2}>

946 Clone our development container reference implementation.844 <Card title="Best practices" icon="lightbulb" href="/en/best-practices">

947</Card>845 Patterns for getting the most out of Claude Code

846 </Card>

847 

848 <Card title="How Claude Code works" icon="gear" href="/en/how-claude-code-works">

849 Understand the agentic loop and context management

850 </Card>

851 

852 <Card title="Extend Claude Code" icon="puzzle-piece" href="/en/features-overview">

853 Add skills, hooks, MCP, subagents, and plugins

854 </Card>

855 

856 <Card title="Reference implementation" icon="code" href="https://github.com/anthropics/claude-code/tree/main/.devcontainer">

857 Clone our development container reference implementation

858 </Card>

859</CardGroup>

948 860 

949 861 

950---862---

desktop.md +11 −0

Details

32 32 

33Claude Code on desktop provides:33Claude Code on desktop provides:

34 34 

35* **Diff view**: Review Claude's changes file by file before creating a pull request, and comment on specific lines to iterate further

35* **Parallel local sessions with `git` worktrees**: Run multiple Claude Code sessions simultaneously in the same repository, each with its own isolated `git` worktree36* **Parallel local sessions with `git` worktrees**: Run multiple Claude Code sessions simultaneously in the same repository, each with its own isolated `git` worktree

36* **Include files listed in your `.gitignore` in your worktrees**: Automatically copy files in your `.gitignore`, like `.env`, to new worktrees using `.worktreeinclude`37* **Include files listed in your `.gitignore` in your worktrees**: Automatically copy files in your `.gitignore`, like `.env`, to new worktrees using `.worktreeinclude`

37* **Launch Claude Code on the web**: Kick off secure cloud sessions directly from the desktop app38* **Launch Claude Code on the web**: Kick off secure cloud sessions directly from the desktop app

38 39 

40## Review changes with diff view

41 

42After Claude makes changes to your code, the diff view lets you review modifications file by file before creating a pull request.

43 

44When Claude makes changes to files, a diff stats indicator appears showing the number of lines added and removed (for example, `+12 -1`). Click this indicator to open the diff viewer, which displays a file list on the left and the changes for each file on the right.

45 

46### Comment on specific lines

47 

48Click on any line in the diff to open a comment box. Type your feedback and press **Enter** to send. In the full diff view, press **Enter** to accept each comment, then **Cmd+Enter** to send them all. Claude reads your comments and makes the requested changes, which appear as a new diff you can review.

49 

39## Using Git worktrees50## Using Git worktrees

40 51 

41Claude Code on desktop enables running multiple Claude Code sessions in the same repository using Git worktrees. Each session gets its own isolated worktree, allowing Claude to work on different tasks without conflicts. The default location for worktrees is `~/.claude-worktrees` but this can be configured in your settings on the Claude desktop app.52Claude Code on desktop enables running multiple Claude Code sessions in the same repository using Git worktrees. Each session gets its own isolated worktree, allowing Claude to work on different tasks without conflicts. The default location for worktrees is `~/.claude-worktrees` but this can be configured in your settings on the Claude desktop app.

Details

246 246 

247## Manage installed plugins247## Manage installed plugins

248 248 

249Run `/plugin` and go to the **Installed** tab to view, enable, disable, or uninstall your plugins.249Run `/plugin` and go to the **Installed** tab to view, enable, disable, or uninstall your plugins. Type to filter the list by plugin name or description.

250 250 

251You can also manage plugins with direct commands.251You can also manage plugins with direct commands.

252 252 

Details

56 56 

57 **Skills can be reference or action.** Reference skills provide knowledge Claude uses throughout your session (like your API style guide). Action skills tell Claude to do something specific (like `/deploy` that runs your deployment workflow).57 **Skills can be reference or action.** Reference skills provide knowledge Claude uses throughout your session (like your API style guide). Action skills tell Claude to do something specific (like `/deploy` that runs your deployment workflow).

58 58 

59 **Use a subagent** when you need context isolation. The subagent might read dozens of files or run extensive searches, but your main conversation only receives a summary. Custom subagents can have their own instructions and can preload skills.59 **Use a subagent** when you need context isolation or when your context window is getting full. The subagent might read dozens of files or run extensive searches, but your main conversation only receives a summary. Since subagent work doesn't consume your main context, this is also useful when you don't need the intermediate work to remain visible. Custom subagents can have their own instructions and can preload skills.

60 60 

61 **They can combine.** A subagent can preload specific skills (`skills:` field). A skill can run in isolated context using `context: fork`. See [Skills](/en/skills) for details.61 **They can combine.** A subagent can preload specific skills (`skills:` field). A skill can run in isolated context using `context: fork`. See [Skills](/en/skills) for details.

62 </Tab>62 </Tab>


97 </Tab>97 </Tab>

98</Tabs>98</Tabs>

99 99 

100### Understand how features layer

101 

102Features can be defined at multiple levels: user-wide, per-project, via plugins, or through managed policies. You can also nest CLAUDE.md files in subdirectories or place skills in specific packages of a monorepo. When the same feature exists at multiple levels, here's how they layer:

103 

104* **CLAUDE.md files** are additive: all levels contribute content to Claude's context simultaneously. Files from your working directory and above load at launch; subdirectories load as you work in them. When instructions conflict, Claude uses judgment to reconcile them, with more specific instructions typically taking precedence. See [how Claude looks up memories](/en/memory#how-claude-looks-up-memories).

105* **Skills and subagents** override by name: when the same name exists at multiple levels, one definition wins based on priority (managed > user > project for skills; managed > CLI flag > project > user > plugin for subagents). Plugin skills are [namespaced](/en/plugins#add-skills-to-your-plugin) to avoid conflicts. See [skill discovery](/en/skills#where-skills-live) and [subagent scope](/en/sub-agents#choose-the-subagent-scope).

106* **MCP servers** override by name: local > project > user. See [MCP scope](/en/mcp#scope-hierarchy-and-precedence).

107* **Hooks** merge: all registered hooks fire for their matching events regardless of source. See [hooks](/en/hooks).

108 

100### Combine features109### Combine features

101 110 

102Each extension solves a different problem: CLAUDE.md handles always-on context, skills handle on-demand knowledge and workflows, MCP handles external connections, subagents handle isolation, and hooks handle automation. Real setups combine them based on your workflow.111Each extension solves a different problem: CLAUDE.md handles always-on context, skills handle on-demand knowledge and workflows, MCP handles external connections, subagents handle isolation, and hooks handle automation. Real setups combine them based on your workflow.

hooks.md +25 −0

Details

6 For a quickstart guide with examples, see [Get started with Claude Code hooks](/en/hooks-guide).6 For a quickstart guide with examples, see [Get started with Claude Code hooks](/en/hooks-guide).

7</Tip>7</Tip>

8 8 

9## Hook lifecycle

10 

11Hooks fire at specific points during a Claude Code session.

12 

13<div style={{maxWidth: "500px", margin: "0 auto"}}>

14 <Frame>

15 <img src="https://mintcdn.com/claude-code/z2YM37Ycg6eMbID3/images/hooks-lifecycle.png?fit=max&auto=format&n=z2YM37Ycg6eMbID3&q=85&s=5c25fedbc3db6f8882af50c3cc478c32" alt="Hook lifecycle diagram showing the sequence of hooks from SessionStart through the agentic loop to SessionEnd" data-og-width="8876" width="8876" data-og-height="12492" height="12492" data-path="images/hooks-lifecycle.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/claude-code/z2YM37Ycg6eMbID3/images/hooks-lifecycle.png?w=280&fit=max&auto=format&n=z2YM37Ycg6eMbID3&q=85&s=62406fcd5d4a189cc8842ee1bd946b84 280w, https://mintcdn.com/claude-code/z2YM37Ycg6eMbID3/images/hooks-lifecycle.png?w=560&fit=max&auto=format&n=z2YM37Ycg6eMbID3&q=85&s=fa3049022a6973c5f974e0f95b28169d 560w, https://mintcdn.com/claude-code/z2YM37Ycg6eMbID3/images/hooks-lifecycle.png?w=840&fit=max&auto=format&n=z2YM37Ycg6eMbID3&q=85&s=bd2890897db61a03160b93d4f972ff8e 840w, https://mintcdn.com/claude-code/z2YM37Ycg6eMbID3/images/hooks-lifecycle.png?w=1100&fit=max&auto=format&n=z2YM37Ycg6eMbID3&q=85&s=7ae8e098340479347135e39df4a13454 1100w, https://mintcdn.com/claude-code/z2YM37Ycg6eMbID3/images/hooks-lifecycle.png?w=1650&fit=max&auto=format&n=z2YM37Ycg6eMbID3&q=85&s=848a8606aab22c2ccaa16b6a18431e32 1650w, https://mintcdn.com/claude-code/z2YM37Ycg6eMbID3/images/hooks-lifecycle.png?w=2500&fit=max&auto=format&n=z2YM37Ycg6eMbID3&q=85&s=f3a9ef7feb61fa8fe362005aa185efbc 2500w" />

16 </Frame>

17</div>

18 

19| Hook | When it fires |

20| :------------------- | :------------------------------ |

21| `SessionStart` | Session begins or resumes |

22| `UserPromptSubmit` | User submits a prompt |

23| `PreToolUse` | Before tool execution |

24| `PermissionRequest` | When permission dialog appears |

25| `PostToolUse` | After tool succeeds |

26| `PostToolUseFailure` | After tool fails |

27| `SubagentStart` | When spawning a subagent |

28| `SubagentStop` | When subagent finishes |

29| `Stop` | Claude finishes responding |

30| `PreCompact` | Before context compaction |

31| `SessionEnd` | Session terminates |

32| `Notification` | Claude Code sends notifications |

33 

9## Configuration34## Configuration

10 35 

11Claude Code hooks are configured in your [settings files](/en/settings):36Claude Code hooks are configured in your [settings files](/en/settings):

Details

257* Shows real-time progress and output257* Shows real-time progress and output

258* Supports the same `Ctrl+B` backgrounding for long-running commands258* Supports the same `Ctrl+B` backgrounding for long-running commands

259* Does not require Claude to interpret or approve the command259* Does not require Claude to interpret or approve the command

260* Supports history-based autocomplete: type a partial command and press **Tab** to complete from previous `!` commands in the current project

260 261 

261This is useful for quick shell operations while maintaining conversation context.262This is useful for quick shell operations while maintaining conversation context.

262 263 

Details

238}238}

239```239```

240 240 

241You can pin to a specific branch, tag, or commit:

242 

243```json theme={null}

244{

245 "name": "github-plugin",

246 "source": {

247 "source": "github",

248 "repo": "owner/plugin-repo",

249 "ref": "v2.0.0",

250 "sha": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0"

251 }

252}

253```

254 

255| Field | Type | Description |

256| :----- | :----- | :-------------------------------------------------------------------- |

257| `repo` | string | Required. GitHub repository in `owner/repo` format |

258| `ref` | string | Optional. Git branch or tag (defaults to repository default branch) |

259| `sha` | string | Optional. Full 40-character git commit SHA to pin to an exact version |

260 

241### Git repositories261### Git repositories

242 262 

243```json theme={null}263```json theme={null}


250}270}

251```271```

252 272 

273You can pin to a specific branch, tag, or commit:

274 

275```json theme={null}

276{

277 "name": "git-plugin",

278 "source": {

279 "source": "url",

280 "url": "https://gitlab.com/team/plugin.git",

281 "ref": "main",

282 "sha": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0"

283 }

284}

285```

286 

287| Field | Type | Description |

288| :---- | :----- | :-------------------------------------------------------------------- |

289| `url` | string | Required. Full git repository URL (must end with `.git`) |

290| `ref` | string | Optional. Git branch or tag (defaults to repository default branch) |

291| `sha` | string | Optional. Full 40-character git commit SHA to pin to an exact version |

292 

253### Advanced plugin entries293### Advanced plugin entries

254 294 

255This example shows a plugin entry using many of the optional fields, including custom paths for commands, agents, hooks, and MCP servers:295This example shows a plugin entry using many of the optional fields, including custom paths for commands, agents, hooks, and MCP servers:

sandboxing.md +25 −2

Details

51 51 

52The sandboxed bash tool leverages operating system security primitives:52The sandboxed bash tool leverages operating system security primitives:

53 53 

54* **Linux**: Uses [bubblewrap](https://github.com/containers/bubblewrap) for isolation

55* **macOS**: Uses Seatbelt for sandbox enforcement54* **macOS**: Uses Seatbelt for sandbox enforcement

55* **Linux**: Uses [bubblewrap](https://github.com/containers/bubblewrap) for isolation

56* **WSL2**: Uses bubblewrap, same as Linux

57 

58WSL1 is not supported because bubblewrap requires kernel features only available in WSL2.

56 59 

57These OS-level restrictions ensure that all child processes spawned by Claude Code's commands inherit the same security boundaries.60These OS-level restrictions ensure that all child processes spawned by Claude Code's commands inherit the same security boundaries.

58 61 

59## Getting started62## Getting started

60 63 

64### Prerequisites

65 

66On **macOS**, sandboxing works out of the box using the built-in Seatbelt framework.

67 

68On **Linux and WSL2**, install the required packages first:

69 

70<Tabs>

71 <Tab title="Ubuntu/Debian">

72 ```bash theme={null}

73 sudo apt-get install bubblewrap socat

74 ```

75 </Tab>

76 

77 <Tab title="Fedora">

78 ```bash theme={null}

79 sudo dnf install bubblewrap socat

80 ```

81 </Tab>

82</Tabs>

83 

61### Enable sandboxing84### Enable sandboxing

62 85 

63You can enable sandboxing by running the `/sandbox` command:86You can enable sandboxing by running the `/sandbox` command:


209 232 

210* **Performance overhead**: Minimal, but some filesystem operations may be slightly slower233* **Performance overhead**: Minimal, but some filesystem operations may be slightly slower

211* **Compatibility**: Some tools that require specific system access patterns may need configuration adjustments, or may even need to be run outside of the sandbox234* **Compatibility**: Some tools that require specific system access patterns may need configuration adjustments, or may even need to be run outside of the sandbox

212* **Platform support**: Currently supports Linux and macOS; Windows support planned235* **Platform support**: Supports macOS, Linux, and WSL2. WSL1 is not supported. Native Windows support is planned.

213 236 

214## See also237## See also

215 238 

settings.md +3 −2

Details

271 271 

272| Keys | Description | Example |272| Keys | Description | Example |

273| :-------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------ |273| :-------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------ |

274| `enabled` | Enable bash sandboxing (macOS/Linux only). Default: false | `true` |274| `enabled` | Enable bash sandboxing (macOS, Linux, and WSL2). Default: false | `true` |

275| `autoAllowBashIfSandboxed` | Auto-approve bash commands when sandboxed. Default: true | `true` |275| `autoAllowBashIfSandboxed` | Auto-approve bash commands when sandboxed. Default: true | `true` |

276| `excludedCommands` | Commands that should run outside of the sandbox | `["git", "docker"]` |276| `excludedCommands` | Commands that should run outside of the sandbox | `["git", "docker"]` |

277| `allowUnsandboxedCommands` | Allow commands to run outside the sandbox via the `dangerouslyDisableSandbox` parameter. When set to `false`, the `dangerouslyDisableSandbox` escape hatch is completely disabled and all commands must run sandboxed (or be in `excludedCommands`). Useful for enterprise policies that require strict sandboxing. Default: true | `false` |277| `allowUnsandboxedCommands` | Allow commands to run outside the sandbox via the `dangerouslyDisableSandbox` parameter. When set to `false`, the `dangerouslyDisableSandbox` escape hatch is completely disabled and all commands must run sandboxed (or be in `excludedCommands`). Useful for enterprise policies that require strict sandboxing. Default: true | `false` |


279| `network.allowLocalBinding` | Allow binding to localhost ports (macOS only). Default: false | `true` |279| `network.allowLocalBinding` | Allow binding to localhost ports (macOS only). Default: false | `true` |

280| `network.httpProxyPort` | HTTP proxy port used if you wish to bring your own proxy. If not specified, Claude will run its own proxy. | `8080` |280| `network.httpProxyPort` | HTTP proxy port used if you wish to bring your own proxy. If not specified, Claude will run its own proxy. | `8080` |

281| `network.socksProxyPort` | SOCKS5 proxy port used if you wish to bring your own proxy. If not specified, Claude will run its own proxy. | `8081` |281| `network.socksProxyPort` | SOCKS5 proxy port used if you wish to bring your own proxy. If not specified, Claude will run its own proxy. | `8081` |

282| `enableWeakerNestedSandbox` | Enable weaker sandbox for unprivileged Docker environments (Linux only). **Reduces security.** Default: false | `true` |282| `enableWeakerNestedSandbox` | Enable weaker sandbox for unprivileged Docker environments (Linux and WSL2 only). **Reduces security.** Default: false | `true` |

283 283 

284**Configuration example:**284**Configuration example:**

285 285 


811| `DISABLE_BUG_COMMAND` | Set to `1` to disable the `/bug` command |811| `DISABLE_BUG_COMMAND` | Set to `1` to disable the `/bug` command |

812| `DISABLE_COST_WARNINGS` | Set to `1` to disable cost warning messages |812| `DISABLE_COST_WARNINGS` | Set to `1` to disable cost warning messages |

813| `DISABLE_ERROR_REPORTING` | Set to `1` to opt out of Sentry error reporting |813| `DISABLE_ERROR_REPORTING` | Set to `1` to opt out of Sentry error reporting |

814| `DISABLE_INSTALLATION_CHECKS` | Set to `1` to disable installation warnings. Use only when manually managing the installation location, as this can mask issues with standard installations |

814| `DISABLE_NON_ESSENTIAL_MODEL_CALLS` | Set to `1` to disable model calls for non-critical paths like flavor text |815| `DISABLE_NON_ESSENTIAL_MODEL_CALLS` | Set to `1` to disable model calls for non-critical paths like flavor text |

815| `DISABLE_PROMPT_CACHING` | Set to `1` to disable prompt caching for all models (takes precedence over per-model settings) |816| `DISABLE_PROMPT_CACHING` | Set to `1` to disable prompt caching for all models (takes precedence over per-model settings) |

816| `DISABLE_PROMPT_CACHING_HAIKU` | Set to `1` to disable prompt caching for Haiku models |817| `DISABLE_PROMPT_CACHING_HAIKU` | Set to `1` to disable prompt caching for Haiku models |

setup.md +6 −5

Details

23 <Tab title="Native Install (Recommended)">23 <Tab title="Native Install (Recommended)">

24 **macOS, Linux, WSL:**24 **macOS, Linux, WSL:**

25 25 

26 ```bash theme={null}26 ```bash theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null}

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

28 ```28 ```

29 29 

30 **Windows PowerShell:**30 **Windows PowerShell:**

31 31 

32 ```powershell theme={null}32 ```powershell theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null}

33 irm https://claude.ai/install.ps1 | iex33 irm https://claude.ai/install.ps1 | iex

34 ```34 ```

35 35 

36 **Windows CMD:**36 **Windows CMD:**

37 37 

38 ```batch theme={null}38 ```batch theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null}

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

40 ```40 ```

41 41 


45 </Tab>45 </Tab>

46 46 

47 <Tab title="Homebrew">47 <Tab title="Homebrew">

48 ```sh theme={null}48 ```sh theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null}

49 brew install --cask claude-code49 brew install --cask claude-code

50 ```50 ```

51 51 


55 </Tab>55 </Tab>

56 56 

57 <Tab title="WinGet">57 <Tab title="WinGet">

58 ```powershell theme={null}58 ```powershell theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null}

59 winget install Anthropic.ClaudeCode59 winget install Anthropic.ClaudeCode

60 ```60 ```

61 61 


192**Option 1: Claude Code within WSL**192**Option 1: Claude Code within WSL**

193 193 

194* Both WSL 1 and WSL 2 are supported194* Both WSL 1 and WSL 2 are supported

195* WSL 2 supports [sandboxing](/en/sandboxing) for enhanced security. WSL 1 does not support sandboxing.

195 196 

196**Option 2: Claude Code on native Windows with Git Bash**197**Option 2: Claude Code on native Windows with Git Bash**

197 198 

skills.md +1 −1

Details

79| Project | `.claude/skills/<skill-name>/SKILL.md` | This project only |79| Project | `.claude/skills/<skill-name>/SKILL.md` | This project only |

80| Plugin | `<plugin>/skills/<skill-name>/SKILL.md` | Where plugin is enabled |80| Plugin | `<plugin>/skills/<skill-name>/SKILL.md` | Where plugin is enabled |

81 81 

82Project skills override personal skills with the same name. If you have files in `.claude/commands/`, those work the same way but a skill takes precedence over a command with the same name.82When skills share the same name across levels, higher-priority locations win: enterprise > personal > project. Plugin skills use a `plugin-name:skill-name` namespace, so they cannot conflict with other levels. If you have files in `.claude/commands/`, those work the same way, but if a skill and a command share the same name, the skill takes precedence.

83 83 

84#### Automatic discovery from nested directories84#### Automatic discovery from nested directories

85 85 

Details

53 Avoid disabling Windows PATH importing (`appendWindowsPath = false`) as this breaks the ability to call Windows executables from WSL. Similarly, avoid uninstalling Node.js from Windows if you use it for Windows development.53 Avoid disabling Windows PATH importing (`appendWindowsPath = false`) as this breaks the ability to call Windows executables from WSL. Similarly, avoid uninstalling Node.js from Windows if you use it for Windows development.

54</Warning>54</Warning>

55 55 

56### WSL2 sandbox setup

57 

58[Sandboxing](/en/sandboxing) is supported on WSL2 but requires installing additional packages. If you see an error like "Sandbox requires socat and bubblewrap" when running `/sandbox`, install the dependencies:

59 

60<Tabs>

61 <Tab title="Ubuntu/Debian">

62 ```bash theme={null}

63 sudo apt-get install bubblewrap socat

64 ```

65 </Tab>

66 

67 <Tab title="Fedora">

68 ```bash theme={null}

69 sudo dnf install bubblewrap socat

70 ```

71 </Tab>

72</Tabs>

73 

74WSL1 does not support sandboxing. If you see "Sandboxing requires WSL2", you need to upgrade to WSL2 or run Claude Code without sandboxing.

75 

56### Linux and Mac installation issues: permission or command not found errors76### Linux and Mac installation issues: permission or command not found errors

57 77 

58When installing Claude Code with npm, `PATH` problems may prevent access to `claude`.78When installing Claude Code with npm, `PATH` problems may prevent access to `claude`.

vs-code.md +1 −1

Details

79The prompt box supports several features:79The prompt box supports several features:

80 80 

81* **Permission modes**: Click the mode indicator at the bottom of the prompt box to switch modes. In normal mode, Claude asks permission before each action. In Plan mode, Claude describes what it will do and waits for approval before making changes. In auto-accept mode, Claude makes edits without asking. Set the default in VS Code settings under `claudeCode.initialPermissionMode`.81* **Permission modes**: Click the mode indicator at the bottom of the prompt box to switch modes. In normal mode, Claude asks permission before each action. In Plan mode, Claude describes what it will do and waits for approval before making changes. In auto-accept mode, Claude makes edits without asking. Set the default in VS Code settings under `claudeCode.initialPermissionMode`.

82* **Command menu**: Click `/` or type `/` to open the command menu. Options include attaching files, switching models, toggling extended thinking, and viewing account usage. The Customize section provides access to MCP servers, hooks, memory, permissions, and plugins. Items with a terminal icon open in the integrated terminal.82* **Command menu**: Click `/` or type `/` to open the command menu. Options include attaching files, switching models, toggling extended thinking, and viewing plan usage (`/usage`). The Customize section provides access to MCP servers, hooks, memory, permissions, and plugins. Items with a terminal icon open in the integrated terminal.

83* **Context indicator**: The prompt box shows how much of Claude's context window you're using. Claude automatically compacts when needed, or you can run `/compact` manually.83* **Context indicator**: The prompt box shows how much of Claude's context window you're using. Claude automatically compacts when needed, or you can run `/compact` manually.

84* **Extended thinking**: Lets Claude spend more time reasoning through complex problems. Toggle it on via the command menu (`/`). See [Extended thinking](/en/common-workflows#use-extended-thinking-thinking-mode) for details.84* **Extended thinking**: Lets Claude spend more time reasoning through complex problems. Toggle it on via the command menu (`/`). See [Extended thinking](/en/common-workflows#use-extended-thinking-thinking-mode) for details.

85* **Multi-line input**: Press `Shift+Enter` to add a new line without sending.85* **Multi-line input**: Press `Shift+Enter` to add a new line without sending.