AI Skill Hub 推荐使用:Token计数工具 是一款优质的AI工具。AI 综合评分 7.2 分,在同类工具中表现稳健。如果你正在寻找可靠的AI工具解决方案,这是一个值得深入了解的选择。
Token计数工具 是一款基于 TypeScript 开发的开源工具,专注于 token计数、CLI工具、成本评估 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
Token计数工具 是一款基于 TypeScript 开发的开源工具,专注于 token计数、CLI工具、成本评估 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 方式一:npm 全局安装 npm install -g tokenu # 方式二:npx 直接运行(无需安装) npx tokenu --help # 方式三:项目依赖安装 npm install tokenu # 方式四:从源码运行 git clone https://github.com/lirantal/tokenu cd tokenu npm install npm start
# 命令行使用
tokenu --help
# 基本用法
tokenu [options] <input>
# Node.js 代码中使用
const tokenu = require('tokenu');
const result = await tokenu.run(options);
console.log(result);
# tokenu 配置说明 # 查看配置选项 tokenu --config-example > config.yml # 常见配置项 # output_dir: ./output # log_level: info # workers: 4 # 环境变量(覆盖配置文件) export TOKENU_CONFIG="/path/to/config.yml"
<p align="center"> <h1 align="center"> tokenu </h1> </p>
<p align="center"> <img width="1216" height="884" alt="tokenu-screenshot" src="https://github.com/user-attachments/assets/7186f3ec-505f-4db2-8927-81686462903b" /> </p>
<p align="center"> A Unix <code>du</code>-like CLI that counts token usage per file and directory. </p>
<p align="center"> <a href="https://www.npmjs.com/package/tokenu"><img src="https://badgen.net/npm/v/tokenu" alt="npm version"/></a> <a href="https://www.npmjs.com/package/tokenu"><img src="https://badgen.net/npm/license/tokenu" alt="license"/></a> <a href="https://www.npmjs.com/package/tokenu"><img src="https://badgen.net/npm/dt/tokenu" alt="downloads"/></a> <a href="https://github.com/lirantal/tokenu/actions/workflows/ci.yml"><img src="https://github.com/lirantal/tokenu/actions/workflows/ci.yml/badge.svg?branch=main" alt="build"/></a> <a href="https://app.codecov.io/gh/lirantal/tokenu"><img src="https://badgen.net/codecov/c/github/lirantal/tokenu" alt="codecov"/></a> <a href="./SECURITY.md"><img src="https://img.shields.io/badge/Security-Responsible%20Disclosure-yellow.svg" alt="Responsible Disclosure Policy" /></a> </p>
Local install:
npm install tokenu
or globally install the tokenu package in your development environment:
npm install -g tokenu
No install needed — run it directly with npx:
npx tokenu .
Prefer a shorter command without installing tokenu globally? Add this alias to your shell config file, such as ~/.zshrc or ~/.bashrc:
alias tu='npx tokenu'
Then use tu anywhere you would use tokenu:
tu .
tokenu [options] [path...]
Recursive token counts per directory:
$ tokenu -a src/
1127 src/bin/cli.ts
1127 src/bin
783 src/formatter.ts
256 src/main.ts
324 src/tokenizer.ts
165 src/types.ts
735 src/walker.ts
3390 src
Human-readable summary:
$ tokenu -hs src/
3.4K src
Depth-limited with grand total:
$ tokenu -d 1 --total myproject/
4143 myproject/tests
2019 myproject/docs
2263 myproject/src
12241 myproject/dist
20666 myproject
20666 total
JSON output (useful for piping to other tools or AI agents):
$ tokenu -a --json src/
Use a specific encoding for older models:
$ tokenu --encoding cl100k_base .
Not directly. tokenu is a diagnostic tool — it reports token counts so you can make informed decisions. For example, you might discover a 40K-token auto-generated file sitting in your project root and decide to exclude it from your AI workflow, saving real money and context space.
Imagine you're running Claude Code (or a similar coding agent) in a project that contains a huge data.json file. Without realizing it, the agent loads that file into context and it consumes your entire context window, leaving no room for actual code.
With tokenu you can build a pre-read hook: before the agent reads any file, run tokenu on it. If the file exceeds a token threshold (say, 10K tokens), the hook can ask for confirmation or skip the file entirely. This keeps the agent focused on what matters.
| Flag | Description |
|---|---|
-s, --summarize | Display only a total for each argument |
-h, --human-readable | Print token counts in human-readable format (1K, 1M) |
-a, --all | Show counts for all files, not just directories |
-d, --max-depth <N> | Print totals only for directories N levels deep |
-c, --total | Produce a grand total |
--json | Output as JSON (for AI agent consumption) |
--encoding <enc> | Tokenizer encoding (default: o200k_base) |
--model <name> | Model name (e.g. gpt-4o, gpt-3.5-turbo) |
--exclude <pat> | Glob pattern to exclude (repeatable) |
--no-ignore | Disable default .git, node_modules, and .gitignore skips |
Supported encodings: o200k_base, o200k_harmony, cl100k_base, p50k_base, p50k_edit, r50k_base
实用的token成本分析工具,设计理念清晰。但活跃度一般,功能单一,适合轻量级使用场景。
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ Apache 2.0 — 宽松开源协议,可商用,需保留版权声明和 NOTICE 文件,含专利授权条款。
总体来看,Token计数工具 是一款质量良好的AI工具,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。
| 原始名称 | tokenu |
| 原始描述 | 开源AI工作流:a unix-like du command line tool to count token usage per files and directories。⭐59 · TypeScript |
| Topics | token计数CLI工具成本评估开发者工具工作流自动化 |
| GitHub | https://github.com/lirantal/tokenu |
| License | Apache-2.0 |
| 语言 | TypeScript |
收录时间:2026-05-21 · 更新时间:2026-05-22 · License:Apache-2.0 · AI Skill Hub 不对第三方内容的准确性作法律背书。