Skip to content

Feature proposal: codexbar guard — a quota-aware exit code to gate automation #2235

Description

@OfficialAbhinavSingh

Update: implemented in #2237 (build + tests green on Linux). Opening it with code + proof rather than waiting on a green light — happy to iterate on the flag shape or close if the direction isn't wanted.

Summary

Add a codexbar guard subcommand that turns CodexBar from a passive display into an active guardrail: it exits 0 when a provider has enough headroom to safely start work, and non-zero when it doesn't — so it can be dropped into scripts and agent loops.

Motivation

Today CodexBar (menu bar and CLI) reports limits — you still have to look, interpret the projection, and decide. For anyone running long or looping agent tasks, the failure mode is hitting a limit mid-task and losing the run.

The data to prevent that is already computed — the CLI prints Pace: On pace | Expected 25% used | Projected empty in 3h 35m. guard just exposes that as a decision an automated caller can act on, via the one thing shell/automation already speaks: an exit code.

Proposed behaviour

codexbar guard --provider <id> [--need <percent>] [--for <duration>] [--json]
  • --need 20% → exit 0 if ≥20% of the relevant window remains, else exit non-zero.
  • --for 3h (optional) → also fail if a reset would land inside that window, or if the current projection ("projected empty in …") is shorter than --for.
  • Exit codes: 0 = safe, 1 = insufficient headroom, 2 = unknown/unreachable (fail-closed by default; --fail-open to invert).
  • --json → emit the decision + the numbers behind it for callers that want detail.

Examples

# stop the loop before it starts a task it can't finish
while codexbar guard --provider claude --need 15%; do run-agent-iteration; done

# gate a long build; if blocked, show when it frees up
codexbar guard --provider codex --need 30% --for 2h \
  && ./long-task.sh \
  || echo "hold off — $(codexbar usage --provider codex | grep -i reset)"

Why this fits CodexBar

  • Delivers the tagline literally — "may your tokens never run out" — by preventing work you can't finish rather than reporting the crash after.
  • Composable, not bloat. One subcommand + exit codes on data the tool already has. No new UI, fits the minimal-CLI style.
  • Squarely for agent-automation users — gating codex/claude loops on remaining quota. Cross-platform (CLI/Core), so it lands for the Linux CLI users too.

Scope (MVP)

Single provider, --need <percent>, exit 0/1/2, fail-closed. --for, --json, and multi-provider (--provider all, pass only if every provider passes) as follow-ups. Deterministic — straightforward to cover with focused tests (no live provider or app run needed).

Status

Implemented in #2237 — build and Linux tests green. Feedback on the flag shape (--need / --window / --fail-open) is very welcome, and I'm happy to close it if a quota-guard / exit-code contract isn't something you'd want in CodexBar, @steipete.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low-risk cleanup, docs, polish, ergonomics, or speculative feature.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.issue-rating: 🌊 off-meta tidepoolIssue quality rating does not apply to this item.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions