Claude Code best practices: the short version

Per Anthropic's documentation, in most cases your first plain prompt in a fresh session already does the right thing. Setup pays off where your project has something Claude cannot see from the code alone: a deploy process that lives in someone's head, a file it must never read, a check that has to pass, a budget. This page is the short version, with links to the longer guides.

When a session goes wrong, it is usually one of four things

  1. Claude built something different from what you had in mind, or it rediscovers the same fact every session. It is missing information it cannot get from the repo.
  2. It said it was done and it was not, usually because it had no way to check its own work.
  3. It did something that must never happen, or skipped a step that must always happen. A prompt alone cannot guarantee either.
  4. It got it right, but cost more time, tokens or permission prompts than the task was worth.

Two kinds of instruction

Everything you tell Claude Code is one of two kinds. Claude decides: your prompt, CLAUDE.md, a skill. It usually follows them, but nothing guarantees it. Claude Code enforces: a hook, a deny rule, a managed setting. These apply every time, whatever the model decided. Most of the time you want Claude to decide. Keep the enforced kind for rules with no exceptions. If you keep adding emphasis to a CLAUDE.md line and Claude still misses it, the docs say that line probably belongs in a hook. The reverse holds too: a hook that only enforces a preference should go.

1. Tell Claude what it cannot see

Claude reads your code well, so write down only what it cannot find, or what it would spend time rediscovering every session. A test before you write anything: could it find this by reading the code, and would it actually go and look? If both are yes, leave it out.

# Commands
- Run one test file: npm test -- path/to/file.test.js
- Typecheck: npx tsc --noEmit

# Gotchas
- src/legacy/ is still live, but do not copy its patterns into new code
- Integration tests need DATABASE_URL, see .env.example

See the memory guide and how to write a skill.

2. Give Claude a check to run

Claude stops when the work looks done. If it has nothing to run that comes back pass or fail, "looks done" is all it has, and you become the test suite. Give it a test file, a build's exit code, a linter, or a script that compares output with an expected file, and it can make a change, run the check, read what broke and fix it. If your repo already has one, the most useful line in CLAUDE.md is the command that runs it.

You choose how strict to be:

Whichever you pick, ask for evidence: the command it ran and its output. "All tests pass" alone tells you little.

{
  "hooks": {
    "Stop": [
      { "hooks": [ { "type": "command", "command": "npx tsc --noEmit 1>&2 || exit 2" } ] }
    ]
  }
}

That goes in .claude/settings.json. The compiler output is redirected to stderr because that is what Claude receives as the reason it cannot finish yet. More in three hooks to paste.

3. Enforce the rules that cannot have exceptions

"Never read .env", "always run the formatter", "do not touch the migrations folder": Claude will follow these almost every time. Where "almost" is not good enough, move them out of CLAUDE.md and into configuration that Claude Code applies itself.

Where a rule lives decides who it applies to: .claude/settings.local.json and ~/.claude/settings.json are yours alone, .claude/settings.json in the repo applies to everyone who works there (its allow rules and hooks wait until each person accepts the folder), and managed settings belong to an organization. Keep the enforced set small; every hook and deny rule will occasionally fire when it should not, and someone has to maintain it. See a starter permissions file, permission modes and which settings file wins.

4. Steer, and keep cost down

See undoing changes and using less quota.

Before you leave a run unattended

Go through five questions for that specific task: does it know what done looks like; can it check its own work; what is it allowed to touch; what stops it (a turn or spend cap); and where does the result go, and who signs off. Claude will carry a long task through on its own. The parts that stay with you are starting it, deciding what "done" means this time, and approving the merge. See running from a script and parallel sessions with worktrees.

What you can stop doing

For how the pieces fit together, see how Claude Code works. If something is not behaving, debug your configuration. All the guides are in the guides index.

This follows Anthropic's best practices documentation as we read it in October 2026. We are not affiliated with Anthropic. We wrote this from the documentation and have not tested every case. Commands, defaults and the permission mode a session starts in change between versions, and where this page and the documentation disagree, the documentation wins.

See also: Everyday workflows.

The free loop-stop skill gives long tasks a limit and a stop rule. If you want a second pair of eyes on your CLAUDE.md and settings, the Tune-Up Kit is a checklist for exactly that.