Claude Code Best Practices for Agentic Coding: Lessons from a Preferred Services Partner

Laptop screen showing HTML code in an editor, illustrating Claude Code best practices for agentic coding

A principal engineer evaluating Claude, powered by Anthropic, for agentic coding does not usually ask whether the model can write correct code. It can. The question that actually determines whether a rollout succeeds is narrower and less glamorous: what happens when an agent works autonomously for twenty minutes across a dozen files, and how does a team make sure that twenty minutes produces something worth reviewing rather than something worth unwinding.

Zartis is a Preferred Services Partner in the Claude Partner Network, and the practices below come from Anthropic’s own documented engineering guidance combined with what shows up repeatedly when we take a team from individual Claude Code usage to a shared, governed workflow. None of this is exotic. It is a short list of disciplines, applied consistently, rather than a single trick.

 

Context is the resource you are actually managing

Claude Code’s context window holds the entire session: every message, every file read, every command output. It fills faster than a session’s task list would suggest, and Anthropic’s own best-practices guidance is direct about the consequence: model performance degrades as the window fills, and as the window gets full Claude may start “forgetting” earlier instructions or making more mistakes. Treating context as an unlimited scratchpad is where teams that have not standardised their usage tend to run into trouble first.

The practical fix is discipline about what enters the window in the first place, rather than a bigger window. Anthropic names both patterns explicitly in its list of common failure modes: the “kitchen sink session,” where an unrelated task gets mixed into an existing conversation until the context is full of irrelevant history, and correcting over and over, where an agent gets something wrong, is corrected, gets it wrong again, and the failed attempts pile up as noise the model has to reason around. The fix for both is the same: clear the session between unrelated tasks, and after two failed corrections on the same issue, clear and restate the problem with what was learned, rather than continuing to patch a polluted context.

Subagents solve a related version of the same problem. A subagent runs in its own isolated context window with its own set of allowed tools, and reports a summary back to the main session rather than flooding it with everything it read along the way. The instinct is to think of subagents as task specialists first, but the more useful framing for a principal engineer deciding how to structure a team’s workflow is that subagents are a context-management primitive: research and exploration that would otherwise consume the working session happen somewhere disposable, and only the conclusion re-enters the conversation that matters.

 

Give the agent something it can check

Claude Code stops when work “looks done.” Without a check it can run, “looks done” is the only signal available, which means a human becomes the verification loop by default, and every mistake waits for someone to notice it. The alternative, and the practice that separates unattended runs that finish correctly from ones that need constant supervision, is giving the agent a test suite, a build exit code, a linter, or a screenshot comparison it can run and read the result of itself. A prompt that says “implement a function that validates email addresses” produces a plausible-looking function. A prompt that specifies three test cases and asks Claude to run them after implementing produces a function that has actually been checked against something.

This extends to how a task ends, not just how it starts. A Stop hook runs your check as a script whenever Claude tries to end its turn, and sends Claude back to work if the script exits with code 2. That turns “looks done” into something much closer to a gate than a judgement call. The gate has a ceiling: Claude Code ends the turn with a warning after eight blocks in a row with no tool call from Claude in between (in current versions), and teams whose checks need more iterations can raise the limit with the CLAUDE_CODE_STOP_HOOK_BLOCK_CAP environment variable. Hook scripts should also check the stop_hook_active field in their input and exit early when it is true, so a failing check cannot keep Claude looping. When work needs a second opinion rather than another run of the same check, hand it to a fresh subagent. Give that subagent only the code changes and the acceptance criteria, not the reasoning behind them, so it judges the result on its own merits. This is the practice we see adopted least often on client engagements relative to how directly it closes the gap between plausible output and verified output: teams will configure permissions and write a CLAUDE.md long before they set up an independent review step, even though the review step addresses what Anthropic names as the trust-then-verify gap, plausible-looking implementations that do not handle edge cases.

 

Permission design is a workflow decision as much as a security one

Every action Claude Code attempts with a tool is checked against a permission rule: deny, ask, or allow, with deny beating ask beating allow at every scope. Engineers who never configure this end up approving the same handful of safe commands over and over. Anthropic’s guidance notes that after the tenth prompt people start approving without reading, which is a worse security posture than a deliberate, narrow allowlist. Auto mode, which interactive sessions now start in, reviews risky actions with a classifier before they run, and deny rules still apply in every mode. Pre-approving specific commands that are genuinely safe, such as a lint script or a scoped git command, gets the friction down without giving up control. Sandboxing, which restricts filesystem and network access at the OS level, supplies the boundary that rules cannot: a deny rule covers the command Claude usually writes, and the same program can often be run in other ways.

The same logic applies to MCP servers, and it is a detail that is easy to get wrong. A server name is a user-assigned label rather than an identity, so an allowlist built on names alone can be satisfied by anything claiming that name. Matching remote servers by URL and local servers by exact command and arguments is the difference between an allowlist that does something and one that looks like it does. At the point where more than a handful of engineers are using Claude Code against the same codebase, this stops being an individual configuration choice and becomes something that belongs in centrally managed settings: permission modes, MCP restrictions, and hook policy set once and enforced everywhere, rather than drifting machine by machine.

 

CLAUDE.md as a shared team artifact

CLAUDE.md is the file Claude reads at the start of every conversation, and the instinct once a team adopts it is to keep adding to it. That instinct is wrong. One CLAUDE.md test is worth applying line by line: would removing this line cause Claude to make mistakes? If not, cut it. A file bloated with self-evident advice or long explanations causes Claude to ignore the instructions that actually matter, which produces the frustrating experience of a rule being ignored even though it is written down. CLAUDE.md is guidance Claude weighs, so a rule with no exceptions belongs in a hook, a deny rule or a managed setting. What belongs in the file is narrow: bash commands Claude cannot guess, code style that differs from the language’s defaults, testing instructions, repository etiquette, architectural decisions specific to the project, and genuine environment quirks. Domain knowledge that only applies sometimes belongs in a skill, loaded on demand, rather than in a file loaded into every conversation regardless of relevance.

The more important shift, and the one that actually separates teams getting compounding value from Claude Code from teams where usage stays individual, is treating CLAUDE.md as a team artefact rather than a personal preference file. It should be checked into git, reviewed when Claude’s behaviour goes wrong and pruned regularly rather than left untouched for months, and owned by someone named rather than left to whoever last edited it. Skills defined in .claude/skills/ and custom subagents defined in .claude/agents/ extend the same principle: they encode a team’s actual workflows, code review criteria, or incident runbooks into something every engineer invokes the same way, rather than something only the person who figured it out knows how to do.

 

The pattern behind all of it

Look again at the practices above and a single pattern runs through them: explore before you plan, plan before you implement, and verify before you call it done, with the context, permissions, and shared configuration structured to make that sequence the default rather than something each engineer has to remember to enforce. None of these disciplines requires a better model. They require a team that has agreed, in writing, on how context gets managed, what the agent is allowed to touch, and what counts as proof the work is finished.

Building that agreement is exactly what Zartis works with engineering teams to do through our Claude Code Workshops and AI-Enabled SDLC engagements: taking the individual habits an engineering team has already discovered informally and turning them into shared configuration, named ownership, and a verification standard the whole team runs against, rather than leaving compounding value dependent on whoever on the team happened to read the documentation most closely.

Newsletter

Zartis AI Review

Your monthly source for AI and software related news.