[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-81713":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":12,"openIssues":13,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":13,"stars7d":13,"stars30d":13,"stars90d":13,"forks30d":13,"starsTrendScore":13,"compositeScore":12,"rankGlobal":10,"rankLanguage":10,"license":14,"archived":15,"fork":15,"defaultBranch":16,"hasWiki":17,"hasPages":15,"topics":18,"createdAt":10,"pushedAt":10,"updatedAt":19,"readmeContent":20,"aiSummary":21,"trendingCount":13,"starSnapshotCount":13,"syncStatus":22,"lastSyncTime":23,"discoverSource":24},81713,"aitok","MagnumGoYB\u002Faitok","MagnumGoYB","  Offline-first Go CLI for summarizing local token usage and estimated USD costs from Claude Code, Codex, and Gemini CLI.","",null,"Go",40,0,"MIT License",false,"main",true,[],"2026-06-12 04:01:35","# aitok\n\n[中文](README.zh-CN.md)\n\n![aitok cover](README.en.jpg)\n\n`aitok` is a lightweight offline CLI for summarizing local token usage from Claude Code, Codex, and Gemini CLI.\n\nIt does not upload data or read API keys. Usage and USD cost summaries are built from local tool logs.\n\n## Install\n\nHomebrew:\n\n```bash\nbrew tap MagnumGoYB\u002Faitok\nbrew install --cask aitok\n```\n\nThe tap step keeps the install command short and avoids the less readable fully qualified cask name.\n\nShell installer:\n\n```bash\ncurl -fsSL https:\u002F\u002Fraw.githubusercontent.com\u002FMagnumGoYB\u002Faitok\u002Fmain\u002Fscripts\u002Finstall.sh | sh\n```\n\nThe installer downloads the matching macOS or Linux GitHub Release archive, verifies it with `checksums.txt`, and installs `aitok` to `\u002Fusr\u002Flocal\u002Fbin`. Override the target directory or version when needed:\n\n```bash\ncurl -fsSL https:\u002F\u002Fraw.githubusercontent.com\u002FMagnumGoYB\u002Faitok\u002Fmain\u002Fscripts\u002Finstall.sh | AITOK_INSTALL_DIR=\"$HOME\u002F.local\u002Fbin\" sh\ncurl -fsSL https:\u002F\u002Fraw.githubusercontent.com\u002FMagnumGoYB\u002Faitok\u002Fmain\u002Fscripts\u002Finstall.sh | AITOK_VERSION=v0.1.30 sh\n```\n\nGo:\n\n```bash\ngo install github.com\u002FMagnumGoYB\u002Faitok\u002Fcmd\u002Faitok@latest\n```\n\nFor local development:\n\n```bash\ngo install .\u002Fcmd\u002Faitok\n```\n\nTo run the CLI from a checkout without writing Go build cache into `~\u002FLibrary\u002FCaches`, use the project Makefile wrapper:\n\n```bash\nmake run ARGS=\"summary --period today\"\n```\n\n`aitok` checks GitHub release metadata at most once every 24 hours before a command runs. If a newer version exists, it prints an upgrade prompt to stderr based on the detected install method. The check does not upload usage data, does not read logs, and can be skipped with `--no-version-check` or `AITOK_NO_VERSION_CHECK=1`.\n\n## Usage\n\n```bash\naitok summary --period today\naitok summary --period today --threads --format json\naitok summary --period this-week --group-by tool,model,provider --format markdown\naitok report --period last-week --format json\naitok tui\naitok tui --lang zh-CN\naitok doctor\naitok version\naitok -v\naitok update\naitok setup gemini --dry-run\naitok pricing audit --period this-month --format markdown\naitok budget check --period this-month --limit-usd 20 --group-by tool,model,cwd\n```\n\n## AI Agent Invocation\n\nAI agents and scripts should prefer JSON output and skip the low-frequency version check:\n\n```bash\naitok --no-version-check summary --period today --format json\naitok --no-version-check summary --period today --threads --format json\naitok --no-version-check pricing audit --period this-month --format json\naitok --no-version-check doctor --format json\naitok --no-version-check budget check --period this-month --limit-usd 20 --format json\n```\n\nFor JSON commands, stdout is reserved for the structured payload. Warnings, version prompts, and budget failure summaries are written to stderr or returned through the process exit status. `budget check` exits with status `1` when the limit is exceeded but still writes the full JSON payload to stdout for parsing.\n\nThe TUI uses English by default. Pass `--lang zh-CN` to start in Chinese, or press `l` inside the TUI to switch languages. Model Usage and Threads sort by descending token usage by default; pass `--sort cost` for cost ordering, or press `s` inside the TUI to switch between Tokens and Cost. When threads are present, use `j\u002Fk` or arrow keys to move the selected row, `home\u002Fend` to jump, `enter` to resume supported local sessions (`codex resume \u003Cid>` or `claude --resume \u003Cid>`), and `c` to copy the selected thread ID through OSC52.\n\n`aitok update` checks the latest GitHub Release immediately and runs the matching local upgrade command when the install method supports it. Homebrew installs use `brew update && brew upgrade --cask aitok`; Go installs use `go install github.com\u002FMagnumGoYB\u002Faitok\u002Fcmd\u002Faitok@latest`. Direct release binaries print the download URL.\n\nPeriods:\n\n- `today`\n- `yesterday`\n- `this-week`\n- `last-week`\n- `this-month`\n\nFilters:\n\n- `--tool claude|codex|gemini`\n- `--model \u003Cname>`\n- `--provider \u003Cprovider-or-auth-type>`\n- `--cwd \u003Cpath-fragment>`\n\nGrouping:\n\n```bash\n--group-by tool,model,provider,day,cwd\n```\n\nReports include request count, token totals, cache tokens, estimated USD cost, and the matched price used for each `model\u002Fprovider` group. Cost uses an offline default model price catalog based on an official public pricing snapshot and can be overridden locally. Rows backed by the bundled catalog show `official`; rows matched by `~\u002F.aitok\u002Fpricing.json` show `custom`. If a custom grouping combines multiple price definitions, the price is shown as `mixed`.\n\nFor Codex, provider attribution uses only local non-secret evidence. Provider-qualified model names like `team-a\u002Fgpt-5.4` are preferred when present. When the model name is bare, aitok can use Codex request-host evidence from local logs only if that host maps uniquely to a configured `[model_providers.*].base_url` in `~\u002F.codex\u002Fconfig.toml`. Same-turn provider evidence is applied by event time: earlier token-count rows keep the best provider known at their own timestamp, and later rows in the same turn can switch once newer auth or request-host evidence appears. Sparse bare turns between two provider anchors stay on the earlier provider segment until later switch evidence appears; Model Usage only applies a narrow correction for short inferred bridge segments bracketed by exact request evidence. Unknown hosts, shared hosts, missing request URLs, or provider URL rotations that are no longer represented in the local config fall back to the provider recorded in the session log.\n\nTo include matching local sessions in the summary payload, pass `--threads`:\n\n```bash\naitok summary --period today --threads --format json\n```\n\nThread rows include ID, name, tool, model, provider, token usage, requests, events, source, estimated USD cost, and matched price details when available. Query output sorts by descending token usage unless `--sort cost` is passed. The title comes from local logs only, preferring custom title, AI summary title, first real user message, cwd basename, then short ID.\n\n```json\n{\n  \"models\": [\n    {\n      \"match\": \"gpt-5.4\",\n      \"input_usd_per_mtok\": 1.25,\n      \"output_usd_per_mtok\": 10,\n      \"cache_hit_usd_per_mtok\": 0.125,\n      \"cache_make_usd_per_mtok\": 1.25,\n      \"cache_make_1h_usd_per_mtok\": 2.5,\n      \"multiplier\": 1\n    }\n  ]\n}\n```\n\nSave this as `~\u002F.aitok\u002Fpricing.json`, or pass a file explicitly:\n\n```bash\naitok summary --pricing .\u002Fpricing.json --format json\n```\n\nYou can also create or update the local override from a terminal Q\u002FA flow:\n\n```bash\naitok pricing configure\n```\n\nThe command writes `~\u002F.aitok\u002Fpricing.json` and asks numbered questions for a model match, provider\u002Fauth label, input\u002Foutput\u002Fcache pricing, and multiplier. For scripted setup, pass the values directly:\n\n```bash\naitok pricing configure \\\n  --model gpt-5.4 \\\n  --provider team-a \\\n  --input-usd-per-mtok 2 \\\n  --output-usd-per-mtok 20 \\\n  --cache-hit-usd-per-mtok 0.2 \\\n  --cache-make-usd-per-mtok 2.5 \\\n  --cache-make-1h-usd-per-mtok 0 \\\n  --multiplier 1\n```\n\nPrices are USD per 1M tokens. `provider` is a local provider\u002Fauth label from tool logs, such as Codex `model_provider` or Gemini `auth_type`; it must not be a raw API key. Use different local labels for different accounts or API-key-backed routes when the upstream tool logs expose those labels. `cache_hit_usd_per_mtok` is cache read pricing. `cache_make_usd_per_mtok` is the default cache write price, and `cache_make_1h_usd_per_mtok` can override one-hour cache write pricing when a source reports that split. Models with provider prompt tiers can also set `prompt_threshold_tokens` plus `above_threshold_*_usd_per_mtok` fields. Reasoning tokens are reported separately and are not charged as billable output by the offline estimate. `multiplier` defaults to `1`.\n\nTo check whether local usage contains models that are not covered by the offline catalog or your override file:\n\n```bash\naitok pricing audit --period this-month --format json\n```\n\nThe audit stays offline and prints unmatched `tool\u002Fmodel\u002Fprovider` groups plus a `pricing.json` skeleton that can be copied into `~\u002F.aitok\u002Fpricing.json`.\n\nTo enforce a local budget in scripts or CI:\n\n```bash\naitok budget check --period this-month --limit-usd 20\n```\n\nThe command exits with status `0` when the estimated cost is within the limit and status `1` when the estimate exceeds the limit. If some events do not match a price, the report includes a warning because the estimate may be low.\n\n`aitok doctor` also reports source event counts, latest event timestamps, Gemini local telemetry safety, and pricing coverage.\n\n## Data Sources\n\n- Claude Code: `~\u002F.claude\u002Fprojects\u002F**\u002F*.jsonl`\n- Codex: `~\u002F.codex\u002Fsessions\u002F**\u002F*.jsonl`\n- Gemini CLI: local telemetry outfile configured in `~\u002F.gemini\u002Fsettings.json`\n\nGemini CLI telemetry is disabled by default. Run:\n\n```bash\naitok setup gemini\n```\n\nThis configures local telemetry output and sets `logPrompts=false` so prompts are not recorded in telemetry.\n\n## Development\n\n```bash\nmake setup\nmake check\nmake test\nmake test-packages PKGS=\".\u002Finternal\u002Fquery .\u002Finternal\u002Freport\"\nmake test-harness\nmake vet\nmake build\nmake validate\nmake validate-pr-body\n```\n\n`make setup` enables the repository commit-msg hook for local commitlint. Harness and AI agent constraints live in `AGENTS.md`, `AGENTS.zh-CN.md`, and `docs\u002Fharness-engineering.md`.\n\n## Open Source Flow\n\n- Contributing guide: `CONTRIBUTING.md` \u002F `CONTRIBUTING.zh-CN.md`\n- Security policy: `SECURITY.md` \u002F `SECURITY.zh-CN.md`\n- GitHub automation: `docs\u002Fgithub-automation.md` \u002F `docs\u002Fzh-CN\u002Fgithub-automation.md`\n- Code of Conduct: `CODE_OF_CONDUCT.md` \u002F `CODE_OF_CONDUCT.zh-CN.md`\n- Support: `SUPPORT.md` \u002F `SUPPORT.zh-CN.md`\n- License: MIT\n","aitok 是一个轻量级的离线 Go 语言命令行工具，用于从 Claude Code、Codex 和 Gemini CLI 中汇总本地 token 使用情况及预估的美元成本。其核心功能包括基于本地工具日志生成使用和成本摘要，不上传数据也不读取 API 密钥，确保了用户隐私安全。该工具支持多种安装方式如 Homebrew、Shell 脚本以及 Go 语言直接安装，并提供丰富的命令选项来满足不同需求，比如按时间范围、线程数或特定格式（如 JSON、Markdown）输出报告。此外，aitok 还具备版本自动检查功能，方便用户及时更新到最新版本。它适用于需要监控和管理 AI 开发过程中资源消耗与成本的场景，特别适合开发者在本地环境中对 AI 模型调用进行有效管理和预算控制。",2,"2026-06-11 04:06:03","CREATED_QUERY"]