[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-92772":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":9,"pushedAt":9,"updatedAt":33,"readmeContent":34,"aiSummary":35,"trendingCount":15,"starSnapshotCount":15,"syncStatus":14,"lastSyncTime":36,"discoverSource":37},92772,"claude-codex-battery","dennykim123\u002Fclaude-codex-battery","dennykim123","macOS menu bar widget showing Claude Code & Codex usage limits as battery icons 🔋",null,"JavaScript",72,9,55,2,0,17,44.7,"MIT License",false,"main",true,[23,24,25,26,27,28,29,30,31,32],"anthropic","bun","claude-code","codex","developer-tools","macos","menu-bar-widget","menubar","swiftbar","usage-tracker","2026-07-22 04:02:07","# 🔋 Claude & Codex Usage Battery\n\n\u003Cp align=\"center\">\n  \u003Ca href=\"LICENSE\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-blue.svg\" alt=\"License: MIT\">\u003C\u002Fa>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fplatform-macOS-000000?logo=apple&logoColor=white\" alt=\"Platform: macOS\">\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSwiftBar-plugin-FF9500\" alt=\"SwiftBar plugin\">\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fruntime-bun-14151A?logo=bun&logoColor=white\" alt=\"Runtime: bun\">\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fdependencies-none-brightgreen.svg\" alt=\"Zero dependencies\">\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fdennykim123\u002Fclaude-codex-battery\u002Fstargazers\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fstars\u002Fdennykim123\u002Fclaude-codex-battery?style=flat&logo=github\" alt=\"GitHub stars\">\u003C\u002Fa>\n\u003C\u002Fp>\n\n> A macOS menu bar widget that shows your remaining **Claude Code** and **Codex** usage limits as battery icons — so you never have to open `\u002Fusage` again.\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"docs\u002Fmenubar@2x.png\" alt=\"Menu bar battery widget\" width=\"280\">\n\u003C\u002Fp>\n\n`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.\n\nBuilt as a single [SwiftBar](https:\u002F\u002Fgithub.com\u002Fswiftbar\u002FSwiftBar) 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`. Network calls: **one to Anthropic's official usage endpoint** (the same data `\u002Fusage` shows, fetched with your own local Claude Code login — [see Privacy](#privacy--security)) and an **optional once-a-day update check** ([see Updating](#updating)). (`ccusage` is an optional extra for the cost breakdown.)\n\n---\n\n## What it shows\n\n| Group | Batteries | Source |\n|-------|-----------|--------|\n| **`C` Claude** | 5-hour session · weekly · **Fable** (top-model weekly cap) | Anthropic's OAuth usage API — queried live with your local Claude Code login; **account-level**, so usage from every device\u002Fsurface is included |\n| **`X` Codex** | 5-hour · weekly (or credit balance on the premium plan) | `~\u002F.codex\u002Fsessions\u002F**\u002F*.jsonl` → `rate_limits` |\n\nClick the widget for a dropdown with, per limit:\n\n```\nClaude Code\n  5h remaining   ▕██████████████░░░░░░▏ 70%  (used 30%)  · resets 3h 18m\n  weekly         ▕██████▋░░░░░░░░░░░░░▏ 33%  (used 67%)  · resets 3d 21h\n  Fable          ▕████░░░░░░░░░░░░░░░░▏ 26%  (used 74%)  · resets 3d 21h\n  today by model ▕████████████▏ Fable $75 · Opus $46 · Sonnet $5 …\n\nCodex · prolite\n  5h remaining   ▕████████████████████▏ 100% (used 0%)\n  weekly         ▕████████████████▋░░░▏ 83%  (used 17%)\n```\n\nColors follow a traffic-light scale: green ≥ 50 % left, amber \u003C 50 %, red \u003C 20 %.\n\n---\n\n## Requirements\n\n| | Required? | Install |\n|---|---|---|\n| **macOS** | ✅ | — |\n| **[SwiftBar](https:\u002F\u002Fgithub.com\u002Fswiftbar\u002FSwiftBar)** | ✅ | `brew install swiftbar` |\n| **[bun](https:\u002F\u002Fbun.sh)** | ✅ | `curl -fsSL https:\u002F\u002Fbun.sh\u002Finstall \\| bash` |\n| **Claude Code** | ✅ for `C` batteries | just needs to be **logged in** on this Mac (the widget reuses its login to query the usage API) |\n| **Codex CLI** | optional | for the `X` batteries; without it, only Claude is shown |\n| **[ccusage](https:\u002F\u002Fgithub.com\u002Fryoppippi\u002Fccusage)** | optional | adds the cost \u002F token \u002F per-model breakdown in the dropdown — **the battery works fully without it** |\n\n> **Note:** This widget shows *your own account's* limits — via your local Claude Code login and your local Codex session logs. If you don't use Claude Code (or Codex), there simply won't be any data to display.\n\n---\n\n## Install\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fdennykim123\u002Fclaude-codex-battery.git\ncd claude-codex-battery\n.\u002Finstall.sh\n```\n\n`install.sh` will:\n\n1. Verify **bun** and **SwiftBar** are present (and tell you how to install them if not)\n2. Copy the plugin into `~\u002F.swiftbar-plugins\u002F`, rewriting the shebang to your machine's `bun` path *(SwiftBar runs plugins with a minimal `PATH`, so an absolute shebang is required)*\n3. Point SwiftBar at the plugin folder and launch it\n4. Register SwiftBar as a login item, so the battery comes back automatically after a reboot\n\nNo `npm install`, no bundled libraries — the plugin is a single self-contained script.\n\nThe battery appears in your menu bar within a few seconds. It refreshes **every 2 minutes** (the `.2m.` in the filename).\n\n### Manual install\n\nIf you prefer not to run the script:\n\n```bash\nmkdir -p ~\u002F.swiftbar-plugins\n# rewrite shebang to your bun path, then copy:\nsed \"1s|.*|#!$(command -v bun)|\" claude-codex-usage.2m.js > ~\u002F.swiftbar-plugins\u002Fclaude-codex-usage.2m.js\nchmod +x ~\u002F.swiftbar-plugins\u002Fclaude-codex-usage.2m.js\ndefaults write com.ameba.SwiftBar PluginDirectory -string ~\u002F.swiftbar-plugins\nopen -a SwiftBar\n```\n\n---\n\n## Updating\n\nThe widget checks GitHub for a newer version **at most once a day** — a tiny background request for the `VERSION` file. 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`). There's also an always-visible **⬆️ update now** row that replaces the plugin with the latest `main` on demand — no waiting for the daily check.\n\nPrefer to do it yourself? From your clone: `git pull && .\u002Finstall.sh`.\n\nTo turn the check off entirely, comment out the `getUpdateInfo()` call near the bottom of the script — then the only network call left is the Anthropic usage query.\n\n---\n\n## Privacy & security\n\n- **Claude limits come straight from Anthropic.** The widget reads your Claude Code OAuth token from the macOS Keychain (item `Claude Code-credentials`) and calls `api.anthropic.com\u002Fapi\u002Foauth\u002Fusage` — the same endpoint `\u002Fusage` uses. The token is sent **only to api.anthropic.com**, passed via stdin (never visible in `ps`), and never written to disk or logs. macOS may show a one-time Keychain permission prompt — click **Always Allow**. (Clicking *Deny* makes macOS re-prompt on every refresh — if you'd rather the widget never touch the Keychain, run `touch ~\u002F.claude\u002Fswiftbar\u002F.no-live` instead; it then reads local cache files only, like v1.1.)\n- **No other secrets read.** Codex `auth.json` and API keys are never touched.\n- **No usage data leaves your machine.** Nothing is uploaded anywhere; the only outbound calls are the Anthropic usage query above and the optional daily update check ([Updating](#updating)).\n- **No conversation content.** From Codex session logs it parses only the `rate_limits` object (numbers), never the messages.\n- **Auditable in one sitting.** The whole widget is a single dependency-free script — grep for `curl`\u002F`fetch` and you've seen every network call it can make.\n\n---\n\n## How accurate \u002F in-sync is it?\n\n**Claude — live.** Every refresh queries Anthropic's usage API directly with your local Claude Code login — the *same* server-side data `\u002Fusage` shows, so the numbers match it by construction. Because the limits are **account-level**, usage from every surface and device (terminal, desktop app, web, another machine) is already included. If the query fails (offline, logged out), the widget falls back to its last successful response and labels the reading with its age in amber.\n\n**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.\n\n**TL;DR** — Claude is live (same source as `\u002Fusage`); Codex is a clearly-labeled snapshot from your last session, not a live feed.\n\n---\n\n## How it works\n\nThe whole thing is one `.js` file run by bun on a timer.\n\n- **Battery icons** are drawn pixel-by-pixel into an RGBA buffer and encoded to PNG using only `node:zlib` (hand-rolled CRC32 + IHDR\u002FIDAT\u002FIEND chunks). A 5×7 bitmap font renders the numbers and the `C`\u002F`X` group labels. SwiftBar displays the PNG at pixels ÷ 2 pt.\n- **Claude limits** are fetched from Anthropic's OAuth usage endpoint using the Claude Code login token in your Keychain, with the last good response cached at `~\u002F.claude\u002Fswiftbar\u002F.claude-usage.json` as an offline fallback. The Fable cap is the `weekly_scoped` entry.\n- **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.\n\n### Codex has one quirk\n\nCodex 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:\n\n- flags values older than 3 hours in the dropdown, and\n- **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×\u002Fday, ~20k tokens each).\n\nIf you'd rather it never spend tokens on its own, comment out the `maybeAutoRefreshCodex(codex)` call near the render section.\n\n---\n\n## Customizing\n\n| Want to change | Where |\n|---|---|\n| Refresh interval | filename `.2m.` → `.1m.`, `.5m.`, `.30s.`, … |\n| Battery size | **↕ row in the dropdown** — toggles between big (4×6 font, default) and small (3×5 font, ~25% narrower); stored in `~\u002F.claude\u002Fswiftbar\u002F.batt-size` |\n| Color thresholds | `heatRemain` \u002F `heatRemainHex` (20 % \u002F 50 %) |\n| Disable Codex auto-refresh | comment out `maybeAutoRefreshCodex(codex)` |\n| Disable live Claude API \u002F Keychain access | `touch ~\u002F.claude\u002Fswiftbar\u002F.no-live` (falls back to local cache files) |\n| Which Claude limits to show | the `battItems.push(...)` block |\n\n---\n\n## Why a SwiftBar plugin (and not a standalone app)?\n\nA single script stays dependency-free, easy to audit, and trivial to fork — and its audience (Claude Code \u002F 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\u002Fyr), and ongoing maintenance. **Roadmap:** if there's enough demand, ship a signed one-click menu-bar `.app` (likely bundling SwiftBar) for non-terminal users.\n\n## Contributing\n\nIssues and PRs welcome — especially for other plans\u002Ftools (e.g. mapping additional `rate_limit` shapes, or adding providers). Keep it dependency-free.\n\n## License\n\n[MIT](LICENSE)\n","这是一个运行于 macOS 系统的菜单栏小工具，用于实时显示 Anthropic Claude Code 和 Codex 服务的用量配额剩余比例，并以电池图标直观呈现。核心功能包括：通过 SwiftBar 插件架构实现轻量级集成；直接调用 Anthropic 官方用量 API（基于本地登录凭证）和本地 Codex 日志解析获取数据；自绘 PNG 电池图标（纯 JavaScript 实现，零外部依赖）；点击展开详细用量分组（如 5 小时会话、周限额、Fable 模型限额等）及重置时间。适用于频繁使用 Claude Code 或 Codex 的 macOS 开发者，帮助其免去手动访问 \u002Fusage 页面即可掌握配额状态。","2026-07-10 02:30:25","CREATED_QUERY"]