I’ve been using Claude Code as my primary coding partner for months now. It’s ridiculously good. The November 2025 step function is real. Working with LLMs, you have to make peace with non-determinism.
But you don’t have to put up with agents acting increasingly inconsistently.
Same task, same repo, same everything—and Claude still finds a way to format it differently on the fifth run, the ninth run, and then every run from 14 thru 19. This is drift: variances in output that emerge across repeated invocations of an agent over time.
Drift is subtle. You might run a workflow a hundred times without noticing anything wrong. Then one day a field gets dropped. A naming convention shifts as ID becomes Id. An output you relied on changes shape. Don’t even get me started on compaction events, those necessary evils that are like amnesiac injections of stupidity. What felt like a well-trained assistant suddenly feels like a brand new intern.
AGENTS.md and CLAUDE.md are rules or directives your agent reads on load (only after you type something first though). A well-built agents file can make your experience far more consistent. A bad set of directives can make things worse.
When it’s working, you open a session and Claude confirms it read all the important directive files, follows your formatting without being reminded, and doesn’t forget everything after a compaction event. When it’s not working, you spend the first five minutes re-explaining things you’ve already written down.
The difference is how you build the CLAUDE.md.
Fair warning: a lot of what makes this hard today is temporary. Context windows are getting larger. Models are getting smarter. If you can afford to wait, some of these problems will solve themselves. But if you’re shipping code today—and most of us are—here’s what helps.
Claude pays more attention to content near the top of a file. Put your most critical directives first. If there’s one rule Claude absolutely must follow, it belongs on line one—not buried in section seven.
This isn’t a Claude quirk. It’s how attention works. First things stick.
“Write clean code” is not an instruction. It’s a wish. “All functions must include a docstring with parameters and return type” is an instruction. One produces consistent results. The other produces whatever Claude felt like doing that particular Tuesday afternoon.
Even if it makes your CLAUDE.md wordier, be explicit. Explicit is reliable. Vague is a ticking drift-bomb.
Frame directives as hard requirements. “Always”, “never”, and “must” signal constraints. “Should” and “nice to have” signal suggestions—and suggestions get deprioritized or forgotten over time. That’s exactly how drift starts.
If you don’t see compliance, use caps and asterisks. You can even ask your agent to “strengthen the wording” and it can reliably do that for you.
There’s a useful distinction here: use agents for tasks that require judgment, and use code for tasks that require consistency. If you want JSON in a specific format with specific fields in a specific order, don’t describe that format in your CLAUDE.md—write a small script that takes the inputs and then outputs exactly what you want. A script is deterministic.
Put another way: anything you repeat often where structure matters, make a Bash or Python script. CLAUDE.md or any prompt can reliably call the script, but they usually can’t reliably enforce formatting over hundreds of non-deterministic invocations.
I admit an irrational fondness for this one. At the very top of your rules file, add a directive that produces a visible signal when Claude loads it:
“When you read this file, ALWAYS say the phrase ‘rainbow carburetor’ before proceeding.”
Or something more practical:
“ALWAYS summarize the current git status—staged, unstaged, and untracked files.”
This gives you two things at once: confirmation that your rules file was loaded, and proof that Claude actually read it. Canaries catch silent failures before they turn into drift. Without one, you’re trusting that everything worked. With one, you know.
I group these into three rough buckets:
Even the simple ones are usually fine. Make sure to use STRONG language. Ask Claude to strengthen the directives if you notice non-compliance. The jokes are mediocre at best.
As your CLAUDE.md grows, important rules get diluted in a sea of context Claude doesn’t need for the current task.
You have a few options for breaking it up. .claude/rules/ works similarly to Cursor’s rules directory—scoped files that usually load when relevant.
My preference is to use your CLAUDE.md as a traffic map. List key files and their purposes so Claude knows where to find more specific directives without stuffing everything into one file.
Here’s an example:
## Key Files
- `prd.md` — the PRD (primary requirements)
- `NOTES.md` — institutional memory (see NOTES.md Rules below)
- `README.md` — project readme (core workflow, key concepts, etc.)
- `testing/CLAUDE.md` — information and standards on testing this project
- `PLAN.md` — build plan and work in progress tracker
- `case_studies/` — when asked to produce a case study, read `case_studies/CLAUDE.md` first — it contains the standard template, required sections, and analysis checklists.
Most drift happens post-compaction. The context gets compressed, the careful instructions get lost, and Claude starts improvising. You can plan for this.
Define explicit recovery instructions:
“After compaction, re-read CLAUDE.md carefully, re-read the current plan file, and confirm via canary before continuing.”
Compaction responses and canaries work best together. The canary tells you whether Claude is operating from your rules or from vibes. The compaction response gives Claude a path back to your rules when it inevitably falls off the wagon.
This guide is written primarily for Claude, but the tactics should work across all major coding harnesses.
Different AI coding tools look for rules files in different places. Quick reference:
| Tool | Rules File Location |
|---|---|
| Claude Code | CLAUDE.md (project root), ~/.claude/CLAUDE.md (global) |
| Cursor | .cursorrules (project root) or .cursor/rules/ |
| OpenCode | AGENTS.md |
| Codex (OpenAI) | AGENTS.md |
| Windsurf | .windsurfrules |
The conventions are still evolving quickly, so check each tool’s docs. But the underlying principle is the same everywhere: give the agent persistent, structured context about your project and preferences.
Some of these that look for AGENTS.md do fall back to CLAUDE.md. More details on rules files, fallbacks, and overrides here.
The official Claude blog also has some great tips.
These techniques were so effective for me, I made my own skill called /warmup and it bundles most all of these into a single skill.
No single tactic here is magic. A canary alone won’t eliminate drift. Specificity alone won’t survive a compaction event. But like the power of friendship, everything bundled together means that the tactics tend to compound.