[FEATURE] Per-session auto-memory scope alongside global memory (cross-agent leakage in multi-agent workflows)
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Claude Code's auto-memory currently has one scope per git repository: every session launched inside that repo reads and writes the same MEMORY.md index at ~/.claude/projects/<encoded-git-root>/memory/. This works for genuine user-level facts but creates cross-agent leakage in multi-agent and multi-session workflows.
In a multi-agent workflow where several Claude Code sessions run concurrently inside one git repo — each session embodying a different "agent" doing unrelated work — a memory entry written by Agent A (e.g., "user is currently debugging issue X in module Y") becomes visible to Agent B in a different session, even though A's and B's work are unrelated.
This has been observed in practice: agents pick up context from other agents' sessions that they shouldn't have, polluting their reasoning and occasionally producing confused behavior.
The current design assumes one user / one workspace / one stream of work per repo. That assumption breaks for:
- Operators running multiple Claude Code sessions in tmux panes / IDE windows on different lanes of work in the same repo
- Multi-agent orchestration where each agent has a distinct identity and lane
- Worktree-based parallel workflows where each worktree should have its own memory
- Any pattern where the "agent" or "session" is the appropriate scope, not "the repo"
(Note: this is distinct from #48416, which requests user-scope as a complement to project-scope — a different direction along the same axis. This request is for going narrower than project, not wider.)
Proposed Solution
Requesting: a per-session (or per-cwd, or per-agent-identity) memory scope as a complement to the existing global scope.
Proposed two-tier model
- Global memory (current behavior): user-level, cross-session, cross-agent — kept for genuine user facts (preferences, identity, durable context).
- Session memory (new): scoped to a session — persists across context clears within that session, but does not leak to other sessions or other agents.
Possible scope keys (any one would help, ordered by increasing precision):
- cwd (so different subdirectories of a repo have separate memory)
- session id / Claude Code process id (so even same-cwd concurrent sessions are isolated)
- agent identity (declared via env var, frontmatter, or
--agent-nameflag) — most flexible for orchestration setups
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
Configuration and settings
Use Case Example
The submitting operator runs ~30 artificial-person Claude Code agents concurrently inside a single git repository, each with a distinct identity and working directory. They have observed agents picking up context written by other agents — a contamination pattern the current single-scope memory makes inevitable.
A per-session/per-agent memory scope would let each agent accumulate local context (debugging state, ongoing TODOs, partial reasoning) without polluting the global memory or leaking into other agents' contexts. Global memory would remain for the small set of genuinely user-level facts.
Additional Context
Related issues
- #48416 — user-scope memory (orthogonal, requesting wider-than-project scope)
- #41283 — memory identity derived from filesystem path
- #28276 — configurable memory storage location
- #23544 — ability to disable auto-memory
- #24044 — MEMORY.md double-load
Submitted via Claude Code on the operator's behalf.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