token-card

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Token Card

Token Card

Produce an SVG card summarising this machine's AI coding agent usage — total tokens, equivalent API cost, current streak, and the split across agents — and write it into the working tree as a file the README can reference.
The card is a committed artifact rather than a hosted image, so it renders from the repository itself and does not depend on a third-party endpoint staying up.
生成一张SVG卡片,汇总本机AI编码Agent的使用情况——总Token数、等效API成本、当前连续使用天数,以及各Agent的使用占比——并将其作为README可引用的文件写入工作区。
该卡片是提交到仓库的静态产物,而非托管图片,因此直接从仓库本身渲染,不依赖第三方端点的可用性。

When to Activate

何时使用

  • Someone wants a usage figure visible in a README or docs page.
  • Someone asks for a shareable summary of their agent activity across tools.
Use
/cost-report
instead when the question is "what did I spend this week". The two read different sources and produce different things:
/cost-report
Token Card
Source
~/.claude/metrics/costs.jsonl
, written by ECC's
stop:cost-tracker
hook
The agents' own session logs
AgentsClaude CodeClaude Code, Codex, Gemini CLI, OpenCode
OutputTerminal summary, optional CSVAn SVG file committed to the repo
  • 有人希望在README或文档页面中展示使用数据。
  • 有人需要一份可分享的、跨工具的Agent活动总结。
如果问题是「我这周花了多少钱」,请使用
/cost-report
。两者读取不同的数据源,产出也不同:
/cost-report
Token Card
数据源由ECC的
stop:cost-tracker
hook写入的
~/.claude/metrics/costs.jsonl
各Agent自身的会话日志
支持的AgentClaude CodeClaude Code、Codex、Gemini CLI、OpenCode
输出形式终端摘要,可选CSV输出提交到仓库的SVG文件

The tool this runs

所用工具

@tokenchit/cli
, MIT licensed: https://github.com/iyashjayesh/tokenchit
Pinned to an exact version, deliberately.
@latest
resolves to whatever the registry currently serves, and this tool reads local session logs — so a compromised future release would be executed with access to them before anyone had reviewed it. Pin, and raise the pin knowingly:
bash
TOKENCHIT_VERSION=0.10.0
To check the pinned artifact before running it the first time:
bash
npm view @tokenchit/cli@0.10.0 dist.integrity dist.tarball
@tokenchit/cli
,MIT许可协议:https://github.com/iyashjayesh/tokenchit
特意固定到精确版本。
@latest
会解析为npm注册表当前提供的任意版本,而该工具会读取本地会话日志——因此如果未来版本被攻破,在有人审核之前就会被执行,且能访问这些日志。请固定版本,并在明确知情的情况下升级版本:
bash
TOKENCHIT_VERSION=0.10.0
首次运行前,可通过以下命令校验固定版本的产物:
bash
npm view @tokenchit/cli@0.10.0 dist.integrity dist.tarball

Workflow

工作流程

  1. Ask before the first download.
    npx
    fetches the package from the npm registry and executes it. That is a remote download of code that will read local logs, so get explicit confirmation from the user before the first run on a machine. If they decline, stop here and say what would have run.
  2. Configure, unless this is a dry run. If
    .tokenchit.json
    is absent, run:
    bash
    npx -y @tokenchit/cli@0.10.0 init
    It detects which agents have logs on this machine and records them. The file is meant to be committed and never contains a credential.
    Skip this entirely when the user passed
    --dry-run
    , and report that
    .tokenchit.json
    would be created. A preview that writes a config file is not a preview.
  3. Render the card. The bare command writes to the configured output —
    tokenchit.svg
    unless
    .tokenchit.json
    names another path:
    bash
    npx -y @tokenchit/cli@0.10.0 sync
    Append only the flags the user actually asked for, each spelled exactly as below. Do not copy a placeholder into the command —
    sync
    ignores an unrecognised positional argument rather than refusing it, so a bracketed
    [--dry-run]
    reaches the CLI as junk and the card is written anyway, which is the opposite of what was asked.
    FlagEffect
    --out <path>
    Write somewhere other than the configured output
    --theme auto
    |
    light
    |
    dark
    Card theme;
    auto
    adapts to the reader's system
    --dry-run
    Print what would be written and touch nothing
    sync
    reads local files and sends nothing: no prompts, no code, no file contents leave the machine, and it transmits nothing to any server. The npx invocation around it is a registry download — that is the network access in this workflow, and step 1 is where it is agreed.
  4. Report and offer. Print the figures it produced — tokens, equivalent cost, streak, per-agent split — and the path written. If the repository has a README that does not yet reference the card, offer to add:
    markdown
    ![tokenchit](./tokenchit.svg)
    sync
    prints the path relative to the repository root. A Markdown image resolves relative to the file it sits in, so rewrite it for the README being edited: a card at
    docs/usage.svg
    is
    ./docs/usage.svg
    from the root README but
    ../usage.svg
    from
    docs/zh-CN/README.md
    . Pasting the printed path into a nested README points at
    docs/zh-CN/docs/usage.svg
    and renders broken.
    Do not edit the README without being asked.
Stop after step 4. Publishing to the public leaderboard is a separate
publish
command that requires explicit opt-in, and is not part of this workflow — run it only if the user asks for it by name.
unpublish
removes the row and the account again.
  1. 首次下载前需询问用户。
    npx
    会从npm注册表获取包并执行。这是一次远程代码下载,且下载的代码会读取本地日志,因此在某台机器上首次运行前,必须获得用户的明确确认。如果用户拒绝,在此停止,并告知原本会执行的操作。
  2. 执行配置(试运行场景跳过)。 如果不存在
    .tokenchit.json
    ,运行:
    bash
    npx -y @tokenchit/cli@0.10.0 init
    该命令会检测本机上哪些Agent存在日志,并记录下来。该文件需要提交到仓库,且绝不会包含凭证信息。
    如果用户传入了
    --dry-run
    参数,完全跳过此步骤
    ,并告知用户
    .tokenchit.json
    本会被 创建。写入配置文件的预览不算真正的预览。
  3. 生成卡片。 不带参数的命令会写入配置的输出路径——如果
    .tokenchit.json
    中没有指定其他路径,则默认为
    tokenchit.svg
    :
    bash
    npx -y @tokenchit/cli@0.10.0 sync
    仅添加用户明确要求的参数,每个参数的拼写必须与下方完全一致。不要在命令中复制占位符——
    sync
    命令会忽略无法识别的位置参数而非报错,因此带括号的
    [--dry-run]
    会作为无效参数传入CLI,最终仍然会生成卡片,这与用户的需求完全相反。
    参数作用
    --out <path>
    写入到配置的输出路径之外的其他位置
    --theme auto
    |
    light
    |
    dark
    卡片主题;
    auto
    会适配读者的系统主题
    --dry-run
    仅打印本会写入的内容,不修改任何文件
    sync
    命令仅读取本地文件,不发送任何数据:没有提示、没有代码、没有文件内容离开本机,也不会向任何服务器传输数据。包裹它的npx调用只是从注册表下载包——这是本工作流程中唯一的网络访问,且已在步骤1中获得用户同意。
  4. 反馈结果并提供可选操作。 输出生成的统计数据——Token数、等效成本、连续使用天数、各Agent占比——以及写入的文件路径。如果仓库的README中尚未引用该卡片,可主动提议添加:
    markdown
    ![tokenchit](./tokenchit.svg)
    sync
    命令输出的是相对于仓库根目录的路径。Markdown图片的路径是相对于其所在文件解析的,因此需要根据被编辑的README的位置调整路径:例如卡片位于
    docs/usage.svg
    时,根目录的README中应写
    ./docs/usage.svg
    ,而
    docs/zh-CN/README.md
    中应写
    ../usage.svg
    。直接将输出的路径粘贴到嵌套的README中会指向
    docs/zh-CN/docs/usage.svg
    ,导致图片无法加载。
    未经用户要求,请勿编辑README。
步骤4完成后即停止。发布到公共排行榜是独立的
publish
命令,需要用户明确选择加入,不属于本工作流程——仅当用户明确要求执行该命令时才运行。
unpublish
命令可移除排行榜中的记录和账户。

Output

输出内容

The path of the SVG, the figures it contains, and the markdown snippet for referencing it. On a dry run: what would have been written, and nothing on disk changed.
SVG文件的路径、其中包含的统计数据,以及引用该卡片的Markdown片段。试运行模式下:输出本会写入的内容,且不会修改磁盘上的任何文件。

Notes

注意事项

  • Requires Node.js 22 or newer (the package declares
    engines: { node: ">=22" }
    ). Nothing is installed globally;
    npx
    fetches the pinned version per run.
  • Reads token counts and timestamps only.
  • 需要Node.js 22或更高版本(该包声明了
    engines: { node: ">=22" }
    )。不会全局安装任何内容;
    npx
    每次运行都会获取固定版本。
  • 仅读取Token数量和时间戳。