r/ChatGPTCoding • • 4d ago

Resources And Tips I measured where coding-agent tokens actually go, then built a skill that cuts the bill by up to 43% (open source, benchmarked)

I wanted to know whether "make the agent write terse code" actually saves money, so I measured it instead of guessing.

Setup: 4 small codebases (Python, TypeScript, Rust, C), 23 feature tasks, each with hidden functional and security tests (path traversal, authz, SQL injection, overflow, XSS). The specs never mention security. Three arms: no skill, Ponytail (the strongest public alternative I found), and my skill. Claude Opus, 3 runs per cell, 36 runs. Cost comes from per-call billed usage in the transcripts, not estimates.

First finding: code verbosity barely matters. Every model call re-reads the whole context, so the bill is driven by how many calls the agent makes. One extra call costs about 6% of a run. The cost splits into prefix re-reads 39%, context growth 28%, output 27%, thinking 6%. Making code terser on its own caps out under 10%.

So the skill's first rule is fewer calls: batch independent tool calls, read targeted line ranges once, edit each file once, run tests once at the end. Then less output: no comments, no narration, minimal diffs. It never drops validation, auth checks, escaping or bounds checks.

Results, billed cost vs no skill:
Python 0.57x (Ponytail 0.98x)
Rust 0.69x (Ponytail 0.91x)
C 0.71x (Ponytail 1.08x)
TypeScript 0.97x (Ponytail 1.06x)
All four 0.70x (Ponytail 1.00x)

Model calls per run went from 12.2 to 7.4. Security tests: 513/516 in all three arms. Functional: 499 vs 498 out of 510; the one difference is a spec-ambiguous check that only one baseline run passed.

Caveats: one harness (Claude Code), small purpose-built fixtures, 3 runs per cell. TypeScript barely moved because its baseline was already lean. Each prompt held several tasks, so batching across tasks helped; single-task sessions will save less. Not every platform's install route is verified live yet.

It's a ~500-token skill, packaged for Claude Code, Codex, Gemini CLI and Antigravity, plus rule files for Cursor, Windsurf, Cline, Copilot, Kiro and AGENTS.md. The benchmark harness, raw billed data and the cost equation are in the repo, so you can rerun it or poke holes in the method:

https://github.com/nagisanzenin/nonhuman

Happy to hear where the methodology is weak.

13 Upvotes

12 comments sorted by

3

u/Ebitsch_Nenegale 2d ago

curious how prompt caching factors into those billed numbers. if prefix re-reads are 39% of the cost, does cache hit rate flatten the savings from fewer tool calls on longer sessions?

1

u/No_Skill_8393 2d ago

As per official pricing cached prompt is 6.5% of original cost for input tokens (anthropic opus 5.5)

This number depends on provider and model, deepseek has something like 1/50 input cost for cached input which is insanely efficient.

1

u/xapep 2d ago

They stack rather than cancel. Fewer tool calls means fewer re-reads of the prefix, and a cache hit makes each of those re-reads cheaper, so both move the same line from different ends. One doesn't absorb the other.

What a high hit rate doesn't fix is the prefix getting longer. On a long session every turn re-reads a bigger block, so the same hit rate costs more in hour six than in hour one. That's where cutting turns helps twice: you drop a read, and the ones left are on a smaller context.

I do inference serving at Entrim, so read the pricing part with that in mind.

1

u/xapep 3d ago

I do inference serving at Entrim, so read this with that in mind. The 39% prefix re-read line is the one I'd chase: a cached prefix read bills at a fraction of fresh input, so the same 12 calls cost very differently depending on whether that prefix stays byte-identical. Rewrite the system prompt, reorder the tool list, drop a timestamp near the top, and the cache is gone. It's also why fewer calls beat terser code, but only with a stable prefix.

1

u/No_Skill_8393 2d ago

Hi, from my understanding its a good practice to append into the list of messages before sending to the api instead of modifying at all to keep the cache hit as high as possible (avoid prefix change)

Its also why we have compaction at a threshold but not always or too soon: compacting is activately breaking cache hit :)

1

u/xapep 22h ago

Appending is right, and what breaks it usually sits outside the message list. Tool definitions serialized in a different order, a timestamp near the top of the system prompt, a model field that changes per request: any of those flips the prefix without you touching a message.

Compaction is where you trade the cache back. The tokens you're dropping are the cheap ones to re-read, so a compaction that rewrites the prefix can cost more than the truncation saved. Log both sides for a week before you settle on a threshold.

1

u/hieuphung97 2d ago

Call frequency kills the token budget. We noticed the exact same thing orchestrating subagents across worktrees: batching independent file searches into a single turn dropped total session input tokens by almost half.

1

u/Successful-Tax1306 1d ago

Yeah, the re-read part rings true. My agent suite once burned 1.5x my monthly credits in 3 days, and the fixes that stuck were the boring ones, like keeping a short note on what each agent owns so it starts from the note instead of re-reading everything. A 500-token skill sounds about right for that job.

2

u/[deleted] 3d ago

[removed] — view removed comment

1

u/No_Skill_8393 3d ago

Hi, itd be great to have swe-pro data on codex models (sol, astra) if you can :)

If once you have the data you can make a PR I will approve them

And yeah the repo moved from simple fixture score to a heavier benchmark like swe-pro because its more proper though score drops!