v0.7.0 — token-burn: SWE worktree spawn over-reads — pass repo context as tool message instead of letting SWE re-discover
Problem
Each SWE spawn opens a fresh worktree and a fresh subagent context. SWE has maxTurns: 150 and the tool allowlist Read, Glob, Grep, Bash, Write, Edit, mcp__plugin_tmb_trajectory-server. The spec_body (capped at SPEC_BODY_MAX_BYTES, often referencing a design doc) tells the SWE what to do, but SWE still performs initial discovery: Read on related source files, Glob for siblings, Grep for callers.
For tightly-scoped TMB tasks, this discovery is largely redundant — bro already knows the relevant files. The token cost adds up: v0.6.0 release with 9 audit-fix SWE spawns averaged 10–30 Reads per spawn before touching code.
Evidence (verified against live source)
agents/swe.mdfrontmatter:model: sonnet,maxTurns: 150,tools: Read, Glob, Grep, Bash, Write, Edit, mcp__plugin_tmb_trajectory-server,skills: [tmb_swe-checklist].skills/tmb_swe-checklist/SKILL.mdis short (26 LOC) and load-time-narrow ("load only when about to atomic-close") — it does NOT prescribe discovery rules; SWE's discovery behavior comes from CC default behavior + spec_body instructions.templates/agents/swe.mdmatchesagents/swe.mdexactly.- Spec docs in
docs/<topic>_<issue>.md(the "big spec doc reference" pattern) already list "Files to touch" — but SWE still rediscovers because the listed paths land as plain text inside the spec_body, not as a structured context-injection.
Plan
- Extend
task_create_batchwith optionalcontext_files: string[]— paths bro already knows are relevant. Server reads them at spawn-time and inlines as a tool message visible to the spawned SWE. - SWE skill update: when
context_fileswas passed, prefer those over re-discovery; do additional Read only on demonstrated need (compiler error, test failure pointing elsewhere, etc.). - Add
tmb_swe-discoveryskill (or extendtmb_swe-checklist) with a "Discovery economy" section: "Trust the spec_body's file list. Don't re-Read files you've been told about. Glob only when the spec hints at uncertainty." - Optional
--lean-spawnmode that skips the standard CC "explore the codebase" preamble for tightly-scoped tasks. - Audit
templates/agents/swe.mdfor redundant discovery instructions; tighten to "use the spec_body as your authoritative file list."
Acceptance criteria
- New L4 test: SWE spawn with
context_filesperforms ≤3 Read calls outside the listed files. - L5 dogfood measures per-spawn Read count; verify ≥40% reduction in mean Reads/spawn.
- No regression in SWE success rate (L6 still passes).
Out of scope
- Pre-tokenizing context_files and sending as cached prompt (Anthropic infra concern).
- Eliminating SWE worktrees entirely.
Coordination
- Pairs with #2912 (inline design doc) — both reduce SWE startup reads.
- Pairs with #2919 (P1 hallucination) —
context_filesprovides verified inputs the SWE can rely on.
Note on source
Previous description correctly cited the swe agent and the pattern. Verified now against agents/swe.md, templates/agents/swe.md, skills/tmb_swe-checklist/SKILL.md. The maxTurns: 150 cap is a separate concern (#2915).