{"id":30062481,"url":"https://github.com/azat-io/token-limit","last_synced_at":"2025-08-08T03:36:22.348Z","repository":{"id":303276265,"uuid":"1012048072","full_name":"azat-io/token-limit","owner":"azat-io","description":"🛰 Monitor how many tokens your code and configs consume in AI tools. Set budgets and get alerts when limits are hit","archived":false,"fork":false,"pushed_at":"2025-07-20T21:24:15.000Z","size":548,"stargazers_count":49,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-03T16:42:08.704Z","etag":null,"topics":["ai","chatgpt","claude","context","tokens"],"latest_commit_sha":null,"homepage":"","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/azat-io.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.config.ts","contributing":"contributing.md","funding":null,"license":"license.md","code_of_conduct":".github/code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-01T18:19:16.000Z","updated_at":"2025-08-02T20:58:26.000Z","dependencies_parsed_at":"2025-07-06T19:17:53.744Z","dependency_job_id":"f95d0519-7cc8-454b-adf5-a1e8188e1db5","html_url":"https://github.com/azat-io/token-limit","commit_stats":null,"previous_names":["azat-io/token-limit"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/azat-io/token-limit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azat-io%2Ftoken-limit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azat-io%2Ftoken-limit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azat-io%2Ftoken-limit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azat-io%2Ftoken-limit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azat-io","download_url":"https://codeload.github.com/azat-io/token-limit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azat-io%2Ftoken-limit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269360638,"owners_count":24404295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"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":["ai","chatgpt","claude","context","tokens"],"created_at":"2025-08-08T03:36:15.571Z","updated_at":"2025-08-08T03:36:22.326Z","avatar_url":"https://github.com/azat-io.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Token Limit\n\n\u003cimg\n  src=\"https://raw.githubusercontent.com/azat-io/token-limit/main/assets/logo.svg\"\n  alt=\"Token Limit logo\"\n  width=\"160\"\n  height=\"160\"\n  align=\"right\"\n/\u003e\n\n[![Version](https://img.shields.io/npm/v/token-limit.svg?color=23a56f\u0026labelColor=2496d6)](https://npmjs.com/package/token-limit)\n[![Code Coverage](https://img.shields.io/codecov/c/github/azat-io/token-limit.svg?color=23a56f\u0026labelColor=2496d6)](https://npmjs.com/package/token-limit)\n[![GitHub License](https://img.shields.io/badge/license-MIT-232428.svg?color=23a56f\u0026labelColor=2496d6)](https://github.com/azat-io/token-limit/blob/main/license.md)\n\nToken Limit helps you monitor how many tokens your AI context files consume. Set token budgets for your prompts, documentation, and configs, then get alerts when limits are exceeded.\n\nKeep your AI costs predictable and avoid hitting context window limits that break your applications.\n\n## Why\n\nAI context files are becoming a standard part of modern development workflows. Projects now commonly include `.context/`, `CLAUDE.md`, `.clinerules`, `.cursorrules`, and other AI instruction files directly in their repositories.\n\nAs these files grow in size and complexity, it becomes crucial to monitor their token consumption to avoid unexpected API costs and context window limitations.\n\n## Key Features\n\n- **Multi-model support** for OpenAI GPT and Anthropic Claude\n- **CI integration** to catch budget overruns in pull requests\n- **Flexible configuration** for different AI use cases\n- **Real token costs** instead of inaccurate file sizes\n- **Cost budgets** in dollars and cents, not just tokens\n- **Up-to-date pricing** from OpenRouter API instead of hardcoded values\n\n###\n\n\u003cbr\u003e\n\n\u003cpicture\u003e\n  \u003csource\n    srcset=\"https://raw.githubusercontent.com/azat-io/token-limit/main/assets/example-light.webp\"\n    media=\"(prefers-color-scheme: light)\"\n  /\u003e\n  \u003csource\n    srcset=\"https://raw.githubusercontent.com/azat-io/token-limit/main/assets/example-dark.webp\"\n    media=\"(prefers-color-scheme: dark)\"\n  /\u003e\n  \u003cimg\n    src=\"https://raw.githubusercontent.com/azat-io/token-limit/main/assets/example-light.webp\"\n    alt=\"Token Limit CLI Example\"\n    width=\"600\"\n  /\u003e\n\u003c/picture\u003e\n\n## How It Works\n\n1. **Configure** your token budgets in `token-limit.config.ts`, `package.json`, or other supported formats\n2. **Analyze** files using official tokenizers for each AI model (tiktoken, Anthropic)\n3. **Report** which files exceed limits with detailed breakdowns\n4. **Prevent** costly overruns by failing CI builds when budgets are exceeded\n\n## Usage\n\n### Quick Start\n\n1. Install Token Limit:\n\n```sh\nnpm install --save-dev token-limit\n```\n\n2. Create a configuration file (e.g., `token-limit.config.ts` or `.token-limit.json`):\n\n```ts\n// token-limit.config.ts\n\nimport { defineConfig } from 'token-limit'\n\nexport default defineConfig([\n  {\n    name: 'AI Context',\n    path: '.context/**/*.md',\n    limit: '100k',\n    model: 'gpt-4',\n  },\n  {\n    name: 'Documentation',\n    path: ['docs/**/*.md', 'docs/**/*.txt'],\n    limit: '$0.05',\n    model: 'claude-sonnet-4',\n  },\n])\n```\n\n3. Add a script to your `package.json`:\n\n```json\n{\n  \"scripts\": {\n    \"token-limit\": \"token-limit\"\n  }\n}\n```\n\n4. Run the analysis:\n\n```sh\nnpm run token-limit\n```\n\n### Command Line Usage\n\nYou can also run Token Limit directly from the command line:\n\n```sh\n# Check specific files\nnpx token-limit README.md docs/guide.md\n\n# Set limits and models\nnpx token-limit --limit 10k --model gpt-4 docs/**/*.md\n\n# Set cost limits\nnpx token-limit --limit '$0.25' --model gpt-4 expensive-prompts/**/*.md\n\n# Name your check\nnpx token-limit --name \"API Docs\" --limit 50k api-docs/**/*.md\n\n# Multiple examples\nnpx token-limit .context/**/*.md\nnpx token-limit --limit 1000 claude.md\nnpx token-limit --limit '5c' --model gpt-3.5-turbo quick-prompts/*.txt\nnpx token-limit --json --hide-passed\n```\n\n## Configuration\n\nToken Limit supports multiple configuration formats to suit your project needs. You can define token limits, models, and file paths in a variety of ways:\n\n### Configuration Formats\n\n- `token-limit.config.{ts,js,mjs,cjs}`\n- `.token-limit.{ts,js,mjs,cjs,json}`\n- `.token-limit`\n- `package.json` (`token-limit` field)\n- Command line arguments\n\n### Supported Models\n\n**OpenAI Models**\n\n- `gpt-4.1`\n- `gpt-4.1-mini`\n- `gpt-4.1-nano`\n- `gpt-4o`\n- `gpt-4o-mini`\n- `gpt-4-turbo`\n- `gpt-4`\n- `gpt-3.5-turbo`\n- `o1`\n- `o1-mini`\n- `o3-mini`\n\n**Anthropic Models**\n\n- `claude-opus-4`\n- `claude-opus-4.1`\n- `claude-sonnet-4`\n- `claude-3.7-sonnet`\n- `claude-3.5-sonnet`\n- `claude-3.5-haiku`\n- `claude-3-opus`\n\n### Limit Formats\n\n**Token Limits**\n\n- Numbers: `1000`, `50000`\n- Human-readable: `\"10k\"`, `\"1.5M\"`, `\"500K\"`\n\n**Cost Limits**\n\n- Dollar amounts: `\"$0.05\"`, `\"$1.50\"`\n- Cents: `\"5c\"`, `\"10c\"`\n- Plain numbers: `0.05`, `1.5` (interpreted as dollars)\n\n## CI Integration\n\n### GitHub Actions Integration\n\nAdd Token Limit to your CI pipeline:\n\n```yaml\n# .github/workflows/token-limit.yml\n\nname: Token Limit\non: [push, pull_request]\n\njobs:\n  token-limit:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: actions/setup-node@v4\n        with:\n          node-version: '18'\n      - run: npx token-limit\n```\n\n## Why Token Limits Matter\n\nUnlike traditional bundle size limits, token limits directly impact:\n\n- **API Costs**: More tokens = higher bills (GPT-4 costs $0.03 per 1K tokens)\n- **Response Quality**: Exceeding context windows truncates input (GPT-4: 128K limit)\n- **Performance**: Larger contexts mean slower API responses\n- **Reliability**: Context overflow can cause API errors\n\nToken Limit helps you catch these issues before they reach production.\n\n## Contributing\n\nSee [Contributing Guide](https://github.com/azat-io/token-limit/blob/main/contributing.md).\n\n## License\n\nMIT \u0026copy; [Azat S.](https://azat.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazat-io%2Ftoken-limit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazat-io%2Ftoken-limit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazat-io%2Ftoken-limit/lists"}