Claude Code Best Practices is a usage guide from the official Claude Code documentation, with the goal of helping users make fuller use of Claude Code. The document opens with three core practices: tell Claude the information it cannot see, give it a check it can run, and enforce rules that admit no exceptions.
Purpose and Positioning The document is aimed at people using Claude Code for software development and addresses common problems: the result Claude builds does not match expectations, or the same fact has to be rediscovered in every session; Claude claims completion but has not actually finished; Claude does something that is never allowed in the repository, or skips steps that must be performed; the task is done correctly but takes too long, consumes too many tokens, or triggers too many permission prompts.
Main Capabilities and Concepts The document distinguishes two types of instructions. Non-deterministic instructions are written by the user and read by the model, such as prompts, CLAUDE.md, or skills; the model decides how to handle them, and they are usually followed but not guaranteed. Deterministic instructions are configured by the user and executed by Claude Code, such as hooks, deny rules, or managed settings; they are applied every time and are not affected by model decisions.
Tell Claude the Information It Cannot See The document recommends writing down information that cannot be obtained from the code, such as decisions made in team meetings, deployment procedures that exist only in someone's head, and environment variables required for integration tests. Specific methods include: bringing file contents into a prompt with @ plus a path, pasting screenshots of designs or errors, and piping command output in (such as cat error.log | claude -p "what's going on here"). CLAUDE.md should stay short, preferably within 200 lines, and can include the exact test, type-check, and lint commands that confirm the work, places in the code that are misleading, decisions that are not present in the repository, and matters that have already been corrected twice. /init can generate an initial version, /doctor can suggest removing content that Claude can infer from the code itself, and /doctor prompt-audit can flag instructions written for older models, pointing to nonexistent files, or contradicting each other. Rules can also be scoped to a part of the codebase, team processes can be put into skills, and Claude can be connected to the tools it needs.
Give Claude a Check It Can Run The document recommends providing checks such as build exit codes, scripts that compare against fixed samples, and browser screenshots compared with design mockups. In a prompt, you can ask it to run the authentication tests and continue until it passesPass; you can use /goal to set conditions, checked after each turn by an independent model; you can use a Stop hook to run a script when Claude tries to end the turn, and if the script exits with code 2, work continues; you can also use /code-review to have a new subagent that has not seen the conversation review the diff.
Enforcing rules with no exceptions Documentation explains that hooks can be used to enforce steps; hooks can be shell commands, HTTP POSTs, tool calls on an MCP server, or prompt/agent hooks decided by the model. Permission rules and sandboxing can restrict access, but a Read rule can block cat .env yet cannot stop a script that opens that file; a WebFetch deny rule for a domain is ineffective against curl when the sandbox is off. Rule scopes are divided into personal (.claude/settings.local.json and ~/.claude/settings.json), repository (.claude/settings.json and its hooks, effective for everyone once committed), and organization-managed settings (from the admin console, MDM, or managed-settings.json, which personal settings cannot override).
Changing default settings Interactive terminal and VS Code sessions start in auto mode by default, run Claude Opus 5.5 at medium effort under most plans and providers, delegate subagents as needed, and automatically compact the conversation. Permission modes include manual mode (approve each item) and bypassPermissions (suitable only for one-off containers). Model and effort level can be adjusted with /effort high, /effort xhigh, /effort low; max suits hard problems handled independently; when a single message requires it, you can write ultrathink in the prompt.
Subagents and cost control Subagents can be used for parallel independent work, isolating long output, getting a reviewer that has not seen the code-writing process, and limiting tool permissions. You can set model: haiku in a subagent definition to reduce cost, require a brief summary in return, and use /usage to see the usage share of each subagent type. Custom subagents can be granted only the Read, Grep, and Glob tools. Ways to control cost and context include: using /clear between unrelated tasks, using /compact with focus, and paying attention to requests generated by background work.
Guiding sessions and running unattended Esc can stopmidway and preserve completed work; /rewind can roll back code, conversation, or both to an earlier prompt; /clear starts over. When letting Claude run unattended, you need to specify the completion criteria, how it should self-check, the scope it is allowed to touch, and the stopping conditions (such as --max-turns, --max-budget-usd), and determine where results go and who signs off.
Scripting and parallelism When running Claude Code from a script, --bare skips hooks, skills, plugins, MCP servers, and CLAUDE.md, and does not use claude.ai login; authentication comes from ANTHROPIC_API_KEY, apiKeyHelper, or cloud provider credentials; --append-system-prompt, --mcp-config, and --settings can explicitly pass in what is needed; --allowedTools pre-approves tools, and --permission-mode dontAsk denies other actions that would prompt; --output-format json outputs a single result object, and stream-json with --verbose streams events. It also supports starting runs on a schedule or event, running sessions in parallel, and cleaning up leftover worktrees.
Applicable scenarios and limitations This documentation applies to scenarios of using Claude Code for development, automation, or team collaboration. The specific commands, default models, default modes, and configuration items in the documentation are subject to the official documentation; fees, prices, or platform support not stated in the materials are not provided for now.