feat(cli): add burn guardrails
Summary
CodeBurn already gives strong post-hoc cost visibility, but there was no small command for catching runaway spend while it is happening. This adds codeburn guard, a one-shot local guardrail check that flags sessions or local-hour windows once they reach configurable USD thresholds.
What changed
- add
codeburn guardwith default thresholds of$3per session and$10per local hour - support existing report-style filters:
--period,--from,--to,--provider,--project, and--exclude - add
--jsonfor scripts and--fail-on-alertfor cron/CI workflows - aggregate hourly spend from parsed assistant calls using local timezone bucketing
- sort alerts by threshold severity so the most urgent guardrail breach appears first
- document the command and add an Unreleased changelog entry
Why one-shot first
A daemon/watch mode could come later, but a one-shot command keeps this first version small and composable. Users can run it manually, from cron, or inside shell scripts without introducing background process state or notification preferences in this PR.
Example
codeburn guard
codeburn guard -p week --max-session-usd 5 --max-hourly-usd 20
codeburn guard --json --fail-on-alert
Validation
npx vitest run tests/guard.test.tsnpx vitest runnpm run buildnode dist/cli.js guard --helpnode dist/cli.js guard --from 2999-01-01 --to 2999-01-02 --json
Note: full npx tsc --noEmit is currently blocked on origin/main by existing src/providers/copilot.ts type errors; this branch does not touch that provider.
Validation run on macOS arm64 with private details omitted. This is behavior proof, not just build proof.
What was checked:
guardwas run with deliberately low thresholds so real local usage produced alert output.- The JSON alert list contained both
sessionandhouralert types, proving both guardrail paths can fire. - A future empty date range (
2999-01-01to2999-01-02) returned zero projects/sessions/calls and an empty alerts array, proving the no-data path does not fabricate alerts.
Commands:
npx vitest run tests/guard.test.ts- 7/7 tests passed.npx tsx src/cli.ts guard -p today --provider claude --max-session-usd 1 --max-hourly-usd 1 --json- JSON parsed and contained both alert classes.npx tsx src/cli.ts guard --from 2999-01-01 --to 2999-01-02 --json- JSON parsed with empty totals/alerts.
No project names, prompts, paths, session IDs, raw costs, usage totals, or private product details are included here.
Closing this — it's an unsolicited feature PR that's gone stale, and per CONTRIBUTING these should start from an issue with maintainer buy-in. Cleaning up my open-PR queue; happy to revisit via an issue if there's interest.