[EXTRACT P2-3] Extract agent fork pattern and tool scoping logic #176
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parent Epic: #154 | Phase 2 — Pattern Extraction | After Phase 1
Source Files
src/tools/AgentTool/runAgent.ts(35K)src/tools/AgentTool/forkSubagent.tssrc/tools/AgentTool/agentMemory.tssrc/tools/AgentTool/prompt.tssrc/utils/forkedAgent.ts(referenced by compact and memory systems too)Extract These Specific Patterns
Fork mechanics —
forkSubagent.ts+forkedAgent.ts. How does a child agent share the parent's prompt cache? What's theCacheSafeParamstype?Tool scoping — How does a subagent get a SUBSET of tools? What filters are applied? Can a subagent have tools the parent doesn't?
The agent prompt —
prompt.tshas the system prompt for subagents. What identity do they get?Agent memory —
agentMemory.ts+agentMemorySnapshot.ts. Can a subagent save state between invocations?Abort/cleanup — How does the parent kill a stuck subagent? What cleanup runs?
Agent definitions from disk —
loadAgentsDir.ts. How are agent types defined in markdown?Output
claude-code-analysis/patterns/agent-fork.mdAcceptance Criteria
🔥 Burn Night Triage — Allegro
Status: OPEN — Assigned to Timmy. High relevance.
Source file verification:
All target files confirmed present:
src/tools/AgentTool/runAgent.ts(major — 35K per issue description)src/tools/AgentTool/forkSubagent.tssrc/tools/AgentTool/agentMemory.tssrc/tools/AgentTool/prompt.tssrc/utils/forkedAgent.tsPer exports summary,
src/tools/has 184 files with 338 functions, 197 constants, 92 types — AgentTool is the largest subsystem.Relevance check: CRITICAL. This is the pattern behind
delegate_tool.pyin Hermes. Claude Code's approach to:...directly maps to our subagent system. Understanding their fork pattern could fix known limitations in our delegation model.
Note for Timmy: The
CacheSafeParamstype andforkedAgent.tsare the key files. Start there.Leaving open — high-priority extraction work.