anthropics / anthropics/claude-code

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

Abierto
#88,886 6 comentarios 0 reacciones 0 asignados Ver en GitHub
area:agent bug memory
Lenguaje dominante
Python
Estrellas
145k
Forks
23.1k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Área
developer-experience, documentation
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.