Reading Three AI Agents' Usage Limits From Their Own Sign-Ins, Without Ever Writing Them
How I built a macOS menu bar app that reads Claude Code, Codex and Grok plan limits: Keychain tricks, undocumented endpoints, and bugs found after shipping.
This article details how the open-source Swift app, gas, can read the usage limits of three AI agents - Claude Code, OpenAI's Codex, and Grok - without writing the applications themselves. All three tools have their own session window and weekly cap, but they do not offer a public "how much of my plan have I used" API. Each AI agent stores its credentials in different locations, requiring gas to bypass security measures.
The key challenge was reading Claude Code's OAuth token from macOS Keychain, as simply reading it with SecItemCopyMatching reset the item's access list each time. The fix was to read the token through the secure binary, /usr/bin/security, which always remains on the item's access list and avoids prompts. Similarly, Codex stores its sign-in in ~/.codex/auth.json, and gas only reads the access token and account ID, avoiding the need to refresh the token itself.
For Grok, gas attempted to start the CLI's agent and ask for billing information using the Agent Client Protocol. However, this approach was rejected due to complexity. The article concludes with a diagram showing the overall architecture, split into a SwiftPM package, UsageCore, containing around 440 tests, and a thin SwiftUI and AppKit shell.
Rewritten by urgent.news; may contain errors — check the original.
Source: hackernoon.com
Read the original at hackernoon.com →
More from HackerNoon on urgent.news
Report a problem with this story
Get the day's news by email. Daily, weekly or monthly. Sign up