Try free

Last updated 13 October 2026

Claude Code conflicts with Prettier rules

The nature of the formatting conflict

The conflict between Claude Code and Prettier starts when the agent writes a block of code using its own internal style weights. Your local environment likely has a Prettier configuration that enforces different rules for indentation, quote types, or trailing commas. When the agent uses the Write or Edit tool, it sends new content to your file system. Your IDE or a background process detects this change and runs Prettier to align the file with your project rules. The file changes again to match your local standards, but this change happens outside the agent's control.

Claude Code sees this external change as a modification it did not authorize or expect. Because it aims to maintain the integrity of the task, it may perceive the formatting change as a corruption of its work. The agent then tries to revert the change or fix what it sees as a styling error. This creates a loop where the agent and your local tools fight over the same lines of code. This cycle consumes your tokens and prevents the agent from finishing the actual development task you assigned it. You must synchronize the agent's behavior with your local tools to stop this behavior.

Using CLAUDE.md as a source of truth

You must make your project rules explicit to the agent using a CLAUDE.md file in the root of your repository. This file is the first document the agent reads when you start a session. It acts as a manual for the agent's behavior in that specific project. You should include a section dedicated to code style and formatting that explicitly names the tools you use. If you use Prettier, state that the agent must respect the rules defined in your configuration file. Specify your preferences for indentation width, the use of tabs or spaces, and your preference for single or double quotes.

The agent refers to this file when it plans its edits. If you tell it to use two spaces for indentation and single quotes, it will attempt to generate code that matches those rules from the start. This reduces the chance that your local Prettier hook will need to change the file after the agent writes to it. If the agent knows that a linter is active, it can even use the Bash tool to check its own work before it considers a task finished. This proactive approach keeps the file system stable and prevents the agent from getting stuck in an infinite loop of style corrections.

Configuring project settings for consistency

Project specific settings live in the .claude/settings.json file within your repository. You can use this file to control how the agent interacts with your tools and permissions. If you find that the agent is frequently making formatting mistakes, you can adjust the permissions for the Edit and Write tools. By setting permissions to require manual approval, you can catch formatting errors before they hit the disk. You cycle through these modes using Shift plus Tab inside an active session. The default mode or the acceptEdits mode will behave differently based on how much trust you place in the agent's ability to follow your CLAUDE.md instructions.

You should also consider your own untracked overrides in .claude/settings.local.json. This is useful if you have personal formatting preferences that differ from the main project but you still want the agent to follow them. If you work across many different environments, the ~/.claude/settings.json file provides a way to set global defaults. However, project specific rules in the local .claude folder will always take priority. This hierarchy allows you to maintain a consistent experience across all your work while still respecting the unique requirements of each individual codebase.

Automating style with hook events

You can use hook events to automate the formatting process and ensure the agent stays in sync with your environment. The PostToolUse hook is particularly effective for this purpose. You can configure this hook in your settings.json file to run a shell command every time the agent finishes using the Edit or Write tool. By setting the hook to run your local Prettier command, you ensure that the file on disk is always formatted correctly before the agent reads it again. This prevents the agent from seeing a version of the file that does not match your project's standards.

Another useful hook is the UserPromptSubmit event. You can use this to perform a quick check of the project's health before the agent starts a new task. If the linter finds errors, the agent can be instructed to fix them as part of its next action. These hooks create a bridge between the agent's internal logic and your external development environment. When the agent knows that its output will be automatically processed by a formatter, it becomes less likely to fight against those changes in subsequent turns of the conversation.

Managing different project styles with adhdTerminal

Working on multiple projects often means dealing with multiple sets of formatting rules. One repository might use a strict ESLint configuration while another uses a more relaxed Prettier setup. If you run multiple Claude Code sessions in standard terminal tabs, it is easy to lose track of which instructions apply to which session. This is where adhdTerminal provides a concrete benefit. The app displays each session as a tile on a wall, and these tiles persist even after you restart your computer. You can name a tile based on the project and give it a specific color to distinguish it from others.

Each tile in adhdTerminal maintains its own session history and context. Because the tiles reopen in the same place and resume the same session, the agent retains the specific formatting instructions you provided in earlier exchanges. You do not have to repeat yourself or re-read the CLAUDE.md file manually every time you switch tasks. The visual feedback on the tile shows whether the agent is working or waiting for you, which is helpful when you are running a long formatting fix across a large directory. This organization prevents the mental fatigue of managing conflicting style rules across several active terminal windows.

