I had a 12,855-line technical plan for a complex feature set across a 30,203-LOC agentic codebase: 29 tasks across 3 phases, touching 38 files, with 16 binding architectural constraints and tight inter-task dependencies.
I kicked off the run before going to sleep. Three hours and seventeen minutes later, the entire spec was implemented and committed cleanly: 1,369 of 1,412 collected tests passed on the first unattended pass (leaving 43 straightforward test fixes in the morning, ending at 1,431 passing tests, 0 failures, 0 lint violations).
Here is the exact workflow, what worked, and what broke.
Caveats Up Front
- Know what you want to build before touching an agent. Spend the effort upfront debating the design until it matches your mental model of the codebase.
- Clean repository structure and disciplined git history are non-negotiable.
- Works with
opencode,claude -p,codex exec, or any CLI coding agent.
Part 1: Building the Master Spec
All of your real leverage is in the spec—the agent's job overnight should be execution, not design.
- Scope & debate the design: Brainstorm the architecture interactively (e.g., with Opus), pushing back on every lazy default until the design reflects someone who knows the codebase inside out. Save the agreed design to Markdown.
- Codebase audit + task chunking: Have a high-reasoning coding model audit the exact files in the repo, add function/class stubs into the design doc, and split the change into context-manageable tasks.
- Architecture & test pass: Stress-test edge cases, interfaces, performance constraints, and the test plan iteratively before writing implementation bodies.
- Full task specs + dependency graph: Expand stubs with exact file paths, failing tests to write first, implementation details, task-level verification gates, and a dependency ordering—plus a short shared preamble (~150 lines) of binding codebase rules.
Part 2: Why Monolithic Plans Fail & Why Task Cards Work
Feeding a 12,855-line plan directly blows out context, while running a naive fresh-context loop without pre-baked specs burns tokens rediscovering cross-task dependencies on every step.
Because the master spec already resolved every design dependency, a small Python splitter sliced it by ### Task N: headers into 29 self-contained Task Cards (100–960 lines each, median ~350 lines):
# Task N: [Title]
> Phase: Phase 1 | Track: Track A
> Dependencies: Task 3, Task 5
> Key Amendments: 2, 7, 8, 9
Before starting: Read `00-amendments.md` for binding rules.
### Files:
- Modify: `src/core/types.py`
- Create: `src/core/new_module.py`
- Create: `tests/unit/test_new_module.py`
### Step 1: Write failing tests
[exact test code]
### Step 2: Implement
[exact implementation code / contract]
### Step 3: Run tests
[verification commands]
### Step 4: Commit
[commit message]
## Post-Task Checklist
- [ ] Task tests pass
- [ ] Full suite passes (no regressions)
- [ ] Linting passes
- [ ] Committed cleanly
Part 3: Progress Manifest, Bash Runner & Pre-Flight
Track state in a simple PROGRESS.md table (Task | Status | Commit) and drive execution sequentially with a plain bash loop:
for task_num in "${TASKS[@]}"; do
prompt="[amendments content]\n\n[task card content]"
opencode run "$prompt" > ".logs/task-${task_num}.log" 2>&1
done
Before running unattended, always run a pre-flight check: verify every task card exists, cross-check every Create: and Modify: path against the filesystem, confirm baseline test counts, and dry-run the runner script.
Results After Morning Audit
| Metric | Value |
|---|---|
| Total tasks | 29 |
| Unattended runtime | ~3.5 hours |
| Tests before | 524 |
| Tests after morning cleanup | 1,431 |
| Test failures / lint violations | 0 / 0 |
| Human time (setup + morning verification) | ~2 hours |
| Tasks needing retry | 1 (Task 13 timed out; passed on retry) |
What Worked
- Self-contained Task Cards (200–800 lines): Full file paths + tests + contract kept the agent focused without context drift.
- Sequential execution: Zero merge conflicts and a clean, bisectable git log.
- Pre-flight + structured morning audit: Grep-enforced architectural checks caught subtle violations unit tests missed.
What Broke (and What to Change Next Time)
- Shared preamble was too long (150 lines): The agent ignored half the global rules (e.g., bare
exceptblocks). Embed only the 3–4 rules relevant to each card. - Missing per-task timeout: Task 13 (668 lines) hung once—always wrap agent invocations in
timeout 1200. - Missing hard phase gates: Halt the loop automatically if a phase-boundary test suite regresses instead of continuing into downstream tasks.
Originally published on X (@wthagi).