{
  "markdown": "[![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> **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",
  "bytes": 4998,
  "sha": "86301cdf0f38068b6f29f426590b779bf9a707cb0c461d1b4afe7e5f7418e053",
  "repo_slug": "thedavidwhiteside/claude-code-tokenbudget",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/plg_thedavidwhiteside_claude_code_tokenbudge_4d42ba1f/readme"
}