Changing the AI context: How Moderne Prethink accelerates coding agents and reduces token use
Contents
- Coding agents are working without deterministic codebase context.
- Prethink resolves the codebase once so agents stop rebuilding it.
- The context starts from the Lossless Semantic Tree (LST).
- A starter recipe builds the knowledge base.
- The output is committed to the repository in formats agents can read.
- Agents read Prethink before they read code.
- The context refreshes when the code changes.
- Prethink covers the knowledge an experienced developer carries in their head.
- Agents see how the codebase is organized and which conventions recur.
- Service endpoints, database connections, and messaging patterns are resolved.
- The dependency tree includes transitives.
- Security configuration is visible without reading scattered files.
- Architecture is described in CALM.
- Tests are mapped to the code they cover.
- Deployment artifacts are connected back to the code they affect.
- Teams decide what context gets generated.
- Agents start every task already knowing the codebase.
A study by METR found that experienced developers took 19% longer to complete tasks when using AI tools. They were working in large, mature open source repositories that averaged about 10 years old and more than a million lines of code. Developers consistently overestimated how much the tools would help, and spent additional time correcting and rewriting generated code. They accepted less than half of the AI-generated code, and every developer reported having to modify the code they kept. The tools struggled most in large, complex repositories, where the knowledge that matters (architectural intent, conventions, dependencies, and the reasons behind old decisions) is not visible from any individual file or prompt.
Without reliable semantic context, agents infer, and inference produces rework and lost trust. If AI is going to deliver inside real-world codebases, the quality and structure of the context agents work from is the foundation to fix.
Moderne has been working on this problem since before agents entered the SDLC. As the creators of OpenRewrite, we built a multi-repo control plane that gives developers accurate, semantic insight into how code works at scale. Agents need the same thing.
We built Moderne Prethink to make that deterministic code understanding available to coding agents as structured knowledge, so they work faster and more accurately.
Prethink is not MCP, RAG, embeddings, or prompt engineering. Prethink is compiler-accurate code knowledge with patterns, dependencies, connections, endpoints, configurations, and conventions already resolved. Agents spend far less time working out how code is structured or behaves, and far fewer tokens rebuilding that understanding on every prompt. The source of truth is resolved ahead of time, refreshes with the code, and belongs to the team.
This 1-minute demo shows Prethink cutting an agent’s token spend on a real codebase question:
Coding agents are working without deterministic codebase context.
Most complaints about coding agents in enterprise codebases (“they can’t see all of my code,” “they burn through token budgets,” “they hallucinate and need checking constantly”) are a data problem rather than a model problem. The models don’t have the semantic context to be accurate and efficient, so they work from ad hoc, unstructured context, scoped by token limits and assembled differently every time.
Today an agent builds that context one of a few ways. It reads the code directly, file by file, which is expensive in tokens and still gives it a partial picture. It reads the documentation, which is only as reliable as the last person who updated it. Or it retrieves snippets on demand through grep, embeddings, RAG, or MCP-style tools. Retrieval finds text that looks relevant without resolving what it refers to, and the agent repeats it on every interaction.
All of that work to approximate understanding shows up downstream:
- Tokens and time. The agent reconstructs how the repo works before it can start on the task, so even a correct answer takes longer than it should.
- Fragmented understanding. Stitched-together snippets mean more inference, more blind spots, and more wrong assumptions.
- Context rot. As prompts and retrieved artifacts pile up over a session, the context gets noisier, and stale or oversized context makes performance worse.
- Inconsistent results. Without deterministic inputs, results vary between runs, need verification, and erode developer trust.
The knowledge teams worry agents lack (architectural boundaries, dependency relationships, security conventions, organizational standards) is already in the codebase, encoded in structure, configuration, dependencies, and patterns. Agents have no reliable way to read it.
Prethink resolves the codebase once so agents stop rebuilding it.
Prethink gives coding agents repository context as a structured, versioned summary derived from the Lossless Semantic Tree and committed alongside the code. An agent reads it once instead of exploring file by file. Context stops being a pile of prompts and snippets and becomes resolved, semantic knowledge derived directly from the code.
Build LST code models of repos
An LST is a fully resolved, compiler-accurate model of the repository, capturing both structure and meaning of the code.
Run Moderne Prethink recipes to build context
Prethink is generated using a set of recipes that run on the LSTs, bootstrapping repository-level knowledge quickly and consistently—structure, intent, constraints, and relationships.
Store resulting Prethink knowledge
Prethink recipes output inspectable CSV, Markdown, and CALM artifacts to a repo or context registry; agent configurations are updated to point to Prethink.
Agents access Prethink in their workflow
Agents reference Prethink to understand resolved knowledge about the code without needing to parse it—shifting agent effort away from inferring and toward execution.
Re-run Prethink recipes regularly
Teams control exactly when and how that context is refreshed—as part of the CI pipeline, on a scheduled cadence, or after major dependency updates and refactors.
The context starts from the Lossless Semantic Tree (LST).
The LST is the full-fidelity code model that has powered deterministic transformation in OpenRewrite for years. It captures both structure and meaning, reflecting what the code represents rather than what it looks like.
Unlike an AST or an embedding, it is a fully resolved, compiler-accurate model of the repository. The LST is:
- Lossless. No loss of actionable context for agents, including full type attribution, code intent, and comments.
- Semantic. Every symbol, type, method call, configuration reference, and dependency is resolved to what it actually refers to.
- Tree-based. Structured and navigable for search, extraction, and transformation with recipes.
That level of semantic resolution is what makes it possible to build context agents can trust and reuse. The same model is behind Trigrep, Moderne’s type-aware code search for agents.
A starter recipe builds the knowledge base.
The starter runs on the LSTs and bootstraps repository-level knowledge in one pass, and customers can customize it.
io.moderne.prethink.UpdatePrethinkContextStarter builds a comprehensive Prethink knowledge base using deterministic analysis. It exports structured data on dependencies (including transitive trees), test coverage, and related signals, and generates a CALM-formatted architecture diagram.
As a final step, the recipe updates the AI agent configuration files so agents know how to reference Prethink in their day to day work. The starter can also be customized to push Prethink data elsewhere, such as to a context registry.
The output is committed to the repository in formats agents can read.
Prethink writes its artifacts to the repository’s .moderne/context/ directory as Markdown, CSV, and CALM models, where they are versioned and reviewable like any other file.
| Files | What it contains | Examples |
|---|---|---|
| CSV files (data tables) | Structured data that AI agents can parse and query directly; used to generate CALM JSON | service-endpoints.csv, database-connections.csv, dependencies.csv |
| Markdown files | Context and schema information readable by humans and agents | service-endpoints.md, database-connections.md, dependencies.md |
| Architecture files | Architecture as a CALM JSON model, visualized with CALM-compatible tools, plus a Mermaid diagram | calm-architecture.json, architecture.md |
| Updated agent configuration | Enables progressive discovery so agents learn about context first, then read relevant files as needed | CLAUDE.md, AGENTS.md, .cursorrules, .github/copilot-instructions.md |
Agents read Prethink before they read code.
The updated configuration files tell the agent to consult Prethink as its primary source of repository context. The agent starts from resolved knowledge about the codebase instead of parsing it, and it understands the schema and meaning of the data without extra prompting. It can also use the CALM architecture model. Every agent working in the repo uses the same Prethink knowledge base.
The context refreshes when the code changes.
Because Prethink is derived from the code, agents work from context that reflects the current state of the repository. Teams control when it’s regenerated: in the CI pipeline, on a schedule, or after major dependency updates and refactors. Agents working through Moderne’s agent tools can also regenerate context incrementally after their own edits, so the knowledge base keeps up with the work the agent is doing. Nobody has to update it by hand.
Prethink covers the knowledge an experienced developer carries in their head.
To be effective in a real repository, an agent needs the same kinds of knowledge an experienced developer relies on (structure, intent, constraints, and relationships) made explicit and easy to consume. Prethink is designed around that principle, so agents reason faster and more consistently without having to infer or reconstruct it.
Agents see how the codebase is organized and which conventions recur.
Conventions like error handling, dependency usage, and idiomatic structures aren’t obvious from any single file. Prethink records them, so an agent learns how the code is used in practice.
Service endpoints, database connections, and messaging patterns are resolved.
External service calls are resolved too, so agents can reason about impact, integration boundaries, and downstream effects with confidence.
The dependency tree includes transitives.
Version relationships between direct and transitive dependencies are recorded, so impact, compatibility, and risk are visible without relying on incomplete scans.
Security configuration is visible without reading scattered files.
Prethink surfaces framework-level authentication setup and access controls, so an agent can check a change against how security is actually configured.
Architecture is described in CALM.
Component relationships are exported as CALM-formatted architectural artifacts that describe system structure explicitly. CALM (Common Architecture Language Model) was defined in FINOS as a model both humans and machines can read, so architectural decisions are applied consistently and are easy to audit.
Tests are mapped to the code they cover.
Coverage is mapped at the endpoint or method level, with each test linked to the implementation it exercises.
Deployment artifacts are connected back to the code they affect.
Docker and Kubernetes configurations are included, so agents account for deployment constraints and operational considerations when evaluating a change.
Teams decide what context gets generated.
Recipes generate Prethink’s knowledge, and teams can edit and compose those recipes like any other code. Teams decide what context matters most for their agents: architectural boundaries, dependency usage, security considerations, conventions, migration goals, or all of the above.
Agents then reason from the understanding the organization expects instead of from ad hoc prompts or tribal knowledge. Generating only the context a team chose also keeps irrelevant data out of the agent’s context and removes the need for brittle prompt engineering.
For a closer look at where agent tokens go, and why most of them are spent reading rather than writing, see Context engineering: why AI coding agents spend most of their tokens reading, not writing.
Agents start every task already knowing the codebase.
When agents have access to Moderne Prethink, they don’t need to guess how a repository works or what’s allowed. They reason from facts, spend their token budget on the task instead of on understanding the code, and produce consistent results across developers and sessions.


