Context Management
The difference between useful code review and noise isn't how much context you provide — it's having the right context. diffray uses a sophisticated context management system that ensures every agent receives precisely the information it needs.
The Context Problem
Modern LLMs can handle 200k+ tokens, but research consistently shows that more context doesn't mean better results:
Context Dilution
When you dump an entire codebase into an LLM:
- Signal drowns in noise — important details get lost among irrelevant code
- The "lost middle" effect — information in the middle of long contexts gets ignored
- Attention spreads thin — the model can't focus on what matters
- False positive explosion — generic patterns trigger without understanding actual usage
Studies show 10-20% performance degradation when too many documents are included, and context-dump approaches often produce 60-80% false positive rates.
The Practical Limit
While context windows keep growing, practical performance still hits a ceiling around 25-30k tokens for complex reasoning tasks. Beyond that, you're paying for tokens the model can't effectively use.
Curated Context Approach
diffray solves this with intelligent context curation — gathering exactly what each agent needs, nothing more.
How It Works
1. Build Understanding → Dependency graph, call chains, file classification
2. Identify Relevant Code → Only files affected by or affecting the PR
3. Layer Context → Core (always present) + Extended (on-demand)
4. Agent-Specific Bundles → Each agent gets context for its specialty
Dependency Graph Analysis
Before review starts, diffray builds a comprehensive map of your codebase:
- Import/export tracking — understands how modules connect
- Type definition mapping — links types to their usages
- Call chain analysis — traces function calls across files
- Test coverage mapping — connects code to its tests
This graph enables precise context selection — when reviewing a file, we know exactly which other files are relevant.
Smart Filtering
Each agent receives context tailored to its task:
| Agent | Receives | Excludes |
|---|---|---|
| Security Expert | Auth flows, API endpoints, data handling | UI components, styling |
| Performance Specialist | Hot paths, loops, data structures | Documentation, configs |
| Type Safety Reviewer | Type definitions, interfaces, generics | Implementation details |
| API Contract Validator | Endpoint definitions, schemas, contracts | Internal utilities |
This focus means each agent can apply its full attention to relevant code, not wade through unrelated files.
Layered Context
Context is organized in layers:
Core Context (Always Present)
- The diff itself
- Direct dependencies of changed files
- Type definitions used in changes
- Relevant test files
Extended Context (On-Demand)
- Callers of modified functions
- Related implementations
- Documentation and conventions
- Historical patterns
Agents start with core context and fetch extended context only when their investigation requires it.
On-Demand Retrieval
Rather than loading everything upfront, agents retrieve additional context as needed:
Agent: "This function signature changed..."
→ Searches for all call sites
→ Finds 3 files using this function
→ Retrieves those specific sections
→ Analyzes actual impact
This approach:
- Keeps context focused — only what's needed for the current investigation
- Enables deeper dives — can follow leads without upfront token limits
- Reduces noise — irrelevant code never enters the analysis
Context Windows Per Phase
Different phases use context differently:
Data Preparation Phase
- Scans entire codebase structure
- Builds dependency graph
- Classifies files and patterns
- No detailed code analysis yet
Summarize Phase
- Receives the complete diff
- Gets file-level context for each change
- Produces high-level summary for triage
Triage Phase
- Uses summary + file classifications
- Routes files to appropriate agents
- Bundles context for each agent
Review Phase
- Each agent gets:
- Relevant portions of the diff
- Direct dependencies
- Applicable rules
- Type definitions
- Agents can request additional context
Validation Phase
- Receives findings with evidence
- Gets code context for each finding
- Can invoke tools for verification
Comparison: Context Dump vs. Curated
| Aspect | Context Dump | Curated Context |
|---|---|---|
| Token usage | Max (wasteful) | Optimal (efficient) |
| Attention | Scattered | Focused |
| False positives | High (60-80%) | Low |
| Deep analysis | Limited | Enabled |
| Investigation | Impossible | Natural |
| Cost | Higher | Lower |
The Result
With curated context management:
- Every token serves a purpose — no wasted capacity
- Critical info stays in focus — no "lost middle" problem
- Agents go deep — full attention on their specialty
- Investigations are possible — agents can follow leads
- False positives drop — findings are grounded in actual context
This is why diffray catches issues that context-dump approaches miss — and why our findings are actionable rather than generic.
Learn more:
- AI Engines — the foundation powering context management
- Review Agents — specialized agents that use curated context