{"id":49866400,"url":"https://github.com/outbit/claude-code-tokenbudget","last_synced_at":"2026-05-15T03:12:08.774Z","repository":{"id":352136738,"uuid":"1213998106","full_name":"outbit/claude-code-tokenbudget","owner":"outbit","description":"Claude code plugin to implement a budget or quota across all backends (Bedrock, Vertex, direct API) and provides guardrails against surprise token costs. No surprise bills, no config beyond a single env var, no external dependencies.","archived":false,"fork":false,"pushed_at":"2026-05-09T16:04:08.000Z","size":197,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-09T17:22:47.780Z","etag":null,"topics":["budget","claude","claudecode","code","limit","plugin","quota","token","tokens"],"latest_commit_sha":null,"homepage":"","language":"Python","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/outbit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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-04-18T02:02:09.000Z","updated_at":"2026-05-09T16:04:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/outbit/claude-code-tokenbudget","commit_stats":null,"previous_names":["thedavidwhiteside/claude-code-tokenmiser","thedavidwhiteside/claude-code-tokenbudget","outbit/claude-code-tokenbudget"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/outbit/claude-code-tokenbudget","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outbit%2Fclaude-code-tokenbudget","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outbit%2Fclaude-code-tokenbudget/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outbit%2Fclaude-code-tokenbudget/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outbit%2Fclaude-code-tokenbudget/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/outbit","download_url":"https://codeload.github.com/outbit/claude-code-tokenbudget/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outbit%2Fclaude-code-tokenbudget/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33051909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-15T02:00:06.351Z","response_time":103,"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":["budget","claude","claudecode","code","limit","plugin","quota","token","tokens"],"created_at":"2026-05-15T03:12:06.564Z","updated_at":"2026-05-15T03:12:08.759Z","avatar_url":"https://github.com/outbit.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Tests](https://github.com/thedavidwhiteside/claude-code-tokenbudget/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/thedavidwhiteside/claude-code-tokenbudget/actions/workflows/test.yml)\n\n# Claude Code Token Quota Plugin\n\nClaude Code has no built-in spending guardrails. This plugin tracks your token usage and hard stops new prompts once you hit your limit. Supports daily, weekly (rolling 7-day), and monthly (calendar month) quotas. It works with **any backend**: Bedrock, Vertex, direct API, or subscription.\n\n## How it works\n\n| Hook | Event | Action |\n|------|-------|--------|\n| `enforce_quota.py` | `UserPromptSubmit` | Blocks the prompt if any quota (daily/weekly/monthly) is exceeded |\n| `track_tokens.py` | `Stop` | Records token usage after each turn |\n\nUsage is stored in `~/.claude-token-quota/YYYY-MM-DD.json` per day. Daily quotas reset at midnight; the weekly quota uses a rolling 7-day window; the monthly quota resets on the 1st.\n\n---\n\n## Installation\n\n```bash\nclaude plugin marketplace add thedavidwhiteside/claude-code-tokenbudget\nclaude plugin install tokenbudget@claude-code-tokenbudget\n```\n\nThis installs the plugin. It will be active in all future Claude Code sessions without any extra flags.\n\n### Try before installing\n\nIf you want to test the plugin without a permanent install:\n\n```bash\ngit clone https://github.com/thedavidwhiteside/claude-code-tokenbudget.git\ncd claude-code-tokenbudget\nclaude --plugin-dir .\n```\n\nThe plugin is active only for that session. Nothing is written to your global config.\n\n## Uninstall\n\n```bash\nclaude plugin uninstall tokenbudget@claude-code-tokenbudget\n```\n\n### Configuration\n\nOverride any of these in your `~/.claude/settings.json`:\n\n```json\n{\n  \"env\": {\n    \"TOKEN_QUOTA_DAILY\": \"1000000\",\n    \"TOKEN_QUOTA_WEEKLY\": \"5000000\",\n    \"TOKEN_QUOTA_MONTHLY\": \"15000000\",\n    \"TOKEN_QUOTA_DIR\": \"~/.claude-token-quota\",\n    \"TOKEN_QUOTA_RETAIN_DAYS\": \"31\",\n    \"TOKEN_QUOTA_WARN_CRITICAL\": \"95\",\n    \"TOKEN_QUOTA_WARN\": \"85\",\n    \"TOKEN_QUOTA_SNOOZE_TOKENS\": \"1000000\"\n  }\n}\n```\n\n| Variable | Default | Description |\n|---|---|---|\n| `TOKEN_QUOTA_DAILY` | `1000000` | Daily token limit |\n| `TOKEN_QUOTA_WEEKLY` | _(unset)_ | Rolling 7-day token limit (optional) |\n| `TOKEN_QUOTA_MONTHLY` | _(unset)_ | Calendar-month token limit (optional) |\n| `TOKEN_QUOTA_DIR` | `~/.claude-token-quota` | Where ledger files are stored |\n| `TOKEN_QUOTA_RETAIN_DAYS` | `31` | How many days of usage history to keep (≥31 required for accurate monthly totals in 31-day months) |\n| `TOKEN_QUOTA_WARN_CRITICAL` | `95` | % of daily limit at which a visible warning is shown |\n| `TOKEN_QUOTA_WARN` | `85` | % of daily limit at which a stderr warning is shown |\n| `TOKEN_QUOTA_COST_PER_M` | _(unset)_ | Blended cost per 1M tokens — enables `~$X.XX` estimates in status output |\n| `TOKEN_QUOTA_SNOOZE_TOKENS` | `1000000` | Extra tokens added to all limits when `/tokenbudget:snooze` is run |\n\nWeekly and monthly limits are opt-in — omit them to enforce only the daily limit. When multiple limits are set, any one being exceeded blocks new prompts.\n\n**Rough token budgets by spend goal — AWS Bedrock example (Claude Sonnet 4.6):**\n\n\u003e **Note:** Prices below are AWS Bedrock examples only and will change. For current rates check the [AWS Bedrock pricing page](https://aws.amazon.com/bedrock/pricing/). Direct API users: see the [Anthropic pricing page](https://www.anthropic.com/pricing) for your model's rates, then apply the same blended-cost formula below.\n\nSonnet 4.6 standard pricing on Bedrock: ~$3.00 / 1M input tokens, ~$15.00 / 1M output tokens.\nAssuming a ~4:1 input-to-output ratio, blended cost is roughly $5.40 / 1M tokens.\n\n| Daily spend goal | ~Token budget |\n|---|---|\n| ~$5/day | 925,000 |\n| ~$10/day | 1,850,000 |\n| ~$20/day | 3,700,000 |\n\nThe default is 1,000,000 tokens/day (~$5.40/day at the example rates).\n\n---\n\n## Check status\n\nRun `/tokenbudget:status` inside any Claude Code session to see today's usage.\n\n![Status output](img/status.png)\n\nWhen your quota is exceeded:\n\n![Limit reached](img/limit.png)\n\n---\n\n## FAQ\n\n**Why not just set a spending limit in Claude.ai?**\n\nClaude.ai spending limits only apply to your claude.ai subscription. If you're using Claude Code through the direct API, AWS Bedrock, or Vertex AI, those limits don't apply — your API key has no built-in cap. This plugin fills that gap by enforcing a hard stop at the Claude Code layer, regardless of which backend you're on.\n\n---\n\n## Caveats\n\n- Token counts are read from the session transcript after each turn. They should be accurate but may differ slightly from your AWS bill due to rounding.\n- The enforcer checks usage *before* a turn starts, so the very last turn before the limit may slightly exceed it (same behavior as Anthropic's own quota system).\n- Requires Python 3.10+ (no external dependencies).\n\n### Running tests\n\n```bash\npython3 -m unittest tests/test_plugin.py -v\n```\n\n---\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foutbit%2Fclaude-code-tokenbudget","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foutbit%2Fclaude-code-tokenbudget","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foutbit%2Fclaude-code-tokenbudget/lists"}