{"id":50622033,"url":"https://github.com/stormzhang/token-tracker","last_synced_at":"2026-06-06T13:01:25.835Z","repository":{"id":356505010,"uuid":"1232824274","full_name":"stormzhang/token-tracker","owner":"stormzhang","description":"Track token usage across local AI agents (Claude Code, Codex) — Custom StatusLine, CLI Dashboard with cost analysis, rate limit monitoring, and session tracking","archived":false,"fork":false,"pushed_at":"2026-06-05T02:20:58.000Z","size":1364,"stargazers_count":272,"open_issues_count":0,"forks_count":22,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-05T03:09:22.880Z","etag":null,"topics":["ai-agent","claude-code","cli","codex","python","rich","token-tracker"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stormzhang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-08T10:03:52.000Z","updated_at":"2026-06-05T02:21:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/stormzhang/token-tracker","commit_stats":null,"previous_names":["stormzhang/token-tracker"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/stormzhang/token-tracker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stormzhang%2Ftoken-tracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stormzhang%2Ftoken-tracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stormzhang%2Ftoken-tracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stormzhang%2Ftoken-tracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stormzhang","download_url":"https://codeload.github.com/stormzhang/token-tracker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stormzhang%2Ftoken-tracker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33983046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-06T02:00:07.033Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-agent","claude-code","cli","codex","python","rich","token-tracker"],"created_at":"2026-06-06T13:01:25.246Z","updated_at":"2026-06-06T13:01:25.828Z","avatar_url":"https://github.com/stormzhang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Token Tracker (tt)\n\n本地 AI Agent Token 消耗追踪/分析工具，支持 **Claude Code** 和 **Codex** 。\n\n自定义 StatusLine 状态栏 + CLI Dashboard，实时查看 token 用量、等效成本、限额状态。\n\n![Python](https://img.shields.io/badge/python-3.11+-blue) ![License](https://img.shields.io/badge/license-MIT-green)\n\n[English](README_EN.md)\n\n## StatusLine 状态栏\n\n自动为 Claude Code 和 Codex 配置状态栏，`tt setup` 一键配置，脚本更新时自动升级。\n\n**Claude Code**：基于官方自定义 StatusLine 接口，数据完全来自本地 Claude，准确无任何推测\n\n![Claude Code StatusLine](assets/screenshot-statusline-cc.png)\n\n状态栏共三行，从左到右：\n\n| 行 | 字段 | 说明 |\n|----|------|------|\n| 1 | `项目名(分支)` | 当前项目目录 + Git 分支，未提交的修改会标 `*` |\n| 1 | `5h: ██░ 31% (1h19m)` | 5 小时滑动窗口配额用量，括号内为重置倒计时 |\n| 1 | `7d: ██░ 11% (5d8h)` | 7 天滑动窗口配额用量 |\n| 1 | `1.0M Context: ██░ 20%` | 上下文窗口总大小及已用占比 |\n| 2 | `Tokens: in 155k, out 128k` | 本次会话累计输入/输出 Token |\n| 2 | `(本轮: in 1, out 15)` | 当前对话轮次的 Token 用量 |\n| 2 | `Cached: 204k` | 当前轮次命中的 Prompt Cache Token 数 |\n| 2 | `Cost: $35.51` | 本次会话等效成本（按官方定价计算） |\n| 3 | `Model: Opus 4.6/high/nofast` | 模型名 / thinking 级别 / 是否 fast 模式 |\n| 3 | `Duration: 1h33m` | 当前会话已持续时间 |\n\n\u003e 终端宽度不足时会自动降级：先隐藏重置倒计时，再将进度条简化为百分比数字。\n\n**Codex**：官方暂不支持自定义 StatusLine 渲染，沿用官方默认样式，`tt setup` 仅写入字段配置\n\n![Codex StatusLine](assets/screenshot-statusline-codex.png)\n\n| 字段 | 说明 |\n|------|------|\n| `project` | 当前项目目录名 |\n| `five-hour-limit` | 5 小时滑动窗口配额用量 |\n| `weekly-limit` | 7 天滑动窗口配额用量 |\n| `context-remaining` | 上下文窗口剩余占比 |\n| `model-with-reasoning` | 模型名 + 推理强度（如 `gpt-5-codex/high`） |\n\n## Dashboard 数据面板和 日/周/月 数据报表分析\n\n![Token Tracker Dashboard](assets/screenshot.png)\n\n![Token Tracker Daily](assets/screenshot-daily.png)\n\n![Token Tracker Weekly](assets/screenshot-weekly.png)\n\n![Token Tracker Monthly](assets/screenshot-monthly.png)\n\n## 功能\n\n- **多 Agent 追踪** — Claude Code + Codex 统一面板，左右键切换\n- **状态栏集成** — Claude Code statusLine + Codex status_line，首次运行自动配置，脚本更新自动升级\n- **限额监控** — 实时 5h / 7d 配额百分比 + 重置倒计时\n- **成本分析** — 按会话、日、周、月维度的等效成本统计，多 Agent 按来源分组展示\n- **会话洞察** — 项目、模型、时长、消息数一览\n- **零配置** — 自动检测已安装的 Agent，直接读取本地数据\n- **隐私安全** — 数据纯本地存储，不采集、不上传任何用户信息，极轻量无后顾之忧\n\n## 安装\n\n```bash\ncurl -sSL https://raw.githubusercontent.com/stormzhang/token-tracker/main/install.sh | bash\n```\n\n或者通过 pip：\n\n```bash\npip install --force-reinstall token-tracker \u0026\u0026 tt setup\n```\n\n## 使用\n\n```bash\ntt setup          # 初始化配置 Claude Code + Codex status_line\ntt                # 交互式 Dashboard（方向键切换 Agent）\ntt claude         # 仅展示 Claude Code\ntt codex          # 仅展示 Codex\ntt daily          # 按日汇总（按 token 消耗排序）\ntt weekly         # 按周汇总（多 Agent 分组展示）\ntt monthly        # 按月汇总（多 Agent 分组展示）\ntt sessions       # 最近 20 条会话明细数据\ntt unsetup        # 卸载并恢复安装前的配置\n```\n\n### 报告排序\n\n所有报告命令支持 `--sort` 和 `--asc/--desc` 参数：\n\n```bash\ntt daily --sort cost --desc     # 按成本降序\ntt sessions --sort tokens --asc # 按 token 升序\n```\n\n可选排序字段：`tokens` / `cost` / `messages` / `time` / `input` / `output`\n\n### Dashboard 快捷键\n\n| 按键 | 功能 |\n|------|------|\n| `←` `→` | 切换 Agent |\n| `↑` `↓` | 滚动内容 |\n| `s` | 切换排序字段（时间 → Token → 等效成本 → 消息数） |\n| `r` | 反转排序方向 |\n| `+` / `-` | 调整会话显示条数（±10，最少 10 条） |\n| `q` | 退出 |\n\n## 环境要求\n\n- Python 3.11+\n- [Rich](https://github.com/Textualize/rich)（自动安装）\n\n## TODO\n\n未来持续增加更多数据报表，多维度分析。\n\n## License\n\nCopyright (c) 2026 stormzhang. MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstormzhang%2Ftoken-tracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstormzhang%2Ftoken-tracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstormzhang%2Ftoken-tracker/lists"}