Try free

Last updated 13 October 2026

Fix Claude Code vs ESLint auto fix loops

The feedback loop of conflicting formatters

A common frustration occurs when Claude Code writes to a file and your local environment immediately changes it back. This happens because most modern developers use auto-save formatters or linting tools that trigger on file changes. When the agent uses the Write tool to update a file, your IDE or a background process like ESLint might reformat that file to match a specific style. The agent then detects that the file on disk does not match what it just wrote, leading it to believe the write failed or that a new error has appeared. It attempts to fix the file again, which triggers your local formatter again, creating an infinite loop.

This cycle is particularly problematic because it consumes your context window and your credits without making real progress. Every iteration of the loop adds more messages to the session history. If you are running the session in a default permission mode, the agent might continue this behavior for several minutes before stopping. You will see the agent repeatedly using the Read tool followed by the Edit tool on the same lines of code. Identifying the specific linting rule that is causing the conflict is the first step toward breaking the cycle.

Define styling rules in project instructions

The most effective way to prevent these loops is to provide clear guidance in the CLAUDE.md file at the root of your repository. This file serves as the primary source of truth for the agent regarding project standards. You should explicitly list the formatting commands that the agent is allowed to run. Instead of letting the agent guess how to fix a linting error, instruct it to run your local linting script using the Bash tool after it makes an edit. This ensures that the agent and your local environment are using the exact same logic to evaluate the code.

If you have specific rules that are known to be problematic, you can tell the agent to ignore them. For example, if your project uses a strict trailing comma rule that conflicts with the agent's default output, add a section in CLAUDE.md that tells the agent not to attempt manual fixes for trailing commas. By directing the agent to rely on the existing project tools rather than its own internal logic for style, you eliminate the source of the disagreement. The agent will learn to write the code and then execute a command to let the project tools handle the final formatting.

Control agent behavior with permission modes

Permission modes are a powerful way to manually intervene when a loop begins. By default, the agent might try to be helpful by fixing every error it sees. If you notice the agent starting to loop, you should switch the mode to plan by pressing Shift+Tab. In plan mode, the agent will describe what it wants to do without actually executing the tools. This gives you a chance to see if it is about to repeat a failed edit. You can then provide feedback in the prompt to tell it to stop focusing on that specific file or rule.

Using the bypassPermissions mode is generally discouraged when you are dealing with complex linting setups. While it makes the agent faster, it also removes the checkpoint where you can catch a formatting conflict. If a loop occurs in this mode, it can quickly fill the session context. If the agent gets stuck, you can use the Escape key to interrupt its current action. Pressing the Escape key twice will allow you to navigate back through the message history to a point before the loop started, effectively undoing the confusion.

Global configuration for your local environment

If you find that the same formatting loops happen across multiple projects, you should move your instructions to a more global level. You can create a CLAUDE.md file in your home directory at ~/.claude/CLAUDE.md. The agent reads this file for every project you work on. This is the ideal place to put universal rules about your preferred indentation, line lengths, or your stance on auto-formatting. By setting these expectations globally, you save the time of configuring every individual repository you clone.

You can also use the ~/.claude/settings.json file to manage how the agent interacts with your system tools. While this file primarily handles technical configurations, it can also be used to set default permissions for specific tools. If you want to ensure the agent always asks before using the Write tool on sensitive configuration files, you can adjust the permissions settings there. This adds a layer of safety that prevents the agent from making rapid, unapproved changes to your environment during a loop.

Coordinate with the IDE using slash commands

The /ide slash command is specifically designed to help the agent work better alongside your code editor. When you run this command, it optimizes the interaction between the terminal and the IDE. This can help resolve some of the lag or synchronization issues that lead to loops. If the agent is aware of the IDE state, it is less likely to be surprised by the changes your editor makes to a file upon saving. It provides a more cohesive bridge between the command line agent and your graphical development environment.

If you suspect that the agent is confused about the project state, the /doctor command is another useful tool. It checks the health of your Claude Code installation and your environment. It can identify if there are issues with how the agent is reading your files or if there are missing dependencies that might be causing linting errors to be reported incorrectly. Regularly running this command helps maintain a stable environment where the agent can perform its tasks without being tripped up by configuration drift.

Monitor multiple sessions with adhdTerminal

Keeping track of an agent that has entered a loop is difficult if you only have one terminal window open. This is a scenario where adhdTerminal provides a distinct advantage for your workflow. It allows you to run many Claude Code sessions side by side, with each session appearing as a tile on a wall. Each tile displays a status indicator showing if the session is working, waiting for you, or idle. If a tile for a specific project stays in the working state for an unusually long time, it is a clear visual signal that the agent might be stuck in a formatting loop.

The tiles in adhdTerminal also show the last exchanges of the conversation and headlines published by the project. This allows you to monitor the progress of a linting task without having to give it your full attention. If you see the same headlines repeating in a tile, you can immediately jump into that session to resolve the conflict. Because the app mirrors this wall to a mobile app over an encrypted link, you can even keep an eye on a long running task while away from your desk and send a prompt to stop the agent if a loop occurs.

Manage session context and history

When a formatting loop occurs, the session history grows rapidly with redundant information. This extra context can make the agent less accurate and more expensive to run. You should use the /compact command to summarize the conversation so far. This command reduces the amount of space the previous messages take up in the context window while preserving the important outcomes of the session. It is a necessary step after a loop to ensure the agent doesn't stay confused by its own previous mistakes.

If the loop was particularly severe and the agent seems unable to recover even after a summary, the /clear command is your best option. This command starts the session over in the same folder. It wipes the conversation history but leaves your files intact. You can then start a new interaction with a fresh context window. Before you begin the new session, make sure you have updated your CLAUDE.md or .claude/settings.json to address the conflict that caused the loop in the first place.

Automate validation with hook events

Advanced users can use hook events to create a more resilient setup. By defining behavior for the PostToolUse hook, you can trigger a script that runs every time the agent finishes using the Write or Edit tool. This script can verify that the file still passes linting after your local formatter has had a chance to run. If the script fails, it can provide an immediate notification to the agent with the correct file content, preventing it from guessing what went wrong and entering a cycle of trial and error.

You can also use custom subagents defined in .claude/agents to handle specific parts of your workflow. For instance, you could have a subagent that is strictly responsible for reviewing code changes without having the permission to write to files. This separation of concerns ensures that the main agent stays focused on the logic of your task while the subagent handles the validation. This layered approach to automation makes your development process more stable and significantly reduces the chance of conflicting tools fighting over your source code.

Questions people ask

How do I immediately stop an agent that is stuck in a formatting loop?

You should press the Escape key once to interrupt the current tool execution. If the agent continues to try new things, press the Escape key twice to bring up the message history and select a point before the loop started to reset the conversation state.

Can I tell Claude Code to never touch my formatting or linting?

Yes, you should add a specific instruction to your CLAUDE.md file telling the agent to ignore all linting and formatting rules. You can also use Shift+Tab to switch to plan mode, which allows you to review and approve every change before the agent writes it to the disk.

What should I do if my session becomes slow after a loop?

Use the /compact command to summarize the session history and free up space in the context window. If the performance does not improve, use the /clear command to wipe the history and start a fresh session in the same directory.

Read next

More on when it goes wrong·All posts