{"id":45531612,"url":"https://github.com/chriswiegman/vscode-ai-usage-limits","last_synced_at":"2026-05-27T01:04:17.464Z","repository":{"id":340048562,"uuid":"1164303460","full_name":"ChrisWiegman/vscode-ai-usage-limits","owner":"ChrisWiegman","description":"Shows Claude and Codex usage budgets in the VS Code status bar using existing extension logins.","archived":false,"fork":false,"pushed_at":"2026-05-16T14:44:42.000Z","size":223,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-16T16:47:33.258Z","etag":null,"topics":["anthropic","budget","claude","codex","openai","usage","vscode-extension"],"latest_commit_sha":null,"homepage":"https://marketplace.visualstudio.com/items?itemName=ChrisWiegman.ai-usage-limits","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChrisWiegman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-22T23:18:36.000Z","updated_at":"2026-05-16T14:41:44.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ChrisWiegman/vscode-ai-usage-limits","commit_stats":null,"previous_names":["chriswiegman/vscode-ai-usage-limits"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/ChrisWiegman/vscode-ai-usage-limits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisWiegman%2Fvscode-ai-usage-limits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisWiegman%2Fvscode-ai-usage-limits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisWiegman%2Fvscode-ai-usage-limits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisWiegman%2Fvscode-ai-usage-limits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChrisWiegman","download_url":"https://codeload.github.com/ChrisWiegman/vscode-ai-usage-limits/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisWiegman%2Fvscode-ai-usage-limits/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33162448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T22:39:12.733Z","status":"online","status_checked_at":"2026-05-18T02:00:06.436Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anthropic","budget","claude","codex","openai","usage","vscode-extension"],"created_at":"2026-02-23T01:19:15.437Z","updated_at":"2026-05-18T02:12:29.472Z","avatar_url":"https://github.com/ChrisWiegman.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AI Limits\n\nA VS Code extension that shows your **Claude** and **Codex** usage in the status bar using the credentials already managed by their companion tools.\n\n## Features\n\n- **Claude budget** – powered by the [Claude Code](https://marketplace.visualstudio.com/items?itemName=anthropic.claude-code) extension login\n- **Codex budget** – powered by the [ChatGPT](https://marketplace.visualstudio.com/items?itemName=openai.chatgpt) extension login\n- **Quick jump to account settings** – click either status bar meter to open that service's settings page\n- **Manual refresh** – run `AI Limits: Refresh Now` from the Command Palette to clear the cache and fetch immediately\n- Shows **last 5 hours** and **last 7 days** in the status bar\n- Displays **USD spend** for API-key based accounts and **percentage utilization** for OAuth/session-based accounts\n- Shows clear states for **Please log in**, **loading**, **No usage yet**, and **error**\n- Tooltip shows detailed breakdown, reset times when available, and refresh timing\n- Auto-refreshes every 5 minutes and whenever authentication sessions change\n\n## Requirements\n\nInstall at least one of the companion extensions and sign in:\n\n| Extension | Marketplace ID | Purpose |\n|-----------|---------------|---------|\n| Claude Code | `anthropic.claude-code` | Provides Anthropic authentication |\n| ChatGPT | `openai.chatgpt` | Provides OpenAI authentication |\n\n**AI Limits** only shows a status bar item for companion extensions that are installed.\nIf an installed companion extension is not authenticated, the item stays visible and shows `Please log in`.\nIf neither companion extension is installed, the extension activates silently with no UI impact.\n\n## Status bar Format\n\n```\n✳ 5h: 80% 7d: 14%   ◎ 5h: 3% 7d: 13%\n```\n\nExamples of the compact states:\n\n| State | Example |\n|------|---------|\n| Not logged in | `✳ Please log in` |\n| Loading | `✳ ...` |\n| No usage in either window yet | `✳ No usage yet` |\n| Error | `✳ error` |\n| Usage available | `✳ 5h: 80% 7d: 14%   ◎ 5h: 3% 7d: 13%` |\n\nHover over an item for a detailed tooltip with exact figures, reset times when known, and refresh timing.\n\nClicking a status bar item opens the corresponding usage/settings page in your browser. VS Code may show a trusted-domain warning the first time you open links to `https://claude.ai` or `https://chatgpt.com`. To avoid future prompts, add those domains once through `Trusted Domains: Manage Trusted Domains`.\n\n## How It Works\n\n1. On startup the extension checks whether `anthropic.claude-code` and/or `openai.chatgpt` are installed.\n2. For each installed extension it reads credentials from the same on-disk or keychain locations that extension uses:\n   - **Claude Code**: reads the macOS Keychain entry for service `\"Claude Code-credentials\"` (account = `$USER`). Falls back to `~/.claude/.credentials.json` on non-macOS systems or if the keychain is unavailable.\n   - **Codex / ChatGPT**: reads `~/.codex/auth.json` (or `$CODEX_HOME/auth.json`).\n3. The extension resolves usage data from the most reliable source available:\n   - **Claude API key auth**: `GET https://api.anthropic.com/v1/usage` with `start_time` / `end_time`\n   - **Claude OAuth auth**: `GET https://api.anthropic.com/api/oauth/usage` for 5-hour and 7-day utilization percentages\n   - **OpenAI API key auth**: `GET https://api.openai.com/v1/usage?date=YYYY-MM-DD` plus `GET /v1/dashboard/billing/subscription`\n   - **Codex ChatGPT OAuth auth**: searches `~/.codex/sessions/` recursively for the most recently modified `.jsonl` file and uses the embedded `rate_limits` snapshot (`300` minute and `10080` minute windows)\n4. The status bar renders one of five compact states per provider (checked in this order):\n   - `Please log in` when the companion extension is installed but no usable credentials are found\n   - `error` when credentials were found but the data fetch failed\n   - `...` while data is being loaded\n   - `No usage yet` when both usage windows are currently empty or unavailable\n   - Usage values when at least one window is available\n5. Results are cached by token, refreshed every 5 minutes, and refreshed again when VS Code reports extension or authentication changes. If a companion extension was not yet registered at startup (VS Code does not guarantee all extensions are visible when `onStartupFinished` fires), a one-time retry runs 10 seconds later so the status bar items appear without requiring a manual refresh.\n6. Run **AI Limits: Refresh Now** from the Command Palette at any time to clear the cache and trigger an immediate fetch.\n\n## Known Limitations\n\n### Claude Fallback Behavior\n\nWhen the Claude APIs do not provide usable usage data, the extension falls back to local Claude project JSONL files where possible. This fallback can estimate USD usage for API-key based workflows, but it does not help OAuth percentage mode when no percentage snapshot is available.\n\n### 5-Hour Window (OpenAI API Key Mode)\n\nOpenAI's usage endpoint returns data aggregated by UTC calendar day. The 5-hour figure is pro-rated from today's usage based on the elapsed fraction of the day, so it is an approximation.\n\n### OAuth and Session-Based Modes\n\nWhen authenticated through Claude OAuth or ChatGPT/Codex OAuth, the extension shows **percentage utilization** for the 5-hour and 7-day windows instead of USD spend.\n\nFor Codex, those percentages come from the latest local rollout snapshot. Older snapshots are intentionally ignored once they are too stale, so the UI may show `No usage yet` rather than a misleading old value.\n\n### Trusted-Domain Prompts\n\nWhen you click a status bar item, the extension uses VS Code's standard external-link handling to open the service's usage page. VS Code may ask you to trust `https://claude.ai` and `https://chatgpt.com` before opening them. This trust list is controlled by VS Code rather than by the extension, so the prompt cannot be suppressed automatically.\n\nIf you want to stop seeing that warning, run `Trusted Domains: Manage Trusted Domains` from the Command Palette and add:\n\n- `https://claude.ai`\n- `https://chatgpt.com`\n\n### Cost Estimation\n\nWhen the API response does not include a pre-computed cost field, costs are estimated using hardcoded list pricing:\n\n| Service | Model assumed | Input | Output | Cache write | Cache read |\n|---------|--------------|-------|--------|-------------|------------|\n| Anthropic | Claude 3.5 Sonnet | $3 / 1M | $15 / 1M | $3.75 / 1M | $0.30 / 1M |\n| OpenAI | GPT-4o | $5 / 1M | $15 / 1M | — | — |\n\nCache pricing applies only to the Anthropic JSONL local-file fallback path. Actual costs may differ if you use other models or have negotiated pricing.\n\n## Testing\n\nThe quickest manual check is to press `F5` in this repo and use the Extension Development Host:\n\n1. Install the companion extension you want to test.\n2. Sign out to verify `Please log in`.\n3. Sign in and wait for a refresh to verify live usage formatting.\n4. Use an account or environment with no current usage window data to verify `No usage yet`.\n\nAutomated coverage for the status bar states lives in `test/suite/statusBarManager.test.ts`.\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Compile TypeScript\nnpm run compile\n\n# Run tests (requires VS Code to be installed)\nnpm test\n\n# Watch mode\nnpm run watch\n```\n\n### Project Structure\n\n```\nsrc/\n  extension.ts          Entry point; wires providers, status bar, and refresh timer\n  types.ts              Shared TypeScript interfaces\n  statusBarManager.ts   Creates and updates the two status bar items\n  fetchWithRetry.ts     Fetch wrapper with retry/back-off logic\n  sharedCache.ts        In-memory cache keyed by token hash\n  providers/\n    claudeProvider.ts   Reads Claude credentials, then uses API and local fallbacks\n    openaiProvider.ts   Reads Codex credentials, then uses API or session snapshots\ntest/\n  runTests.ts           Launches the VS Code Extension Development Host test runner\n  suite/\n    index.ts            Mocha suite loader\n    extension.test.ts\n    claudeProvider.test.ts\n    openaiProvider.test.ts\n    sharedCache.test.ts\n    statusBarManager.test.ts\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchriswiegman%2Fvscode-ai-usage-limits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchriswiegman%2Fvscode-ai-usage-limits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchriswiegman%2Fvscode-ai-usage-limits/lists"}