fix: per-process scope for Claude Code sub-agent cache isolation (#1292) - #1293
Closed
yvgude wants to merge 0 commit into
Closed
fix: per-process scope for Claude Code sub-agent cache isolation (#1292)#1293yvgude wants to merge 0 commit into
yvgude wants to merge 0 commit into
Conversation
yvgude
force-pushed
the
fix/1292-claude-code-subagent-scope
branch
from
July 28, 2026 16:12
ccd0a98 to
1587891
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1292.
Claude Code sub-agents (spawned via the
Agenttool) share the parent'ssession_id— Claude Code does not setCURSOR_TASK_IDor any equivalent per-subagent identifier. Each sub-agent gets its own lean-ctx MCP process (stdio mode), but they all share the on-diskread_stub_index. The cold stub gate passed because both parent and sub-agent resolved to the samesession_id, serving[unchanged]stubs for files the sub-agent never received.Fix
Extend
subagent_scope()with a multi-host scope resolution chain:LEAN_CTX_SCOPE— explicit operator/integration override (new)CURSOR_TASK_ID— Cursor subagents (existing)CLAUDECODE=1— per-processproc:{pid-ts}scope (new, ctx_read cache returns stub to sub-agents that never received file contents #1292)When
CLAUDECODE=1is detected, each lean-ctx process generates a unique, lifetime-stable scope ID. Since each MCP connection is a separate stdio process, parent and sub-agent caches are fully isolated — warm stubs stay per-process, and cold stubs from the persisted index never match across processes.Also extends
is_subagent_context()to detectCLAUDE_CODE_ENTRYPOINT=local-agent(future Claude Code sub-agent marker) as a defense-in-depth fallback for when scoping is disabled.Tradeoff
In Claude Code, cold stubs (persisted index) no longer survive process restarts — each new lean-ctx process gets a fresh scope. This is acceptable: cold stubs are a minor optimization, and the warm cache handles 95%+ of re-reads within a session.
Changes
rust/src/core/conversation.rs: Newresolve_scope()pure-core resolver,process_unique_id()generator, updatedsubagent_scope(), 8 new testsrust/src/tools/ctx_read/dispatch.rs: Extendedis_subagent_context()forCLAUDE_CODE_ENTRYPOINT=local-agentTest plan
--lib)cargo fmt --checkcleanMade with Cursor