ctxbudget
Does your prompt actually fit in this model's context window?
A zero-dependency CLI for planning token budgets against local LLM context limits. Know before you run whether your system prompt + user message + retrieved RAG context will overflow — and by how much.
Built by GhettoBoxAI — technical field reports on local LLMs, agents, RAG, and AI automation.
Why this exists
You've got a 32K-context Qwen2.5 running locally. Your system prompt is 2K tokens. Your RAG pipeline retrieves 4 chunks × 1024 tokens each. You want 1K tokens of output. Does it fit?
Most token-cost tools assume you're paying per API call. Local models are free — but the window is hard. Overflow means truncated context, lost instructions, or a crash. ctxbudget answers this in one command, offline, no API key needed.
Install
# npm (Node CLI)
npm install -g ctxbudget
# or one-shot:
npx ctxbudget --list
# PyPI (Python lib + CLI)
pip install ctxbudget
Usage
Quick fit check
# Does 8192 tokens of input fit in Llama 3.1 8B?
ctxbudget llama-3.1-8b 8192
# Same, but reserve 2048 tokens for output
ctxbudget llama-3.1-8b 8192 --reserve 2048
RAG budget breakdown
# System: 2K, User: 512, Retrieved context: 4K, Reserve output: 1K
ctxbudget qwen2.5-7b --system 2048 --user 512 --context 4096 --reserve 1024
Output:
==================================================
Qwen2.5 7B Instruct — Context Budget
==================================================
Total window: 32K tokens
────────────────────────────────────────
System prompt: 2K tokens (6.2%)
User message: 512 tokens (1.6%)
Retrieved ctx: 4K tokens (12.5%)
────────────────────────────────────────
Total input: 6.5K tokens (20.3%)
Output reserve: 1K tokens
Usable budget: 31K tokens
[PASS] Margin: +24.5K tokens
List all known models
ctxbudget --list
JSON output (for scripting)
ctxbudget llama-3.1-8b 4096 --json
# {"model":"llama-3.1-8b","context":131072,"input_tokens":4096,"fits":true,"margin":126976}
Supported Models
| Family | Models | Context |
|---|---|---|
| Llama 3.x | 1B, 3B, 8B, 70B | 128K |
| Mistral / Mixtral | 7B, 8x7B, 8x22B, Small 24B | 32K–128K |
| Qwen2.5 | 0.5B–32B, Coder 7B/32B | 32K |
| Gemma 2/3 | 9B, 27B, 4B, 12B | 8K–32K |
| Phi-3/3.5/4 | Mini, Medium, 14B | 4K–128K |
| DeepSeek R1 | Distill Qwen/Llama | 32K–128K |
| Cohere Command | R, R+ | 128K |
Context windows reflect native model config. Some models support extended context via YaRN/position interpolation — check your serving framework.
When to use this
- Before deploying a RAG pipeline — verify your chunk count × chunk size + system prompt fits
- When switching models — "I'm moving from Llama 8B (128K) to Gemma 2 9B (8K). Does my prompt still fit?"
- In CI/CD — gate deployment on token budget:
ctxbudget $MODEL $TOKEN_COUNT --reserve $OUTPUT || exit 1 - When debugging truncation — confirm whether your framework is silently dropping context
Related Guides
- LLM Ops Cheatsheet — practical local LLM operations
- Building RAG Systems in Production — chunking, retrieval, context management
- Prompt Engineering Playbook — 12 patterns that work
License
Metadata
Release files for ctxbudget 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ctxbudget-0.1.0.tar.gz | 7.2 kB | Without provenance | Details for ctxbudget-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ctxbudget-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ctxbudget-0.1.0-py3-none-any.whl |
Total release size: 15.0 kB
Release files / ctxbudget-0.1.0.tar.gz
| Download URL | ctxbudget-0.1.0.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dab41b25e3ed521298b3b05a0f6cebf8ee61241c94105e6069b0ea5f9e5d73d2
|
|
BLAKE2b-256 checksum How to use checksums |
f88793946487ce6cdc4739b87344db1eca268a2d6ec592a037119cc56383d32a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Release files / ctxbudget-0.1.0-py3-none-any.whl
| Download URL | ctxbudget-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ca4410063b7092b658d7230c4f49cbf48dafd7939c265a795ee9c785a208530
|
|
BLAKE2b-256 checksum How to use checksums |
5be8f84ba53564ff3cc063b5b62978a8f2abd28f90bcce35de7cbbd8a53b0f4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Security for ctxbudget 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.