From Copy-Paste to COSAW: Beating the Context Wall

From Copy-Paste to COSAW: Beating the Context Wall

How a development workflow evolved through four generations of tooling, hit a hard wall at 350K tokens, and solved it with context-isolated sub-agents.
Reading time: ~8 minutes


The Evolution in One Picture

GEN 1 Copy-Paste
ChatGPT → manual file writing
✗ Slow, error-prone
GEN 2 Shell Scripts
LLM → bash scripts → project
~ Predictable, fragile
GEN 3 Agent Sessions
Claude / pi.dev / opencode
~ Better, hits context wall
GEN 4 COSAW
Main + sub-agents + advisor
✓ Peak performance always

Four generations. Each one fixed the previous generation’s bottleneck. The fourth one solved a problem that most people don’t even know they have.


Gen 1: The Copy-Paste Dark Ages

You know the drill. ChatGPT generates 200 lines of beautiful Rust. You copy it. You open src/main.rs. You paste. You save. You go back. Copy the next file. Open src/config.rs. Paste. Save. Repeat 15 times.

It works. But every project beyond 5 files turns into a tedious assembly line of browser tabs and editor windows. One missed closing brace costs you 10 minutes of debugging. And God help you if you need to reproduce the setup six months later.

The bottleneck wasn’t code generation — it was file transfer.


Gen 2: The Script Awakening

The solution was obvious once you saw it: make the LLM write a script that writes the files for you.

Instead of 30 copy-paste cycles, you get one:

# LLM-generated build script
mkdir -p src tests
cat > src/main.rs << 'EOF'
// ... your code ...
EOF
cat > Cargo.toml << 'EOF'
// ... your config ...
EOF
git init && git add -A && git commit -m "init"
echo "Run with: cargo run"

One copy-paste. The entire project materializes. Git history clean. Build instructions embedded. Repeatable on any machine.

This pattern scaled to ~30-file projects before the scripts themselves became unwieldy. A 500-line bash script with embedded source is not fun to debug.


Gen 3: The Agent Era — And Why It Almost Worked

Tools that can touch the filesystem directly were the next leap. Instead of generating text for me to execute, the LLM could execute it.

I went on a tool safari:

  • Claude Code — Could edit files, run commands, fix compilation errors. Game-changer for the feedback loop.
  • picoclaw — Minimal memory footprint, but too constrained for complex work.
  • claw-code / opencode — Interesting approaches, immature integrations.
  • pi.dev — The skill system was genuinely well-designed. I used it for weeks.

I circled back to Claude Code. The reasons: native sub-agent support, MCP protocol for custom tools, git worktree isolation, and a permission model that didn’t drive me insane.

There was just one problem. A big one.


The 350K Token Wall

Context Size vs. Effective Reasoning Quality

LLM context windows are not a free resource. Every token you spend on history is a token the model can’t attend to for reasoning. The attention mechanism has O(n²) cost — as context grows, the signal-to-noise ratio flattens.

The numbers, from real usage:

Context Size What Happens
0-100K Peak performance. Sharp, correct, fast.
200-300K Noticeable fuzziness on edge cases.
350-400K Degradation threshold. Complex multi-step reasoning breaks.
400-500K Obviously degraded. Testing catches things the LLM missed.
500-650K Unreliable for engineering. Okay for simple lookups.
650K+ Genuinely impaired reasoning. Avoid.

The old workflow had a fatal pattern:

Session start → 50K → 150K → 300K → 500K
Quality:      ✅    ✅    ⚠️    ❌    💀

The last 40% of every project took 3x longer and had 2x the bugs. Not because the LLM got dumber — because it was drowning in its own history.


Gen 4: COSAW — Context-Optimized Sub-Agent Workflow

The insight was simple: if LLMs are excellent at ~100K context and terrible at ~500K, don’t give them 500K contexts.

Decompose. Isolate. Keep it tight.

┌─────────────────────────────────────────────────────────────────┐
│  MAIN SESSION (oversight)                                      │
│  Context: ~50K — architecture, planning, review                │
│  Model: flash (cheap)                                          │
│                                                                │
│  1. Analyze codebase → decompose into phases                   │
│  2. Write a ~15K brief per phase                               │
│  3. Launch sub-agents                                           │
│  4. Review → merge → next                                      │
└─────────────────────────┬───────────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────────────┐
│  SUB-AGENT (implementation) × N phases                         │
│  Context: ~20K — brief only, zero history bleed                │
│  Model: flash (cheap)                                          │
│                                                                │
│  Reads brief → implements → advisor review → signals complete   │
└─────────────────────────┬───────────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────────────┐
│  FRAO-ADVISOR (quality gate)                                   │
│  Context: ~5-10K — diff review only                            │
│  Model: pro (medium cost, high quality)                        │
│                                                                │
│  3 checkpoints: architect → code-reviewer → final consult      │
└─────────────────────────────────────────────────────────────────┘

