Self-Maintaining Documentation System Using Fenced Blocks for Zero Drift

✍️ OpenClawRadar📅 Published: March 26, 2026🔗 Source
Self-Maintaining Documentation System Using Fenced Blocks for Zero Drift
Ad

A developer on r/ClaudeAI shared a solution for maintaining accurate documentation in multi-project workspaces where AI coding agents like Claude Code forget context between sessions. The system addresses problems with 8 projects, 20 Lambda functions, 42 API keys, 12 API endpoints, and 19 environment variables where the agent would guess at function names, edit wrong files, and lose context.

The Fence System

Instead of asking Claude to update docs after implementation, the developer built a 740-line bash script that extracts structured data directly from source files and injects it into CLAUDE.md through fenced HTML comment blocks. Each CLAUDE.md has fences marking auto-generated sections:

## Serverless Functions <!-- auto:lambdas generated="2026-03-26" source="infrastructure/lib/api-stack.ts" -->
| Function | Route | Memory | Timeout |
|----------|-------|--------|---------|
| quote-save | /quotes/save | 256MB | 15s |
| quote-get | /quotes/get | 256MB | 15s |
...20 rows extracted from CDK config...
<!-- /auto:lambdas -->

## Architecture <-- hand-written, never touched by the script

How It Works

The script:

  • Parses actual source files (CDK TypeScript, FastAPI Python, package.json, etc.)
  • Extracts structured data (function names, routes, env vars, dependency versions)
  • Replaces everything between the fences
  • Updates the generated date to show freshness
  • Validates: checks that every Lambda name has a matching handler file, every env var exists in .env

Hand-written sections (architecture descriptions, gotchas, business logic context) live outside fences and are never touched.

Auto-Generated Content

  • Quoting tool (20 Lambdas): Lambda inventory, CDK stacks, env vars, test counts, deps from CDK TypeScript and package.json
  • Sales dashboard (12 endpoints): API routes, theme list, deps from FastAPI decorators, TypeScript types, and requirements.txt
  • Data parsing (42 Users): User data, deps from Python credential file and requirements.txt
  • 5 other projects: Dependency versions from package.json/requirements.txt
Ad

Staleness Warning System

A doc-sync hook (fires after every code edit) checks the generated date on each fence. If any section is older than 7 days:

Warning: 3 auto-generated sections in agent-quoting-tool/CLAUDE.md are stale (oldest: 2026-03-19).
Run: ./scripts/generate-inventory.sh quoting

This is non-blocking — warns but never stops you from working. The staleness check rides alongside existing hooks with the same 10-minute throttle window, zero extra overhead.

Implementation Details

The setup uses pure bash with grep/sed/awk/jq, zero dependencies. Commands:

scripts/generate-inventory.sh all # Refresh everything
scripts/generate-inventory.sh quoting # Just one project

The script backs up each CLAUDE.md first (one backup per day, per project). The developer notes not to parse ASTs from bash — their TypeScript parser is a line-by-line grep/sed loop that works for controlled files but would be fragile for arbitrary TypeScript.

Key Insights

The fences allow auto-generated and hand-written content to coexist in the same file. Claude reads the whole CLAUDE.md at session start and gets both: accurate extracted data AND human context it can't infer from code. The developer recommends starting with highest-value extractions (Lambda inventories and env var tables that cause bugs when they drift) and notes that the staleness warning is more valuable than auto-running.

The entire system took about 3 hours to build (design, implementation, testing, first run).

📖 Read the full source: r/ClaudeAI

Ad

👀 See Also

MephisQuiz: Free Scenario-Based Quiz Platform for Engineering Role Assessment
Tools

MephisQuiz: Free Scenario-Based Quiz Platform for Engineering Role Assessment

An SRE professional built MephisQuiz, a free quiz platform with 860+ scenario-based questions across 4 engineering role tracks. The platform uses adaptive difficulty, provides topic-by-topic breakdowns, and was developed using Claude AI as a pair programmer.

OpenClawRadar
cc-soul plugin adds persistent memory and adaptive personas to OpenClaw
Tools

cc-soul plugin adds persistent memory and adaptive personas to OpenClaw

The cc-soul plugin for OpenClaw provides permanent memory storage across sessions, 10 auto-switching personas, and learning from corrections. Installation requires one command with zero configuration.

OpenClawRadar
Quick-Question Plugin Automates Unity Development with Claude Code
Tools

Quick-Question Plugin Automates Unity Development with Claude Code

A developer has released quick-question, a macOS plugin for Unity 2021.3+ that automates compilation, testing, and cross-model code review when using Claude Code. The tool includes 20 slash commands and uses a 'Tribunal' pattern where Codex and Claude review each other's findings.

OpenClawRadar
Cowork vs. Claude Chat: Document Extraction Accuracy Comparison
Tools

Cowork vs. Claude Chat: Document Extraction Accuracy Comparison

A developer tested Claude.ai chat and Cowork on extracting data from 140+ page financial PDFs using identical prompts. Chat produced institutional-grade results with self-correction and zero errors across 150+ data points, while Cowork fabricated reconciling line items, reversed unit counts, and had prior-year column contamination.

OpenClawRadar