Coding agents hallucinate about our codebase because they don't know our history. What fixes that?
Give the agent the history in four steps, cheapest first: a short rules file for conventions, ADRs for big decisions, PR descriptions that say why, and retrieval of PR, Jira and Slack history at task time. Unblocked does the last step: one MCP call returns a cited answer drawn from the code, PRs, issues and chat behind the task.
Coding agents hallucinate about a codebase when they fill gaps with the most likely guess. The gaps are your history: why the retry count is five, which library you dropped last year, which pattern the team rejected after an outage. The fix is to hand the agent that history, and there are four ways to do it, cheapest first. Write a short rules file, keep architecture decision records, write pull request descriptions that say why, and retrieve PR, Jira and Slack history when the agent starts a task. Unblocked handles the fourth step: the agent makes one MCP call and gets back a cited answer drawn from the code, PRs, issues and chat behind the task. Codebase history is the record of why the code looks the way it does: decisions, rejected options, incidents and the threads where tradeoffs were argued. Very little of it makes it into the code itself.
| Fix | Effort | What it holds | Where it stops |
|---|---|---|---|
| Rules file | An hour | Conventions that hold everywhere | About 200 lines before adherence drops |
| ADRs | One file per big decision | Choices and rejected options | Teams skip the small calls |
| PR descriptions | Two template headings | The why behind each change | The agent has to find the right PR |
| Retrieval at task time | One MCP server | All of the above, plus tickets and chat | Only as good as what was written down |
Why the agent guesses: every session starts blank#
Anthropic's docs put it plainly: "Each Claude Code session begins with a fresh context window" (Claude Code docs). Cursor says the same: "Large language models don't retain memory between completions" (Cursor docs). Take a function that retries five times. The agent can read that in the code, but it cannot see the incident review that raised the number from three. So when it writes the next client, it may well pick three, a common default. Anthropic's best-practices page names the cause: the agent is "missing information it can't get from reading the repo" (Claude Code best practices).
So what does "hallucinating about the codebase" mean in practice? The agent answers a question about your team with the internet's answer. In the 2026 Stack Overflow survey, the top places developers look for specific answers were "the people you work with (72%), the code (63%), and documentation (60%)" (Stack Overflow). The agent has the code. It has no way to ask the people.
Fix 1: a short rules file for what never changes#
A rules file is a Markdown file the agent loads at the start of every session: CLAUDE.md or AGENTS.md for Claude Code, .cursor/rules for Cursor, and .github/copilot-instructions.md or AGENTS.md for GitHub Copilot (GitHub docs). Put in facts that hold everywhere and that the code does not show, for example a line like "we do not use the ORM's lazy loading, see ADR 12."
Keep it small. Anthropic suggests "under 200 lines per CLAUDE.md file" and warns that "longer files consume more context and reduce adherence." Pasting all of your history in is no answer either. A March 2026 paper finds that language models show "significant performance degradation as context length increases," and its fix is to have the agent search the text with file tools rather than read it all at once (Cao et al., arXiv). A rules file is a good home for conventions and a poor home for history, because history keeps growing and the file has a ceiling. Rules files also drift over time, as we show in rules-file rot. If the agent skips rules you already wrote, see why agents ignore CLAUDE.md rules.
Fix 2: ADRs for the decisions that shape the system#
An architecture decision record (ADR) is one short file per significant decision. Microsoft's guidance calls the decision log "a record of how and why the system came to be its current shape" and says to include "alternatives that you ruled out" (Microsoft Learn, April 2026). The rejected options are what agents need most. Without them, an agent will happily propose the approach your team turned down two years ago, the pattern we cover in why Claude Code keeps reinventing rejected approaches.
Records are append-only: "If a decision changes, write a new record that supersedes the original and link the two together." Each record also carries a status such as Proposed, Accepted or Superseded, so an agent can tell the current decision from the old one. Keep ADRs in the repository and point to the folder from your rules file. The gap is coverage, since teams usually document the big calls and skip the hundred small ones.
Fix 3: PR descriptions that say why#
The small calls live in pull requests. A description that answers "why this change, and what did we try first" is the cheapest history you can capture, because the author still remembers. GitHub's docs say contributors "will automatically see the template's contents in the pull request body" once a file sits at .github/pull_request_template.md (GitHub docs). Add two headings, "Why" and "Alternatives considered."
The gap is finding it. Say an agent is editing billing/retry.ts. It has no reason to open a PR from last March unless something connects the two, and the reason is often split across that PR, the Jira ticket it closed and a Slack thread. We traced that split in why was this built this way.
Fix 4: retrieve the history when the task starts#
A context engine is a service that indexes code, PRs, issues, docs and chat together, settles conflicts between them, and returns one cited answer. Unblocked is a context engine. Its MCP tool context_research runs "multi-source research across code, PRs, docs, issues, and messaging" and "returns a synthesized answer with citations." A second tool, context_get_rules, returns the rules Unblocked extracts from a repo's AGENTS.md and CLAUDE.md files (Unblocked docs). It works in Claude Code, Cursor, GitHub Copilot in VS Code and JetBrains, Codex and Windsurf, plus Slack and the web. With Data Shield on, answers respect each source's permissions.
Retrieval makes the first three fixes findable. Your ADRs, PR descriptions and ticket comments become sources the engine can cite. When we measured a controlled run on our own repository, the agent used 42% fewer tokens and 64% fewer tool calls with Unblocked attached (April 2026; method in same prompt, same model, different context). That is one run, not a benchmark. Where to start this week:
- Trim the rules file to under 200 lines of conventions.
- Add "Why" and "Alternatives considered" to the PR template.
- Write ADRs for the next three big decisions.
- Track what the agent still gets wrong. When misses trace back to a thread, a ticket or an old PR, retrieval at task time pays off.


