cd /news/developer-tools/catch-token-cost-regressions-in-ci-b… Β· home β€Ί topics β€Ί developer-tools β€Ί article
[ARTICLE Β· art-67624] src=dev.to β†— pub= topic=developer-tools verified=true sentiment=↑ positive

Catch token-cost regressions in CI before they ship

Wartzar-bee released a GitHub Action called ci-guardrail that catches token-cost regressions in CI before they ship. The action performs static analysis of agent code to estimate structural token costs and can block pull requests if costs exceed a configurable threshold. It was inspired by a real incident where a team's Claude bill jumped 40% from a small prompt change.

read2 min views1 publishedJul 21, 2026

Last year a team shipped a "small prompt improvement" on a Friday. By Monday their Claude bill had jumped 40%. Nobody caught it in review β€” the diff looked fine. The tokens were invisible.

We wrote about the extreme end of this in We burned 136 million tokens running an autonomous agent studio β€” here's how we cut the bill ~90%. That was a runaway agent. But most cost regressions aren't dramatic β€” they're a prompt that grew by 200 tokens, a context window that stopped being trimmed, a new tool whose description is 800 words long. They compound quietly until the bill arrives.

We built the guardrail we wish we'd had.

** wartzar-bee/ci-guardrail** is a GitHub Action that:

@wartzar-bee/tokenscope

Here's what the PR comment looks like when a regression is caught:

## 🚨 wartzar-bee Cost Guardrail

| Metric          | Value      |
|-----------------|------------|
| Base tokens     | 12,400     |
| This PR tokens  | 16,200     |
| Delta           | **+30.6%** |
| Threshold       | 20%        |

### Top token consumers (HEAD)
| File                      | Tokens |
|---------------------------|--------|
| src/agent/prompts.ts      | 8,100  |
| src/agent/context.ts      | 4,200  |
| src/tools/search.ts       | 3,900  |

β›” Build blocked β€” cost regression exceeds the 20% threshold.
Reduce prompt size, add caching, or raise the threshold if intentional.

The comment is idempotent β€” it updates in place on each push, no spam.

Add one file to your repo:

name: Cost Guardrail
on: [pull_request]

jobs:
  cost-check:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: wartzar-bee/ci-guardrail@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          threshold-pct: 20   # block if tokens grow >20% vs base

That's it. No API keys. No external service. GITHUB_TOKEN

is the only secret β€” it's already in every repo.

Not ready to block builds yet? Set threshold-pct: 0

:

- uses: wartzar-bee/ci-guardrail@v1
  with:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    threshold-pct: 0   # always comment, never block

You get visibility without the gate. Add the gate when you're ready.

The action uses tokenscope scan

β€” a static analysis of your agent code (prompts, context configs, tool definitions). It doesn't run your agent. That means:

The tradeoff: it estimates structural token cost, not runtime cost (which depends on conversation history, tool outputs, etc.). For catching regressions from prompt edits and config changes, static analysis catches the majority of real-world cases. Live sandbox execution is on the roadmap.

The 136M-token burn postmortem identified three root causes that appear in almost every cost incident:

The CI guardrail addresses all three: it establishes a per-PR baseline, provides an optional gate, and shows exactly which files are responsible.

The action is available now. The repo is at ** wartzar-bee/ci-guardrail** β€” copy the workflow above and you're running in under two minutes.

If you hit an edge case or want to discuss the approach, open an issue or find us at @wartzarbee.

*wartzar-bee builds cost-efficient autonomous agents. *

@wartzar-bee/tokenscope

is our open-source token analysis tool β€” ~90 installs/month and growing.

── more in #developer-tools 4 stories Β· sorted by recency
── more on @wartzar-bee 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/catch-token-cost-reg…] indexed:0 read:2min 2026-07-21 Β· β€”