Coding agent built from an empty while loop: phases lift success rate from 29% to 85%

tejaskumarlol · reddit · 2026-11-04

A developer documented building a coding agent harness from scratch with TypeScript and the Anthropic SDK on Claude Haiku 5.5: a while loop around one model call, an inner tool loop, 5 file/shell tools, step/token caps with a y/N gate before writes and bash, plus context management (prompt caching, truncating tool results over 12,000 chars, server compaction at 90k tokens).

The surprise: at 99% per-step success, a 122-step job in one long loop finishes only 29% of the time. Splitting it into short phases (fresh context each, returning a 5-line note, one retry each) lands near 85%. Compaction fixed cost but not success rate — only phases fixed both.

Swapping in IBM Granite 4 via Ollama's Anthropic-compatible endpoint worked with zero harness changes at $0 per call.

Original post →

More from coding & agent

coding & agent channel →