Skip to main content

tokenMetre

AI 时代的开发工作量计量器。把 LLM 消耗的 token 作为衡量开发工作量的参考指标。

参考值,非权威计价标准。零 hook、纯 transcript 采集、按项目统计、可选云端协作。

它做什么

  1. 注册项目: tokenmetre register add <cwd> 登记目录
  2. 扫描 transcript: tokenmetre scan 纯文件读取 ~/.claude/projects/**/*.jsonl
  3. 确定性分类: 同 token 合并成 LLM 调用组 → 工具→5 类映射
  4. 落盘 SQLite: 14 字段 Record,UNIQUE(session_id, ts) 天然去重
  5. Web 面板: tokenmetre web 启动瘦统计面板
  6. 可选云端协作: 注册后可连 tokenmetre.umap.earth 多成员汇聚

线上入口

https://tokenmetre.umap.earth — 营销站 / · 用户工作台 /app · 运维后台 /admin。


本地端安装

pip install tokenmetre
tokenmetre install claude-code --verify
  • pip install 把 CLI 装进系统(PyPI: tokenmetre)
  • tokenmetre install claude-code 做数据侧部署:幂等写 ~/.claude/settings.json 的 cleanupPeriodDays
  • 运行时数据落在 ~/.tokenmetre/(SQLite + 配置缓存)

快速上手:Web 管理面板

# 登记项目(同时自动 scan 一次)
tokenmetre register add E:\work\ai\your-project

# 启动本地管理面板
tokenmetre web          # 默认 http://127.0.0.1:8080

浏览器打开面板,看到的就是你的全部 AI 工具消耗数据:

本地 Web 管理面板

面板提供项目统计、Token 用量、权重配置、Agent 管理和云端协作入口——日常使用的主界面。

CLI 辅助命令

面板之外,偶尔需要快速查数或脚本集成时可以用 CLI:

tokenmetre report --all                   # 全局摘要
tokenmetre report --project myprj         # 单项目明细
tokenmetre scan --force                   # 强制重扫 transcript

CLI 命令速查

命令 作用
install claude-code [--verify] 安装/验证 CC adapter
register add <cwd> 登记激活目录(自动 scan)
register remove <cwd> 取消登记
register list 查看已登记项目
register claim <cwd> --id <tm_xxx> 显式认领(目录搬家后归位)
scan [--force] [--project <cwd>] 扫描 transcript → SQLite
report [--all] [--project <slug>] CLI 统计摘要
web [--port] 启动本地 Web 面板
cloud add [cwd] --base <url> --token <token> 启用某项目云端协作
cloud show / cloud remove 查看/关闭 cloud 配置
sync [--project <slug>] push 本地 pending records 到云端
config sync [--base <url>] 拉取云端全局配置

分类规则

5 类确定性映射(采集端不调 LLM),优先级: documentation > coding > execution > exploration > discussion

category 含义
文档 documentation 写 markdown 文件
编码 coding 写/改代码文件
实施 execution 跑命令: 安装/构建/执行/文件操作
调研 exploration 读文件/搜索/查 git/上网
讨论 discussion 纯对话交互

详细判定规则见 docs/spec.md §I.3。

数据位置

路径 用途
~/.tokenmetre/tokenmetre.db SQLite 主库 — records + processed_sessions
~/.tokenmetre/projects.json 项目注册表(active/ignored/claims)
~/.tokenmetre/config.json 云端全局配置缓存(config sync 拉取)
~/.tokenmetre/weights.yaml provider 计价比重(无云端缓存时回退用)

数据安全

Claude Code 默认 30 天清理 transcript。install 自动确保 cleanupPeriodDays ≥ 1(默认 365)。想长期保留就设大数字,无哨兵值。


云端部署(运维侧)

本地启动

# 1. 配置 .env(参考 .env.example):
#    DATABASE_URL / TMCOM_API_TOKEN / TMCOM_JWT_SECRET / TMCOM_ADMIN_PASSWORD
# 2. 安装依赖
pip install -e .
# 3. 从项目根启动(不能 cd api/)
python -m api.server --port 9000

首次启动自动: Alembic 迁移建表 + 种子 admin。

Vercel + Supabase(生产)

# schema 变更后本地直连线上库执行迁移
python -c "from api import db; db.init()"

# 部署(CLI 直推,GitHub 自动部署已断开)
vercel deploy --prod --yes

环境变量(Vercel Dashboard): DATABASE_URL(Supabase pooler :6543) / TMCOM_API_TOKEN / TMCOM_JWT_SECRET / TMCOM_ADMIN_PASSWORD / TMCOM_OPEN_REGISTER(默认关) / 可选邮件 OAuth 配置。

前端构建

cd api/web/site;  npm install; npm run build   # 营销站
cd ../user;       npm install; npm run build   # 用户工作台
cd ../admin;      npm install; npm run build   # 运维后台

数据库

PostgreSQL(Supabase 免费档)。连接串用 pooler :6543 transaction mode;密码含特殊字符需 percent-encode。


机器端接入

用户登录 /app/projects → 引导卡复制自己的 token:

tokenmetre cloud add --base https://tokenmetre.umap.earth --token tm_xxxx
tokenmetre sync

配套文档

Metadata

Release files for tokenmetre 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tokenmetre 0.2.1
File Size Uploaded
tokenmetre-0.2.1.tar.gz 167.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tokenmetre 0.2.1
File Interpreter ABI Platform
tokenmetre-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 341.6 kB

Release files / tokenmetre-0.2.1.tar.gz

Download URL tokenmetre-0.2.1.tar.gz
Size 167.3 kB
Tags Source
SHA-256 checksum
How to use checksums
eb6d0f980105cc8837290c3944dcc689a55aae92f0ad1d5bfea37ae1e6b9ef32
BLAKE2b-256 checksum
How to use checksums
347525b2c4e359d4fe7ce098d896432b7b1f7a1f608910a6e1d57be7d3165eec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / tokenmetre-0.2.1-py3-none-any.whl

Download URL tokenmetre-0.2.1-py3-none-any.whl
Size 174.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe647890417a7366a5e93099fa20ed239cb38794b349fa68b2ea883c679e5f3f
BLAKE2b-256 checksum
How to use checksums
415f3166850d633df985912e4374bb8499f7b9cbc1f05bee83245c405b8fda71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

0.2.3

2 release files

0.2.2

2 release files

This release

0.2.1 This release

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page