How to Diagnose Abnormal Credit Usage in AI Coding Assistants
Agentic coding workflows can burn credits far faster than a few extra prompts. This article explains how API metering differs from subscription quotas, how history, tools, sub-agents, compression, and cache misses stack as multipliers, how to detect compression spinning near the context limit, and which logs and engineering controls make usage measurable again.
Agentic coding assistants often consume credits for reasons that go well beyond “asking a few more questions.” A routine edit, test run, or repo read can repeatedly pull conversation history, tool results, system prompts, and tool schemas into the model. Developers report faster quota drain under similar habits, frequent auto-compaction, little context reduction after compaction, and unstable cache hits. To explain the pattern, separate the credit ledger, check whether compaction actually frees window, then use observables to tell heavier tasks and config changes from metering quirks.
Two ledgers: API metering is not the same formula as subscription credits
Cloud LLM API bills typically break out input/output tokens, request count, and unit price. Subscription or workspace credits often also mix model tier, task type, multi-agent usage, and long-context settings. Public per-token price lists cannot be converted directly into “hours left this week.” Token-level breakdown is a reference frame: it can explain why one round was expensive, but it does not by itself prove a metering bug. Before calling usage abnormal, align three things: the same model and context cap, the same tool set and repo scale, and the same reporting window (calendar day vs. rolling week). Larger tasks, deeper repos, and more sub-agents can jump the ledger without being a fault.
Four multipliers, amplified in agent sessions
1. Input size per request. Agent turns almost always carry history, tool results (a large diff or full-file read can add thousands of tokens), repeatedly injected project conventions, and structured tool descriptions. Tool schemas are easy to miss: extra search, terminal, or browser tools occupy a fixed JSON block every turn as billed input.
2. Turn count and sub-agents. A planner plus parallel sub-agents reading files, running tests, and editing modules copies the same system prompt and tool schemas. “Dozens of compactions a day, ten-plus on main and each sub-agent” is common: parallelism scales compaction count—and credits—roughly linearly.
3. Cost of compaction itself. Auto-compaction is not free cleanup. Summarizing long context burns input and output; if “effective context” still sits at tens of thousands of tokens, the next request stays heavy. If compaction barely frees space, the system may compact again near the threshold: compact → still over limit → compact again.
4. Cache hits. Stable prefixes can make prefix cache cut billed input. Compaction that rewrites prefix structure invalidates cache keys, so later requests look like full new input. Compaction cost plus cache miss feels like a cliff. High or jumpy hit rates after compaction must be split: hits on the new summary prefix vs. the old session prefix mean different things on the bill.
Spinning near the compaction threshold: no window freed, still paying
Long-context products typically auto-compact near the cap. Users may see a threshold around 200k+ tokens, post-compaction still 140k–160k, and the next normal request still near 240k. Policy may prefer keeping recent detail over hard quota release. Three consecutive compactions with almost unchanged input will hit the threshold again. Each compaction is an expensive request; without a hard “must drop below a waterline” rule, spinning continues until the session is reset.
This is often a policy vs. product-goal conflict, not a billing bug: agents must remember tool traces and file snippets, so summaries stay conservative; the named window is large but writable space is small. Record input tokens at trigger, after compaction, interval, and whether large tool writes accompanied it. If three compactions barely move the waterline, treat it as an implementation or overly conservative policy issue—not “the model got smarter.”
Turn “feels like overcharge” into checkable logs
Collect on the client or gateway: per-turn input/output tokens, prefix-cache hit, compaction flag, lengths before/after, sub-agent count, tool-return size (chars or estimated tokens), and fixed cost of system prompt plus tool schemas. Time series usually fall into three patterns: single-turn input jumping from tens of thousands to 200k+ (large files or full diffs re-read); compaction density up but post-compaction length down less than 20% (spin); cache hit rate zero after compaction and not recovering (prefix rewritten).
A/B is useful: same repo and task, disable some tools, forbid sub-agents, shorten history, persist large tool results and return only paths plus summaries. If credits return to the old magnitude, the issue is context engineering, not a mistaken account restriction. If tokens and turns are controlled but credits still jump by an order of magnitude, reconcile subscription stats with the API bill so delayed weekly displays are not mistaken for overuse.
Practical cost control and anti-spin measures
Keep the fixed prefix stable and short (conventions, tool list, identity) so prefix cache keeps hitting. Do not rewrite the system prompt every turn. Trim tool schemas per task; unused tools should not stay on the session.
Limit tool return size. Truncate diffs, logs, and page bodies, or summarize locally first. Read large files by line range; never dump the whole repo. Deduplicate repeated reads in-session.
Give compaction a hard waterline: after crossing the threshold, require compression below e.g. 60% of the cap before auto-loop continues, otherwise pause and ask for a new session. Structure summaries: current goal, files changed, open errors, key commands—not a narrative almost as long as the old chat.
Constrain sub-agent fan-out. Parallelize only independent read-only exploration; keep write paths on a single agent. Use shorter context templates for sub-agents.
Align in-product stats with API stats. Treat API-side tokens as the audit source; the subscription page is a quota reminder. If “twenty minutes used what used to last an hour,” export the request list for that window before escalating.
Conclusion: most “anomalies” are stacked context mechanics
Sudden drain, frequent compaction, almost no window after compaction, and odd cache behavior can co-occur and reinforce each other. Before blaming a metering bug, split the four multipliers, verify waterline before/after compaction, and check whether prefix cache was broken. For most agentic coding, smaller tool returns, stable prefixes, limited fan-out, and hard compaction constraints bring usage back into a predictable range. Only if input scale is reproducible, logs are complete, and figures still diverge badly from the API bill should you escalate as a metering-consistency issue. Splitting the ledger beats switching models on emotion if the goal is to keep a week of credits.
