compare

Your subagents forget everything they find

Claude Code subagents start with a blank context window. When they finish, the transcript disappears. A shared state folder lets every subagent read what the others wrote.

How subagents work

The orchestrator spawns a subagent with a prompt and a set of tools. The subagent gets its own context window, does its work, then reports a final message back.

The full transcript (every tool call, every intermediate thought) dies with the subagent. The orchestrator only sees the summary. Isolation prevents cross-contamination, but no discovery survives unless someone writes it down.

Where findings evaporate

Without shared stateWith shared state
FindingsSummary onlyFull files on disk
EvidenceLost with transcriptPersisted in state folder
Next subagentStarts from zeroReads prior work first
RetriesRe-learn everythingContinue from last state

Files as the coordination layer

Instead of only reporting a summary, the subagent writes its findings to a shared folder. The next subagent reads that folder before it starts. The folder is the shared memory, not the orchestrator's context window.

This pattern works because files are durable, inspectable, and tool-accessible. Any subagent with access to the folder can read what any other subagent wrote, regardless of when it ran.

Agent A writes, Agent B reads

gcontext is an MCP server that serves a folder of plain text files. Every subagent connected to the parent session gets the same tools: read_file, write_file, list_dir, grep.

Every file is also an MCP resource at gcontext://modules/research/findings.md. The orchestrator can attach a resource directly to a subagent's prompt.

subagent-a writes
$ # Agent A writes research findings
$ gcontext write_file modules/research/findings.md \
"## API rate limits\n- /users: 100 req/min\n- /search: 20 req/min"
wrote 3 lines to modules/research/findings.md

Agent B reads before it searches

The second subagent reads the prior findings before it starts its own work. It skips redundant searches and builds on what Agent A already discovered.

Tell your subagents to read the module index before they start work. Add one line to the orchestrator prompt: "Before searching, read modules/task/index.md for prior findings."

subagent-b reads
$ # Agent B reads prior findings before starting
$ gcontext read_file modules/research/findings.md
## API rate limits
- /users: 100 req/min
- /search: 20 req/min

Patterns that work

  • Scratchpad per run. Each run writes to modules/task/runs/YYYY-MM-DD/. Delete them after you extract what matters.
  • Learnings promoted to the module index. Move durable findings from the run folder to modules/task/index.md.
  • Decision log (append-only). One file where each entry is a timestamped paragraph. Agents append, never overwrite.
  • One topic per file. Small files are easier to read, cheaper to attach, and safer for concurrent writes.

Limits

Concurrent writes need discipline. If two subagents write to the same file at the same time, the last write wins. Use append-only files, or give each agent its own output file.

State reads cost tokens. Every file a subagent reads consumes context window space. Keep files small and focused so agents only load what they need.

Questions

Do Claude Code subagents share memory?

No. Each subagent starts with a fresh context window. They share access to MCP servers connected to the parent session, but they do not share the parent's conversation history.

How do I pass context to a subagent?

Two ways: through the prompt string the orchestrator sends, or by connecting both the parent and the subagent to an MCP server where the context is stored as files.

Can two agents write the same file?

Yes, but the last write wins. Use append-only patterns or separate files per agent to prevent conflicts.

Related

Claude Code memory
What persists across sessions and what does not
What is agent state?
Definition and management patterns
Self-improving agents
The learnings-file pattern
Skills and MCP state
Instructions vs accumulated knowledge
Give your subagents a shared memory

One MCP server. Every subagent reads and writes the same state folder.

View on GitHubClaude Code memory guide