An AI coding agent's context window represents its entire working memory. In modern software engineering with frontier reasoning models (Gemini 3 Pro, Claude 3.5 Sonnet / 3.7 Sonnet, GPT-5 / o3), the context window is both finite and perishable: as token count scales, attention degrades exponentially across long horizons — an empirical reality known as context rot.
Context engineering has superseded conversational prompt engineering as the definitive discipline of agentic software development. The central engineering challenge is no longer "how do I phrase this prompt?", but rather: "How do I supply the exact, minimum-entropy set of ground-truth tokens required for the current execution step while keeping irrelevant context externalized?"
flowchart TD
subgraph Tier_1["Tier 1: Standing Invariants (500–1,500 tokens)"]
RULES["Root Instruction Files<br/>(AGENTS.md / CLAUDE.md)"]
CONTRACTS["Core Normative Rules & Architectural Boundaries"]
RULES --- CONTRACTS
end
subgraph Tier_2["Tier 2: Progressive Procedural Skills (Deferred)"]
SKILLS_DEF["Skill Registry / Headers<br/>(name + 60-token description)"]
SKILL_BODY["Loaded Skill Body<br/>(.agents/skills/<name>/SKILL.md)"]
SKILLS_DEF -->|Triggered on demand| SKILL_BODY
end
subgraph Tier_3["Tier 3: Ephemeral Session Memory (Active Working Window)"]
HIST["Conversation Trajectory & Tool Call I/O"]
DIFF["Working Tree Diffs & Scratch Scripts"]
HIST --- DIFF
end
subgraph Tier_4["Tier 4: Sovereign Semantic Knowledge Base (Externalized)"]
WIKI[("Wikantik Semantic Knowledge Base<br/>(Living specs, ADRs, RDF Knowledge Graph)")]
MCP["Knowledge MCP Server<br/>(/knowledge-mcp, 21 read tools)"]
WIKI --- MCP
end
Tier_1 --> AGENT{"Coding Agent Runtime<br/>(Antigravity agy / Claude Code)"}
Tier_2 --> AGENT
Tier_3 <--> AGENT
AGENT <-->|Dynamic Retrieval: assemble_bundle / get_page_for_agent| Tier_4
A robust context architecture partitions project knowledge across four distinct operational tiers:
| Tier | Substrate | Token Lifetime | Cost Timing | Purpose | Failure Mode if Misplaced |
|---|---|---|---|---|---|
| Tier 1: Standing Invariants | Root repository files (AGENTS.md, CLAUDE.md) | Permanent across all sessions | Incurred unconditionally on session initialization | Absolute rules, non-derivable constraints, build/test command truth | Kitchen-sink bloat; rule dilution |
| Tier 2: Progressive Skills | Modular skill directories (.agents/skills/*/SKILL.md) | Injected only when skill is activated | Header: 50–80 tokens; Body: 1,500–3,000 tokens at trigger time | Procedural runbooks and complex step-by-step methodologies | Context hoarding if loaded upfront |
| Tier 3: Ephemeral Working Memory | Agent session scrollback, scratchpad, CLI tool outputs | Ephemeral to the active task (cleared on /compact or new session) | Dynamic; burns window during execution | In-flight reasoning, diff analysis, compiler error diagnostics | Context rot; loss of focus |
| Tier 4: Sovereign Knowledge Base | Semantic wiki (Wikantik) via Model Context Protocol (MCP) | Externalized; queried on demand via hybrid retrieval | Micro-queries (200–1,200 tokens) returned via token-budgeted tools | Living architectural contracts, ADRs, schema mappings, multi-repo truth | Stale documentation drift; hallucinations |
AGENTS.md and CLAUDE.md)Standing instruction files represent the project's permanent voice. Every mature coding agent framework loads these files automatically upon session boot (AGENTS.md in Antigravity and Codex; CLAUDE.md in Claude Code).
jspwiki; propose architectural handoffs as wiki RFCs")../bin/wikantik lint <slug> rather than generic linter assumptions).\$").In the Simple Agility ecosystem, every repository installs a standardized Agent Header pointing to the central architectural hub on Wikantik:
<!-- SIMPLE-AGILITY-AGENT-HEADER-START -->
## Simple Agility Architectural Context
This repository is part of the **Simple Agility** small-business ecosystem:
- **Role in Stack:** Content strategy, SEO telemetry analysis, and architectural coordination engine.
- **Architecture Hub:** Refer to `SimpleAgilityStackHub` on Wikantik (`https://wiki.wikantik.com/SimpleAgilityStackHub`).
- **Active Initiatives & Coordination:** Check `SimpleAgilityAgentCoordination` for in-flight tasks and cross-repo dependencies.
- **Architectural Decisions:** Consult `SimpleAgilityDecisionLog` before changing cross-repo APIs, logging, or telemetry conventions.
<!-- SIMPLE-AGILITY-AGENT-HEADER-END -->
By enforcing this header, any agent initialized in any repository immediately acquires orientation and the exact wiki slugs required for deeper retrieval.
Attempting to place every operational runbook into AGENTS.md triggers immediate context exhaustion. The proven defense is progressive disclosure:
sequenceDiagram
autonumber
actor User as Engineer
participant Agent as Coding Agent Runtime
participant Skills as Local Skill Registry (.agents/skills)
participant Execution as Product Repository
User->>Agent: "Execute structured page curation on VectorIndexingInternals"
Note over Agent: Agent matches intent against 60-token description in skill registry
Agent->>Skills: Loads SKILL.md for project_structured_page_curation
Skills-->>Agent: Injects full procedural runbook (1,800 tokens)
Agent->>Execution: Executes step-by-step curation commands
Agent-->>User: Reports verified outcome
A procedural skill packaged in .agents/skills/<name>/SKILL.md contains two functional blocks:
By loading only the descriptor into the root context, the harness defers 98% of the token cost until the agent actively determines that the skill's capabilities are required.
While instruction files and skills scale within a single repository, they break down across multi-repository architectures. If an engineer manages five microservices or distinct components (stockroom
, roller
, jakemon
, wealthview
, wiki-content-agent
), copy-pasting documentation across repos guarantees desynchronization and stale drift.
The Level 5 maturity pattern (AgenticCodingMaturityModel) replaces local file hoarding with an authoritative external knowledge plane:
flowchart LR
subgraph Repositories["Decoupled Product Repositories"]
R1["roller (docker2)<br/>Customer Weblog"]
R2["stockroom (docker1)<br/>Inventory WMS"]
R3["jakemon (inference)<br/>Observability Plane"]
end
subgraph Knowledge_Plane["Sovereign Knowledge Backbone (Wikantik)"]
WIKI_CORE[("Wikantik Core Engine<br/>Markdown + Frontmatter")]
KG[("RDF Knowledge Graph<br/>Entities & SPARQL")]
MCP_K["Knowledge MCP Server<br/>(/knowledge-mcp)"]
WIKI_CORE --- KG
KG --- MCP_K
end
R1 <-->|assemble_bundle / get_briefing| MCP_K
R2 <-->|read_pages / get_page_for_agent| MCP_K
R3 <-->|sparql_query / retrieve_context| MCP_K
The Wikantik Knowledge MCP server (https://wiki.wikantik.com/knowledge-mcp) provides 21 read-only tools designed specifically for high-efficiency agent grounding:
assemble_bundle(query): The primary retrieval tool. Runs hybrid BM25 + dense vector semantic search, extracts relevant section chunks, de-duplicates overlapping text, and computes a mathematical coverage.confidence score (strong, adequate, weak).get_page_for_agent(canonicalId, tokenBudget): Returns a token-budgeted projection of a page. Rather than dumping an entire 3,000-word markdown file into context, it emits:
verified_at, verified_by)retrieve_context(query): Returns ranked page and section candidates without full bodies, allowing the agent to evaluate relevance before committing context budget.read_pages(slugs): Fetches raw markdown for up to 20 verified slugs in a single batched network round-trip.sparql_query(query): Executes read-only SPARQL queries over the RDF Knowledge Graph to resolve architectural relationships, component dependencies, and ontology hierarchies deterministically.To wire coding agents directly to Wikantik, configure Streamable HTTP in the project's .mcp.json:
{
"mcpServers": {
"wikantik-knowledge": {
"type": "http",
"url": "https://wiki.wikantik.com/knowledge-mcp",
"headers": {
"Authorization": "Bearer ${WIKANTIK_KNOWLEDGE_API_KEY}"
}
}
}
}
Context is not an unlimited commodity; attention efficiency decays mathematically as the working context expands.
Empirical attention retention across long token sequences can be formalized by an exponential decay function:
Where:
When active tokens exceed 50% of nominal capacity without externalized notes, the probability of instruction omission or hallucinated API parameters scales rapidly.
To maintain optimal reasoning fidelity (retention ≥ 0.85), the orchestrator enforces a strict budget allocation:
When complex refactoring spans hours or days, context engineering relies on three complementary architectural mechanisms:
When context utilization crosses a threshold (~75%), mature harnesses trigger compaction. The craft of compaction is asymmetric retention:
The agent must write durable state outside the context window. Storing execution progress in on-disk plan files or scratch scripts (scratch/plan.md) ensures that if a session crashes, compacts, or transfers to a secondary agent, the plan is re-read cold with zero fidelity loss (SpecDrivenDevelopment).
Tasks requiring extensive file scanning or broad log exploration should be delegated to ephemeral subagents. A subagent consumes its own isolated 60,000-token window exploring 40 source files, returning only a 300-token distilled summary to the primary coordinator.
CLAUDE.md: Dumping complete API documentation, database schemas, and style guides into the standing instruction file. This burns 15,000 tokens on every prompt and causes the model to ignore foundational safety rules.view_file.CLAUDE.md, a skill prompt, and an external wiki page state contradictory rules, the agent resolves the conflict non-deterministically. Maintain one authoritative source of truth per domain (SimpleAgilityDecisionLog).