Try free

Last updated 13 October 2026

Make Claude Code follow a coding style guide

The challenge of inconsistent code styles

You run a command and the agent writes code that works but looks wrong. It uses tabs instead of spaces. It puts braces on new lines when your project puts them on the same line. This forces you to manually edit the output or run a formatter every time. It breaks your flow and wastes your time. You want the agent to think like a member of your team from the first line it writes.

Inconsistent formatting creates friction during code reviews. If an agent changes the indentation of fifty lines while adding one logic change, your diff becomes unreadable. You end up fighting the tool instead of solving the problem. This is especially true when you use an agent across multiple projects with different requirements. A single set of internal rules is not enough for a developer who works on a diverse range of repositories.

The role of project memory in following rules

Claude Code uses a specific file structure to maintain project memory. The most important file for your style guide is CLAUDE.md. You must place this file in the root directory of your repository. The agent reads this file at the start of every session to understand the context and constraints of your project. It treats these instructions as persistent rules that govern how it writes every line of code.

When you define your coding standards in this file, the agent incorporates them into its planning process. It is not just a reference document for you. It is a set of active constraints for the agent. By listing your preferred naming conventions and library choices here, you ensure the agent does not guess. This reduces the number of times you have to tell the agent to fix a minor stylistic error after it has already finished a task.

Defining specific linting and formatting rules

To make the agent follow your style, you should be concrete about the tools you use. If your project relies on Prettier, ESLint, or Ruff, list these names in your CLAUDE.md file. Instruct the agent to always run your linting command using the Bash tool before it considers a task finished. This creates a self-correcting loop where the agent identifies its own formatting mistakes and fixes them before you ever see the code.

You should also specify the exact command the agent should run. For example, tell it to run a specific script from your package.json or a direct shell command. Mention that the agent should fix any style violations it finds during the process. This ensures that the code it writes matches your existing codebase exactly. You can even provide a small snippet of what good code looks like in your project to give the agent a visual reference for your preferences.

Leveraging directory specific instructions

Directory specific instructions help in repositories that contain multiple languages or frameworks. If your project has a frontend in React and a backend in Go, one set of rules is not enough. You can put a CLAUDE.md file in the frontend folder and another in the backend folder. The agent applies the rules from the subdirectory that matches the files it is currently editing. This allows for fine-grained control over different parts of a complex system.

This approach is useful for monorepos where different teams might have different standards. It also helps when you have legacy code in one folder that must follow old patterns and new code in another folder that uses modern features. The agent will adapt its style based on which directory it is working in. This prevents the agent from applying modern styles to legacy files where they would be out of place and hard to maintain.

Using global instructions for personal preferences

Your personal preferences might stay the same across every project you touch. If you always prefer certain patterns regardless of the project, use the file at ~/.claude/CLAUDE.md. This file applies to every session you run on your machine. It is the best place for high-level preferences like your favorite testing framework or a ban on certain deprecated functions. These global rules combine with your project-specific rules to create a tailored environment.

Global instructions are helpful for setting up your default environment. If you always want the agent to use a specific type of comment or a certain way of organizing imports, put it here. This saves you from repeating the same instructions in every new repository you start. It ensures that the agent always feels familiar and consistent with your personal workflow, no matter what codebase you are currently exploring.

Managing multiple coding projects simultaneously

Working on several projects with different styles is a challenge for your focus. You might be jumping between a legacy project with strict older rules and a greenfield project with modern standards. This is where adhdTerminal is useful. It lets you see multiple Claude Code sessions as tiles on a single screen. Each tile represents a different folder with its own CLAUDE.md rules. You can watch the agent work on a refactor in one project while you start a new feature in another.

The visual layout of adhdTerminal helps you keep track of which style guide is currently active in each session. Each tile can have a name and a color, making it easy to distinguish between your frontend and backend tasks. You do not have to worry about the agent mixing up the rules between projects because each tile runs an isolated session in its own directory. This allows you to scale your productivity without losing track of the specific requirements of each codebase.

Verifying style compliance with automated tools

The agent uses the Bash tool to verify its work. You should explicitly tell the agent to use this tool to check for syntax errors and style issues before it submits its changes. If the agent makes a mistake, it can see the output from the linter and correct itself. This loop reduces the amount of manual review you need to do. It transforms the agent from a simple text generator into a developer that respects your build pipeline.

You can also use settings.json to manage how the agent handles permissions during these checks. If you trust your linting scripts, you can configure the agent to run them without asking for permission every time. This speeds up the feedback loop. The goal is to make the agent as autonomous as possible while ensuring it never pushes code that fails your CI checks. This level of automation is what makes the tool feel like a true extension of your own capabilities.

Adjusting rules and maintaining context

Maintaining the context window is vital for long sessions. As you add more rules and files, the context fills up. You can use the /compact command to summarize the session and keep the important style rules in focus while clearing out old conversation details. If you find the agent is starting to ignore your style guide, you can use /memory to see what it currently remembers. This helps you decide if you need to update your CLAUDE.md files.

Sometimes a rule that sounded good at the start of a project becomes a burden. You should update your CLAUDE.md file as your project evolves. The agent will pick up the changes in the next session or when it re-reads the file. If you need to clear the slate entirely because the conversation has become too cluttered with old style discussions, use the /clear command. This resets the session in the same folder while keeping your project instructions intact.

Extending standards with custom commands

Custom commands allow you to define specific workflows for enforcing standards. You can create markdown files in the .claude/commands folder to define these actions. For example, you could create a command that specifically checks for accessibility standards in your HTML or documentation coverage in your source code. When you run this custom slash command, the agent follows the steps you defined to audit the code.

This extends the agent beyond simple code generation. It becomes a specialized tool for your specific needs. You can share these custom commands with your team by committing them to the repository. This ensures that every developer using Claude Code on your project is using the same set of specialized tools and following the same standards. It creates a unified development environment that scales across the entire team.

Questions people ask

What happens if CLAUDE.md conflicts with my linter config?

The agent generally prioritizes the instructions in CLAUDE.md because they are part of its active project memory. However, if you tell it to run a linter via the Bash tool, it will see the linter output and realize there is a conflict. You should update CLAUDE.md to match your linter configuration to avoid confusing the agent and causing unnecessary edit loops.

Can I use .claude/settings.json to enforce code styles?

No, settings.json is primarily for configuring the behavior of the Claude Code tool itself, such as permission modes and MCP server settings. For coding styles, naming conventions, and project-specific logic, you must use CLAUDE.md. The agent reads CLAUDE.md as context for its tasks, while settings.json controls the environment and tool permissions.

How does the agent handle styles when I use the /add-dir command?

When you use /add-dir to bring in context from another folder, the agent may see the CLAUDE.md file in that new directory. It will try to reconcile the instructions from both the current project and the added directory. To avoid confusion, ensure that your directory-specific rules are clearly labeled or placed in the appropriate subdirectories where they naturally apply.

Read next

More on claude code basics·All posts