Back to Development
developmentL5 AutonomousContext Engineering

Self-healing context: agent detects stale docs, updates

At L5, agents monitor context quality continuously - detecting when CLAUDE.md entries, README sections, or architecture diagrams no longer match the codebase, and automatically proposing or applying updates.

  • ·Agents maintain persistent identity and memory across sessions (Beads/Git-backed)
  • ·Production telemetry feeds back into agent context automatically (deploy, error, performance data)
  • ·Agents detect stale documentation and update it without human initiation
  • ·Agent memory persists architectural decisions and their rationale across sessions
  • ·Self-healing context updates are validated by automated tests before commit

Evidence

  • ·Agent memory store with session-spanning entries and timestamps
  • ·Production telemetry-to-context pipeline configuration with update frequency
  • ·Git history showing agent-authored documentation updates with passing CI

What It Is

Documentation rot is one of the oldest unsolved problems in software engineering. Teams invest in writing good documentation, and then the codebase evolves while the documentation stays still. At L1, teams discover the rot when something breaks or someone asks a question the documentation answers incorrectly. The fix is manual, reactive, and easy to forget.

Self-healing context is an L5 pattern where agents actively monitor the accuracy of context files - CLAUDE.md, README, architecture diagrams, convention documents - and detect when they've drifted from reality. When a drift is detected, the agent doesn't just flag it; it generates a proposed correction and, depending on the configured policy, either creates a pull request for human review or applies the correction directly.

The detection mechanism works by comparing claims in context files against the actual codebase. A CLAUDE.md that says "we use Jest for testing" when the test runner has been switched to Vitest is a detectable inconsistency - an agent can read the CLAUDE.md claim, check the package.json and test file imports, and determine that the claim is stale. A README that says "deploy with npm run deploy" when the deployment script has been renamed to npm run ship is similarly detectable. An architecture diagram that references AuthService when the service was renamed IdentityService six months ago is a falsifiable claim.

Not all documentation drift is detectable by static analysis. "We prioritize reliability over feature velocity" can't be verified from code. But a large fraction of the most practically harmful documentation drift - wrong commands, stale dependencies, incorrect file paths, outdated service names, wrong tech stack claims - is mechanically verifiable.

At L5, this detection runs continuously: after each significant commit, or on a scheduled basis, agents scan context files for falsifiable claims and verify them. Drift reports are generated, and depending on policy, corrections are proposed or automatically applied.

Why It Matters

Self-healing context closes the loop that manual documentation processes always leave open:

  • Documentation is continuously accurate - not accurate until the next undocumented change, but continuously maintained by the same agents that generate the changes
  • Documentation debt doesn't accumulate - each change that would create a context file inconsistency is caught at the time it occurs, not discovered months later
  • Agent behavior is predictably correct - agents that read context files and find accurate information make better decisions; the quality of agent behavior is a direct function of context quality
  • Human attention is preserved for nuance - mechanical documentation errors (wrong commands, stale file paths) are fixed automatically; humans review changes that require judgment (updated architectural guidance, revised conventions)
  • Builds trust in context - when developers know that CLAUDE.md is actively maintained and verified, they trust it more and use it more. This creates a virtuous cycle.

The irony of reaching L5 is that the same agents whose behavior depends on accurate context can be responsible for maintaining that context. The system becomes self-reinforcing: good context enables good agents; good agents maintain good context.

Tip

Before deploying automatic context updates, run the agent in "proposal only" mode for 30 days - every proposed update generates a pull request for human review. This validates that the agent's drift detection is accurate before enabling any automatic updates.

Getting Started

6 steps to get from here to the next level

Common Pitfalls

Mistakes teams actually make at this stage - and how to avoid them

How Different Roles See It

B
BobHead of Engineering

Bob's team has excellent context engineering infrastructure at L3-L4. CLAUDE.md files are well-maintained, MCP servers are running, and BYOC pipelines are assembled. But Bob keeps getting complaints from developers that the CLAUDE.md "is wrong again." The problem is that the files were written once but are being updated manually, and manual updates lag behind the pace of codebase change. Bob is frustrated - he invested heavily in context engineering and now it's becoming a maintenance burden.

What Bob should do - role-specific action plan

S
SarahProductivity Lead

Sarah is tracking context quality as a metric - she runs quarterly audits where developers rate the accuracy of their team's CLAUDE.md files and README documentation. The scores have been declining quarter over quarter despite increasing context engineering investment. More documentation is being written, but the codebase is evolving faster than documentation can be updated manually.

What Sarah should do - role-specific action plan

V
VictorStaff Engineer - AI Champion

Victor has been manually auditing the CLAUDE.md files in his repositories every month. It takes 4-5 hours and invariably finds the same categories of errors: renamed commands, updated dependencies, reorganized file paths. He knows this is mechanical work that shouldn't require his time, but he also knows that if he stops doing it, the CLAUDE.md files will drift and agent quality will degrade. He's caught in a maintenance loop.

What Victor should do - role-specific action plan