[BUG] Subagents with `memory` field never create or update MEMORY.md — memory system not functional for Task() subagents
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Custom agents with memory: user|project|local in their frontmatter never create or update MEMORY.md when spawned as subagents via Task(). The memory directories exist at the correct paths, but MEMORY.md is never written.
This happens consistently even when:
- The agent's system prompt explicitly includes a "Save to memory" step
- The turn budget allocates turns for memory saving
- The agent has Write/Edit tools available and uses them for other files
- The agent is NOT running out of turns (verified via turn count in reports)
Tested 4 agents across all 3 memory scopes — none saved memory:
| Agent | memory scope | Spawned via | MEMORY.md created? |
|-------|-------------|-------------|-------------------|
| conductor | user | claude --agent (main thread) | No |
| laravel-dev | project | Task() from conductor | No |
| code-reviewer | local | Task() from conductor | No |
| frontend-dev | project | Task() from conductor | No |
What Should Happen?
- When an agent with
memory: userstarts, MEMORY.md at~/.claude/agent-memory/<agent-name>/MEMORY.mdshould be loaded into the agent's context (first 200 lines, per docs) - The agent should be able to write to this file via the Write tool during its session
- On the next invocation, the agent should see its previous MEMORY.md content in its context
Per the documentation: "The first 200 lines of MEMORY.md are loaded into each session" and "Read/Write/Edit are automatically included for managing memory."
Error Messages/Logs
No errors. The agent silently skips the memory-saving step. No error message about memory being unavailable or paths being wrong.
After running the full pipeline:
# Check all memory directories
find ~/.claude/agent-memory/ -type f 2>/dev/null
# Empty — no files created
find .claude/agent-memory/ -type f 2>/dev/null
# Empty — no project-scope files
find .claude/agent-memory-local/ -type f 2>/dev/null
# Empty — no local-scope files
Steps to Reproduce
- Create an agent
~/.claude/agents/test-mem.md:
```yaml
---
name: test-mem
description: Test memory saving
tools:
- Read
- Write
- Bash
- Glob
memory: user
model: sonnet
maxTurns: 20
---
You are a test agent. For EVERY task, you MUST:
- Check if MEMORY.md exists in your memory directory and read it
- Do the requested task
- MANDATORY: Write what you learned to MEMORY.md
- Report results
Your memory directory: ~/.claude/agent-memory/test-mem/
```
- From a normal Claude session, delegate:
````
Delegate to test-mem: "Read the nearest package.json or composer.json. Report the project name. Save the project name and stack to your MEMORY.md."
- After the agent completes, check:
``bash``
cat ~/.claude/agent-memory/test-mem/MEMORY.md
# File does not exist
- Even if you add explicit Write commands in the prompt:
````
After completing the task, run: Write to ~/.claude/agent-memory/test-mem/MEMORY.md with content "Project: <name>"
The agent still doesn't write to MEMORY.md.
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.69 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
Possible root causes:
- MEMORY.md not injected into subagent context — per #25318, MEMORY.md may not be loaded into the system prompt for subagents. If the agent never sees a MEMORY.md reference in its context, it has no awareness of the memory system.
- Memory paths not resolved for Task() subagents — the
memoryfield may only work for top-levelclaude --agentsessions, not for subagents spawned viaTask().
- Write tool path resolution — the agent may not have write access to the memory directory, or the path may not be resolved correctly relative to the subagent's working directory.
My workaround attempt: I strengthened all agent prompts from:
9. Save to memory (1 turn) — save patterns to MEMORY.md. Skip if already has this info.
to:
9. Save to memory (MANDATORY, 1 turn) — you MUST update memory before reporting.
This is not optional. Create MEMORY.md if it doesn't exist.
Status: Untested whether stronger prompts fix this, because the issue may be at the platform level (MEMORY.md never injected → agent doesn't know about memory → ignores save instructions).
Related issues: #25318, #4418, #4588
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