Skip to content

Context cache bands

A client keeps the longest unchanged prefix of an instruction file in its prompt cache. One edit near the top of a compiled file invalidates every byte after it. Cache bands order AGENTS.md so the text that rarely changes comes first.

Start here

Add three marker lines to AGENTS.md, each on a line of its own:

<!-- praetor:head -->
<!-- praetor:config -->
<!-- praetor:tail -->

A marker opens its band and the band runs to the next marker. Text before the first marker is head. Then run praetorctl compile-context.

Band Put here Changes when
head title, invariants, operational rules never in a normal run
config the text register block, ## <Client> sections a manifest or client edit
tail verification commands, repository-state text the repository changes

The bands order AGENTS.md itself and any full-content projection compiled from it. Pointer vendor files (CLAUDE.md, .cursor/rules/hiss-invariants.mdc, .windsurfrules, .gemini/GEMINI.md and .codex/rules.md) refer to AGENTS.md instead of copying shared text (an @AGENTS.md or @../AGENTS.md import, native AGENTS.md reading, or the fallback sentence "Read AGENTS.md for canonical agent instructions." for an undocumented target in canonicalReference in internal/agentcontext/render.go), and keep only their static generated header and their own ## <Client> section in the config band. Copilot's .github/copilot-instructions.md sets fullContent: true in internal/agentcontext/render.go and copies the shared head, config and tail bands with its ## GitHub Copilot section in the config band (TestProjectionLoadingContract in internal/agentcontext/pointer_test.go, TestBandsEmitHeadConfigTailInOrderForEveryVendorFile in internal/agentcontext/bands_test.go), because Copilot IDE chat and code review include surfaces that do not load AGENTS.md. The markers do not appear in the compiled files. Blank lines at a band edge are trimmed and the bands are joined by one blank line.

Reference

  • A ## <Client> section (## Claude Code, ## Cursor, ...) always joins the config band, and a marker ends the section.
  • A marker inside a fenced code block is text, not a marker.
  • An AGENTS.md without markers compiles in source order. compile-context --verify, compile-context --verify-stable and praetorctl audit print a warning that names the markers to add.
  • This repository's AGENTS.md places the markers after the title, before ## Text Register and before ## Primary Verification Commands.

Stability gate

praetorctl compile-context --verify-stable checks two things:

  1. Two renders of AGENTS.md under different injected clocks and shuffled target visit orders (agentcontext.RenderEnv) produce identical bytes in every vendor file. Today the renderer reads neither the clock nor the order, so this half guards later changes: a render that starts to read RenderEnv.Now or the visit order is refused (TestVerifyRenderTwice_Negative_ClockReadingRenderRefused).
  2. The head band holds no volatile text. The scanner matches exact shapes only, so ordinary prose passes (retry count: 3, Run: 2 passes, a static 40-digit commit pin, /var/tmp named in a sentence):
  3. a timestamp with seconds (2026-10-07T12:30:00Z, 2026-10-07 12:30:00Z, 2026-10-07T12:30:00);
  4. sha256: followed by 12 or more hex digits (abbreviated or full digest);
  5. an absolute path: /home/<name>/..., /Users/<name>/..., /Volumes/<disk>/..., /root/... or /tmp/..., a path with two components under /var /mnt /srv /opt /etc /usr /private /workspace /nix (/etc/ssl/certs), a drive path (C:\work, D:/work) or a UNC path (\\host\share);
  6. a run or build counter: run #7, run_id: <value>, build number 12, build #12.

compile-context --verify, praetorctl audit and MCP standards_audit run the same check, so a drifting or volatile head fails the gate that already guards the compiled files. The tests are internal/compiler/stable_test.go (a planted timestamp, digest, path and counter in the head are refused) and internal/agentcontext/bands_test.go (band order for every vendor file, render identity, final newline, and a head edit leaving the bytes before it and after it untouched). cmd/standardsctl/audit_context_stable_test.go and cmd/standards-mcp/audit_context_stable_test.go prove that the CLI and MCP audits refuse a planted head timestamp and print the unlayered warning for an unmarked source.

