tkm

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Token Manager (tkm) with orbit CLI

基于orbit CLI的Token Manager (tkm)

Track AI token consumption, costs, and usage trends across Claude Code sessions. Data is ingested automatically from Claude Code session JSONL files and stored in a local SQLite database.
追踪Claude Code会话中的AI token消耗、成本及使用趋势。数据会自动从Claude Code会话JSONL文件中导入,并存储在本地SQLite数据库中。

Prerequisites

前提条件

  1. orbit
    CLI installed — if
    which orbit
    fails, install with:
    • macOS/Linux (Homebrew):
      brew install jorgemuza/tap/orbit
    • macOS/Linux (script):
      curl -sSfL https://raw.githubusercontent.com/jorgemuza/orbit/main/install.sh | sh
    • Windows (Scoop):
      scoop bucket add jorgemuza https://github.com/jorgemuza/scoop-bucket && scoop install orbit
  2. Claude Code installed and used (session files in
    ~/.claude/projects/
    )
No profile or service configuration needed — tkm works entirely with local data.
  1. 已安装
    orbit
    CLI —— 如果执行
    which orbit
    无结果,可通过以下方式安装:
    • macOS/Linux(Homebrew):
      brew install jorgemuza/tap/orbit
    • macOS/Linux(脚本):
      curl -sSfL https://raw.githubusercontent.com/jorgemuza/orbit/main/install.sh | sh
    • Windows(Scoop):
      scoop bucket add jorgemuza https://github.com/jorgemuza/scoop-bucket && scoop install orbit
  2. 已安装并使用Claude Code(会话文件位于
    ~/.claude/projects/
    目录下)
无需配置配置文件或服务——tkm完全基于本地数据运行。

Quick Reference

快速参考

bash
undefined
bash
undefined

Today's token usage and cost

今日token使用量及成本

orbit tkm status
orbit tkm status

This week's summary

本周汇总

orbit tkm status --period week
orbit tkm status --period week

Daily usage breakdown

每日使用明细

orbit tkm usage
orbit tkm usage

Weekly usage

每周使用量

orbit tkm usage --period weekly
orbit tkm usage --period weekly

Monthly usage

月度使用量

orbit tkm usage --period monthly
orbit tkm usage --period monthly

Cost breakdown by model

按模型划分的成本明细

orbit tkm cost
orbit tkm cost

Monthly cost trends

月度成本趋势

orbit tkm cost --period month
orbit tkm cost --period month

Recent sessions with token counts

包含token数量的近期会话

orbit tkm sessions
orbit tkm sessions

More sessions

查看更多会话

orbit tkm sessions --limit 50
orbit tkm sessions --limit 50

Filter by project

按项目筛选

orbit tkm status --project /path/to/project orbit tkm usage --project /path/to/project
orbit tkm status --project /path/to/project orbit tkm usage --project /path/to/project

Filter by model

按模型筛选

orbit tkm usage --model opus
orbit tkm usage --model opus

Force sync session data

强制同步会话数据

orbit tkm sync
orbit tkm sync

Full re-sync (re-process all files)

完全重新同步(重新处理所有文件)

orbit tkm sync --full
orbit tkm sync --full

JSON output for scripting

输出JSON格式用于脚本编写

orbit tkm status -o json orbit tkm cost -o json
orbit tkm status -o json orbit tkm cost -o json

Manually record a usage event

手动记录使用事件

orbit tkm track --model claude-opus-4-6 --input 1000 --output 500
orbit tkm track --model claude-opus-4-6 --input 1000 --output 500

Clear all tracking data

清除所有追踪数据

orbit tkm clear --confirm
undefined
orbit tkm clear --confirm
undefined

Core Workflows

核心工作流

Check daily spending

查看每日支出

bash
orbit tkm status
orbit tkm cost --period today
bash
orbit tkm status
orbit tkm cost --period today

Weekly cost review

每周成本回顾

bash
orbit tkm usage --period weekly --limit 8
orbit tkm cost --period week
bash
orbit tkm usage --period weekly --limit 8
orbit tkm cost --period week

Per-project analysis

按项目分析

bash
undefined
bash
undefined

Check spending on a specific project

查看特定项目的支出

orbit tkm status --period month --project /Users/me/Projects/my-app orbit tkm sessions --project /Users/me/Projects/my-app
undefined
orbit tkm status --period month --project /Users/me/Projects/my-app orbit tkm sessions --project /Users/me/Projects/my-app
undefined

Model cost comparison

模型成本对比

bash
orbit tkm cost --period month
bash
orbit tkm cost --period month

Export data for reporting

导出数据用于报告

bash
orbit tkm usage --period monthly -o json > monthly-usage.json
orbit tkm cost -o json > cost-breakdown.json
orbit tkm sessions -o json > sessions.json
bash
orbit tkm usage --period monthly -o json > monthly-usage.json
orbit tkm cost -o json > cost-breakdown.json
orbit tkm sessions -o json > sessions.json

Data Storage

数据存储

  • Database:
    ~/.config/orbit/tkm.db
    (SQLite)
  • Source:
    ~/.claude/projects/<encoded-path>/<session-id>.jsonl
  • Auto-sync: Runs automatically on every read command (status, usage, cost, sessions)
  • Incremental: Only parses new data since last sync (byte-offset tracking)
  • Retention: Skips files older than 90 days
  • 数据库:
    ~/.config/orbit/tkm.db
    (SQLite)
  • 数据源:
    ~/.claude/projects/<encoded-path>/<session-id>.jsonl
  • 自动同步: 每次执行读取命令(status、usage、cost、sessions)时自动运行
  • 增量同步: 仅解析上次同步后新增的数据(基于字节偏移量追踪)
  • 数据保留: 跳过90天以上的文件

RTK Integration (Optional)

RTK集成(可选)

RTK is a companion tool that compresses command output before it reaches the LLM, saving 60-90% of input tokens. orbit tkm handles the analytics side.
ToolRole
RTKCompresses command output (git, grep, npm, etc.)
orbit tkmTracks usage, calculates costs, reports trends
RTK is optional — tkm works standalone. To add RTK compression:
bash
undefined
RTK是一款配套工具,可在命令输出传递给LLM之前对其进行压缩,节省60-90%的输入token。orbit tkm负责分析统计部分。
工具作用
RTK压缩命令输出(git、grep、npm等)
orbit tkm追踪使用情况、计算成本、报告趋势
RTK为可选组件——tkm可独立运行。如需添加RTK压缩功能:
bash
undefined

Install RTK

安装RTK

brew install rtk-ai/tap/rtk
brew install rtk-ai/tap/rtk

Set up Claude Code hooks

设置Claude Code钩子

rtk init -g
rtk init -g

Verify compression is working

验证压缩功能是否正常工作

rtk verify
undefined
rtk verify
undefined

Model Pricing

模型定价

Default pricing (per million tokens):
ModelInputOutputCache ReadCache Write
claude-opus-4-6$15.00$75.00$1.50$18.75
claude-sonnet-4-6$3.00$15.00$0.30$3.75
claude-haiku-4-5$0.80$4.00$0.08$1.00
For full command details and flags, see
references/commands.md
.
默认定价(每百万token):
模型输入输出缓存读取缓存写入
claude-opus-4-6$15.00$75.00$1.50$18.75
claude-sonnet-4-6$3.00$15.00$0.30$3.75
claude-haiku-4-5$0.80$4.00$0.08$1.00
如需了解完整命令详情及参数,请查看
references/commands.md