Sub-agent research artifacts written to /tmp are lost between sessions, causing redundant re-analysis

Resolved 💬 3 comments Opened Mar 12, 2026 by esciara Closed Mar 12, 2026

Problem

When Claude Code spawns sub-agents (via the Agent tool) to analyze a codebase, those agents often produce valuable research artifacts (architecture summaries, code analysis documents, quick reference guides). However, they write these files to /tmp, where they are:

  1. Invisible to future sessions — new sessions have no knowledge of these files
  2. Not referenced by the parent agent — even within the same session, the parent often doesn't know the files exist
  3. Result: identical analysis is repeated session after session, wasting significant tokens and user time

Example

Over 2 days of working on a Metabase migration project, sub-agents created 11 separate analysis files in /tmp:

/tmp/metabase_architecture.txt          (Mar 11)
/tmp/metabase_project_analysis.md       (Mar 11)
/tmp/QUICK_REFERENCE.md                 (Mar 11)
/tmp/README_ANALYSIS.md                 (Mar 11)
/tmp/metabase_research_summary.md       (Mar 12)
/tmp/metabase_technical_details.md      (Mar 12)
/tmp/metabase_codebase_analysis.md      (Mar 12)
/tmp/metabase_summary.txt              (Mar 12)
/tmp/legacy_metabase_summary.md         (Mar 12)
/tmp/legacy_code_samples.md             (Mar 12)
/tmp/QUICK_REFERENCE.txt               (Mar 12)

Most of these contain overlapping content — the same codebase was re-analyzed from scratch multiple times because previous artifacts were forgotten.

Expected behavior

Sub-agent research artifacts should be:

  1. Written to a discoverable, project-local location (e.g., .claude/analysis/ or .claude/cache/) — not /tmp
  2. Discoverable by future sessions — new sessions should check for existing analysis before re-doing work
  3. Kept up to date — if the codebase changes, stale artifacts should be refreshed, but unchanged analysis should be reused

Current workaround

User manually copies files from /tmp into the project tree (CLAUDE.md instructions could reference them), but this defeats the purpose of automated analysis.

Root cause

The Agent tool's sub-agents have no convention or mechanism for persisting research outputs in a location that survives session boundaries. They default to /tmp because it's writable and doesn't trigger permission prompts.

Related issues

  • #25292 — Temp file handling: use session-specific directories instead of /tmp (same symptom, different focus: collision vs. reusability)
  • #31294 — Subagent memory system not functional (same root cause family: agents can't persist/recall knowledge)
  • #31385 — Agent memory writes to unpredictable location (related: even when memory works, location is inconsistent)
  • #25999 — Persistent state across context compaction (related: state persistence problem at compaction level)

Suggested solutions

  1. Project-local analysis cache: Sub-agents write research artifacts to .claude/cache/ (gitignored). Future sessions check this directory before re-analyzing.
  2. Agent research memory: Extend the existing memory system so research agents can store and retrieve analysis results keyed by project path + topic.
  3. Parent-agent awareness: When a sub-agent writes a file, surface it to the parent agent so it can reference it in CLAUDE.md or similar persistent context.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