Claude Code Best Practices: 3 Lessons from 400,000 Sessions

Claude Code Best Practices: 3 Lessons from 400,000 Sessions

I used to assume Claude Code greatest practices have been a matter of style. Plan mode or not. Lengthy CLAUDE.md or quick. Decide what fits you, transfer on.

Then Anthropic scored roughly 400k classes from over 235k customers towards laborious proof of success. Checks passing, commits touchdown, customers confirming they acquired what they requested for. Style turned out to be measurable. On this article, I’ll stroll by means of what separated the classes that labored from those that didn’t.

The hole had nothing to do with the mannequin. It was behaviour.

And the research didn’t outline experience by job title or years of expertise. It learn three issues off the transcript:

  1. Precision: how exactly the particular person framed their instructions
  2. Verification: what they requested Claude to test earlier than trusting it
  3. Correction course: whether or not the particular person corrected Claude, or Claude corrected the particular person

One factor to notice earlier than we get into them: experience right here is task-specific. A senior engineer asking their first Rust query is a newbie at Rust. An accountant who’s by no means written Python, however who tells Claude precisely which reconciliation guidelines to implement and catches the sting case it fumbles at month finish, is an knowledgeable at that job. All ten of the most important occupation teams landed inside seven factors of software program engineers.

Lesson 1: Precision in How You Ask

The research discovered that in novice classes, every immediate set off about 5 Claude actions and roughly 600 phrases of output. In knowledgeable classes, every immediate set off about twelve actions and three,200 phrases. Greater than twice the work and 5 occasions the output, from the identical instrument.

The distinction just isn’t immediate size. It’s whether or not the immediate incorporates the issues Claude can not infer: which file, which state of affairs, what counts as carried out, and what sample to observe.

The 4 upgrades that matter most

As an alternative of Say this
add assessments for foo.py write a check for foo.py masking the case the place the person is logged out. keep away from mocks.
why does ExecutionFactory have such a bizarre api? look by means of ExecutionFactory’s git historical past and summarise how its api got here to be
add a calendar widget have a look at how present widgets work on the house web page. HotDogWidget.php is an efficient instance. observe that sample for a calendar widget with month choose and yr pagination. no new libraries.
repair the login bug customers report login fails after session timeout. test src/auth/, particularly token refresh. write a failing check that reproduces it, then repair it.

Discover what the right-hand column has in widespread. Each names a location, a state of affairs, and a definition of carried out. None of them is longer than two sentences of actual info.

Cease describing recordsdata, begin handing them over

That is the behavior I picked up newest and remorse most. Quite than telling Claude the place one thing lives, give it the factor instantly:

# Reference a file inline, Claude reads it earlier than answering
> clarify the token refresh logic in @src/auth/session.ts

# Pipe information straight in, works on recordsdata outdoors the undertaking
cat error.log | claude -p "group these errors by root trigger"

# Paste or drag a picture instantly into the immediate
> [screenshot] implement this design

You too can give Claude URLs for API docs and let it fetch what it wants itself. Use /permissions to allowlist domains you hit usually so you aren’t approving the identical fetch repeatedly.

Give Claude the proper instruments, not simply the proper phrases

A precision behavior that’s straightforward to overlook: the instruments out there to Claude form how exactly it will possibly act. CLI instruments are probably the most context-efficient technique to attain an exterior service, as a result of the output comes again compact and Claude already is aware of the syntax.

If you happen to use GitHub, set up the gh CLI. Claude will use it to open points, create pull requests, and browse feedback. With out it, Claude falls again to the GitHub API, the place unauthenticated requests hit charge limits. The identical applies to aws, gcloud, and sentry-cli.

It additionally learns instruments it has by no means seen. This immediate form works surprisingly properly:

Use 'foo-cli-tool --help' to study foo instrument, then use it to
clear up A, B, C.

For companies with no good CLI, MCP servers are the reply. Our information to connecting MCP servers with Claude covers the setup for each Claude Desktop and Claude Code.

For something giant, let Claude interview you first

This one felt unusual the primary time and is now how I begin each function greater than a day of labor. As an alternative of writing a protracted spec your self, make Claude extract it from you:

I wish to construct [brief description]. Interview me intimately utilizing
the AskUserQuestion instrument.

