Token 知識庫

額度什麼時候重置、怎麼省 token?依目錄查閱各個主題,Codex 和 Claude 分開說明,附官方原文和連結。

subagent 太耗 token,怎麼幫它指定便宜的模型?

Claude Code 在 subagent 檔案開頭寫 model: haiku;Codex 在 ~/.codex/config.toml 的 [agents] 裡設 default_subagent_model。每個 subagent 各跑各的請求,扣的是同一份額度,所以搜尋、讀檔這類簡單的工作交給小模型最省。

Codex

在 ~/.codex/config.toml 的 [agents] 裡設 default_subagent_model,所有 subagent 預設就用小模型。

不設定的話,subagent 會沿用主工作階段的模型和推理強度。可以在 config.toml 的 [agents] 裡替全部 subagent 設預設值,也可以替某一個 subagent 另外建 .toml 檔案、寫上 model 和 model_reasoning_effort;檔案裡寫的優先於全域預設。官方的分工是:GPT-5.6 Terra 適合搜尋、讀大檔案、處理資料,GPT-5.6 Luna 適合範圍明確、重複量大的工作。想限制同時開幾個,就在 [agents] 裡設 max_concurrent_threads_per_session。

官方原文

Because each subagent does its own model and tool work, subagent workflows consume more tokens than comparable single-agent runs.
OpenAI docs · Subagents
If you don't configure a subagent model or model_reasoning_effort, the subagent inherits the parent agent's model and reasoning effort.
OpenAI docs · Subagents
To balance intelligence, speed, and price for each task, request a specific model or reasoning effort in your prompt, configure [agents] defaults in config.toml, or set model and model_reasoning_effort directly in the custom agent file.
OpenAI docs · Subagents
Use gpt-5.6-terra when you want a faster, lower-cost option for lighter subagent work.
OpenAI docs · Subagents
If a custom agent file sets model or model_reasoning_effort, the value in the file takes precedence.
OpenAI docs · Subagents

Claude

在 subagent 檔案開頭寫 model: haiku;想一次改全部,就設環境變數 CLAUDE_CODE_SUBAGENT_MODEL。

/usage 面板上的原話是:每個 subagent 各跑各的請求,別隨手開,簡單的 subagent 可以考慮指定便宜的模型(Each subagent runs its own requests. Be deliberate about spawning them — and consider configuring a cheaper model for simpler subagents.)。subagent 的定義檔在 .claude/agents/(目前專案)或 ~/.claude/agents/(所有專案),開頭的 model 可以填 haiku、sonnet、opus、fable、完整型號或 inherit;不寫就沿用主工作階段的模型。CLAUDE_CODE_SUBAGENT_MODEL 能替所有 subagent 設一個預設值,但它只是預設值:檔案裡寫了 model 的、Claude 分派工作時點名了模型的,都排在它前面。subagent 執行時輸入 /tasks,能看到它實際用的是哪個模型。

官方原文

For simple subagent tasks, specify model: haiku in your subagent configuration.
Claude Code docs · Manage costs effectively
CLAUDE_CODE_SUBAGENT_MODEL is a default, so a subagent's definition or a model Claude passes still takes precedence over it. To apply one model to every subagent, teammate, and workflow agent, also set CLAUDE_CODE_SUBAGENT_MODEL_FORCE to 1.
Claude Code docs · Create custom subagents
A user or project subagent named Explore overrides the built-in and keeps its own model field, so define one with model: haiku to keep exploration on a lower-cost model.
Claude Code docs · Create custom subagents
Agent teams use approximately 7x more tokens than standard sessions when teammates run in plan mode, because each teammate maintains its own context window and runs as a separate Claude instance.
Claude Code docs · Manage costs effectively
A single burst of heavy activity, such as a large workflow fanout, can exhaust the weekly allowance before the session window resets.
Claude Code docs · Error reference

Codex:實際怎麼寫

替所有 subagent 設預設:在 ~/.codex/config.toml 的 [agents] 下寫兩行,default_subagent_model = "gpt-5.6-terra" 和 default_subagent_reasoning_effort = "medium"。

只改某一個:在 .codex/agents/(目前專案)或 ~/.codex/agents/(所有專案)下建一個 .toml 檔案,寫上 name、description、developer_instructions 三個必填項,再加 model 和 model_reasoning_effort。官方範例 pr-explorer.toml 裡寫的是 name = "pr_explorer"、model = "gpt-5.6-luna"、model_reasoning_effort = "medium"。

取值順序:分派工作時點名的模型,其次是 [agents] 裡的預設值,最後是主工作階段的模型;定義檔裡寫了的,優先於全域預設。

Claude Code:實際怎麼寫

只改某一個:在 .claude/agents/ 下建 log-reader.md,檔案開頭兩行 --- 之間寫三行,第一行 name: log-reader,第二行 description: 讀日誌、跑測試,只回報失敗項目,第三行 model: haiku;開頭區塊下面寫給它的指示,例如:只回報失敗的測試和對應的錯誤訊息,不要貼完整輸出。

替所有 subagent 設預設:在 settings.json 的 env 裡加 "CLAUDE_CODE_SUBAGENT_MODEL": "haiku"。要讓所有 subagent 一律用它、沒有例外,再加 "CLAUDE_CODE_SUBAGENT_MODEL_FORCE": "1"(需要 v2.1.257 或更新版本)。

只想讓內建的 Explore 便宜一點:自己建一個同名的 Explore subagent,寫 model: haiku,就會蓋掉內建的。

取值順序:分派工作時指定的模型,其次是定義檔裡的 model,再其次是 CLAUDE_CODE_SUBAGENT_MODEL,最後是主工作階段的模型。

常見誤解

  • subagent 有自己的額度,平行開多少都不影響主工作階段

    沒有。subagent、agent 團隊、雲端平行任務扣的都是同一份 5 小時額度和每週額度,平行只是把它花得更快。

  • 設了 CLAUDE_CODE_SUBAGENT_MODEL,所有 subagent 就都換成小模型了

    不是。它只是預設值:定義檔裡寫了 model 的、Claude 分派工作時點名了模型的,都排在它前面;內建的 Explore 和 Plan 也不受它影響。要全部強制,再加 CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1,然後用 /tasks 確認。

  • 把工作交給 subagent 能省 token

    不一定。subagent 省的是主工作階段的上下文——長輸出留在它那邊,主工作階段只收摘要;但它自己要從頭讀一遍背景,總 token 往往更多。適合交出去的是輸出又長又雜的工作(跑測試、抓文件、看日誌),而且搭配小模型才划算。

小提醒

  • 先挑最常跑的那個 subagent 改。Claude Code 的 /usage 會列出哪個 subagent 占得最多,改它見效最快。
  • 搜尋、讀檔、跑測試、看日誌交給小模型;要做決定的工作(架構、難解的 bug)留給主工作階段的模型。
  • 少開。Claude 的 agent 團隊大約是一般工作階段 7 倍的 token,一次大規模平行可能在 5 小時額度重置之前就把每週額度用光。
  • 分派工作時寫清楚範圍和要回傳什麼,例如「只回報失敗的測試和錯誤訊息」;/usage 面板對常跑的 subagent 給的建議就是換小模型,或把提示寫得更精簡。
  • 用完就關。還沒結束的 teammate 會一直消耗 token。
  • Codex 也可以直接在提示裡點名:「這個 subagent 用 gpt-5.6-terra、medium」;分派工作時指定的優先於全域預設。
  • Claude Code 的 subagent 還能單獨設 effort(low、medium、high 等),和 model 寫在同一個檔案開頭。

Codex 重置公告與紀錄 · Claude 重置公告與紀錄