Feature request: programmatic memory appends from observability loops
Context
A pattern that is becoming genuinely useful: a background script observes session telemetry (tool-call patterns, retry cycles, subagent turn counts), detects recurring failure modes, and writes a permanent behavioral rule to CLAUDE.md that Claude reads on the next session start. Next iteration's metrics measure whether the rule actually changed behavior. If not, the rule fires again with updated numbers and the loop continues.
This turns CLAUDE.md from a static config file into a self-improving operating system.
Problem
Anything that appends to CLAUDE.md today risks:
- Clobbering hand-authored content if the script has a bug
- Duplicate entries with no idempotency guarantee
- Unclear provenance -- a human reading CLAUDE.md can't tell which rules were auto-generated vs. hand-written
- Merge conflicts between multiple tools both trying to append
Proposal
A reserved section in CLAUDE.md, something like:
<!-- @auto-generated:start -->
- [rule-id] {rule text} (source: <tool>, updated: <date>)
<!-- @auto-generated:end -->
Or frontmatter-driven: a sub-file pattern like CLAUDE.auto.md that Claude Code auto-includes but tools own exclusively.
Either way, the guarantees we'd want:
- Tools can safely append, dedupe, and remove their own entries by ID
- Human-authored sections are never touched
- Claude reads both at session start
- There's a convention for what counts as an auto-rule (source + ID + date)
Why this matters
Observability loops like this are how AI tooling actually gets better over time. Without a safe append target, every tool rolls its own convention and they collide.
Context: my current implementation
Built a weekly digest (claude_performance_digest.py) that reads JSONL from ~/.claude/projects/, detects verbose-agent and model-routing issues, and appends to ~/.claude/CLAUDE.md. It works but relies on fragile string matching for idempotency. A first-class pattern would let tools like this compose cleanly.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