anthropics / anthropics/claude-code

Subagents receive a CLAUDE.md/memory snapshot from parent session start, not spawn — undocumented, no way to refresh

Aperta
#88,886 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area:agent bug memory
Lingua principale
Python
Stelle
145k
Fork
23.1k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Version: 2.1.237 (Linux)

## What happens

When a subagent is spawned via the Agent tool, the CLAUDE.md and memory content in its context is not read from disk at spawn time. It is the copy the parent session captured when the parent started.

In a long-running session this drifts arbitrarily far. Measured in one session:

- parent session started 12:31, subagent dispatched 21:10 — the subagent's copy was 8h39m old
- a memory file DELETED from disk at 12:50 was still present in the subagent's context, and its index still pointed at the (now nonexistent) path
- three memory files WRITTEN after 12:31 were absent entirely
- the deleted file contained a rule that had been reversed; the subagent would have acted on the reversed version

Nothing in the subagent's context marks any of it as stale. A superseded instruction reads exactly like a current one, so the agent proceeds confidently and produces a correct-looking result from an out-of-date rule. A missing file announces itself when you reach for it; a stale one never does.

## Repro

1. Start a session in a project with CLAUDE.md and memory files.
2. Edit CLAUDE.md and add/delete a memory file.
3. Spawn a subagent and ask it to print what it received.
4. It reports the pre-edit content.

## What doesn't help

- SessionStart and UserPromptSubmit hooks do not fire on subagent dispatch (verified). There is no SubagentStart event.
- No agent-definition frontmatter field controls context injection or refresh.
- No setting or env var appears to affect it.
- Reading or editing memory in the parent mid-session does not refresh the parent's cached copy, so children keep inheriting the old one.
- Forks inherit the parent conversation, which carries the corrections, but not a fresh snapshot — and at full context cost.

## Asks

1. Document the actual behaviour — whether it's a snapshot, when it's captured. Right now the docs say subagents load CLAUDE.md and memory, which reads as a live read.
2. Some way to opt into a fresh read at spawn, or a SubagentStart hook so a project can inject current state itself.

Workaround in use: a script the subagent runs as step one, which diffs its context files against git and prints what moved since the session directory's birth time. It works, but every project has to invent it, and it only works for memory that lives in git.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Start with the Agent tool dispatch path and the documentation describing CLAUDE.md and memory loading; compare that description with the four-step reproduction. Review the noted SessionStart and UserPromptSubmit hook behavior and the absence of a SubagentStart event. Done means documenting when the snapshot is captured and/or specifying a supported refresh mechanism.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Ambito
developer-experience, documentation
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.