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 装进系统
  • tokenmetre install claude-code 做数据侧部署:幂等写 ~/.claude/settings.json 的 cleanupPeriodDays + 软链 skill/command markdown
  • 运行时数据落在 ~/.tokenmetre/(SQLite / 配置缓存)

验证: tokenmetre install claude-code --verify

使用流程

# 1. 登记要计量的项目
tokenmetre register add E:\work\ai\some-project
tokenmetre register add E:\work\ai\another-project

# 2. 扫描(register add 已自动 scan;定期手动补扫)
tokenmetre scan

# 3. 看 Web 面板
tokenmetre web                    # http://127.0.0.1:8080

# 4. 或 CLI 报表
tokenmetre report --all

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.0

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.0
File Size Uploaded
tokenmetre-0.2.0.tar.gz 166.3 kB Details

Built distribution (wheel)

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

Total release size: 340.1 kB

Release files / tokenmetre-0.2.0.tar.gz

Download URL tokenmetre-0.2.0.tar.gz
Size 166.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0507010c9664162a7e31267365275fc64fd5be49dd305d1ceb7c7c75625e091c
BLAKE2b-256 checksum
How to use checksums
1a3c6a0e5fcaba86f4b10bbd65a6441d9fd6ec603a7862a9f7ad84e0c5a3b643
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.0-py3-none-any.whl

Download URL tokenmetre-0.2.0-py3-none-any.whl
Size 173.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
012093a1ad1d767f84b028a9b1eff285ddfa36ee38d6fde9fd0064a1d030db50
BLAKE2b-256 checksum
How to use checksums
290a0818bc6299f584c2417da74f51de37da718568b790e85640e0dffc05104e
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

0.2.1

2 release files

This release

0.2.0 This release

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