How mitchforest/context-layer works
Purpose
Context Layer is a Claude Code extension that generates and maintains hierarchical AGENTS.md architecture documentation for arbitrary codebases. It is not an application runtime; its behavior is expressed through Claude agent prompts, skills, and a shell installer.
Installation and Entry Points
The distribution entry point is install/install.sh, intended to run from a target project root. It installs the packaged agents and skills into that project’s .claude/ directory.
User-facing Claude Code commands are defined by the installed skills:
• “Build context layer” — skills/context-layer.md
• Rule capture / placement — skills/add-rule.md
Orchestration Layer
The coordinator is the workflow authority in agents/context-layer-coordinator.md. It determines whether the target project needs an initial build, incremental update, review, or issue remediation; discovers documentable functional systems; and controls the capture/synthesis sequence.
It treats generated target-project state such as .context-layer/manifest.json and review output as persistent workflow inputs, even though those files are created outside this repository.
System Capture Stage
agents/context-layer-capture.md defines the per-system analysis worker. For each selected subsystem, it inspects source and dependency relationships and produces a focused AGENTS.md describing:
• ownership and exclusions,
• inbound and outbound dependencies,
• integration contracts,
• lifecycle/data flow,
• non-type-enforced invariants.
Capture is intentionally sequential under coordinator control, limiting overlap and allowing later captures to use earlier results.
Synthesis Stage
agents/context-layer-synthesis.md converts individual system captures into a navigable documentation hierarchy. It aggregates dependencies, identifies parent systems, adds architecture and data-flow context, and moves shared conventions to the lowest common ancestor.
A key preservation boundary is user-authored ## Rules: synthesis must retain these rather than overwrite them. The resulting hierarchy uses AGENTS.md as canonical content and CLAUDE.md symlinks for Claude Code compatibility.
Rules and Human Knowledge Boundary
skills/add-rule.md handles knowledge that cannot reliably be inferred from code: prohibitions, mandatory practices, defaults, and approval gates. It scopes a rule to the appropriate documentation node and can recommend elevating duplicated rules to a shared parent.
This separates generated architectural analysis from durable human policy, while allowing synthesis to reorganize code-derived material safely.
Runtime and External Dependencies
The required execution environment is Claude Code, including its agent-spawning capability and model selection (Opus for orchestration/synthesis or major captures; Haiku for smaller updates). Installation requires a POSIX shell plus network access to retrieve install/install.sh from GitHub. Generated documentation is designed to be consumable by other AI coding tools that read AGENTS.md or CLAUDE.md.
Main entry points: context-layer-coordinator.md Context Layer coordinator · install.sh Shell installer · context-layer-synthesis.md Documentation synthesis · context-layer-capture.md System capture
Components 14
Distribution
- Shell installer · Installs packaged agents and skills into a target project.
install/install.sh
Claude Code workflow
- Context Layer coordinator · Selects build, update, review, or remediation and controls capture.
agents/context-layer-coordinator.md - System capture · Sequentially documents each selected functional subsystem.
agents/context-layer-capture.md - Documentation synthesis · Builds the documentation hierarchy while preserving user rules.
agents/context-layer-synthesis.md - Build context layer
skills/context-layer.md - Add rule · Captures non-inferable human policy at the appropriate scope.
skills/add-rule.md
Target project outputs
Created in the project being documented.
- Target codebase
- Workflow manifest · Records generated workflow state for subsequent operations.
- System captures · Focused subsystem AGENTS.md analyses.
- AGENTS.md hierarchy · Architecture and data-flow documentation organized by system.
- CLAUDE.md symlinks · Claude Code-compatible links to canonical documentation.
- User-authored rules · Preserved Rules sections for prohibitions, defaults, and approval gates.
Other components
- Claude Code · Runs skills and agents with model selection and agent spawning.
- AI coding tools · Tools that consume AGENTS.md or CLAUDE.md.
Connections 21
- Shell installer → Build context layer: installs
- Shell installer → Add rule: installs
- Shell installer → Context Layer coordinator: installs
- Shell installer → System capture: installs
- Shell installer → Documentation synthesis: installs
- Claude Code → Build context layer: invokes
- Claude Code → Add rule: invokes
- Build context layer → Context Layer coordinator: starts
- Context Layer coordinator → Workflow manifest: reads workflow state
- Context Layer coordinator → Target codebase: discovers systems
- Context Layer coordinator → System capture: dispatches sequentially
- System capture → Target codebase: inspects
- System capture → System captures: produces
- Context Layer coordinator → Documentation synthesis: initiates
- System captures → Documentation synthesis: aggregates
- Documentation synthesis → AGENTS.md hierarchy: writes
- User-authored rules → Documentation synthesis: preserves
- Add rule → User-authored rules: places rules
- AGENTS.md hierarchy → CLAUDE.md symlinks: links via symlinks
- AGENTS.md hierarchy → AI coding tools: documents architecture
- CLAUDE.md symlinks → AI coding tools: compatibility access