Each sub-agent starts fresh. No conversation history, no baggage, no "actually, going back to what I said 400K tokens ago…" — just a tight brief and a focused task.


How It Actually Works

The toolchain, from the ground up:

Layer Component Job Cost
Orchestration Main Claude session Plan, decompose, review $0.14/M
Implementation Sub-agent per phase Build the thing $0.14/M
Quality Frao Advisor Architecture + code review $0.435/M
Lifecycle Phase Orchestrator tmux sessions, resource monitoring Free

The Flow

  1. User says: "Build the dashboard"
  2. Main session: Explores codebase, produces architecture plan with N phases (~50K context — efficient)
  3. For each phase: Creates a git worktree (isolated branch), writes a ~15K condensed brief
  4. Sub-agent starts: Fresh session, ~20K total context. Loads skills. Reads the brief. Runs advisor architecture review. Implements. Runs advisor code review. Fixes CRITICAL/HIGH findings. Signals done.
  5. Main session: Reviews, merges to dev, moves to next phase
  6. Result: Every phase runs at peak LLM performance. Zero context degradation.

Critical detail: the sub-agent doesn’t commit. It stages (git add -A) and prints === PHASE_COMPLETE ===. The main session handles all commits and merges. This keeps the audit trail clean.


BEFORE: Single Session
500K context · degrading quality · serial
PhaseCtxQual
Analysis30K100%
Core features180K85%
Advanced features350K50%
Polish / edge cases500K+30%
$0.50-2.00/feature · 40% rework rate
AFTER: COSAW
20K per sub-agent · peak quality · parallel
PhaseCtxQual
Analysis (main)50K100%
Phase 1 (sub-agent)20K100%
Phase 2 (sub-agent)20K100%
Phase N (sub-agent)20K100%
$0.15-0.60/feature · <5% rework

Frao Advisor: Quality at Scale

Frao Advisor is a multi-expert review system that uses a high-reasoning model (deepseek-v4-pro) to audit every phase of development. It supports 7 specialized expert personas:

Persona When What It Checks
Architect After planning System design, component boundaries, data flow, failure modes
Code Reviewer After implementation Correctness, edge cases, error handling, test coverage
Security Analyst Auth/networking changes Vulnerabilities, secrets exposure, access control
Debugger During failures Root cause analysis, fix verification
Tech Lead High-stakes decisions Trade-offs, alternatives, roadmap alignment
Scope Analyst Before starting Effort estimation, risk assessment, dependency mapping
Researcher Unknown domains Literature review, best practices, technology comparison

The clever part: the expensive model only runs on small review payloads (diffs, not full conversations). The cheap flash model runs everything else. ~3x cost savings vs. using premium models for everything, with premium quality where it matters. Every call is logged to advisor.db with full metadata.

Every sub-agent goes through three mandatory checkpoints:

1. Architecture review (after planning, before coding)
The advisor’s "architect" persona reviews the approach. Component boundaries. Data flow. Failure modes. If the plan is wrong, this is where it gets caught — before a single line of code is written.

2. Code review (after implementation)
The "code-reviewer" persona reads every diff. Correctness, edge cases, error handling, test coverage. CRITICAL and HIGH findings must be fixed before proceeding.

3. Final consultation (before completion)
A comprehensive check: did we build what we said we’d build? Any regressions? Any security concerns? The advisor’s verdict is included in the completion summary.


The Numbers

Cost-Quality Comparison (normalized)
Metric Single Session COSAW
Context per task 200-500K 15-30K
Reasoning quality Degrades over time Peak throughout
Cost per feature $0.50-2.00 $0.15-0.60
Production bugs Baseline ~80% fewer (caught by advisor)
Reproducibility Low (conversation drift) High (fixed briefs)

The Lessons, Condensed

  1. Context budgeting is real. Every token spent on history is a token not spent on reasoning. A 500K context isn’t "10x more information" — it’s "10x more noise."

  2. Fresh sessions are free. A new Claude session costs pennies. A production bug costs hours. Split the task.

  3. The brief is the product. Sub-agent output quality is proportional to brief quality. State exactly what exists, what to build, which files to touch, and what NOT to do. Ambiguity wastes the sub-agent’s context budget.

  4. Advisor reviews pay for themselves. Catching a bug in review costs ~$0.10.

  5. Match the model to the task. Cheap flash models for implementation, premium pro models for review (small payloads). Using a sledgehammer for finishing nails and a finishing hammer for concrete are both wrong.


Where to Go From Here

The full COSAW infrastructure lives in the Frao Technologies development workflow. You don’t need all of it to get the benefit — the core pattern (separate planning from execution, keep contexts under 100K, review everything) works with just Claude and a text editor.

For the full architecture and implementation details, see the Environment Separation Plan document that covers the dual-stack VPN isolation that makes this kind of parallel development possible.


— Richard Primera, Frao Technologies
Last updated: 2026-07-27