Context Drift vs. Context Rot: A Cleanup Guide for Skills and AGENTS.md
As AI coding agents work across growing repositories, project knowledge can fall out of sync across multiple files, causing context drift that differs from the context rot seen in long sessions. This article explains how drift originates, why models rarely report conflicting instructions, and how to fix it with a single source of truth. It includes a five-step cleanup process, a conflict-handling contract, a sample conflict matrix, a verification command, and an acceptance checklist.
1. Starting With an Acceptance Scenario
One refund policy document says 14 days. Another says 30 days. You ask a coding agent to answer a customer based on the project documentation, and it quickly gives you a number. As the person reviewing the answer, can you tell whether the model ever saw the other value?
Most likely not. The response is clean, confident, and shows no hesitation. It reads as if the model has reviewed the entire repository. The problem hides in that cleanliness: the model may have seen both conflicting sources, picked one according to some internal priority, and quietly discarded the other.
A developer relations practitioner ran a controlled experiment on a personal blog and broke this behavior into observable outcomes. The setup was a coding sandbox with real repository files. The model could read docs, write code, and run tests. The task instructions and the project-wide rules were deliberately made to contradict each other. The result: the model followed the task instructions 95% to 100% of the time, and across 110 runs where it was not asked to report conflicts, it raised the discrepancy with the user zero times.
The value of these numbers is not the percentages themselves. It is that they separate two things people often conflate: the model choosing correctly and the model letting you know it made a choice are two different things. The discussion below is limited by these models and this task setup and should not be generalized to all models, but the structural problem it exposes is widespread.
2. Two Context Problems Require Separate Treatment
Anyone who uses AI to write code for a while knows the feeling: at some point in a conversation, it is time to start a new session. Earlier approaches pile up in the context, some of which no longer work, and the model picks them up and retries them. Compressing history, removing distracting information, and starting over all address the same class of problem: as a session grows longer, noise degrades answer quality. This is commonly called context rot.
The experiment points to a different phenomenon. Suppose the project-wide rules file in the root directory has changed the refund window to 14 days, the skill instructions for a customer support task still say 30 days, and the docs directory still holds a policy from three months ago. A skill file is an operational guide the model reads when it receives a specific task. Even if you open a fresh conversation, these files will still produce different answers. This state, where sources gradually fall out of sync with one another, can be called context drift.
The difference can be summarized as follows:
- Timing: rot appears in the middle or later stages of a long session; drift exists in the first turn of a new session.
- Source of noise: rot comes from accumulated message history; drift comes from multiple inconsistent sources within the project.
- User experience: rot shows up as off-track answers and repeated failed approaches; drift shows up as smooth answers that provide only one version without explanation.
- Where to investigate: rot is addressed by clearing history and restating the task; drift requires going back to the files, finding the conflicting text, and checking which source is still valid.
Conflating the two is where many teams’ remediation efforts begin to fail: they keep reopening sessions and trimming prompts but never open the files that conflict with each other.
3. How Drift Happens: Nobody Makes a Big Mistake
Creating drift does not require anyone to be negligent. One team updates the integration guide while another keeps its own maintained copy. A new hire finds only one of them in the task directory, follows it, and delivers successfully. Months later, the model faces two documents written with equal confidence, and encounters the very gap left behind during the human handoff.
Common sources of drift fall into a few categories:
- Copy-based spread: a spec is copied into subdirectories, sample projects, and template repositories, but updates happen in only one place.
- Task-local overrides: local guidance written for a task actually conflicts with the global rules, and no one cross-checks them.
- Version leftovers: old versions of documents are not marked as obsolete; they just “look outdated.”
- Generated content flowing back: model-generated instructions are committed directly into the repository and exist alongside manually maintained versions.
What they share is this: each document looks reasonable on its own, and the conflict only becomes visible when they are read together.
4. Why the Model Does Not Report Conflicts
Not reporting conflicts may not be a defect. It is more likely a natural result of the training objective. Instruction following is usually reinforced to a very high priority: when local task instructions disagree with global rules, the model tends to follow the more specific one, the one closer to the current task, because that is “correct behavior” in most evaluations.
At the same time, “pointing out that the user’s materials contradict each other” is often seen as unnecessary or even offensive in ordinary conversation. Without explicit permission and a format requirement, the model takes the path of least resistance: give the answer, skip the explanation of the tradeoff.
So relying on the model to disclose conflicts on its own is unreliable. A practical approach is to turn disclosure into an explicit contract written into the project rules:
## Conflict Handling Convention- When two or more sources give different values for the same fact, do not choose silently.- First output a conflict list: file path, original snippet, and value.- Before the user confirms, output only the items pending confirmation, not a final conclusion.- If the user asks for an answer first, also provide the discarded version and its source.
This kind of convention does not change the model’s capabilities. It only changes its output obligations, at very low cost and with direct benefit.
5. Doing a Real Cleanup
The core of drift remediation is establishing a single source of truth and turning other materials into references rather than copies.
Step 1: Inventory. List all project-wide rules, task-level skill instructions, and in-directory documentation, noting the maintainer and last update time for each. Files with no maintainer should be treated as suspect sources by default.
Step 2: Build a conflict matrix. Use “fact item × file” as the two axes, and fill in the different values for the same fact. Empty cells and duplicate values are equally worth attention.
| Fact | Project-wide rules | Task skill instructions | Docs directory |
|---|---|---|---|
| Refund window | 14 days | 30 days | 30 days (three months old) |
| Callback timeout | Undefined | 5 seconds | Undefined |
Step 3: Designate authority. Allow only one authoritative source per row, and change the other locations into references:
Refund window: see the "Refunds" section of the project-wide rules in the root directory (authoritative source).This file no longer repeats the value, to avoid copy drift.
Step 4: Executable verification. Turn the convention into a runnable check instead of relying on people to remember:
# Example: scan whether a key fact appears with multiple different valuesrg -n "refund\s+(window|period).{0,10}[0-9]+\s*days" . \| awk -F: '{print $1"\t"$3}' | sort -u# The same fact matching multiple files with different values -> output as items pending manual review
Step 5: Wire it into the process. Add documentation consistency checks and obsolete-marking checks to continuous integration, and add “did this introduce a new copy of a spec?” to the review checklist. Cleanup without process support will revert within weeks.
6. Acceptance Checklist
- In the first turn of a new session, ask about a key fact and check whether the answer includes the source path.
- Deliberately leave one conflict in place and check whether the model reports the conflict before answering, per the convention.
- Check whether each fact has only one authoritative location in the repository, with the rest as references.
- Check whether outdated documents are explicitly marked as obsolete rather than just “looking old.”
- Check whether consistency checks are part of the automated process rather than dependent on individual memory.
7. Conclusion
The essence of context drift is not a poor model memory. It is that project knowledge lacks a versioned single source. Reopening sessions cannot fix it, because the contradiction lives in the files, not in the conversation. Defining the authoritative source, writing conflict disclosure into a contract, and putting consistency checks into the process are the reusable solutions. In code repositories and knowledge bases that require long-term maintenance, this governance approach also applies to scenarios such as logging services and monitoring alerts, where multiple configurations describe the same fact. Wherever “the same fact is described in multiple places,” there needs to be one authoritative location.
