{"id":"agent-context-isolation","name":"agent-context-isolation","summary":"エージェントコンテキストの隔離","body":"# Agent Context Isolation\n\nPrevent agent output from polluting the main context window.\n\n## Rules\n\n### 1. Use Background Agents with File-Based Coordination\n```\n# RIGHT - background agent writes to file, main reads file\nTask(subagent_type=\"...\", run_in_background=true, prompt=\"... Output to: /path/to/file.md\")\n\n# WRONG - foreground agent dumps full transcript into main context\nTask(subagent_type=\"...\", run_in_background=false)\n```\n\nBackground agents with `run_in_background=true` isolate their context. Have them write results to files in `.claude/cache/agents/<agent-type>/`.\n\n### 2. Never Use TaskOutput to Retrieve Results\n```\n# WRONG - dumps entire transcript (70k+ tokens) into context\nTaskOutput(task_id=\"<id>\")\nTaskOutput(task_id=\"<id>\", block=true)\n\n# RIGHT - check expected output files\nBash(\"ls -la .claude/cache/agents/<agent-type>/\")\nBash(\"bun test\")  # verify with tests\n```\n\nTaskOutput returns the full agent transcript. Always use file-based coordination instead.\n\n### 3. Monitor Agent Progress via System Reminders\n```\n# System reminders come automatically:\n# \"Agent a42a16e progress: 6 new tools used, 88914 new tokens\"\n\n# To detect completion:\n# - Watch for progress reminders to stop arriving\n# - Poll for expected output files: find .claude/cache/agents -name \"*.md\" -mmin -5\n# - Check task output file size growth: wc -c /tmp/claude/.../tasks/<id>.output\n```\n\n**Stuck agent detection:**\n1. Progress reminders stop arriving\n2. Task output file size stops growing\n3. Expected output file not created after reasonable time\n\n### 4. Verify with Tests, Not Output\nAfter agent work:\n1. Run the test suite directly: `bun test`\n2. Report pass/fail counts\n3. Only investigate failures if tests fail\n\n### 5. File-Based Agent Pipeline Pattern\n```\nResearch agent → .claude/cache/agents/oracle/output.md\n                          ↓\nPlan agent → .claude/cache/agents/plan-agent/output.md (reads research)\n                          ↓\nValidate agent → .claude/cache/agents/validate-agent/output.md (reads plan)\n                          ↓\nImplement agent → src/module.ts (reads validated plan)\n```\n\nEach agent reads the previous agent's file output, not TaskOutput.\n\n## Why This Matters\n\nAgent context isolation preserves the main conversation's context budget. Reading agent outputs via TaskOutput floods context, causing:\n- Mid-conversation compaction\n- Lost context about user's original request\n- Repeated explanations needed\n\n## Source\n- Session where TaskOutput flooded 70k+ tokens into main context\n- Session 2026-01-01: Successfully used background agents with file-based coordination for SDK Phase 3","author":"@parcadei","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/parcadei/Continuous-Claude-v3/tree/main/.claude/skills/agent-context-isolation","license":"MIT","category":"writing","lang":"en","tokens":601,"stars":0,"calls30d":2,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":[]}}