# My coding agent spends 10 to 20 minutes re-exploring the codebase before every task. How do I stop the repeat discovery?


URL: https://getunblocked.com/answers/stop-coding-agent-repeat-discovery-before-every-task/
Published: 2026-10-29T15:30:00Z
Updated: 2026-10-27T23:52:52Z
Author: Brandon Waselnuk
Categories: Context Engine, Engineering Insights

**Short answer:** The agent re-explores because every session starts with an empty context window, and CLAUDE.md, rules and memory files hold instructions, not the codebase's structure or decisions. Three fixes, in order: shrink the rules file to a map of where things live, make 'gather context first' the opening instruction, and give the agent a context engine over MCP so discovery is one query instead of a crawl.

---
Your agent re-explores because it has no other way to learn the codebase. Every session opens with an empty context window. The files you hand it on the way in, such as CLAUDE.md, Cursor rules or memory notes, carry instructions and preferences, and nothing about how the system is shaped or why. **Repeat discovery** is the time an agent spends re-reading the same files, re-running the same searches and re-deriving the same facts at the start of every task, because nothing carried them over. The fix has three steps, and the order matters. Shrink the rules file to a map, make "gather context first" the opening instruction, and give the agent somewhere to ask, so discovery becomes a query rather than a crawl.

## Why the agent starts from zero every time

Anthropic's docs say that "each Claude Code session begins with a fresh context window" ([Claude Code memory docs](https://code.claude.com/docs/en/memory)). Two mechanisms carry knowledge across sessions, CLAUDE.md files and auto memory, and both are loaded "as context, not enforced configuration". The best-practices page names your symptom: Claude "has to rediscover the same fact at the start of every session. It's missing information it can't get from reading the repo" ([Claude Code best practices](https://code.claude.com/docs/en/best-practices)).