praetorctl compile-context also writes the text register block into the config band when a layered AGENTS.md has no register block yet (TestSpliceRegisterBlock_LayeredSourceGetsTheSectionInTheConfigBand).

Scope

This page covers the compiled context files. The MCP tool list and tool output are not changed by cache bands.

Client size caps and imports

praetorctl compile-context and --verify refuse oversized context before writing projections. The registry is beside vendorTargets in internal/agentcontext/render.go; the limits below were checked for issue #1674 on 2026-10-28.

File Cap Source
.codex/rules.md plus AGENTS.md and tracked nested files on one root-to-directory path 32,768 bytes together Codex CLI agents_md.rs and config/mod.rs, project_doc_max_bytes default
.gemini/GEMINI.md 24,000 bytes after import expansion Antigravity rules; Antigravity reads this file too, so the strictest reader wins
.windsurfrules plus AGENTS.md 12,000 Unicode characters Windsurf documentation, workspace rule limit

The remaining vendor targets have no documented hard size cap in this registry. Generated headers count toward the loaded context caps. Every client's line budget also counts the text it loads: its projection plus AGENTS.md for native readers (Cursor, Windsurf and Codex, plus any sentence-fallback target) in directSize (internal/agentcontext/imports.go) and the largest tracked nested AGENTS.md chain for Codex (checkLoadedSize), the full-content projection alone for Copilot (directSize, TestCopilotLoadedLineBudget in internal/agentcontext/pointer_test.go; issue #2029 tracks the Copilot cloud agent, which loads both .github/copilot-instructions.md and AGENTS.md), or the expanded imports for Claude Code and Gemini CLI (expandedSize). Client-owned sections count wherever loaded, including both files when a native reader loads both. TargetFile.LineCount continues to describe the emitted file alone; the loaded line budget is checked separately by the renderer. A refusal names the file, measured size, unit and cap, for example: target file .gemini/GEMINI.md exceeds client size cap (25000 bytes > 24000). A Codex AGENTS.md refusal also names the deepest file of the largest nested chain, the path to trim.

A standalone @path line outside fenced code is an import. Paths resolve from the repository root. Claude Code and Gemini CLI keep that line; their sizes include the imported content in place of the line, including nested imports. Client-only imports in Cursor, Copilot, Windsurf and Codex rules instead receive See path (read on demand). Fenced examples, indented lines and inline mentions remain unchanged. This translation adds no automatically loaded content for clients without @path expansion.

Expansion uses an iterative stack, refuses cycles, and allows four import hops for Claude Code and five for Gemini CLI. Missing or unreadable imports name the path. Reads use the compiler's confined, deadline-bound snapshot reader, limited to 1 MiB per file; traversal is bounded to 256 imports per projection. These safety bounds also apply to import-capable clients without a documented size cap. Import behavior sources: Claude Code memory and Gemini CLI context files, checked for issue #1674 on 2026-10-28.

Regression evidence: internal/agentcontext/imports_test.go covers byte and character boundaries, canonical-plus-projection line boundaries for all six clients, nested and repeated import line budgets, translation, fenced examples, expansion, cycles, missing files and depth limits; internal/compiler/imports_test.go exercises real file reads, nested project documents, compile/write/readback and verification refusal.

Adopted repositories

praetorctl adopt writes the harness with the three markers (internal/adopt/harness.go), so a fresh adoption compiles layered (TestHarnessCarriesTheCacheBandMarkers).

An already adopted repository keeps its existing AGENTS.md: a plain praetorctl adopt leaves the harness as it is and adds no markers. Run praetorctl adopt --force to refresh the harness region with the markers, or add the three markers by hand as shown above. Until then compile-context compiles in source order and warns.