claude-code - 💡(How to fix) Fix Feature request: programmatic memory appends from observability loops [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#49401Fetched 2026-04-17 08:42:11
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
labeled ×2commented ×1

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.

Root Cause

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.

Code Example

<!-- @auto-generated:start -->
- [rule-id] {rule text} (source: <tool>, updated: <date>)
<!-- @auto-generated:end -->
RAW_BUFFERClick to expand / collapse

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:

  1. Clobbering hand-authored content if the script has a bug
  2. Duplicate entries with no idempotency guarantee
  3. Unclear provenance -- a human reading CLAUDE.md can't tell which rules were auto-generated vs. hand-written
  4. 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.

extent analysis

TL;DR

Implement a reserved section in CLAUDE.md for auto-generated rules to prevent clobbering hand-authored content and ensure idempotency.

Guidance

  • Introduce a clear separator, such as <!-- @auto-generated:start --> and <!-- @auto-generated:end -->, to define the auto-generated section in CLAUDE.md.
  • Use a standardized format for auto-generated rules, including a unique rule-id, rule text, source, and date, to enable tools to safely append, dedupe, and remove their own entries.
  • Consider using a sub-file pattern like CLAUDE.auto.md as an alternative approach, allowing tools to own and manage their auto-generated rules exclusively.
  • Ensure that Claude reads both the main CLAUDE.md file and the auto-generated section or sub-file at session start.

Example

<!-- @auto-generated:start -->
- [rule-123] Avoid verbose-agent issues (source: claude_performance_digest.py, updated: 2023-02-20)
- [rule-456] Optimize model routing (source: claude_performance_digest.py, updated: 2023-02-20)
<!-- @auto-generated:end -->

Notes

The proposed solution relies on tools adhering to the standardized format and separator convention to maintain idempotency and prevent conflicts.

Recommendation

Apply the workaround by introducing a reserved section in CLAUDE.md, as it provides a clear and standardized approach to managing auto-generated rules and prevents potential conflicts with hand-authored content.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING