Context Engineering: Structuring PRDs and Architectural Memory for LLMs
Why LLM context windows degrade when overloaded with unstructured tokens, and how standardized filesystem schemas keep autonomous coding agents aligned with project constraints across hundreds of turns.
1. The Degradation of Long-Context Windows
Modern frontier models boast 200k to 2M token context windows. However, empirical testing reveals that as raw unstructured tokens accumulate in the attention buffer, the model's retrieval accuracy and adherence to architectural invariants experience severe degradation (the “lost in the middle” phenomenon).
Dumping an entire monorepo into the system prompt guarantees token bloat and hallucinated API boundaries. The solution is deterministic context engineering: maintaining structured, compact markdown records that agents dynamically load on demand.
Standard .context/ Hierarchy
.context/ ├── project-overview.md # Core technical goals, tech stack, constraints ├── architecture-decisions/ # Immutable ADRs for breaking choices (001-orm.md) ├── schemas/ # Canonical TypeScript / SQL database interfaces └── tasks/active-sprint.md # Real-time state machine for current execution
2. The ContextOS Standard
We formalized this research into ContextOS — an open-source project memory protocol designed for Claude Code, Codex, and CraftCode agents.
By enforcing compact schemas and automatic validation hooks, coding agents spend under 2,000 tokens to absorb the entire architectural context of a million-line repository.
Sakshyam Pokhrel
Founder of CraftResearch Tech. Exploring multi-agent systems and context engineering.
pokhrel.tech ↗
