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.md frontmatter: 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.md is 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.md matches agents/swe.md exactly.
  • 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

  1. Extend task_create_batch with optional context_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.
  2. SWE skill update: when context_files was passed, prefer those over re-discovery; do additional Read only on demonstrated need (compiler error, test failure pointing elsewhere, etc.).
  3. Add tmb_swe-discovery skill (or extend tmb_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."
  4. Optional --lean-spawn mode that skips the standard CC "explore the codebase" preamble for tightly-scoped tasks.
  5. Audit templates/agents/swe.md for redundant discovery instructions; tighten to "use the spec_body as your authoritative file list."

Acceptance criteria

  • New L4 test: SWE spawn with context_files performs ≤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_files provides 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).

Edited by Zax Shen