I built a CLI that tells you if your codebase fits an LLM's context window
I built a CLI that tells you if your codebase fits an LLM’s context window
我开发了一个 CLI 工具,可以检测你的代码库是否超出了 LLM 的上下文窗口
Every time I wanted to paste a whole project into Claude or ChatGPT, I ended up guessing whether it would even fit — and often found out the hard way, mid-conversation, that it didn’t. So I built Tokenazire, a small CLI tool that solves exactly that. 每当我想要将整个项目粘贴到 Claude 或 ChatGPT 中时,我总是不得不猜测它是否放得下——而且往往在对话进行到一半时才痛苦地发现它超出了限制。因此,我开发了 Tokenazire,这是一个专门解决该问题的小型 CLI 工具。
What it does: 它的功能:
- Scans a local folder or a GitHub repo (just pass the URL, it clones it for you)
- 扫描本地文件夹或 GitHub 仓库(只需传入 URL,它会自动为你克隆)
- Counts tokens per file using tiktoken (the same tokenizer OpenAI models use, a solid approximation across most LLMs)
- 使用 tiktoken 计算每个文件的 Token 数(这是 OpenAI 模型使用的分词器,对于大多数 LLM 来说是一个可靠的近似值)
- Shows a color-coded breakdown (green → yellow → orange → red) so you instantly see which files are “heavy”
- 显示颜色编码的分析结果(绿色 → 黄色 → 橙色 → 红色),让你一眼就能看出哪些文件是“大块头”
- Calculates what percentage of a model’s context window (default 200k, configurable) your whole project takes up
- 计算整个项目占用了模型上下文窗口(默认 200k,可配置)的百分比
- Ignores .git, venv, node_modules, and other noise automatically
- 自动忽略 .git、venv、node_modules 以及其他无关文件
- Has an —export flag that bundles the entire project — folder structure plus every file’s content — into a single text file, ready to paste straight into an LLM chat
- 具备 —export 标志,可以将整个项目(包括文件夹结构和每个文件的内容)打包成一个文本文件,直接粘贴到 LLM 对话中即可使用
I kept hitting the same annoying loop: copy a project into a chat, get cut off or told the input’s too long, then manually trim files and try again. This automates the “will it fit, and if not, what’s taking up the most space” question up front. The —export step came later — once I knew what would fit, I still had to manually copy-paste files one by one into the chat. Now it just spits out one clean file with a project tree on top and clearly separated file contents, ready to paste. 我之前一直陷入同一个恼人的循环:将项目复制到对话中,结果被截断或提示输入过长,然后不得不手动删减文件再重试。这个工具在最开始就自动化解决了“放得下吗?如果放不下,是什么占用了空间?”的问题。—export 功能是后来加的——因为即使我知道什么能放得下,之前也必须手动将文件一个一个复制粘贴到对话中。现在,它直接生成一个整洁的文件,顶部带有项目树,文件内容清晰分隔,随时可以粘贴。
Tech stack 技术栈
Plain Python, tiktoken for tokenization, rich for the terminal output (tables, colors, progress bar). No config files, no external services beyond git for cloning. 纯 Python 编写,使用 tiktoken 进行分词,使用 rich 库处理终端输出(表格、颜色、进度条)。无需配置文件,除了用于克隆的 git 外,不依赖任何外部服务。
Try it 试用一下
Repo: https://github.com/DeKlain4ik/token-counter (MIT licensed) 仓库地址:https://github.com/DeKlain4ik/token-counter (MIT 协议)
Still early — feedback, issues, and PRs are welcome. 项目尚处于早期阶段,欢迎提供反馈、提交 Issue 和 PR。