Maintain compiled context artifacts for stateless agent spawning...
Triggers: "compile context", "update context", "cms compile", "cms update", "refresh context"
Maintain a set of compiled context artifacts so any agent can spawn stateless and still get deep, up-to-date understanding without rereading the entire repo.
CMS produces:
Agents consume these artifacts on startup instead of scanning the repo.
All artifacts live in .claude/compiled/:
.claude/compiled/
├── BOOT_CONTEXT.md # Stable project brain (~500-1500 tokens)
├── DELTA_CONTEXT.md # Recent changes (~200-500 tokens)
├── FEATURES/ # Working-set context slices
│ ├── <feature>.md
│ └── ...
├── MANIFEST.json # Hashes, timestamps, provenance
└── FEATURE_MAP.yaml # Feature definitions
Goal: The smallest truthful "project brain" that doesn't change often.
Contains:
Rules:
Goal: What changed since last compile, with implications.
Contains:
Rules:
Goal: Working-set context slices for parallel agents.
Each feature file includes:
Goal: Deterministic rehydration + auditing.
Tracks:
Every worker agent spawn uses this startup order:
.claude/compiled/BOOT_CONTEXT.md.claude/compiled/DELTA_CONTEXT.md.claude/compiled/FEATURES/<feature>.mdHard prohibition: Do not scan directories or "rediscover architecture" unless CMS explicitly marks "unknown".
This is what makes the system save tokens.
Triggers:
Output:
Triggers:
Output:
PROJECT=$(basename $(pwd))
COMPILED_DIR=.claude/compiled
mkdir -p $COMPILED_DIR/FEATURES
# Get current git state
git rev-parse HEAD
git status --porcelain
Read to understand:
Write using template from references/BOOT_CONTEXT_TEMPLATE.md:
# BOOT_CONTEXT | <project> | <timestamp>
## Architecture
[Dense overview - what this project IS]
## Invariants
[Rules that must never be broken]
## Key Flows
[How data/control moves through the system]
## File Map
[Critical files with purposes - NOT every file]
## Conventions
[Code style, naming, patterns to follow]
## How to Work Here
[Agent-specific guidance for this codebase]
On full compile, write:
# DELTA_CONTEXT | <project> | <timestamp>
## Baseline
Compiled from: [commit hash]
No prior delta - clean compile.
## Changes
None - fresh compile.
## Agent Actions
Read BOOT_CONTEXT, then proceed with assigned task.
Read FEATURE_MAP.yaml (create if missing using template).
For each feature, generate FEATURES/<feature>.md:
# Feature: <name>
## Purpose
[What this feature does]
## Key Files
- `path/file.ts:L10-50` - [what it does]
## Invariants
[Rules for this feature]
## Current Tasks
- [ ] Task from CONTEXT.md if applicable
## Known Issues
- [Issue] → [Workaround]
## Interface
**Inputs:** [what this feature receives]
**Outputs:** [what this feature produces]
**Depends on:** [other features]
{
"compiled_at": "2026-01-20T23:00:00-05:00",
"mode": "compile",
"baseline": {
"git_commit": "abc123def",
"dirty": false
},
"inputs": {
"files": {
"src/index.ts": "sha256:...",
"package.json": "sha256:..."
}
},
"outputs": {
"BOOT_CONTEXT.md": "sha256:...",
"DELTA_CONTEXT.md": "sha256:...",
"FEATURES/api.md": "sha256:..."
},
"features": {
"api": {
"files": ["src/api/"],
"keywords": ["endpoint", "route", "handler"]
}
}
}
CMS Compile Complete
BOOT_CONTEXT.md: Generated (1,234 tokens)
- Architecture: 5 sections
- File map: 12 files
DELTA_CONTEXT.md: Reset (clean compile)
Features: 3 bundles
- api: 4 files tracked
- ui: 6 files tracked
- data: 2 files tracked
MANIFEST.json: Written
Baseline: abc123def
Compiled: 2026-01-20 23:00
MANIFEST=.claude/compiled/MANIFEST.json
# If no manifest, trigger full compile instead
if [ ! -f "$MANIFEST" ]; then
echo "No manifest - run compile first"
exit 1
fi
BASELINE=$(jq -r '.baseline.git_commit' $MANIFEST)
# Files changed since baseline
git diff --name-only $BASELINE HEAD
# Uncommitted changes
git status --porcelain
Bucket each changed file:
For each relevant changed file, record high-level changes:
Keep it factual, not narrative.
# DELTA_CONTEXT | <project> | <timestamp>
## Baseline
Prior compile: [old commit] → Current: [new commit]
## Changes Since Baseline
- `src/api/routes.ts` - Added /users/:id endpoint
- `src/utils/cache.ts` - NEW: caching utility
- `config.json` - Added CACHE_TTL setting
## Implications
- New endpoint requires auth middleware
- Caching may affect test isolation
## New Decisions
- Use in-memory cache for v1 (rationale: simplicity)
## Risks / Blockers
- Cache invalidation strategy TBD
## Agent Actions
1. When working on API: note new /users/:id endpoint
2. When writing tests: account for cache side effects
BOOT_CONTEXT changes only if:
If only DELTA-level changes, BOOT stays stable.
For each feature whose files changed:
Update all hashes, timestamp, and baseline.
CMS Update Complete
BOOT_CONTEXT.md: Unchanged
DELTA_CONTEXT.md: Updated
- 3 file changes
- 1 new decision
- 2 agent actions
Features: 1 updated
- api: +1 file, tasks updated
MANIFEST.json: Updated
Baseline: abc123 → def456
Updated: 2026-01-20 23:30
# Feature definitions for parallel agent work
api:
description: REST API endpoints and handlers
files:
- src/api/
- src/routes/
keywords: ["endpoint", "route", "handler", "middleware"]
depends_on: []
ui:
description: Frontend components and views
files:
- src/components/
- src/views/
keywords: ["component", "render", "useState", "props"]
depends_on: [api]
data:
description: Data layer and storage
files:
- src/models/
- src/db/
keywords: ["model", "schema", "query", "database"]
depends_on: []
A feature bundle must include:
.claude/runtime/agents/<agent_id>/SESSION.md
Each agent writes its own session notes here.
.claude/CONTEXT.md remains the official shared human-approved state.
Agents propose updates, CMS (or human) merges them.
| Skill | Relationship |
|---|---|
session-save |
Human-facing session handoff; CMS is agent-facing compiled context |
context-extract |
Verbose history archive; CMS is optimized snapshot |
onboard |
Should read BOOT_CONTEXT + DELTA if available |
| Need | Use |
|---|---|
| Quick human handoff | session-save |
| Full history archive | context-extract |
| Agent spawning | context-manager (this) |
| Getting up to speed | onboard + CMS artifacts |
Templates in references/:
BOOT_CONTEXT_TEMPLATE.md - Template for BOOT_CONTEXTDELTA_CONTEXT_TEMPLATE.md - Template for DELTA_CONTEXTFEATURE_TEMPLATE.md - Template for feature bundlesMANIFEST_SCHEMA.json - JSON schema for MANIFESTFEATURE_MAP_TEMPLATE.yaml - Template for feature definitions