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 summarization and compaction), 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; Token-Fold Compresses 12–25x per node type (~50K raw → 2–4K PackedContext); subagents and output caps Isolate noise. Result: sessions that get cheaper and sharper with use instead of re-paying the 8.59M-token re-reading tax.

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 needsToken-Fold Micro/Meso/Macro compression plus per-node ratios (files 20x, decisions 16x, bugfixes 24x, threads 25x). Typical sessions drop from ~50K raw tokens to 2–4K of PackedContext — a 12–25x per-node design estimate.
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 the Anvaya product repos.

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 compress ~20x, decisions ~16x, bugfixes ~24x, threads ~25x — measured per node type in the Mind repos, not a benchmark run.

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; Token-Fold compresses what enters. Session N+1 starts from calibrated memory instead of zero, so context quality rises with use.

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%.

Stop Starting From Zero.

One binary. 11+9 Rust crates. 545 tests. Hand-written HNSW index. Three transport modes. Four providers, Ollama, Anthropic, OpenAI, Siemens. Zero API keys required to start. Mind remembers everything after the first session.