Skip to content

Context window optimization: decisions.md pruning, spawn template dedup, Init Mode compression #37

Closed

Description

@bradygaster

Problem

decisions.md has ballooned to 298KB (~80K tokens) — that's 40% of a 200K context window consumed on every agent spawn. Combined with squad.agent.md growth (29K tokens) and agent histories (~47K tokens), each agent spawn now costs 82-93K tokens (41-46% of context). This leaves agents working with barely half a context window.

Root Causes

  1. decisions.md bloat — 266 blocks, 131 of which are sub-section fragments from old analysis docs. No pruning/archival mechanism exists (unlike history.md which has Scribe summarization). Most blocks are stale sprint artifacts from v0.3.0 planning.

  2. squad.agent.md spawn template duplication — Three near-identical spawn templates (background, sync, generic) at lines 592-809, each ~1,800 tokens. They differ only in mode/description examples and placeholder names.

  3. Init Mode dead weight — Init Mode (lines 28-112, ~1,471 tokens) is loaded on every message but only used once per repo lifetime (when .ai-team/team.md doesn't exist).

Solution

Immediate (this issue — v0.4.0)

  • Prune decisions.md: Manual pass — keep ~30-40 active decisions, archive rest to decisions-archive.md. Target: 298KB → ~50KB (~13K tokens)
  • Dedup spawn templates: Collapse 3 templates into 1 generic template with mode as a variable. Save ~3,600 tokens
  • Compress Init Mode: Reduce redundancy, compress post-setup sources. Target: ~1,471 → ~800 tokens
  • Update README: Context Window Budget table with post-optimization numbers

Future (v0.5.0 — automated)

  • Add Scribe-driven decisions.md pruning: identify blocks older than N weeks, summarize, archive originals to decisions-archive.md
  • Similar to existing history.md summarization (Scribe step 6) but for the shared decision ledger
  • Add an evergreen tag for decisions that should never be pruned (e.g., "zero dependencies", "cost-first model selection")

Impact

Metric Before After (target)
decisions.md ~80K tokens ~13K tokens
squad.agent.md ~29K tokens ~23K tokens
Per-agent spawn cost 82-93K tokens (41-46%) 19-28K tokens (10-14%)
Context remaining for work 54-59% 86-90%

Labels

type:chore, priority:p0, release:v0.4.0

Activity

  1. bradygaster commented on Feb 13, 2026

    @bradygaster
    CollaboratorAuthor

    Shipped in b5aa6c1.

    Results:

    Metric Before After
    decisions.md ~80K tokens (251 blocks) ~33K tokens (78 blocks)
    squad.agent.md ~29K tokens (1,529 lines) ~26K tokens (1,771 lines)
    Spawn templates 3 near-identical 1 unified
    Init Mode 84 lines 48 lines
    Per-agent spawn cost 41-46% of context 17-23% of context
    Context remaining for work 54-59% 78-83%

    173 archived decisions preserved in decisions-archive.md. Memory doc updated. README budget table updated.

  2. added a commit that references this issue on Mar 27, 2026
    a31fded
  3. added 2 commits that reference this issue on Jun 9, 2026
    f9894c8
    deb94a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions