Context optimization
Collect, score, compress, and pack repository context before agents run.
Context optimization
Context optimization is implemented in application/internal/contextopt: a collector gathers candidate files, a relevance scorer ranks them, a reducer or compressor trims low-value material, and a packer emits the blob agents actually see. The intent is to send smaller, better-targeted context to paid APIs while keeping the reduction rules inspectable from the CLI.
Pipeline
flowchart LR
C[Collect files] --> R[Relevance score]
R --> X[Compress / reduce]
X --> P[Context pack]
P --> A[Agent prompt]CLI
agentflow context billing-v2 --task task-003
agentflow context billing-v2 --task task-003 --optimize
agentflow work "develop billing-v2" --show-context-planwork runs context optimization in the V3 pipeline unless --no-context-reduction is set.
Configuration
Investigation limits that cap grep output and large files are shared with local investigation: they live under mcp.investigation in config and apply even when the MCP server is disabled, because they govern the local tooling that feeds the collector.
Trade-offs
| Benefit | Limit |
|---|---|
| Smaller prompts | May drop relevant files if heuristics miss |
| Faster cloud calls | Not a substitute for reading critical paths manually |