Learning resourcesReviewed · Anthropic

Best practices for Claude Code

This Claude Code documentation page is for developers and teams who already use Claude Code, an AI coding assistant that reads a repository, edits files and runs commands in the terminal or VS Code, and want more reliable results when its default behavior is not enough. It explains when to use prompts, CLAUDE.md, skills, hooks, permission rules and sandboxing, then covers verification, usage controls and unattended runs.

Researched 14 Nov 2026

In short.

This Claude Code documentation page is for developers and teams who already use Claude Code, an AI coding assistant that reads a repository, edits files and runs commands in the terminal or VS Code, and want more reliable results when its default behavior is not enough. Its examples need adaptation and do not establish real-world reliability. Its strongest contribution is explaining which instructions the model interprets and which controls the surrounding application enforces. It provides concrete configuration examples and describes important exceptions, including permission-rule gaps, Stop-hook limits and headless settings that disable hooks. Nothing was executed; effectiveness, actual costs and security enforcement remain unverified.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage is the complete selected page at [https://code.claude.com/docs/en/best-practices.md], supplied as selected-page.txt. Its examples, notes and warnings are included. The documentation index and all linked pages are excluded. Configuration snippets are illustrative; no commands, hooks, integrations, applications or unattended jobs were executed, and no behavior or performance was independently verified.

The overview

Identity

Best practices for Claude Code is a documentation page at [https://code.claude.com/docs/en/best-practices.md]. It teaches how to configure and supervise Claude Code, an AI coding assistant that reads a repository, edits files and runs commands in the terminal or VS Code, when ordinary prompts and default behavior are insufficient.

The resource is a guide containing explanations, commands and configuration examples. It covers project knowledge, completion checks, enforced restrictions, efficiency and unattended work.

Assessment

The guide is useful for diagnosing distinct problems: misunderstood requirements, repeated rediscovery of project facts, premature completion, missed restrictions and excessive usage. It connects each problem to a specific mechanism instead of treating stronger prompt wording as a universal remedy.

Its examples make the advice actionable, and it acknowledges limitations in its own controls. Statements about how reliably current models work are documentation claims; this page supplies no comparative benchmarks or measured productivity results.

Users

Developers already using Claude Code can use the guide to improve prompts, preserve otherwise hidden project knowledge and give the assistant meaningful completion checks. Beginners get explanations of the main configuration choices; experienced developers get details about hooks, tool permissions, sandbox boundaries and headless execution.

Repository maintainers and automation owners are particularly relevant readers. Organization administrators are directed to a separate setup guide, so this page alone does not provide a complete organization-wide deployment reference.

Capabilities

The page teaches specific task prompts, short CLAUDE.md files, path-scoped rules, reusable team skills and connections through command-line tools or MCP servers. It explains verification through tests, builds, linters, screenshots and independent code review.

It also covers hooks, deny rules, strict sandboxing, permission modes, model effort, subagent overhead, context management, scripted runs, schedules and separate Git worktrees. These are documented techniques; their behavior was not demonstrated through execution.

Using it

Requirements

Applying the guidance requires access to Claude Code and the relevant project. Verification requires working project commands, such as tests or a typechecker. The TypeScript examples assume pnpm and the appropriate project dependencies; command hooks may require additional tools such as jq or Prettier.

External integrations require an installed and authenticated CLI or a configured MCP server. The page describes shell sandbox support on macOS, Linux and WSL2, and says cloud scheduled tasks require a claude.ai login. Complete installation requirements, supported versions and feature entitlements are not established here.

Mechanism

The central distinction is between instructions the model interprets and controls Claude Code applies around it. Prompts, CLAUDE.md and skills guide model decisions. Configured hooks, permission rules, sandbox restrictions and external acceptance gates can enforce specific conditions.

The details matter: prompt and agent hooks still ask a model to judge. Command or HTTP hooks can enforce a check, with onFailure: "block" available when hook failures must also stop the action. Permission rules match tool calls, while the sandbox adds operating-system restrictions to the shell commands it confines.

Setup

For an existing repository, the guide recommends keeping CLAUDE.md focused on exact verification commands, misleading legacy patterns and decisions the code cannot reveal. Rules limited to particular files belong in .claude/rules/ with paths filters. Longer procedures can live in .claude/skills/<name>/SKILL.md.

Shared repository hooks and permissions go in .claude/settings.json. Personal settings have separate locations, and organization-managed settings cannot be overridden by personal files. A skill marked disable-model-invocation: true must be started explicitly by the user. The page also explains how workspace trust affects shared hooks and allow rules.

Example

For a TypeScript project using pnpm, the page shows a Stop hook in .claude/settings.json that runs pnpm tsc --noEmit 1>&2 || exit 2. Compiler output is sent to standard error, and exit code 2 blocks that attempt to finish while returning the errors to Claude.

This illustrates how a known command can become a completion check. It only checks what the configured compiler checks; it does not establish that the application works correctly for users. The snippet was not executed, and the documented Stop-hook block cap limits repeated enforcement.

Assessment & evidence

Limitations

The guide explicitly warns that auto mode uses a classifier that can make mistakes. A Read deny rule catches common file-reading commands such as cat .env, but the page says it will not catch a script that opens the file. The page recommends also turning on the sandbox, which applies Read deny rules and WebFetch domain rules to the shell commands it confines, so for security-related rules you want both. A WebFetch domain restriction does not itself restrict curl. Sandbox coverage and strict mode therefore matter when evaluating actual access boundaries.

Stop hooks also have a documented cap: after eight consecutive blocked stops without an intervening tool call, the next block is overridden by default. Checkpoints do not restore files changed only through Bash. Headless --bare runs skip hooks, skills, plugins, MCP servers and CLAUDE.md, including hooks supplied through --settings.

Passing a configured check establishes only what that check covers. No runtime behavior, security boundary or example configuration was tested.

Reasoning

The guide supports a useful decision rule: provide missing knowledge through instructions, provide observable completion criteria through checks, and put mandatory boundaries into enforceable configuration. This follows directly from its distinction between model judgment and application controls.

Its value is greatest when a project already has meaningful checks or clear restrictions that can be encoded. The page does not establish how much these practices improve outcomes, and stronger enforcement still depends on correct configuration and adequate check coverage.

Alternatives

Within Claude Code, the page presents several levels of setup: request an existing check in a prompt, use a goal to continue unfinished work, configure a Stop hook, or require external CI and human approval. It also describes fresh-session code review as another way to inspect a change.

The page does not compare competing coding assistants or independent learning resources. Relative pricing, reliability and feature coverage are unknown.

Evidence

The evidence is the complete supplied documentation page at [https://code.claude.com/docs/en/best-practices.md], retained as selected-page.txt. It includes explanatory text, configuration snippets, commands, warnings and links to more detailed documentation.

This supports describing the guide and its documented mechanisms. Linked pages were not included, and there are no execution logs, benchmark results or independently observed outcomes. Nothing was executed.

Access & freshness

Costs

The page does not provide subscription prices, token rates or measured task costs. Actual cost is unknown.

It explains that subagents make their own requests against the same usage budget, long conversations repeatedly include accumulated context, and background loops or goal checks continue consuming usage. It recommends /usage for inspecting consumption and describes --max-turns, --max-budget-usd with -p, and configured spend limits as ways to bound work. No savings are quantified.

Rights

The supplied page contains no explicit license or redistribution grant for its documentation and examples. Permission to redistribute the captured page or package its examples is unknown.

Claude Code service terms, commercial-use conditions and rights in generated outputs are not established by this page.

Freshness

The supplied copy was captured on 2026-11-14 at 11:16:03.453 UTC. A publication date, last-update date and pinned Claude Code application version are not established by the supplied text.

Statements about default models, permission modes, plan availability, context windows, cache duration and preview features describe this captured copy. Their current availability or behavior beyond the capture is unknown.

Actions

Start with a bounded repository task and an existing pass-or-fail check. Confirm the command works in the intended environment, then add that command to CLAUDE.md, where the page says it is the single most useful line, alongside project knowledge Claude cannot find by reading the code. Inspect command output when evaluating completion. Use hooks for mandatory steps and permission rules with sandboxing for access boundaries.

Before unattended work, define success, allowed files and branches, a turn or spending limit, and who approves the result. Check the intended configuration in a controlled environment, including failure behavior. If a run depends on hooks, account for the page's warning that --bare disables them.

Evidence for this report

selected-page.txtselected · checked 2026-11-14