codex-token-usage

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Codex Token Usage

Codex令牌使用情况

Overview

概述

Use the bundled script to read local Codex session logs and produce a consistent token usage report. Prefer deterministic script output over ad hoc
rg
summaries.
使用捆绑的脚本读取本地Codex会话日志,生成一致的令牌使用报告。优先使用确定性脚本输出,而非临时的
rg
摘要。

Workflow

工作流程

  1. Identify the reporting window from the user request.
    • If the user asks for "one month" or "last month" without naming a calendar month, use the last 30 local calendar days ending today.
    • If the user asks for "this month" or names a specific month, use that calendar month, clipped to today if it is the current month.
    • Use the user's timezone from context when available; default to the local machine timezone only if no timezone is provided.
  2. Run
    scripts/codex_token_usage.py
    .
  3. Report results in a table with these rows: total, input, cached input, output, reasoning output, non-cached input, net usage, cache hit rate, and daily average total.
  4. Include the peak day and busiest week with exact dates.
  5. State the net usage formula.
  1. 根据用户请求确定报告时间范围。
    • 如果用户要求“一个月”或“上个月”但未指定具体日历月,则使用截至今日的过去30个本地日历日。
    • 如果用户要求“本月”或指定了具体月份,则使用该日历月;若为当前月份,则截止到今日。
    • 若上下文提供了用户时区,则使用该时区;仅当未提供时区时,默认使用本地机器时区。
  2. 运行
    scripts/codex_token_usage.py
  3. 以表格形式报告结果,包含以下行:总计、输入、缓存输入、输出、推理输出、非缓存输入、净使用量、缓存命中率、日均总计。
  4. 包含峰值日和最繁忙周的具体日期。
  5. 说明净使用量的计算公式。

Script

脚本

Run from the skill directory or pass an absolute script path:
bash
python scripts/codex_token_usage.py --days 30 --timezone Asia/Shanghai
Useful options:
bash
python scripts/codex_token_usage.py --start 2026-03-30 --end 2026-04-28 --timezone Asia/Shanghai
python scripts/codex_token_usage.py --month 2026-04 --timezone Asia/Shanghai
python scripts/codex_token_usage.py --codex-home C:\Users\admin\.codex --days 30
python scripts/codex_token_usage.py --days 30 --format json
python scripts/codex_token_usage.py --days 30 --format markdown --language en
If
python
is not on PATH, use the bundled Codex runtime if available:
bash
C:\Users\admin\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe scripts\codex_token_usage.py --days 30 --timezone Asia/Shanghai
从技能目录运行,或传入脚本的绝对路径:
bash
python scripts/codex_token_usage.py --days 30 --timezone Asia/Shanghai
实用选项:
bash
python scripts/codex_token_usage.py --start 2026-03-30 --end 2026-04-28 --timezone Asia/Shanghai
python scripts/codex_token_usage.py --month 2026-04 --timezone Asia/Shanghai
python scripts/codex_token_usage.py --codex-home C:\Users\admin\.codex --days 30
python scripts/codex_token_usage.py --days 30 --format json
python scripts/codex_token_usage.py --days 30 --format markdown --language en
如果
python
不在PATH中,若有捆绑的Codex运行时则使用它:
bash
C:\Users\admin\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe scripts\codex_token_usage.py --days 30 --timezone Asia/Shanghai

Definitions

定义

  • total
    : sum of
    last_token_usage.total_tokens
    across
    token_count
    events.
  • input
    : sum of
    last_token_usage.input_tokens
    .
  • cached input
    : sum of
    last_token_usage.cached_input_tokens
    .
  • output
    : sum of
    last_token_usage.output_tokens
    .
  • reasoning output
    : sum of
    last_token_usage.reasoning_output_tokens
    .
  • non-cached input
    :
    input - cached input
    .
  • net usage
    :
    non-cached input + output
    .
  • cache hit rate
    :
    cached input / input
    .
  • daily average total
    :
    total / number of local calendar days in the reporting range
    .
Avoid summing
total_token_usage
for each event because it is cumulative within a session and will overcount. Sum
last_token_usage
instead.
  • total
    :所有
    token_count
    事件中
    last_token_usage.total_tokens
    的总和。
  • input
    last_token_usage.input_tokens
    的总和。
  • cached input
    last_token_usage.cached_input_tokens
    的总和。
  • output
    last_token_usage.output_tokens
    的总和。
  • reasoning output
    last_token_usage.reasoning_output_tokens
    的总和。
  • non-cached input
    input - cached input
  • net usage
    non-cached input + output
  • cache hit rate
    cached input / input
  • daily average total
    total / 报告范围内的本地日历天数
请勿对每个事件的
total_token_usage
求和,因为它在会话内是累积的,会导致重复统计。请改为对
last_token_usage
求和。

Response Format

响应格式

Use a concise Markdown table. Localize row labels to the user's language. For Chinese responses, use labels like total, Input, Cached input, Output, Reasoning output, non-cached Input, and net usage in Chinese where appropriate.
markdown
| Metric | Tokens | Notes |
|---|---:|---|
| Total | 730,366,547 | Sum of `total_tokens` |
| Input | 724,204,405 | Input tokens, including cached input |
| Cached input | 640,615,168 | Cached input tokens |
| Output | 3,239,893 | Output tokens |
| Reasoning output | 456,198 | Reasoning output tokens |
| Non-cached input | 83,589,237 | `Input - Cached input` |
| Net usage | 86,829,130 | `Non-cached input + Output` |
| Cache hit rate | 88.44% | `Cached input / Input` |
| Daily average total | 24,345,552 | `Total / days in range` |
Then add one sentence for the peak day and busiest week:
markdown
The peak day was 2026-04-01: 72,000,000 tokens.
The busiest week was 2026-03-30 to 2026-04-05: 244,371,620 tokens.
Use
--format json
when the result will feed another script, dashboard, automation, or report generator. Use Markdown for direct user answers.
使用简洁的Markdown表格。将行标签本地化到用户使用的语言。对于中文响应,可酌情使用中文标签,如总计、输入、缓存输入、输出、推理输出、非缓存输入、净使用量等。
markdown
| 指标 | 令牌数 | 说明 |
|---|---:|---|
| 总计 | 730,366,547 | `total_tokens`的总和 |
| 输入 | 724,204,405 | 输入令牌,包含缓存输入 |
| 缓存输入 | 640,615,168 | 缓存输入令牌 |
| 输出 | 3,239,893 | 输出令牌 |
| 推理输出 | 456,198 | 推理输出令牌 |
| 非缓存输入 | 83,589,237 | `输入 - 缓存输入` |
| 净使用量 | 86,829,130 | `非缓存输入 + 输出` |
| 缓存命中率 | 88.44% | `缓存输入 / 输入` |
| 日均总计 | 24,345,552 | `总计 / 时间范围天数` |
然后添加一句话说明峰值日和最繁忙周:
markdown
峰值日为2026-04-01:72,000,000令牌。
最繁忙周为2026-03-30至2026-04-05:244,371,620令牌。
当结果将用于其他脚本、仪表板、自动化或报告生成器时,使用
--format json
。直接向用户回复时使用Markdown格式。