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