Prilixor
All blogs

AI & Automation

CLAUDE.md Best Practices: Giving an AI Coding Agent Your Conventions

Prilixor Engineering
· 7 min read
Share
CLAUDE.md Best Practices: Giving an AI Coding Agent Your Conventions - Prilixor

Short answer: CLAUDE.md best practices: what to put in, what to leave out and how to keep the file short so an AI coding agent follows your project conventions.

Picture a new developer on day one. Nobody tells them the build command, which folders are generated, or that the team never mocks the database in tests. They find out by breaking things.

An AI coding agent is in that exact spot every time it opens your repository. A CLAUDE.md file is how you stop the guessing.

Most of these files end up in one of two camps: empty, or an essay nobody reads. These CLAUDE.md best practices are my rules of thumb for the middle path, a file that stays short and actually changes what the agent does.

By the end you should be able to decide what goes in, what stays out, and when it is time to split things up.

Why CLAUDE.md Best Practices Matter

Microsoft Learn describes Claude Code as an agentic coding tool that reads your codebase, edits files, runs commands and plugs into your development tools. That is a lot of freedom for something that has never met your team.

The code shows what exists. It rarely shows why, and it almost never shows the habits around it: how you run tests, what you refuse to touch, which shortcut caused an outage once.

Even the Microsoft guide for running Claude Code on Microsoft Foundry (updated September 2026) lists creating project context files as one of its setup steps. So this is not a side topic. It is part of getting the tool ready to work.

What a CLAUDE.md File Actually Is

It is a plain markdown file that lives in your repository. It sits in version control, so you review changes to it in pull requests like any other file.

Other tools have their own versions of the same idea. The Skills for Fabric repository, in a doc updated in late September 2026, carries CLAUDE.md, .cursorrules, .windsurfrules and AGENTS.md side by side in its root. Different filenames, same job.

My mental model is an onboarding note for a teammate who reads fast, remembers only what is in front of them, and never asks a follow-up question.

What to Put In

Here is what earns a place in the file:

  • Commands: how to build, run all tests, run one test, lint and start the app locally. Write the exact commands, not a description of them.
  • Architecture in one paragraph: the main projects and what each one owns. Skip the full folder tour.
  • Conventions that differ from the default: naming, error handling, where dependency registration lives, how async code should look. Things a smart newcomer would not guess.
  • Hard rules: never edit generated files, never commit secrets, schema changes go through one specific process.
  • Known traps: the flaky test, the folder that must stay untouched, the environment variable that has to be set first.

If a line would not change what the agent does, it probably does not belong.

What to Leave Out

The “no” list matters just as much as the “yes” list:

  • Anything a tool already enforces: formatting and style belong in your formatter and analyzer settings. The agent will see those failures anyway.
  • Long style essays: if a rule needs a page of explanation, nobody follows it, human or otherwise.
  • Things that change weekly: sprint goals and ticket numbers go stale fast and then mislead.
  • Secrets and connection strings: the file is in source control. This one is not negotiable.
  • Vague wishes: “write clean code” and “follow best practices” say nothing the agent can act on.

Keep It Short on Purpose

An agent has a limited amount of context to work with, and every line you add competes with the task itself.

The Agent Framework documentation on Agent Skills (updated November 2026) makes the same point from another angle. It describes loading only what is needed, when it is needed, advertises each skill with roughly a hundred tokens up front, and suggests keeping a SKILL.md under 500 lines with detail moved into separate files. Those numbers are for skills, not for CLAUDE.md, but the lesson carries over.

My rule of thumb is simple. If the file runs past a screen or two, move the detail into separate docs and link each one with a single line. The main file stays a map, not the territory.

Where CLAUDE.md Best Practices Go Wrong

A stale file is worse than no file. If it says to run one command and the build moved on months ago, the agent follows the old advice with full confidence.

Too many rules is the next problem. When everything is marked important, nothing is. Priorities blur and the one rule that mattered gets lost in the pile.

Rules written only as prohibitions are weak too. “Don’t use X” leaves a gap, so say what to use instead.

And please don’t treat the file as a security control. An instruction is a request, not a guardrail. Permissions, branch protection and review are what actually stop a bad change.

What I Would Do Instead of One Giant File

I’d start tiny and grow from friction. Write the commands and a short architecture paragraph, then stop.

Every time the agent gets the same thing wrong twice, add one line that would have prevented it. Every few weeks, prune lines that no longer earn their place.

Keep the root file for rules that apply everywhere. For deeper areas like testing, deployment or database changes, write a short separate doc and link it. That way the agent only reads the long material when the task needs it.

A Practical Example

Say you have a .NET solution with an API, a background worker and a shared library, deployed to Azure App Service. Here is how I would apply these CLAUDE.md best practices to it.

  • Add the commands: restore, build, run all tests, run a single test project, and start the API locally.
  • Write one paragraph on the layout: the API handles HTTP, the worker handles queued jobs, the shared library holds domain logic and nothing else references the API.
  • Add three conventions that are easy to miss, such as how errors are returned, where services are registered, and the rule that async methods are awaited, never blocked on.
  • Add two hard rules: generated files are never edited by hand, and secrets only come from configuration, never from the repo.
  • Add one trap, for example a test that needs a local emulator running before it passes.
  • Give the agent a real task, watch where it goes wrong, and add one line for each miss.

You end up with a file of maybe thirty lines that a new teammate could read in two minutes. That size is the goal.

A Quick Checklist

Before you commit the file, run through these:

  • Can a newcomer run the tests using only this file?
  • Does every line change what the agent would do?
  • Is anything here already enforced by a tool?
  • Is there a secret, a ticket number or a date that will rot?
  • Does each prohibition say what to do instead?

Final Thoughts

A good CLAUDE.md is small, specific and honest about the traps in your project. It is closer to a well kept onboarding page than to a rulebook, and it only stays useful if you keep editing it.

If you take one thing from these CLAUDE.md best practices, make it this: add a line when the agent fails, remove a line when it stops mattering.

What is the one line in your own project instructions that has saved you the most rework?

#ClaudeCode #ClaudeMDBestPractices #AICodingAgents #DotNet #DeveloperProductivity #SoftwareEngineering #AIAssistedDevelopment

Key takeaways

  • Microsoft Learn describes Claude Code as an agentic coding tool that reads your codebase, edits files, runs commands and plugs into your development tools.
  • It is a plain markdown file that lives in your repository.
  • An agent has a limited amount of context to work with, and every line you add competes with the task itself.
  • A stale file is worse than no file. If it says to run one command and the build moved on months ago, the agent follows the old advice with full confidence.
  • I’d start tiny and grow from friction. Write the commands and a short architecture paragraph, then stop.

Related reading and services: our Azure AI engineering team, recent case studies, and our Claude and MCP development services. Official reference: Anthropic Claude Code memory documentation.

Planning something like this?

Talk to our engineers. Contact Prilixor or see our US team for a conversation about your project.

Originally published on LinkedIn.