Skip to content

v6.4.0 — Codex and Claude jobs report what they cost

Choose a tag to compare

@moerasermax moerasermax released this 06 Oct 06:37
· 184 commits to master since this release
claude mcp add ai-cli -s user -- npx -y @tkflyc/ai-cli-mcp

Codex and Claude jobs now report what they cost

Until now nobody could see what a dispatched job cost. ai-cli never parsed the usage that Codex and Claude report, and the strict path runs Codex with --ephemeral, so those jobs leave no session file to check afterwards either. When we tried to estimate ai-cli's share of a busy project's spend, the jobs that could not be measured were easy to mistake for jobs that cost little.

Finished Codex and Claude jobs now carry agentOutput.usage in both wait and get_result, normalized to one shape: total input, cached input, cache writes, output, and reasoning tokens. Claude adds num_turns and cost_usd_nominal — a list-price estimate, not a subscription bill, and named so it cannot be mistaken for one.

  • input_tokens means the same thing for both vendors: everything sent to the model, cache included. Codex already reports it that way; Claude's raw figure excludes cache, so it is summed.
  • If usage cannot be measured, the field is absent — never zero. If some Codex turns report malformed usage, usage covers the valid ones and carries incomplete: true instead of silently undercounting; if none are valid, usage is omitted.
  • A failed job that reports usage but no reply still returns its raw stdout/stderr. An early draft hid the error text in that case; the independent audit caught it before release.

Expensive effort levels are flagged

When the effort actually sent is xhigh, max, or ultra — whether passed explicitly, implied by an alias, or set in config — the MCP run tool returns warnings saying so and naming the source. It warns; it does not block. (The CLI ai-cli run gained the same warnings in 6.5.0.)

Dispatch guidance now covers cost

models → dispatchGuidance gains four entries based on measurement: each job pays a fixed overhead before doing any work (measured here at about 20k input tokens for a minimal Codex job and about 30k of context for a minimal Claude job; the Claude figure depends on your CLAUDE.md, hooks, and MCP servers), so batch small tasks; don't dispatch the same thing twice; poll with wait near 90 seconds instead of short loops; and record agentOutput.usage when a job finishes.

Fixed: query_usage said ok without a number

Run as an administrator, Codex 0.160's interactive mode refuses to start its shared daemon. The usage panel never appeared, yet query_usage returned status: "ok". The quota TUI now starts with --no-daemon, retrying without it on older CLIs that reject the flag, and a result with no quota numbers is an error, not ok — the raw screen is kept either way.

Compatibility

If Claude's output arrives as a single JSON document, the vendor's raw usage object now lives in raw_usage, and usage holds the normalized shape.

Full details: CHANGELOG.


繁體中文

codex 與 claude 的 job 會回報花了多少

在這之前,派出去的 job 花了多少,誰都看不到。ai-cli 從來沒解析 codex 和 claude 回報的用量;strict 路徑又讓 codex 帶 --ephemeral 執行,不留 session 檔,事後也查不到。我們在估算一個忙碌專案裡 ai-cli 佔多少花費時,就很容易把「量不到」誤當成「花得少」。

現在 codex 和 claude 的 job 結束時,wait 和 get_result 都會帶 agentOutput.usage,兩家統一成同一個形狀:總輸入、快取讀取、快取寫入、output、推理 token。claude 另外帶 num_turns 和 cost_usd_nominal。後者是依牌價估的名目成本,不是訂閱帳單,欄位名稱就寫明了這一點。

  • input_tokens 在兩家的意思相同:送進模型的全部輸入,包含快取。codex 回報的值本來就是這樣;claude 原始的數字不含快取,所以把幾項加總。
  • 量不到用量時,這個欄位不會出現,不會填 0。如果 codex 有部分 turn 回報的用量格式壞掉,usage 只算有效的那幾筆,並標上 incomplete: true,不會默默少算;全部無效時就不放 usage。
  • job 失敗、只回報用量而沒有回覆時,仍會帶回原始的 stdout/stderr。早期草稿在這種情況下會把錯誤原文藏掉,發版前的獨立稽核抓到了。

高成本的 effort 會提醒

實際送出的 effort 是 xhigh、max 或 ultra 時,不論是明確指定、alias 預設還是設定檔帶出來的,MCP 的 run 都會回傳 warnings 說明這件事,並標出來源。只提醒,不擋派工。(CLI 的 ai-cli run 在 6.5.0 才加上同樣的警告。)

派工建議納入成本

models → dispatchGuidance 依實測新增四條建議:每個 job 在做事之前都有固定開銷(這裡實測,最小的 codex job 約 2 萬 input tokens,最小的 claude job 約 3 萬 context;claude 的數字會隨你的 CLAUDE.md、hook 和 MCP server 而變),所以零碎的小任務要合併;同一件事不要派兩次;輪詢用接近 90 秒的 wait,不要短間隔反覆查;job 結束後記下 agentOutput.usage。

修正:query_usage 沒有數字卻回 ok

以系統管理員權限執行時,codex 0.160 的互動模式拒絕啟動共用 daemon,額度面板一直沒出現,query_usage 卻回 status: "ok"。現在查額度的 TUI 改帶 --no-daemon,舊版 CLI 不認得這個參數時會拿掉重跑一次;而且沒有任何額度數字的結果一律回 error,不再是 ok。兩種情況都會保留原始畫面。

相容性

claude 的輸出如果整段是單一 JSON,vendor 原始的 usage 物件改放在 raw_usage,usage 則是正規化後的形狀。

完整內容:CHANGELOG。