claude-codex-battery

skill
Guvenlik Denetimi
Basarisiz
Health Gecti
  • License รขโ‚ฌโ€ License: MIT
  • Description รขโ‚ฌโ€ Repository has a description
  • Active repo รขโ‚ฌโ€ Last push 0 days ago
  • Community trust รขโ‚ฌโ€ 15 GitHub stars
Code Basarisiz
  • execSync รขโ‚ฌโ€ Synchronous shell command execution in claude-codex-usage.2m.js
Permissions Gecti
  • Permissions รขโ‚ฌโ€ No dangerous permissions requested

Bu listing icin henuz AI raporu yok.

SUMMARY

macOS menu bar widget showing Claude Code & Codex usage limits as battery icons ๐Ÿ”‹

README.md

๐Ÿ”‹ Claude & Codex Usage Battery

License: MIT Platform: macOS SwiftBar plugin Runtime: bun Zero dependencies GitHub stars

A macOS menu bar widget that shows your remaining Claude Code and Codex usage limits as battery icons โ€” so you never have to open /usage again.

Menu bar battery widget

C = Claude ยท X = Codex. Each battery shows the remaining % of a limit window โ€” full & green means plenty left, red means almost out. Click for a detailed breakdown with reset times.

Built as a single SwiftBar plugin โ€” one self-contained script, no third-party libraries. The battery icons are rendered as PNGs from scratch in pure JavaScript (node:zlib only), so there's no image library and no npm install. The only network call is an optional once-a-day update check (see Updating) โ€” disable it and the widget makes none at all. (ccusage is an optional extra for the cost breakdown.)


What it shows

Group Batteries Source
C Claude 5-hour session ยท weekly ยท Fable (top-model weekly cap) ~/.claude/MEMORY/STATE/usage-cache.json โ€” updated live by Claude Code
X Codex 5-hour ยท weekly (or credit balance on the premium plan) ~/.codex/sessions/**/*.jsonl โ†’ rate_limits

Click the widget for a dropdown with, per limit:

Claude Code
  5h remaining   โ–•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ– 70%  (used 30%)  ยท resets 3h 18m
  weekly         โ–•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ– 33%  (used 67%)  ยท resets 3d 21h
  Fable          โ–•โ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ– 26%  (used 74%)  ยท resets 3d 21h
  today by model โ–•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ– Fable $75 ยท Opus $46 ยท Sonnet $5 โ€ฆ

Codex ยท prolite
  5h remaining   โ–•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ– 100% (used 0%)
  weekly         โ–•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹โ–‘โ–‘โ–‘โ– 83%  (used 17%)

Colors follow a traffic-light scale: green โ‰ฅ 50 % left, amber < 50 %, red < 20 %.


Requirements

Required? Install
macOS โœ… โ€”
SwiftBar โœ… brew install swiftbar
bun โœ… curl -fsSL https://bun.sh/install | bash
Claude Code โœ… for C batteries needs ~/.claude/MEMORY/STATE/usage-cache.json to exist
Codex CLI optional for the X batteries; without it, only Claude is shown
ccusage optional adds the cost / token / per-model breakdown in the dropdown โ€” the battery works fully without it

Note: This widget reads your own local usage files. If you don't use Claude Code (or Codex), there simply won't be any data to display.


Install

git clone https://github.com/dennykim123/claude-codex-battery.git
cd claude-codex-battery
./install.sh

install.sh will:

  1. Verify bun and SwiftBar are present (and tell you how to install them if not)
  2. Copy the plugin into ~/.swiftbar-plugins/, rewriting the shebang to your machine's bun path (SwiftBar runs plugins with a minimal PATH, so an absolute shebang is required)
  3. Point SwiftBar at the plugin folder and launch it

No npm install, no bundled libraries โ€” the plugin is a single self-contained script.

The battery appears in your menu bar within a few seconds. It refreshes every 2 minutes (the .2m. in the filename).

Manual install

If you prefer not to run the script:

mkdir -p ~/.swiftbar-plugins
# rewrite shebang to your bun path, then copy:
sed "1s|.*|#!$(command -v bun)|" claude-codex-usage.2m.js > ~/.swiftbar-plugins/claude-codex-usage.2m.js
chmod +x ~/.swiftbar-plugins/claude-codex-usage.2m.js
defaults write com.ameba.SwiftBar PluginDirectory -string ~/.swiftbar-plugins
open -a SwiftBar