Ask about technical implementation, UI/UX, edge circumstances, issues, and
tradeoffs. Do not ask apparent questions, dig into the laborious elements I
won't have thought of.

Hold interviewing till we have coated the whole lot, then write a
full spec to SPEC.md.

It surfaces the selections you’d in any other case hit midway by means of implementation. As soon as the spec is completed, begin a recent session to construct it, so the implementation has clear context and a written doc to work towards.

The most effective specs title the recordsdata and interfaces concerned, state what’s out of scope, and finish with an end-to-end test that proves the function works. Time spent sharpening the spec pays again greater than time spent watching the construct.

Do this now: Take the subsequent function in your record. Paste the interview immediate above with a one-line description. Reply actually, together with the questions you don’t have solutions to but. That hole is the precise work.

Lesson 2: Give Claude One thing It Can Test

That is the behavior that pays again most, and the one I see skipped most.

Claude stops when the work appears carried out. If there is no such thing as a test it will possibly run, then “appears carried out” is the one sign out there, and also you change into the verification loop. Each mistake waits so that you can discover it.

Give Claude one thing that returns cross or fail and the loop closes by itself. Claude does the work, runs the test, reads the outcome, and iterates till it passes. A check suite, a construct exit code, a linter, a script that diffs output towards a fixture, a browser screenshot in comparison with a design. Something that produces a sign it will possibly learn.

# Weak: no technique to know when it's carried out
> implement a operate that validates e-mail addresses

# Robust: the test is within the immediate
> write a validateEmail operate. check circumstances: [email protected] is true,
  'invalid' is fake, '[email protected]' is fake. run the assessments after
  implementing.

4 ranges of how laborious the test gates the work

As soon as a test exists, you select how strictly it stops Claude from declaring victory. Every stage trades a little bit of setup for a bit much less of your consideration:

Degree The way it works Setup value
In a single immediate Ask Claude to run the test and iterate in the identical message None, works right now
Throughout a session Set the test as a /aim situation. An evaluator re-checks after each flip and Claude retains going till it holds Low
As a tough gate A Cease hook runs your test as a script and blocks the flip from ending till it passes Medium, one script
Second opinion A verification subagent or dynamic workflow has a recent mannequin attempt to refute the outcome Medium

Value figuring out about Cease hooks: Claude Code overrides the hook and ends the flip after 8 consecutive blocks. It won’t loop without end in case your test can by no means cross.

The immediate model works on any job proper now. The /aim and Cease hook variations are what let an unattended run end appropriately when you are someplace else. That’s the actual payoff.

Ask for proof, not assurance

Associated behavior that prices nothing: inform Claude to point out the check output, the command it ran and what got here again, or a screenshot of the outcome. Studying proof is quicker than re-running the verification your self, and it’s the solely technique to overview a session you weren’t watching.

The adversarial overview step

The longer Claude works with out you, the extra an impartial test issues earlier than you name it carried out. A reviewer operating in a recent subagent context sees solely the diff and the standards you give it, not the reasoning that produced the change. So it judges the outcome by itself phrases.

Use a subagent to overview the speed limiter diff towards PLAN.md.
Test that each requirement is carried out, the listed edge circumstances
have assessments, and nothing outdoors the duty's scope modified.
Report gaps, not fashion preferences.

As a result of the reviewer is a subagent, findings come again into the identical session, so Claude can repair them and re-review with out you copying textual content between home windows. There’s additionally a bundled /code-review talent that critiques the present diff for bugs in a recent subagent in the event you simply need a correctness cross.

A lure to learn about: a reviewer requested to search out gaps will normally report some, even when the work is sound, as a result of that’s the job you gave it. Chasing each discovering results in over-engineering, additional abstraction, and assessments for circumstances that can’t occur. Inform the reviewer to flag solely gaps affecting correctness or your acknowledged necessities, and deal with the remainder as optionally available.

Lesson 3: Who Ends Up Correcting Whom

The third sign the classifier appeared for was course of correction. In weaker classes, Claude spends its time correcting the person’s misunderstanding of their very own codebase. In stronger ones, the person catches Claude early and redirects.

The research discovered one thing blunt about what occurs when this goes fallacious. Amongst classes that hit actual bother, 19% of novice-rated ones have been deserted outright with zero strains of code written, towards 5 to 7% for everybody else. The hole just isn’t in hitting issues. It’s in recovering from them.

Course-correct instantly, not finally

Motion What it does
Esc Cease Claude mid-action. Context is preserved so you’ll be able to redirect.
Esc Esc or /rewind Open the rewind menu. Restore dialog, code, or each.
“undo that” Have Claude revert its personal modifications.
/clear Reset context fully between unrelated duties.

The 2-correction rule

That is the rule that modified my classes probably the most, and it’s counterintuitive.

When you have corrected Claude greater than twice on the identical problem in a single session, cease correcting. The context is now stuffed with failed approaches, and each additional try is reasoning towards that noise. Run /clear and begin recent with a greater immediate that features what you simply discovered.

Do this now: Subsequent time you’re in your third correction of the identical downside, resist the fourth. Copy what you’ve gotten discovered right into a notice, run /clear, and write one particular immediate that guidelines out the approaches that failed. Examine how that goes.

Handle context earlier than it degrades your output

Practically each greatest follow traces again to at least one constraint: the context window fills quick and output high quality drops because it fills. Each message, each file Claude reads, each command output goes in there. One debugging session can burn tens of 1000’s of tokens.

When the window will get full, Claude begins forgetting earlier directions and making extra errors. That is the useful resource to handle.

Command When to make use of it
/clear Between unrelated duties. Most cost-effective and most underused.
/compact While you want historical past however need it condensed. Give course: /compact Deal with the API modifications
/context To see what is definitely loaded and what it prices
/btw Facet questions. The reply seems in a dismissible overlay and by no means enters historical past.
Esc Esc then Summarize Condense solely a part of the dialog, from or as much as a selected checkpoint

You too can inform Claude find out how to compact. Placing a line like “when compacting, all the time protect the total record of modified recordsdata and any check instructions” in CLAUDE.md means the small print you depend on survive summarisation.

Delegate analysis so it doesn’t eat your context

Since context is the constraint, subagents are one of many strongest instruments out there. When Claude explores a codebase it reads numerous recordsdata, and all of that lands in your context. A subagent explores in its personal separate window and studies again a abstract:

Use subagents to analyze how our authentication system handles
token refresh, and whether or not we now have present OAuth utilities I
ought to reuse.

You get the discovering with out the hundred recordsdata. That is additionally the repair for the sample the place you ask Claude to “look into” one thing unscoped and it quietly consumes your complete window.

The Workflow That Ties All Three Collectively

Discover, plan, implement, commit. 4 phases, and the worth is in holding them separate. Letting Claude go straight to code is the way you get a well-built resolution to the fallacious downside.

Section 1 and a pair of: discover and plan, in plan mode

claude --permission-mode plan

> learn /src/auth and perceive how we deal with classes and login.
  additionally have a look at how we handle surroundings variables for secrets and techniques.

> I wish to add Google OAuth. What recordsdata want to alter?
  What is the session circulate? Create a plan.

In plan mode Claude reads and solutions however modifications nothing. When the plan seems, press Ctrl+G to open it in your editor and alter it instantly earlier than Claude acts on it. That single keystroke is the distinction between reviewing a plan and truly proudly owning it.

Section 3 and 4: implement and commit

> implement the OAuth circulate out of your plan. write assessments for the
  callback handler, run the check suite and repair any failures.

> commit with a descriptive message and open a PR

When to skip planning fully

Plan mode has actual overhead and it’s not all the time price it. The check I take advantage of now: if I might describe the diff in a single sentence, I skip the plan. Typos, log strains, renaming a variable. Simply ask for it.

Planning earns its value when you’re uncertain of the strategy, when the change touches a number of recordsdata, or once you have no idea the code being modified properly. That’s it.

5 Methods Classes Go Flawed

These are the failure patterns price recognising early, as a result of each has a particular repair and the signs all appear like “Claude is being unhelpful right now”.