Verifying code style with the Bash tool

The Bash tool is your most powerful asset for enforcing formatting rules. You should instruct the agent to run your project's linting or formatting command via Bash before it claims a task is complete. You can add this requirement to your CLAUDE.md file so the agent knows it must verify its work. If the linter returns a non-zero exit code, the agent should read the error output and use the Edit tool to fix the violations. This process forces the agent to use your local tools as the final authority on what constitutes correct code.

If the agent is unsure about a specific rule, it can use the Read tool to examine your prettierrc or eslintrc files. By reading the actual configuration files, the agent can gain a deeper understanding of the project's constraints than what is provided in a general summary. This is especially important for complex projects with nested configuration files. If the agent knows exactly what the linter expects, it can produce compliant code on the first attempt, which saves time and reduces the number of tool calls needed to finish a feature.

Handling subdirectories and specific agents

Large repositories often have different formatting rules for different subdirectories. For example, your frontend might use Prettier while your backend uses a different linter. Claude Code handles this by looking for a CLAUDE.md file in the current subdirectory. If it finds one, it applies those rules to its work in that part of the tree. You can use this to provide granular instructions that prevent the agent from applying the wrong style to a specific part of your project. This hierarchical approach ensures that the agent always has the most relevant context for the file it is editing.

You can also define custom subagents in the .claude/agents directory. These are markdown files that describe specific roles or sets of behaviors. You might create an agent specifically for refactoring that has strict instructions to always run the formatter after every edit. You invoke these subagents using the /agents command inside a session. This allows you to switch between different modes of operation, such as a creative mode for new features and a strict mode for maintenance and style compliance, without changing your global settings.

Using permissions to control edits

The permission system in Claude Code allows you to restrict how the agent modifies your files. In the default mode, the agent will ask for permission before using tools that change the file system. If you are experiencing formatting loops, you can use this opportunity to inspect the proposed changes. If you see that the agent is trying to change the indentation to an incorrect value, you can deny the request and provide a correction in the prompt. This manual intervention helps train the agent's context for the remainder of the session.

For a more automated workflow, you can set specific permissions in your settings.json file. You can allow the Bash tool to run without confirmation while requiring a prompt for the Write and Edit tools. This allows the agent to check the linting status independently but prevents it from making unauthorized changes to your code. If you trust the agent and your CLAUDE.md instructions are solid, you can use the bypassPermissions mode to speed up the work. You should only do this once you have confirmed that the agent is correctly following your formatting rules to avoid a large volume of style errors.

Resetting the session state when conflicts persist

If the agent gets stuck in a formatting loop that you cannot break with simple instructions, you may need to reset the session. The /clear command starts the conversation over in the same folder, which removes the immediate history of the conflict. This is often better than trying to argue with the agent about style rules that have already cluttered the context window. After clearing, ensure your CLAUDE.md file is updated with the correct rules before you start a new task. This gives the agent a clean slate with the right instructions.

If you do not want to lose all your progress, you can use the /compact command. This summarizes the conversation so far and frees up space in the context window. It can help by distilling the complex history of formatting arguments into a simple set of rules that the agent can follow moving forward. If the agent continues to struggle, use the /doctor command to check your installation and ensure that Claude Code can correctly interact with your shell and file system. A healthy environment is essential for the agent to follow the instructions you provide in your settings and project files.

Questions people ask

How do I stop an active formatting loop immediately?

Press the Escape key once to interrupt the agent while it is running a tool. If it has already made incorrect changes, press Escape twice to see your message history and select a previous state to revert the conversation and the files.

Can I make the agent run Prettier automatically after every change?

Yes, you can configure a PostToolUse hook in your .claude/settings.json file. Set the hook to execute your local Prettier or linting command so the file is formatted correctly before the agent continues its work.

Where should I put global formatting rules that apply to all my projects?

Create a CLAUDE.md file in your home directory at ~/.claude/CLAUDE.md. The agent will read these instructions for every project, allowing you to enforce personal preferences like quote types or tab widths across your entire machine.

Read next

More on when it goes wrong·All posts