Writing a Good CLAUDE.md
From the publisher’s feed, collected in the ZeroLabs newsroom.
An CLAUDE.md or (AGENTS.md , GEMINI.md) file is the single highest-leverage configuration point for coding agents. It’s injected into every conversation, acting as the agent’s onboarding document to your codebase. But reasearch shows that doing it wrong actively hurts performence. Here’s how to do it right, backed by data from “Evaluating AGENTS.md” (ETH Zurich, 2025).The Data Says: Less Is MoreAuto-generated AGENTS.md files reduce task success rates by ~3% on average across multiple agents and models, while increasing inference cost by over 20%.Human-written AGENTS.md files only marginally improve performance (~4%), and still increase cost by up to 19% due to extra steps the agent takes.Stronger models don’t generate better context files. GPT-5.2-generated files improved performance on one benchmark by 2% but degraded it on another by 3%.Codebase overviews in AGENTS.md don’t help agents navigate faster. Agents found relevant files in roughly the same number of steps with or without an overview section.LLM-generated files are redundant with existing docs. When all other documentation was removed, LLM-generated files actually improved performance by 2.7%, they only hurt when they duplicate what’s already discoverable.Instructions ARE followed, that’s the problem. Agents respect AGENTS.md instructions, but unnecessary requirements make tasks harder, increasing reasoning tokens by 14–22%.Based on the analysis of the Claude Code harness indicates that Claude Code’s system prompt contains ~50 individual instructions. Depending on the model you’re using, that’s nearly a third of the instructions your agent can reliably follow already and that’s before rules, plugins, skills, or user messages.This implies that your CLAUDE.md file should contain as few instructions as possible - ideally only ones which are universally applicable to your task.Progressive DisclosureWriting a concise CLAUDE.md file that covers everything you want Claude to know can be challenging, especially in larger projects.To address this, we can leverage the principle of Progressive Disclosure to ensure that claude only sees task- or project-specific instructions when it needs them.Instead of including all your different instructions about building your project, running tests, code conventions, or other important context in your CLAUDE.md file, we recommend keeping task-specific instructions in separate markdown files with self-descriptive names somewhere in your project.For example:agent_docs/ |- building_the_project.md |- running_tests.md |- code_conventions.md |- service_architecture.md |- database_schema.md |- service_communication_patterns.mdThen, in your CLAUDE.md file, you can include a list of these files with a brief description of each, and instruct Claude to decide which (if any) are relevant and to read them before it starts working. Or, ask Claude to present you with the files it wants to read for aproval first before reading them.Prefer pointers to copies. Don’t include code snippets in these files if possible they will become out-of-date quickly. Instead, include file:line references to point Claude to the authoritative context.Conceptually, this is very similar to how Claude Skills are intended to work, although skills are more focused on tool use than instructions.What to IncludeThe WHAT: Your tech stack, project structure, and what each part does. Critical for monorepos tell the agent what the apps, shared packages, and services are.The WHY: The purpose of the project and its key components. Help the agent understand intent, not just structure.The HOW: How to build, test, and verify changes. Include non-obvious tooling (e.g., uv instead of pip, bun instead of npm). Tools mentioned in AGENTS.md get used 160x more often than unmentioned ones.What NOT to IncludeDetailed codebase overviews or directory listings. The paper found these don’t help agents navigate faster, and agents can discover structure themselves.Code style guidelines. Use linters and formatters instead they’re faster, cheaper, and deterministic. LLMs are in-context learners and will follow existing patterns in your code.Task-specific instructions that only apply sometimes. Since AGENTS.md goes into every session, non-universal instructions dilute focus. Frontier models can reliably follow ~150–200 instructions; the agent harness already uses ~50 of those.Auto-generated content. Don’t use /init or let the agent write its own AGENTS.md. The data shows this hurts more than it helps.How to Structure ItKeep it short. General consensus is Use progressive disclosure. Don’t put everything in AGENTS.md. Instead, keep task-specific docs in separate files (e.g., agent_docs/running_tests.md, agent_docs/database_schema.md) and list them in AGENTS.md with brief descriptions so the agent reads them only when relevant.Prefer pointers over copies. Reference file:line locations rather than embedding code snippets that will go stale.Write it yourself, deliberately. A bad line in AGENTS.md cascades into bad plans, bad code, and bad results across every session. Treat it like infrastructure, not a scratchpad.Don’t use /init or auto-generate your CLAUDE.mdBoth Claude Code and other harnesses with OpenCode come with ways to auto-generate your CLAUDE.md file (or AGENTS.md).Because CLAUDE.md goes into every single session with Claude code, it is one of the highest leverage points of the harness - for better or for worse, depending on how you use it.A bad line of code is a bad line of code. A bad line of an implementation plan has the potential to create a lot of bad lines of code. A bad line of a research that misunderstands how the system works has the potential to result in a lot of bad lines in the plan, and therefore a lot more bad lines of code as a result.But the CLAUDE.md file affects every single phase of your workflow and every single artifact produced by it. As a result, we think you should spend some time thinking very carefully about every single line that goes into it:Hierarchy of LeverageClaude Code PlaybookThis CLAUDE.md files turns Claude Code into a much better coding agent.It’s basically a playbook for how an AI should behave while building software.Boris Cherny (creator of Claude Code at Anthropic) shared internal workflows his team uses every day. Someone turned those ideas into a structured CLAUDE.md you can drop directly into your repo.CLAUDE.mdThe idea is simple: give the AI a set of operational rules before it starts coding.𝗧𝗵𝗲 𝗳𝗶𝗹𝗲 𝗶𝗻𝗰𝗹𝘂𝗱𝗲𝘀 𝗽𝗿𝗮𝗰𝘁𝗶𝗰𝗲𝘀 𝗹𝗶𝗸𝗲:Workflow orchestration : plan before buildingSub-agent strategy : split complex work into smaller agentsSelf-improvement loop : capture lessons after every mistakeVerification before done : prove code works before closing tasksAutonomous bug fixing : debug from logs and failing testsCore engineering principles : simplicity, minimal changes, root-cause fixesThe interesting part is the feedback loop.Every time you correct Claude Code, the rule gets written into a lessons file. Over time the system compounds knowledge and reduces mistakes.In other words: you’re not just prompting, you are pushing to learn the workflow around it.In ConclusionCLAUDE.md is for onboarding Claude into your codebase. It should define your project's WHY, WHAT, and HOW.Less (instructions) is more. While you shouldn’t omit necessary instructions, you should include as few instructions as reasonably possible in the file.Keep the contents of your CLAUDE.md concise and universally applicable.Use Progressive Disclosure don’t tell Claude all the information you could possibly want it to know. Rather, tell it how to find important information so that it can find and use it, but only when it needs to to avoid bloating your context window or instruction count.Claude is not a linter. Use linters and code formatters, and use other features like Hooks and Slash Commands as necessary.CLAUDE.md is the highest leverage point of the harness, so avoid auto-generating it. You should carefully craft its contents for best results.ResourcesEvaluating AGENTS.md : Are Repository-Level Context Files Helpful for Coding Agents?Claude Code SkillsThanks for reading! If you have any questions or feedback, please let me know on Medium or LinkedInWriting a Good CLAUDE.md was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.