Sample What it appears like Repair
Kitchen sink session You begin one job, ask one thing unrelated, then return to the primary. Context is stuffed with noise. /clear between unrelated duties
Correcting in circles Flawed, corrected, nonetheless fallacious, corrected once more. Context is polluted with failed makes an attempt. After two failed corrections, /clear and rewrite the immediate
Over-specified CLAUDE.md The file acquired lengthy, so Claude ignores half of it as a result of actual guidelines are buried in noise. Prune laborious. If Claude already does it proper with out the rule, delete the rule or make it a hook.
Belief-then-verify hole A believable implementation that doesn’t deal with edge circumstances. All the time present verification. If you happen to can not confirm it, don’t ship it.
Infinite exploration You ask Claude to analyze with out scoping it. It reads lots of of recordsdata and fills the window. Scope it narrowly, or delegate to a subagent

The CLAUDE.md one is price a re-assessment as a result of the symptom is deceptive. If Claude retains doing one thing you’ve gotten an specific rule towards, the intuition is so as to add emphasis or repeat the rule. Normally the file is simply too lengthy and the rule is getting misplaced. Deal with CLAUDE.md like code: overview it when issues break, prune it commonly, and check modifications by watching whether or not behaviour truly shifts.

The check for each line is one query: would eradicating this trigger Claude to make errors? If not, lower it. For area data that solely issues generally, use a talent as a substitute so it masses on demand reasonably than in each dialog. Claude Expertise Defined covers constructing these.

Scaling Previous One Session

All the pieces above assumes one human, one Claude, one dialog. Two patterns are price figuring out as soon as you’re previous that.

Author and reviewer, in separate classes

Contemporary context makes for higher code overview, as a result of Claude just isn’t biased towards code it simply wrote. Run two classes: one implements, one critiques with no data of the implementation reasoning.

The identical form works for assessments. Have one session write the assessments, then one other write code to cross them, with neither seeing the opposite’s reasoning.

Fan out throughout many recordsdata

For big migrations, distribute the work throughout many separate invocations reasonably than one lengthy session:

# 1. Have Claude generate the duty record first
# 2. Then loop, one invocation per file

for file in $(cat recordsdata.txt); do
  claude -p "Migrate $file from React to Vue. Return OK or FAIL." 
    --allowedTools "Edit,Bash(git commit *)"
carried out

Take a look at on two or three recordsdata first, repair your immediate primarily based on what goes fallacious, then run the total set. The –allowedTools flag issues right here as a result of no one is watching every invocation.

The Half That Stayed With Me

Coding brokers make a coding background much less related to delivery working software program. They reward understanding the issue as a substitute.

Many of the achieve got here from novice to intermediate, not intermediate to knowledgeable. A working grasp of your area captures almost all of it.

Which is why none of this reads like superior approach:

  • Title the file.
  • Give it a check it will possibly run.
  • Discover on the second correction, not the fifth.

The constraint was by no means your mannequin or your plan tier. It’s how clearly you state what you need, what you’re prepared to confirm, and how briskly you see a fallacious reply.

All the pieces on this article traces to 2 sources: Anthropic’s research on agentic coding and returns to expertise for the info, and the official Claude Code best practices documentation for the patterns. Each are price studying in full.

Regularly Requested Questions

Q1. What’s the single highest-impact behavior to undertake first?

A. Give Claude a test it will possibly run. Put the check circumstances, the construct command, or the comparability standards within the immediate and ask it to run them and iterate. It converts you from the verification loop into the particular person reviewing proof, and it’s the distinction between a session you need to watch and one you’ll be able to stroll away from.

Q2. Do I must be a software program engineer to get good outcomes?

A. The info says no. Throughout classes that produced code, all ten of the most important occupation teams landed inside seven factors of software program engineers on verified success. Administration occupations scored barely above them. What predicted success was task-specific area experience, that means you perceive the issue properly sufficient to specify it exactly and spot a fallacious reply.

Q3. When ought to I take advantage of /clear versus /compact?

A. Use /clear when the subsequent job is unrelated to the final one, because you lose nothing you want. Use /compact when you’re persevering with the identical work however the historical past has grown heavy. Give /compact directions about what to protect, for instance /compact Deal with the API modifications and the check instructions.

Hello , I’m Sree Vamsi a passionate Information Science fanatic at present working at Analytics Vidhya. My journey into information science started with a curiosity for uncovering insights from advanced information and has developed into constructing end-to-end Generative AI purposes, RAG pipelines, agentic AI workflows, and multi-agent techniques that clear up real-world enterprise issues.

Login to proceed studying and revel in expert-curated content material.