Cursor works the same way with different file names. Rules are "system-level instructions to Agent" ([Cursor rules docs](https://cursor.com/docs/context/rules)). For finding code, Cursor ships Instant Grep, an exact-match engine that "builds and queries its index on your machine" and "does not store embeddings of your codebase for search" ([Cursor search docs](https://cursor.com/docs/context/codebase-indexing)). Grep answers "where does this string appear", not "how does billing work" or "why did we stop retrying".

That reading has a second cost. A March 2026 paper from Duke researchers notes that LLMs show "significant performance degradation as context length increases" ([Cao et al., arXiv](https://arxiv.org/abs/2603.20432)). Every file opened during discovery stays in the window for the rest of the task, so a long crawl also means a worse edit.

## What the vendors give you today, and where it stops

Claude Code's answer is a short CLAUDE.md plus notes the agent writes for itself. The memory docs say to "target under 200 lines per CLAUDE.md file", because longer files "consume more context and reduce adherence". Auto memory is machine-local, and only "the first 200 lines of MEMORY.md, or the first 25KB" load at session start. Subagents keep exploration out of the main conversation, but each one "starts with a fresh, isolated context window", and the built-in Explore agent is one-shot ([Claude Code subagents docs](https://code.claude.com/docs/en/sub-agents)). The best-practices page adds the catch: "a fresh subagent first has to gather context your conversation already had, so it can end up slower than doing the task where you are" (best practices, linked above).

All of these live on one machine, in one repo, and hold what a person or one agent chose to write down. None of them know what a pull request decided in March, what a Slack thread settled last week, or which of two services owns a table. For a team of twenty, that is twenty agents re-deriving the same facts. The [guide to agent skills vs rules files vs retrieved context](https://getunblocked.com/blog/agent-skills-vs-rules-files/) covers why rules-file tuning alone never closes that gap.

## The three fixes for repeat discovery, in order

### 1\. Shrink the rules file to a map

The test Anthropic gives is simple: "only write down what Claude can't find by reading the repo, or what it would otherwise spend time rediscovering every session" (best practices, linked above). So the rules file holds entry points, where each concern lives, how to run the tests, and the handful of facts not visible from the code. The cost docs suggest the same shape as a skill. For example, a "codebase-overview" skill "could describe your project's architecture, key directories, and naming conventions", so the agent "gets this context immediately instead of spending tokens reading multiple files" ([Claude Code cost docs](https://code.claude.com/docs/en/costs)). A step-by-step pass is in [how to audit and fix a bloated CLAUDE.md](https://getunblocked.com/blog/audit-fix-bloated-claude-md/).

### 2\. Make "gather context first" the opening instruction

The cost docs warn that "vague requests like 'improve this codebase' trigger broad scanning", so name the task and the order: find the current behaviour and the reason for it, then change it. This step's job is to stop the agent from skipping discovery and guessing, which is the more expensive failure.

### 3\. Give the agent somewhere to ask

Steps one and two shorten and aim the crawl, and this third step is the one that replaces it. **A context engine** is a service that indexes code history, PRs, issues, docs and chat together, settles conflicts between them, and returns one cited answer over a single MCP connection. Unblocked's server exposes two tools. `context_research` is documented as "multi-source research across code, PRs, docs, issues, and messaging" that "returns a synthesized answer with citations", and `context_get_urls` fetches what the citations point to ([Unblocked MCP docs](https://docs.getunblocked.com/unblocked-mcp/mcp-overview)). "How does X work, what was decided, and what changed recently" becomes one call, and with [Data Shield](https://docs.getunblocked.com/team-settings/data-shield) on, answers follow the source systems' permissions. Justin McCraw, Software Engineer at The Information, describes the setup: "My setup tells the agent: before you implement anything, go check Unblocked. It has everything — our repos, Notion, Slack, coding standards — and it surfaces things I wouldn't have thought to look for. GitHub Copilot doesn't have any of that organizational context. I'd rate the impact an eight or nine out of ten, and it's only gotten better." If every engineer runs their own MCP servers, see [what fixes that](https://getunblocked.com/answers/everyone-connects-their-own-mcp-servers/).

## How to measure the win against repeat discovery

Pick three numbers before you change anything, and record them on five routine tasks.

- **Time to first edit** is the wall clock from the prompt to the first file write.
- **Tokens per task.** In Claude Code, the Session block in `/usage` shows "detailed token usage statistics for your current session". Totals reset on `/clear`, so one task per session gives a clean figure. OpenTelemetry export sends the same per-user counts to your own dashboards (cost docs, linked above).
- **Tool calls per task.** Count the reads and searches before the first edit.

Re-run the same five tasks after each fix. We measured this once under controlled conditions on 2026-04-16: same prompt, same model, same repository, with and without a context engine attached. With it, the agent used 42 percent fewer tokens, finished 27 percent faster, and made 29 tool calls instead of 80 ([same prompt, same model, different context](https://getunblocked.com/blog/same-prompt-same-model-different-context/)). One run is not a population, so get your own number. One more check: did the answer the agent worked from cite its sources? In Stack Overflow's 2026 survey, 93 percent tied trust in AI output to source attribution ([Stack Overflow](https://stackoverflow.blog/2026/10/06/the-results-of-the-2026-developer-survey-are-here/)). If discovery gets faster but the agent cannot say where a fact came from, you have traded a slow crawl for a fast guess.

## Read more

- [How to Audit and Fix a Bloated CLAUDE.md File](https://getunblocked.com/blog/audit-fix-bloated-claude-md/)
- [Agent Skills vs Rules Files vs Retrieved Context: What Goes Where in 2026](https://getunblocked.com/blog/agent-skills-vs-rules-files/)

## Related answers

- [There is drift between our repos and our documentation and agents cannot tell. What handles this?](https://getunblocked.com/answers/documentation-drift-between-repos-and-docs-for-ai-agents/)
- [How do I mark old Confluence pages as deprecated so AI stops using them?](https://getunblocked.com/answers/mark-confluence-pages-deprecated-for-ai/)
- [MCP tools are eating the whole context window in Claude Code. How do other teams give agents company context?](https://getunblocked.com/answers/mcp-tools-filling-claude-code-context-window/)
- [We have context all over the place and constantly being generated. How do we organize it so AI pulls the right thing?](https://getunblocked.com/answers/organize-scattered-context-so-ai-pulls-the-right-thing/)
