# tokenu — du-like Token Counter for Repos > tokenu is a du-like CLI to measure token usage per file/dir for LLM context planning; verified 59★ with `npx tokenu .` and JSON output for agents. ## Install Copy the content below into your project: ## Quick Use ```bash npx tokenu . tokenu -d 1 -hs . tokenu --json -s . > tokenu.json ``` ## Intro tokenu is a du-like CLI to measure token usage per file/dir for LLM context planning; verified 59★ with `npx tokenu .` and JSON output for agents. **Best for:** Agent builders who need to budget context windows and avoid accidentally loading 40K-token folders **Works with:** Node.js + npx/npm, agent pipelines that can read JSON output, hook-based pre-read guards **Setup time:** 2-6 minutes ### Key facts (verified) - GitHub: 59 stars · 1 forks · pushed 2026-05-13. - License: Apache-2.0 · owner avatar + repo URL verified via GitHub API. - README-backed entrypoint: `npx tokenu .`. ## Main - Use it before feeding a repo into an agent: token counts show which folders (like `dist/`) will blow up your context budget. - Prefer `--json` for agent pipelines so the agent can plan what to read within a fixed token limit. - If token counts vary between models, use `--model` / `--encoding` to compare costs across tokenizers. ### Source-backed notes - README shows a no-install quick start: `npx tokenu .`. - README documents JSON output for agent consumption: `tokenu --json`. - README lists encodings (`o200k_base`, `cl100k_base`, etc.) and flags like `--max-depth` and `--exclude`. ### FAQ - **Does tokenu reduce token usage automatically?**: No — README says it measures token cost so you can decide what to exclude or summarize. - **Can an agent use tokenu programmatically?**: Yes — use `tokenu --json` so the agent can parse per-dir token counts. - **Is it an estimate or real tokenization?**: README says it uses actual tokenization via a tokenizer library, not heuristics. ## Source & Thanks > Source: https://github.com/lirantal/tokenu > License: Apache-2.0 > GitHub stars: 59 · forks: 1 --- ## Quick Use ```bash npx tokenu . tokenu -d 1 -hs . tokenu --json -s . > tokenu.json ``` ## Intro tokenu 是类似 du 的 CLI,用于统计文件/目录的 token 消耗以做上下文预算;已验证 59★,支持直接 `npx tokenu .` 与 agent 可消费的 JSON 输出。 **Best for:** 需要做上下文预算、避免误把 40K token 目录塞进 agent 的开发者 **Works with:** Node.js + npx/npm、能读取 JSON 输出的 agent 管线,以及可接入 pre-read hook 的工作流 **Setup time:** 2-6 minutes ### Key facts (verified) - GitHub:59 stars · 1 forks;最近更新 2026-05-13。 - 许可证:Apache-2.0;作者头像与仓库链接均已通过 GitHub API 复核。 - README 中可对照的入口命令:`npx tokenu .`。 ## Main - 在把仓库交给 agent 之前先跑一遍:token 统计能快速定位哪些目录(如 `dist/`)会吞掉上下文预算。 - agent 管线优先用 `--json` 输出,让 agent 在固定 token 上限内规划要读哪些文件。 - 需要比较不同模型的 token 开销时,用 `--model`/`--encoding` 对比不同 tokenizer 的差异。 ### Source-backed notes - README 提供免安装 Quick Start:`npx tokenu .`。 - README 支持 agent 可消费 JSON 输出:`tokenu --json`。 - README 列出 encodings(`o200k_base`、`cl100k_base` 等)及 `--max-depth`、`--exclude` 等参数。 ### FAQ - **tokenu 会自动帮我省 token 吗?**:不会。README 说明它是测量工具,用于告诉你成本,方便你决定排除/摘要哪些内容。 - **agent 能程序化使用吗?**:可以。用 `tokenu --json` 输出结构化结果让 agent 解析。 - **这是估算还是实际分词?**:README 表示它使用真实 tokenizer 做实际 tokenization,而非启发式估算。 ## Source & Thanks > Source: https://github.com/lirantal/tokenu > License: Apache-2.0 > GitHub stars: 59 · forks: 1 --- Source: https://tokrepo.com/en/workflows/tokenu-du-like-token-counter-for-repos Author: Script Depot