keepcalculator

06 Numbers and Powers

Fix AI Coding Agents Making Repeated or Conflicting Changes

Card No. 06·41079 · Updated · Standard formula, shown below

This guide helps developers stop AI coding agents from making the same edits over and over or fighting each other with conflicting changes. You’ll learn practical steps to set clear boundaries, improve context, and establish a review workflow that keeps the agent’s output stable and consistent.

What You’ll Need

  • Access to the AI coding agent’s configuration files (e.g., AGENTS.md, CLAUDE.md, or project-specific settings).
  • A version control system (Git) with a clean working tree to test changes.
  • Basic familiarity with your codebase’s structure and the agent’s command-line or IDE interface.

Step-by-Step

  1. Identify the pattern of repeated or conflicting changes. Look at recent commits or diffs. Note which files or functions the agent touches repeatedly. Are they reverting its own previous edits? Are two different agents (or two sessions) editing the same area? Understanding the pattern helps you target the fix.
  2. Define a single source of truth for project rules. Create or update a top-level file like AGENTS.md (for many agents) or CLAUDE.md (for Claude Code) that explicitly lists coding conventions, file organization, and “do not edit� areas. For example: “Never modify generated files in /dist� or “Use the existing error-handling pattern in /utils.� This gives the agent clear boundaries.
  3. Break large tasks into smaller, focused prompts. Instead of “refactor the authentication module,� ask for one specific change: “Change the login function to use the new session service, but do not touch other functions in the file.� Smaller prompts reduce the chance of unintended side effects.
  4. Use a task queue or issue tracker to manage concurrent work. If multiple agents or sessions run in parallel, assign each a distinct area of the codebase (e.g., “Agent A handles frontend components, Agent B handles backend routes�). This prevents them from stepping on each other’s toes.
  5. Implement a mandatory review step before applying changes. Configure the agent to output a diff or patch file instead of directly modifying the working tree. Review the diff, then apply it manually or with a tool like git apply. This catches conflicting changes before they land.
  6. Add a “context snapshot� to each prompt. Before asking for a change, include the current state of the relevant files (or a summary) in the prompt. This prevents the agent from working with stale information and redoing previous work.
  7. Use idempotent operations where possible. Instruct the agent to write code that can run multiple times without changing the result. For example, “Insert this line only if it doesn’t already exist� or “Update the config value only if it differs.� This reduces repeated changes.
  8. Monitor and log agent actions. Enable verbose logging or use a tool like git log to see what the agent did. If you notice a loop (e.g., it keeps reformatting the same file), stop the agent and investigate the cause—often it’s missing context or a rule conflict.
  9. Adjust the agent’s temperature or randomness settings. Some agents allow you to set a “temperature� for code generation. Lower values (e.g., 0.1) make output more deterministic, reducing the chance of different responses to the same prompt.
  10. Test with a clean checkout. After making rule changes, run the agent on a fresh branch with no pending changes. This ensures the agent isn’t reacting to its own previous edits.

Common Mistakes

  • Ignoring the agent’s context window. If the agent can’t see the full file or recent changes, it may overwrite them. Always provide relevant snippets or a summary.
  • Using vague rules. “Follow best practices� is too ambiguous. Be specific: “Use 2-space indentation� or “Never use any in TypeScript.�
  • Allowing the agent to edit files outside its scope. Restrict file paths in the configuration if possible, or use a separate directory for agent-generated changes.
  • Not reviewing diffs. Skipping review is the fastest way to let conflicting changes pile up. Always at least skim the diff before accepting.
  • Running multiple agents without coordination. Even with rules, two agents can conflict if they both touch the same files. Use a lock or a simple “who owns what� list.

Tips

  • Start with a small pilot. Test your new rules on a small feature before rolling out to the whole codebase.
  • Use a “do not touch� list. Explicitly list files or directories the agent should never modify, like lock files or generated assets.
  • Leverage version control branches. Have the agent work on a separate branch and merge only after passing tests and review.
  • Create a “definition of done� for each task. Tell the agent what “finished� looks like: “All tests pass, no new warnings, and the diff is under 50 lines.�
  • Keep a changelog of agent rules. When you update rules, note what changed and why. This helps you debug future issues.
  • Consider using a deterministic model. If the agent supports it, choose a model with lower variability for routine edits.

Troubleshooting

  • The agent still makes repeated changes after adding rules. Check if the agent actually reads the rules file—some agents ignore it if the file name is wrong. Confirm the correct filename for your tool (e.g., AGENTS.md is common, but Claude Code uses CLAUDE.md). Also verify the rules are in the root of the project, not a subfolder.
  • Conflicts occur only when two agents run simultaneously. Use a simple file lock (e.g., a .lock file) or a task assignment system. If that’s not possible, run agents sequentially with a short delay.
  • The agent reverts its own previous work. This often happens when the agent doesn’t see the current state. Provide the latest diff or file contents in the prompt. Also, disable any “auto-format on save� that might trigger the agent.
  • Changes are correct but not idempotent. Add explicit instructions: “Check if the change already exists; if so, skip.� Or write a small script that checks for the presence of a marker before applying the change.
  • The agent ignores “do not touch� lists. Some agents don’t support file restrictions. In that case, move sensitive files to a separate directory or use a pre-commit hook to block changes to those paths.
  • You’re not sure if the agent is the cause. Use git blame or check the commit author. If the agent is a separate user in Git, you can filter by that user.

Frequently Asked Questions

Why does my AI agent keep making the same change over and over?

It likely lacks context that the change was already made. Include the current file state or a diff in the prompt, and make the operation idempotent.

Can I run two AI agents on the same project without conflicts?

Yes, but you need clear boundaries. Assign different directories or modules to each agent, and use a shared task list to avoid overlapping work.

What’s the best format for agent rules?

Use a plain-text file (like AGENTS.md) with bullet points. Keep it short—under 50 lines—and use specific, testable statements.

Should I let the agent commit directly to the main branch?

No. Always have the agent work on a branch and submit a pull request. This gives you a chance to review and catch conflicts.

How do I stop the agent from reformatting my code?

Add a rule: “Do not change formatting unless explicitly requested.� Also, configure your code formatter to run automatically, so the agent doesn’t feel the need to do it.

Is it worth using a lower temperature setting?

For routine edits, yes—it reduces variability. But for creative tasks like writing tests, a slightly higher temperature might help. Experiment on a small task first.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →