You wrote the instructions.
You created an AGENTS.md, CLAUDE.md, or Copilot instruction file. You documented the architecture, commands, conventions, testing rules, and everything the coding agent should avoid.
Then you gave the agent a task.
And it ignored part of the instructions anyway.
The obvious conclusion is that the AI coding agent is bad at following instructions.
Sometimes it is. But there is another possibility:
Your instructions may be bad at being followed.
This guide shows why coding agents drift from repository rules, how to diagnose the failure, and how to turn a growing collection of Markdown instructions into a system an agent can actually use.
What you will build
A practical instruction-debugging system that helps AI coding agents receive the right rules, at the right scope, with clear priorities and measurable validation.
Best for
Developers and teams using Codex, GitHub Copilot, Claude Code, or other AI coding agents with repository-level instruction files.
The quick answer
If your AI coding agent keeps ignoring repository instructions, adding more rules is usually not the first thing to try.
Start by checking whether the existing instructions are scoped correctly, actionable, internally consistent, prioritized, and connected to a validation step.
| Failure | What the agent experiences | Better approach |
|---|---|---|
| Wrong scope | Irrelevant rules compete with task context | Keep global rules global and local rules close to the code |
| No priorities | Several valid rules compete | Define which requirements win when they conflict |
| Contradictory instructions | No solution can satisfy every rule | Remove or explicitly resolve the conflict |
| Vague guidance | The agent must invent the meaning | Turn preferences into observable actions |
| Documentation overload | Critical rules disappear inside background context | Use instruction files as maps to deeper documentation |
| No definition of done | The agent decides when validation is sufficient | Specify completion checks |
| No feedback loop | Bad instructions remain bad | Test instructions against small representative tasks |
The core principle is simple:
Reliable coding agents need an instruction architecture, not an instruction pile.
Why AI coding agents appear to ignore instructions
A repository instruction file is only one source of context available to an AI coding agent.
Depending on the tool and task, the agent may also be working with:
- The current user request.
- Repository-level instructions.
- Directory or path-specific instructions.
- Existing source code.
- Tests and configuration files.
- Tool output and command failures.
- Architecture documentation.
- Previously loaded project context.
That means the real question is not:
Did I write the rule?
It is:
Did the right rule reach the agent at the right scope, with enough clarity to influence the decision?
That distinction explains many of the failures that look like simple disobedience.
1. Your instruction exists — but it is in the wrong scope
Imagine a repository with a frontend and backend:
/
├── AGENTS.md
├── frontend/
│ ├── src/
│ └── tests/
└── backend/
├── app/
└── tests/
The root instruction contains:
Run npm test after every change.
That may be correct for the frontend.
It is much less useful when the agent is working inside a Python backend.
Now imagine the root file also contains React conventions, database migration rules, API patterns, CSS guidance, deployment commands, accessibility requirements, CI instructions, and backend test commands.
The agent has received more instructions, but the signal-to-noise ratio has become worse.
Better approach
Keep repository-wide instructions truly repository-wide.
Repository-wide:
- Do not expose secrets.
- Do not modify generated files manually.
- Keep changes within the requested scope.
- Run the relevant validation before completion.
- Report checks that could not be performed.
Then keep stack-specific instructions close to the area where they apply.
Frontend:
- Reuse existing React components before creating new shared components.
- Run npm test for frontend behavior changes.
- Run npm run lint before completion.
Backend:
- Follow existing service and repository boundaries.
- Run pytest for backend changes.
- Do not create database migrations unless the task requires one.
Global rules should describe global behavior. Local rules should describe local work.
2. Everything in your instruction file is a priority
A common repository instruction file contains rules like these:
Follow existing architecture.
Write clean code.
Use best practices.
Optimize performance.
Maintain security.
Write tests.
Avoid duplication.
Keep files small.
Maintain backward compatibility.
Update documentation.
None of those rules is obviously wrong.
The problem appears when two valid goals compete.
Suppose preserving backward compatibility requires an adapter that adds duplication.
Should the agent preserve compatibility or remove duplication?
Your instructions may not say.
The agent then has to invent a priority system on your behalf.
Define the priority order
When requirements conflict, use this priority:
1. Do not break existing production behavior.
2. Preserve security and data integrity.
3. Follow existing architecture.
4. Keep the change as small as practical.
5. Improve code quality only within the requested scope.
Now the agent has a decision framework instead of a collection of slogans.
3. Your instructions contradict each other
Instruction conflicts are easy to create when rules are added over time.
One instruction says:
Always add tests for changed behavior.
Another says:
Only modify files explicitly requested by the user.
The task requests a change to:
src/auth/login.ts
But the correct test belongs in:
tests/auth/login.test.ts
The agent cannot satisfy both instructions literally.
What looks like the agent ignoring a rule may actually be the agent choosing between incompatible constraints.
Resolve the conflict explicitly
Only modify files necessary to complete the requested task.
Test files are considered part of the requested scope when behavior changes.
One clarification removes the contradiction.
This is why instruction debugging should resemble software debugging: do not inspect rules only in isolation. Inspect how they interact.
4. Your rules are too vague to execute
Consider this instruction:
Write production-quality code.
It sounds professional.
It tells the agent almost nothing about what your repository considers production-ready.
Compare it with:
Before completing backend changes:
- run the relevant test suite
- remove debug output
- use the existing error classes
- do not introduce a new dependency unless necessary
- preserve the public API unless the task explicitly changes it
The second version turns a quality preference into observable actions.
Replace vague instructions with executable ones
| Weak instruction | More actionable instruction |
|---|---|
| Follow our coding style | Follow patterns in neighboring files and run the existing formatter |
| Be careful with the database | Do not drop or rename columns without explicit approval |
| Test thoroughly | Run tests covering changed behavior and report the commands executed |
| Avoid unnecessary components | Search the shared component directory before creating a new component |
| Use best practices | Follow the existing repository pattern unless the task requires a new one |
A useful rule should answer at least one of these questions:
- What should the agent do?
- When should it do it?
- What should it avoid?
- How can it verify success?
If a rule answers none of them, it may be documentation rather than an instruction.
5. Your instruction file became a documentation dump
Instruction files tend to grow one incident at a time.
A bug happens. You add a rule.
A deployment problem happens. You add another paragraph.
A reviewer finds a recurring mistake. Another warning appears.
Eventually the file contains architecture history, coding conventions, API documentation, database notes, deployment instructions, testing rules, troubleshooting advice, and exceptions to exceptions.
The important instructions become buried inside accumulated context.
Use the instruction file as a router
The primary instruction file does not need to contain everything an agent could possibly know.
It can tell the agent where deeper knowledge lives.
# Project instructions
## Before making changes
Read the documentation relevant to the task:
- Architecture: docs/architecture.md
- Testing: docs/testing.md
- Database: docs/database.md
- API conventions: docs/api.md
## Global rules
- Preserve existing behavior unless the task changes it.
- Make the smallest reasonable change.
- Do not claim tests passed unless they were actually run.
- Do not expose secrets.
The instruction file becomes a map rather than an encyclopedia.
If you are still deciding what belongs in each instruction format, read AGENTS.md vs Copilot Instructions vs CLAUDE.md: What Goes Where?.
6. You explain what to do — but not what “done” means
This instruction sounds reasonable:
Always update tests when necessary.
The dangerous phrase is when necessary.
Who decides when a test is necessary?
The agent.
The same problem appears in phrases such as:
Refactor if needed.
Update documentation where appropriate.
Improve error handling when necessary.
Those rules hand the important decision back to the model.
Define completion conditions
A coding task is not complete until:
1. the requested behavior is implemented
2. relevant existing tests pass
3. changed behavior has a test when practical
4. relevant linting or formatting checks pass
5. the final response states which checks were actually performed
You have now transformed a preference into a workflow.
Workflows are easier for coding agents to follow because they provide a sequence and a stopping condition.
7. You have no feedback loop
Creating an instruction file is not the end of the process.
Your instruction system needs testing just like the code it is supposed to guide.
Give the agent a small representative task and inspect what happens.
- Did it find the relevant instructions?
- Did it read the correct files?
- Did it use existing repository patterns?
- Did two instructions compete?
- Did it modify files outside the intended scope?
- Did it run the expected validation?
- Did it accurately report what was tested?
Then update the instructions based on the observed failure.
The goal is not to write a perfect AGENTS.md in one sitting.
The goal is to build an instruction system that becomes more reliable as real failures reveal weak spots.
A practical workflow for debugging agent instructions
When an AI coding agent repeatedly ignores a rule, resist the instinct to immediately add another warning.
Use this workflow instead.
Step 1: Inventory every instruction source
List the context layers that can influence the task.
Global agent configuration
↓
Repository instructions
↓
Directory or path-specific instructions
↓
Project documentation
↓
Current task prompt
↓
Code and tests
You cannot debug an instruction system if you do not know which sources are participating.
Step 2: Find the smallest failing rule
Do not debug the entire instruction architecture at once.
Choose one recurring failure.
The agent keeps creating new components instead of reusing existing ones.
Then locate the rule intended to prevent that behavior.
Reuse existing components where possible.
Now you have one rule to test.
Step 3: Make the rule observable
“Avoid unnecessary components” requires interpretation.
Replace it with an explicit sequence:
Before creating a reusable UI component:
1. search src/components for an existing equivalent
2. extend an existing component when that preserves its purpose
3. create a new shared component only when no appropriate component exists
Step 4: Add a validation condition
Before completion, report whether an existing component was found and reused.
The rule now contains an action and evidence that the action was considered.
Step 5: Search for competing rules
You may discover another instruction:
Prefer isolated components with minimal dependencies.
Now the agent has two plausible directions.
Resolve the trade-off:
Prefer reusing existing components over creating isolated duplicates.
Create a new component when reuse would materially change the responsibility of an existing component.
Step 6: Test the change with a small task
Do not use a five-hour refactor as your first instruction test.
Use something controlled:
Add a loading state to the user profile save button.
Then verify whether the agent:
- found the existing component;
- followed the relevant local patterns;
- changed only necessary files;
- ran the expected validation;
- reported the result accurately.
If it fails again, update the instruction based on the new evidence.
A reusable pattern for better agent instructions
Important repository rules become easier to follow when they contain four elements:
WHEN:
Describe the situation that activates the rule.
DO:
Describe the expected action.
DO NOT:
Describe the unwanted or dangerous alternative.
CHECK:
Describe how success should be verified.
For example:
WHEN:
Changing API response behavior.
DO:
Preserve existing response fields unless the task explicitly changes the contract.
DO NOT:
Rename or remove existing fields as part of cleanup.
CHECK:
Run the relevant API tests and review the final diff for response schema changes.
This format is not required by a particular coding agent.
Its value is simpler: it removes ambiguity.
Before and after: turning a policy into an instruction system
Consider this common instruction block:
Write clean and maintainable code.
Use existing patterns.
Test everything.
Do not break anything.
Keep security in mind.
Update documentation when needed.
Use reusable components.
It sounds responsible, but almost every line requires interpretation.
A stronger version looks like this:
# Working rules
## Scope
Make the smallest change that completes the requested task.
Do not perform unrelated refactors.
## Existing code
Before creating a new shared utility or component, search for an existing equivalent.
Prefer extending an existing abstraction when doing so preserves its current responsibility.
## Safety
Do not remove or rename public APIs, database fields, or configuration keys unless the task explicitly requires it.
Never place credentials or secrets in source files.
## Validation
After changing behavior:
1. run the relevant existing tests
2. add or update tests for changed behavior when practical
3. run the formatter or linter for changed files
4. report which checks were actually run
Never state that validation passed if it was not executed.
## Failure
If a required command cannot run, explain the blocker and continue only with checks that are still possible.
The second example is better because it describes:
scope → action → boundary → validation → failure behavior.
That structure leaves the agent with fewer important decisions to invent.
Seven common instruction-system mistakes
1. Adding “IMPORTANT” instead of fixing ambiguity
Writing IMPORTANT, VERY IMPORTANT, or CRITICAL does not repair a rule whose scope or expected action is unclear.
2. Copying the same rule into every instruction file
Duplicated rules eventually drift and create conflicting sources of truth.
3. Treating every preference as a hard requirement
Too many absolute rules make legitimate trade-offs impossible.
4. Mixing global and local instructions
A React-specific rule should not compete for attention during an unrelated backend task.
5. Using subjective language
Terms such as “clean,” “proper,” “careful,” and “best practice” need repository-specific meaning before they become useful instructions.
6. Forgetting completion criteria
An agent cannot reliably validate work when the repository never defines what successful completion requires.
7. Never testing the instructions
Instruction files should evolve from observed agent failures, not only from what the team believes might go wrong.
How to audit your AI coding instructions
- List every instruction file and source of persistent agent context.
- Identify rules duplicated across multiple files.
- Find contradictory commands, priorities, or boundaries.
- Separate global rules from directory-specific rules.
- Replace subjective language with observable actions.
- Move deep background documentation into normal project docs.
- Define explicit completion and validation requirements.
- Verify every documented command still works.
- Test the system with a small representative coding task.
- Update instructions based on the agent’s actual failure.
AI coding instruction checklist
- Global instructions truly apply across the repository.
- Local rules are scoped close to the code they affect.
- Conflicting instructions have been removed or prioritized.
- Critical rules describe observable actions.
- Vague phrases have been replaced with repository-specific expectations.
- Instruction files point to deeper documentation instead of copying it.
- The agent knows what validation is required.
- The agent knows what to report when a check cannot run.
- High-risk changes have clear stop or approval conditions.
- Important rules contain a definition of success.
- Repository commands are current.
- Instruction behavior has been tested on representative tasks.
- Recurring failures are converted into focused rules.
Frequently asked questions
Why does my AI coding agent ignore AGENTS.md?
The file may be loaded correctly while individual rules still fail because they are too broad, conflict with another instruction, apply at the wrong scope, or do not provide an observable action and validation condition.
Should I make my instruction file longer?
Not automatically. More instructions can increase ambiguity and make important rules harder to identify. Add context only when it solves a specific recurring failure.
Should I repeat important rules in AGENTS.md, CLAUDE.md, and Copilot instructions?
Usually avoid maintaining full duplicate copies. Keep shared rules in a clear source of truth and use tool-specific files for behavior that genuinely differs between tools.
Can instructions guarantee that an AI agent will follow every rule?
No. Repository instructions improve context and consistency, but they do not replace tests, automated checks, code review, or human approval.
What makes an instruction easier for a coding agent to follow?
Strong instructions usually define when the rule applies, what action is expected, what should not happen, and how the result should be checked.
How often should repository instructions be reviewed?
Review them when repository architecture, commands, tooling, or recurring development failures change. An obsolete instruction can be more harmful than a missing one.
Final takeaway
AI coding agents will still make mistakes. No Markdown file can remove uncertainty from software development.
But there is a major difference between an agent failing to follow a clear instruction and an agent being forced to interpret a confusing instruction environment.
If the same rule keeps failing, resist this progression:
IMPORTANT: ALWAYS DO THIS.
VERY IMPORTANT: NEVER IGNORE THIS.
CRITICAL!!! YOU MUST ABSOLUTELY ALWAYS...
At that point you are no longer designing an instruction system.
You are shouting into a Markdown file.
Instead, debug the rule. Check its scope. Find conflicts. Set priorities. Make the expected action observable. Define the validation step. Then test it on a real task.
Reliable AI coding workflows are not built by giving agents more instructions.
They are built by giving agents fewer reasons to misunderstand them.
Related guides
- AGENTS.md vs Copilot Instructions vs CLAUDE.md: What Goes Where?
- AI Coding Workflow: From Task Brief to Tested Pull Request
- How to Review AI-Generated Code Without Missing Hidden Bugs