Pillar · Context Engineering

Context Engineering for Coding Agents.

Prompt engineering phrases one request. Context engineering designs everything the model sees across a whole session, and it is where most agent failures and most of the token bill actually live.

Direct answer

Context engineering is the practice of curating the exact tokens a coding agent sees on each turn: system instructions, retrieved code, memory, tool definitions, and history. The community-standard taxonomy is four levers, Write (persist knowledge outside the window), Select (retrieve the right slice at the right moment), Compress (shrink what enters via caps, compaction and folding), and Isolate (give subtasks fresh windows via subagents). Anvaya implements all four as infrastructure: the Mind graph Writes experience as typed, decaying nodes; six-stage Prism retrieval plus submodular Quorum packing Selects under a 2000/4096-token budget; the context guard and macro compaction Compress by default, with micro-fold measured at −11.0% median uncached (n=5, verification 19/19) and gated for promotion; subagents and output caps Isolate noise. The per-node 12–25x ratio and 2–4K target are design estimates, not a measured session average.

The Four Levers

Write, Select, Compress, Isolate.

The vocabulary the whole industry converged on, implemented as running code, not advice.

01Write: persist outside the windowStanding knowledge lives in files the agent reads every session (AGENTS.md, CLAUDE.md, .anvaya/mind/). Anvaya Mind goes further: session outcomes become typed nodes (Decision, Pattern, BugFix, Approach) with half-lives, so the standing context improves instead of rotting.
02Select: retrieve at the moment of needSix-stage Prism retrieval (keyword FTS, file + symbol semantic search, recency, graph expansion, bug-boost) plus intent bias, then submodular Quorum packing under a 2000/4096-token budget. The agent gets the few nodes that matter, not the whole graph.
03Compress: keep only what the step needsThe shipped default is a context guard plus macro compaction: each tool output is capped at 30% of the window with an explicit re-fetch marker, and a two-stage summary fires at 80% with hard-drop at 95%. Micro-fold (disk artifact offload) measured −11.0% median uncached and stays gated pending promotion; retired meso variants are published as negative results.
04Isolate: keep unrelated work apartSubagents get fresh windows and return 1–2K summaries; tool outputs are capped before they enter context; the daemon watches files so indexing never pollutes the loop. Noise never reaches the model.

The Numbers

What Bad Context Costs.

Observed session data and per-node design estimates from Anvaya's memory design work.

018.59M tokens, one sessionObserved Claude Code session at 97.2% cache: ~90% of tokens re-reading files, ~10% reasoning. Without memory, every session re-learns the codebase at full price.
02~50K → 2–4K per turnPackedContext design estimate: six-stage retrieval plus Quorum packing serves a few thousand curated tokens instead of tens of thousands of raw file reads.
0312–25x per node typeFiles ~20x, decisions ~16x, bugfixes ~24x, threads ~25x, per-node design estimates. Measured end-to-end: micro-fold −11.0% median uncached (n=5, verification 19/19).

Questions

Asked About Context Engineering.

Q

What is context engineering?

The set of strategies for curating the optimal token set a model sees on each inference call, system instructions, retrieved code, memory, tool outputs, history. Anthropic's one-liner: the smallest possible set of high-signal tokens that maximizes the chance of the desired outcome. Prompt engineering phrases one request; context engineering designs the whole information environment across a session.

Q

Why doesn't a bigger context window fix bad context?

Models attend unevenly across long windows (lost-in-the-middle), every extra token costs money on every subsequent turn, and irrelevant content actively degrades answers: 30–70% of typical agent context is noise. A focused 5K context routinely beats a stuffed 50K one. Windows are headroom, not an invitation.

Q

How does Anvaya do context engineering automatically?

Three compounding layers: the Mind graph stores experience as typed, decaying, drift-checked nodes; Prism + Quorum retrieve and pack only the top few under a token budget each turn; the context guard, macro compaction and (gated) micro-fold control what enters. Session N+1 draws on calibrated memory instead of a blank slate, so context quality can rise with use, which Phase 6 of the benchmark program measures.

Q

What is the 8.59M-token problem?

An observed Claude Code session that burned 8.59M tokens (97.2% cache) with ~90% spent re-reading files and ~10% reasoning, a 175:1 input-to-output ratio. It is the canonical example of what happens without a memory layer: every session pays full price to re-learn the codebase.

Q

Do I still need AGENTS.md or CLAUDE.md with Anvaya?

Yes, keep short, non-inferable rules in versioned instruction files (they load every turn and survive compaction). Anvaya handles the rest: the accumulated why behind decisions, bug history, and patterns that don't belong in a hand-maintained file. Studies show well-scoped instruction files cut runtime ~29% and output tokens ~17%.

Run Agents That Fit On Your Laptop.

25.6 MB median RSS. 25 agents ran in parallel on a Core 2 Duo with 4 GB RAM. Hundreds on your machine. Zero cloud required on the Ollama path.

Requires Rust/cargo to build from source. Linux and macOS today, Windows not yet supported. Pre-1.0, public beta. Pricing TBD.