Skip to main content

Claude Code Best Practices and Tips

Tell Claude what it cannot see, give it a check to run, enforce the rules that cannot bend, and keep parallel work in separate checkouts.

Goal​

Get reliable results from Claude Code with a small amount of setup. Each tip below comes from the Claude Code best practices page as of December 2026, with the commands it names. Treq's own angle, parallel agents and review, comes last.

Sort instructions into two kinds​

Every instruction you give Claude Code is one of two kinds. A prompt, CLAUDE.md, or a skill is read by the model, which decides how to apply it. A hook, a deny rule, or a managed setting is executed by Claude Code every time, whatever the model decided.

Most guidance belongs in the first kind, because Claude judges well whether a guideline fits the code in front of it. Move a rule to the second kind only when an exception is never acceptable.

Write down only what Claude cannot see​

Claude reads the repository at the start of every task and finds your layout, conventions, and test framework on its own. It cannot find a decision made in a meeting, a deploy process that lives in one person's head, or the environment variable your integration tests need.

Keep CLAUDE.md to that missing information. Run /init to generate a first version, then delete lines. The docs recommend staying under 200 lines. Put personal preferences in CLAUDE.local.md and add it to .gitignore. Put a rule that applies to one directory in .claude/rules/ with a paths: filter, so it loads only when Claude works there.

Write a specific prompt​

Name the file, describe the symptom, and say what fixed looks like.

Instead ofTry
"fix the login bug""users report login fails after the session times out. look at token refresh in src/auth/, write a failing test that reproduces it, then fix it"
"add a calendar widget""follow the pattern in HotDogWidget.php and build a calendar widget that lets you pick a month and page between years. no new libraries"

Hand over what you already have. Type @ and a path to include a file, paste a screenshot, or pipe output with cat error.log | claude -p "what's going on here". When you have not pinned the feature down yet, ask Claude to interview you and write the answers to SPEC.md, then build from that file in a fresh session.

Give Claude a check to run​

Claude stops when the work looks done. A test, a build exit code, a linter, or a screenshot next to the mockup lets it check its own work and fix what broke. The most useful line in CLAUDE.md is the command that runs your checks.

You choose how strict to make the check:

Where the check livesExampleWho decides it passed
Prompt"run the auth tests after, and keep going until they pass"Claude
Goal/goal all tests in tests/auth pass and lint is cleanA separate model, after every turn
Stop hookA command that exits 2 until the check passesClaude Code
Review/code-review, run in a fresh subagentA reviewer that did not write the code

Whichever you pick, ask for evidence: the command Claude ran and its output.

Enforce the rules that cannot bend​

"Never read .env" in CLAUDE.md works almost every time. Make it a permission rule when almost is not enough:

{
"permissions": {
"allow": ["Bash(pnpm tsc --noEmit)"],
"ask": ["Bash(git push *)"],
"deny": ["Read(./.env)", "Read(./.env.local)", "Read(./secrets/**)"]
}
}

deny rules hold in every permission mode, including auto and bypassPermissions. Rules match tool calls, not intent, so a script that opens the file is not covered. Turn on the sandbox with /sandbox for an OS-level limit on files and network.

Steer early​

Watch the first minute of a session.

  • Esc stops Claude mid-action and keeps the work so far.
  • /rewind, or Esc twice on an empty prompt, rolls the code, the conversation, or both back to an earlier prompt.
  • After two failed corrections, run /clear and write one better prompt. A third correction adds to a conversation that already holds two failed attempts.

Checkpoints only cover files Claude changed with its own file tools, so a file changed by a Bash command is not restored. Use them alongside git.

Keep context cheap​

Every request sends the whole conversation. Run /clear between unrelated tasks. Use /compact with a focus, such as /compact keep the API changes and the test commands. Check /usage to see which skills, subagents, plugins, and MCP servers take the most. Each connected MCP server adds its tool names to the context, so turn off the ones you do not need from /mcp.

Use subagents for the right jobs​

Subagents pay off for parallel pieces of work, for keeping noisy output out of the main conversation, and for a reviewer that did not watch the code being written. They do not produce a smarter answer, and each one costs tokens. Give a reviewer subagent tools: Read, Grep, Glob so Claude Code stops it from editing.

Run parallel work in separate checkouts​

Give each separate piece of work its own checkout so edits cannot collide. claude -w feature-auth starts a session in a new worktree. A worktree is a fresh checkout, so gitignored files such as .env are missing and dependencies are not installed. List small gitignored files in .worktreeinclude at the repository root and Claude Code copies them into each worktree it creates.

A second session is also the cheapest independent reviewer. One session writes the change, another reviews the file without having watched it being written, and you carry the findings back.

Prepare unattended runs​

Before you leave a run alone, answer five questions for that task:

  1. Does it know what done looks like?
  2. Can it check its own work?
  3. What is it allowed to touch?
  4. What stops it, such as --max-turns or --max-budget-usd?
  5. Where does the result go, and who approves it?

For scripted runs, claude -p runs once and exits. Add --allowedTools to pre-approve tools and --permission-mode dontAsk to refuse anything else.

Advice you can drop​

The docs list habits that current models made unnecessary:

  • Managing the context window aggressively. Most current models have a 1M-token window and compact on their own. /clear between tasks still helps.
  • Adding emphasis words or capital letters to instructions. Current models follow a plainly worded line. A rule that cannot bend belongs in a hook or deny rule.
  • Writing "think harder" in the prompt. Effort level is the control. ultrathink still asks for deeper reasoning on one turn.
  • Describing your architecture in CLAUDE.md. Claude reads the repository itself.

How Treq fits​

Treq applies the last few tips by default. Each task runs in its own workspace, a separate working copy and branch, so parallel agents never share a checkout. Workspace Checks give every workspace a pass or fail result from your own commands. You then read each diff in the workspace's Review tab before it merges. The parallel AI coding agents guide walks through the full loop.