Updating

The widget checks GitHub for a newer version at most once a day โ€” a tiny background request that is the only network call it ever makes. When a new version is out, a green ๐Ÿ†• update row appears in the dropdown; click it to replace the plugin in place and refresh (your previous copy is kept as .bak).

Prefer to do it yourself? From your clone: git pull && ./install.sh.

To turn the check off entirely, comment out the getUpdateInfo() call near the bottom of the script โ€” then the widget makes zero network calls.


Privacy & security

  • No usage data leaves your machine. Limits are read from local files and rendered locally; the only network call is the optional daily update check above.
  • No secrets read. It never touches auth.json, credentials, or keychains.
  • No conversation content. From Codex session logs it parses only the rate_limits object (numbers), never the messages.
  • Usage values are read at runtime โ€” nothing is baked into the code, so sharing the script shares no data.

How accurate / in-sync is it?

Claude โ€” effectively real-time. The limits come from usage-cache.json, the same rate-limit data Claude Code uses for its own /usage. The widget just reads that file (every 2 min), so its numbers track Claude's. Measured on a live machine: the widget's weekly and Fable readings matched the source file exactly; the 5-hour figure differed only by the live drift between two reads a minute apart.

Codex โ€” as fresh as your last Codex run. Codex writes rate-limit data to its session logs only while you use it, and records no reset time. So the value is a snapshot from your most recent session โ€” the dropdown labels it "measured N ago" and warns past 3h. Run Codex and it re-syncs instantly.

TL;DR โ€” Claude is live (same source as /usage); Codex is a clearly-labeled snapshot from your last session, not a live feed.


How it works

The whole thing is one .js file run by bun on a timer.

  • Battery icons are drawn pixel-by-pixel into an RGBA buffer and encoded to PNG using only node:zlib (hand-rolled CRC32 + IHDR/IDAT/IEND chunks). A 5ร—7 bitmap font renders the numbers and the C/X group labels. SwiftBar displays the PNG at pixels รท 2 pt.
  • Claude limits come from usage-cache.json, which Claude Code keeps current. The Fable cap is the weekly_scoped entry.
  • Codex limits come from the newest session's rate_limits. The premium plan reports a credits object instead of percentages when exhausted; the widget handles both shapes.

Codex has one quirk

Codex only writes limit data to session logs while you use it, and doesn't record a reset time when exhausted. So if you haven't run Codex in a while, the value can be stale. The widget:

  • flags values older than 3 hours in the dropdown, and
  • optionally runs codex exec --sandbox read-only in the background to refresh โ€” but only when Codex is exhausted and the value is 2h+ old, at most once every 6 hours (โ‰ˆ4ร—/day, ~20k tokens each).

If you'd rather it never spend tokens on its own, comment out the maybeAutoRefreshCodex(codex) call near the render section.


Customizing

Want to change Where
Refresh interval filename .2m. โ†’ .1m., .5m., .30s., โ€ฆ
Battery size drawCapsule: bw / bh (5ร—7 font sets the floor)
Color thresholds heatRemain / heatRemainHex (20 % / 50 %)
Disable Codex auto-refresh comment out maybeAutoRefreshCodex(codex)
Which Claude limits to show the battItems.push(...) block

Why a SwiftBar plugin (and not a standalone app)?

A single script stays dependency-free, easy to audit, and trivial to fork โ€” and its audience (Claude Code / Codex developers) already lives in the terminal, so brew install swiftbar is no barrier. A native .app would drop the SwiftBar requirement but adds a Swift codebase, Apple code-signing + notarization ($99/yr), and ongoing maintenance. Roadmap: if there's enough demand, ship a signed one-click menu-bar .app (likely bundling SwiftBar) for non-terminal users.

Contributing

Issues and PRs welcome โ€” especially for other plans/tools (e.g. mapping additional rate_limit shapes, or adding providers). Keep it dependency-free.

License

MIT

Yorumlar (0)

Sonuc bulunamadi