Skip to content

Instantly share code, notes, and snippets.

@yanhua1010
Last active October 9, 2026 14:36
Show Gist options
  • Select an option

  • Save yanhua1010/de94760c972b7cb61f2c0fb9c7f50ba2 to your computer and use it in GitHub Desktop.

Select an option

Save yanhua1010/de94760c972b7cb61f2c0fb9c7f50ba2 to your computer and use it in GitHub Desktop.
Claude Code 工作流/子代理的模型智能分配(2026-10 版:fable/opus/sonnet/haiku + Codex/DeepSeek/Grok)

Claude Code 多模型工作流:Claude × Codex × DeepSeek × Grok

一个 Claude Code 会话里同时用 7 个模型:fable / opus / sonnet / haiku 原生调用,Codex、DeepSeek、Grok 通过本机 CLI 包装成子代理。没有代理层,没有舰队工具,就是一个 CLAUDE.md、三个 agent 文件、三个 shell 脚本。

规则与评分表见 model-allocation-for-workflows.md。

安装

gh gist clone de94760c972b7cb61f2c0fb9c7f50ba2 cc-multimodel && cd cc-multimodel
bash install.sh

或者更懒的办法:把这个 gist 链接丢给 Claude Code,说「按这个 gist 把多模型路由配到我机器上」。

前置条件

组件 用途 安装
Claude Code 主会话 + Claude 四档子代理 已有
Codex CLI cx → codex exec;也是 ds 的运行壳 npm i -g @openai/codex 然后 codex login(ChatGPT 订阅)
DeepSeek API key ds → Codex CLI 当壳 + DeepSeek API 在 shell rc 里 export DEEPSEEK_API_KEY=...(或写到 ~/.config/deepseek/api_key),不需要额外装任何东西
Grok CLI grk → grok -p 安装 grok CLI 后 grok login(Grok 订阅)

只装其中一部分也行:没装的那条路线对应的 worker 会报「未安装 / 未登录」,其余照常。

文件

文件 落点 作用
cx ds grk ~/.local/bin/ 非交互 CLI 包装;终端里也能直接用
codex-worker.md deepseek-worker.md grok-worker.md ~/.claude/agents/ haiku 薄调度层子代理
CLAUDE-routing.md 追加到 ~/.claude/CLAUDE.md 路由规则,全局加载
model-allocation-for-workflows.md 阅读 评分表、规则和设计理由

用法

装完新开一个 Claude Code 会话(agent 在启动时加载),然后正常说话即可,主会话会按规则派发。想手动点名:「用 codex 实现…」「让 deepseek 先扫一遍…」「grok 查一下…」。

Codex 默认模型在 ~/.codex/config.toml 里设 model = "gpt-6-sol";按自己的额度改。

Model routing (multi-model inside Claude Code)

Main session runs on a Claude model. Delegate with the Agent tool and pick by this table (higher is better; cost = how cheap it actually is for this user, not list price).

route how cost intelligence taste use for
fable Agent model: fable 2 10 9 hardest reasoning, architecture, final review
opus Agent model: opus 4 8 8 user-facing output: UI, copy, API design (taste ≥ 7)
sonnet Agent model: sonnet 6 6 7 errands, browser/computer use, medium tasks
haiku Agent model: haiku 9 4 4 rote renames, formatting, file gathering
codex (gpt-6-sol) Agent subagent_type: codex-worker 6 8 6 spec-clear implementation, migrations, log/data analysis
deepseek-v4-pro Agent subagent_type: deepseek-worker 10 7 5 huge-context reads, bulk grep-style investigation, batch mechanical work
grok-4.7 Agent subagent_type: grok-worker 7 7 5 fresh web / X context, trends, current events

Rules:

  • Priority for anything delivered: intelligence > taste > cost. Cost only breaks ties.
  • These are defaults, not ceilings. If a cheap route's output is below par, rerun on a stronger one without asking.
  • Codex defaults to gpt-6-sol; use gpt-6-luna for trivial work and gpt-6-astra only when the user explicitly asks.
  • High-token, low-difficulty work (codebase exploration, bulk file reads, grep investigations) never goes to fable/opus: use deepseek-worker or codex-worker read-only, or a sonnet agent.
  • Plan/implementation review: fable or opus, optionally plus codex-worker as an independent second opinion.
  • Non-Claude models are reached only through the CLIs cx (codex exec), ds (codex exec → DeepSeek API), grk (grok -p); the dispatcher agents above wrap them. Every prompt sent to them must be self-contained: they cannot see this conversation.
name codex-worker
description Run a task on OpenAI Codex (GPT-6 family via ChatGPT Plus). Use for spec-clear implementation, migrations, log/data analysis, and bulk read-only codebase investigation that would waste Claude tokens. Default model gpt-6-sol; pass "model gpt-6-luna" for trivial work, "model gpt-6-astra" only when explicitly asked.
tools Bash, Read, Glob, Grep
model haiku

You are a thin dispatcher. Your only job is to run the task on Codex via the cx CLI and return its output.

Steps:

  1. Turn the task you were given into one self-contained prompt. Include every path, requirement, and acceptance criterion; Codex has no access to this conversation.
  2. Choose flags:
    • read-only investigation or analysis: cx "<prompt>"
    • the task must edit files: cx -w "<prompt>"
    • model override only if the task names one: -m gpt-6-luna / -m gpt-6.1-sol / -m gpt-6-astra
    • effort override only if asked: -e low|medium|high|xhigh
    • work in a specific directory: -C <dir>
  3. Run it with Bash (timeout 600000). Use a heredoc or single quotes so the prompt is passed intact.
  4. Return Codex's final answer verbatim, then one short line noting the model and whether files were changed. Do not redo or "improve" the work yourself.
#!/usr/bin/env bash
# cx — run OpenAI Codex non-interactively (ChatGPT Plus quota, default gpt-6-sol).
# Usage: cx [-w] [-m MODEL] [-e low|medium|high|xhigh] [-C DIR] "prompt"
# -w allow writes in the workspace (default: read-only sandbox)
set -euo pipefail
SANDBOX=read-only; MODEL=""; EFFORT=""; DIR="$PWD"
while getopts "wm:e:C:" o; do case "$o" in
w) SANDBOX=workspace-write;; m) MODEL="$OPTARG";; e) EFFORT="$OPTARG";; C) DIR="$OPTARG";;
*) echo "usage: cx [-w] [-m MODEL] [-e EFFORT] [-C DIR] prompt" >&2; exit 2;; esac; done
shift $((OPTIND-1))
[ $# -ge 1 ] || { echo "cx: prompt required" >&2; exit 2; }
OUT="$(mktemp -t cx-last)"; trap 'rm -f "$OUT"' EXIT
args=(exec -s "$SANDBOX" --skip-git-repo-check --ephemeral -C "$DIR" -o "$OUT" --color never)
[ -n "$MODEL" ] && args+=(-m "$MODEL")
[ -n "$EFFORT" ] && args+=(-c "model_reasoning_effort=\"$EFFORT\"")
# codex exec streams its transcript/banner to stderr; keep only error lines there
codex "${args[@]}" "$*" </dev/null >/dev/null 2> >(grep -E -i '^(ERROR|error:|\{"type":"error")' >&2 || true) || { echo "cx: codex exited non-zero" >&2; cat "$OUT" 2>/dev/null; exit 1; }
cat "$OUT"; [ -s "$OUT" ] && [ "$(tail -c1 "$OUT" | od -An -c | tr -d ' ')" != '\n' ] && echo
exit 0
name deepseek-worker
description Run a task on DeepSeek (deepseek-v4-pro, 1M context, pay-per-token cheapest) through the `ds` CLI, which drives DeepSeek's API with the Codex CLI harness (full read/shell/edit tools). Use for very large context reads, bulk grep-style investigation, summarising many files, or batch mechanical work where cost matters more than taste. Pass "flash" for the cheaper deepseek-flash.
tools Bash, Read, Glob, Grep
model haiku

You are a thin dispatcher. Run the task on DeepSeek via ds and return its output.

Steps:

  1. Write one self-contained prompt with all paths and requirements; DeepSeek cannot see this conversation.
  2. Flags:
    • read-only investigation (default): ds "<prompt>"
    • the task must edit files: ds -w "<prompt>"
    • cheaper model: add -f (deepseek-flash)
    • reasoning effort if asked: -t high|xhigh|max
    • directory: -C <dir>
  3. Run with Bash (timeout 600000), passing the prompt intact via heredoc or single quotes.
  4. If it says DEEPSEEK_API_KEY is not set, stop and report exactly that. Otherwise return DeepSeek's final answer verbatim plus one line stating the model used and whether files changed.
#!/usr/bin/env bash
# ds — run DeepSeek non-interactively through the Codex CLI harness (DeepSeek's API speaks the
# OpenAI Responses protocol, so Codex drives it with full read/shell/edit tools). No proxy, no pi.
# Needs: codex CLI + DEEPSEEK_API_KEY in the environment (or in ~/.config/deepseek/api_key).
# Usage: ds [-w] [-f] [-t high|xhigh|max] [-C DIR] "prompt"
# -w allow writes in the workspace (default: read-only sandbox)
# -f use deepseek-flash instead of deepseek-v4-pro
set -euo pipefail
SANDBOX=read-only; MODEL=deepseek-v4-pro; EFFORT=high; DIR="$PWD"
while getopts "wft:C:r" o; do case "$o" in
w) SANDBOX=workspace-write;; f) MODEL=deepseek-flash;; t) EFFORT="$OPTARG";; C) DIR="$OPTARG";;
r) SANDBOX=read-only;; # kept for backward compatibility: read-only is already the default
*) echo "usage: ds [-w] [-f] [-t EFFORT] [-C DIR] prompt" >&2; exit 2;; esac; done
shift $((OPTIND-1))
[ $# -ge 1 ] || { echo "ds: prompt required" >&2; exit 2; }
if [ -z "${DEEPSEEK_API_KEY:-}" ] && [ -r "$HOME/.config/deepseek/api_key" ]; then
DEEPSEEK_API_KEY="$(tr -d '[:space:]' < "$HOME/.config/deepseek/api_key")"; export DEEPSEEK_API_KEY
fi
[ -n "${DEEPSEEK_API_KEY:-}" ] || { echo "ds: DEEPSEEK_API_KEY not set (export it, or put it in ~/.config/deepseek/api_key)" >&2; exit 3; }
OUT="$(mktemp -t ds-last)"; trap 'rm -f "$OUT"' EXIT
args=(exec -s "$SANDBOX" --skip-git-repo-check --ephemeral -C "$DIR" -o "$OUT" --color never
-c 'model_providers.deepseek.name="DeepSeek"'
-c 'model_providers.deepseek.base_url="https://api.deepseek.com"'
-c 'model_providers.deepseek.env_key="DEEPSEEK_API_KEY"'
-c 'model_providers.deepseek.wire_api="responses"'
-c 'model_provider="deepseek"'
-c "model_reasoning_effort=\"$EFFORT\""
-m "$MODEL")
# codex streams its transcript/banner to stderr; keep only error lines there
codex "${args[@]}" "$*" </dev/null >/dev/null 2> >(grep -E -i '^(ERROR|error:|\{"type":"error")' >&2 || true) || { echo "ds: codex exited non-zero" >&2; cat "$OUT" 2>/dev/null; exit 1; }
cat "$OUT"; [ -s "$OUT" ] && [ "$(tail -c1 "$OUT" | od -An -c | tr -d ' ')" != '\n' ] && echo
exit 0
#!/usr/bin/env bash
# grk — run Grok via the grok CLI in single-turn headless mode (needs `grok login` once).
# Usage: grk [-m MODEL] [-e low|medium|high] [-C DIR] "prompt"
set -euo pipefail
MODEL=grok-4.7; EFFORT=high; DIR="$PWD"
while getopts "m:e:C:" o; do case "$o" in
m) MODEL="$OPTARG";; e) EFFORT="$OPTARG";; C) DIR="$OPTARG";;
*) echo "usage: grk [-m MODEL] [-e EFFORT] [-C DIR] prompt" >&2; exit 2;; esac; done
shift $((OPTIND-1))
[ $# -ge 1 ] || { echo "grk: prompt required" >&2; exit 2; }
cd "$DIR" && exec grok -p "$*" --output-format plain --model "$MODEL" --reasoning-effort "$EFFORT" --always-approve
name grok-worker
description Run a task on Grok (xAI, grok-4.7) through the `grk` CLI. Use when the task needs fresh web or X/Twitter context, current events, trending topics, or a live-market check. Requires `grok login` to have been done once in a terminal.
tools Bash, Read, Glob, Grep
model haiku

You are a thin dispatcher. Run the task on Grok via grk and return its output.

Steps:

  1. Write one self-contained prompt; Grok cannot see this conversation.
  2. Flags: -m <model> only if a model is named, -e low|medium|high if asked, -C <dir> for a working directory.
  3. Run grk "<prompt>" with Bash (timeout 600000).
  4. If the output says not authenticated, stop and report exactly that: the user must run grok login in a terminal. Otherwise return Grok's answer verbatim with one line naming the model.
#!/usr/bin/env bash
# One-shot installer for the Claude Code multi-model routing setup.
# Installs: ~/.local/bin/{cx,ds,grk}, ~/.claude/agents/{codex,deepseek,grok}-worker.md,
# and appends the routing rules to ~/.claude/CLAUDE.md (once).
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BIN="$HOME/.local/bin"; AGENTS="$HOME/.claude/agents"; CLAUDEMD="$HOME/.claude/CLAUDE.md"
mkdir -p "$BIN" "$AGENTS" "$(dirname "$CLAUDEMD")"
for f in cx ds grk; do install -m 755 "$HERE/$f" "$BIN/$f"; echo "installed $BIN/$f"; done
for f in codex-worker.md deepseek-worker.md grok-worker.md; do install -m 644 "$HERE/$f" "$AGENTS/$f"; echo "installed $AGENTS/$f"; done
if ! grep -q "^# Model routing (multi-model inside Claude Code)" "$CLAUDEMD" 2>/dev/null; then
cat "$HERE/CLAUDE-routing.md" >> "$CLAUDEMD"; echo "appended routing rules to $CLAUDEMD"
else
echo "routing rules already present in $CLAUDEMD, skipped"
fi
case ":$PATH:" in *":$BIN:"*) ;; *) echo "NOTE: add $BIN to your PATH";; esac
echo
echo "Prerequisites check:"
for c in claude codex grok; do
if command -v "$c" >/dev/null 2>&1; then echo " ok $c"; else echo " MISSING $c"; fi
done
[ -n "${DEEPSEEK_API_KEY:-}" ] && echo " ok DEEPSEEK_API_KEY" || echo " MISSING DEEPSEEK_API_KEY (export it in your shell rc, or write it to ~/.config/deepseek/api_key)"
echo
echo "Done. Start a NEW Claude Code session so the agents load, then try:"
echo ' "用 deepseek 只读模式统计这个仓库每个目录的主要语言"'

工作流与子代理的模型智能分配(2026-10 版)

模型能力画像

排名数字越高越好。Cost 反映实际支付成本而非标价(Claude 走 Max 订阅、Codex 走 ChatGPT Plus 订阅且主要留给生图、DeepSeek 按 token 付费、Grok 走订阅);Intelligence 指可以无监督托付的问题难度;Taste 涵盖 UI/UX、代码质量、API 设计和文案。

model 调用方式 cost intelligence taste
fable-5.1 Agent model: fable 2 10 9
opus-5.5 Agent model: opus 4 8 8
sonnet-5.5 Agent model: sonnet 6 6 7
haiku-5.5 Agent model: haiku 9 4 4
gpt-6-sol (Codex) Agent subagent_type: codex-worker 6 8 6
deepseek-v4-pro Agent subagent_type: deepseek-worker 10 7 5
grok-4.7 Agent subagent_type: grok-worker 7 7 5

一句话概括:fable 是留给硬仗的大脑,opus 是有审美的熟手,sonnet 是跑腿的,haiku 做机械活,Codex 是规格明确时的实现工,DeepSeek 是海量上下文的廉价苦力,Grok 负责看外面世界发生了什么。

分配规则

  • 这些是默认值,不是上限。 有常设授权可以直接升级:便宜模型的产出不达标,无需询问即可用更强的模型重跑。看产出质量,不看价格标签。
  • 对任何要交付的产出,优先级为 intelligence > taste > cost。 Cost 只作平局裁决。
  • 规格明确的实现、迁移、数据分析、日志排查:codex-worker(gpt-6-sol)。琐碎到不需要思考的用 gpt-6-luna;gpt-6-astra 只在明确要求时用,Plus 额度要留给生图。
  • 高 token 消耗但低难度的任务(代码库探索、批量读文件、grep 式调查、多文件总结):不要用 fable/opus。首选 deepseek-worker 只读模式(1M 上下文、最便宜),其次 codex-worker 只读模式,再次 sonnet 子代理。
  • 需要实时信息的任务(新闻、X 上的动态、趋势、行情):grok-worker。
  • 计算机使用 / 浏览器自动化:sonnet。
  • 面向用户的产出(UI、文案、API 设计)需要 taste ≥ 7:opus 或 fable。
  • 计划 / 实现的审查:fable 或 opus,可选加 codex-worker 作为独立的第三方视角。
  • 最难的推理 / 架构决策:fable。
  • 机械编辑(重命名、格式化、改错字、收集文件):haiku 低 effort。

调用机制

  • Claude 四个模型通过 Agent / Workflow 的 model 参数指定,不需要任何包装。
  • 非 Claude 模型没有代理层,全部通过本机 CLI 包装成子代理,每个子代理是一个 haiku 薄调度层,负责把任务写成自包含 prompt、跑 CLI、原样返回结果:
    • cx → codex exec(默认只读沙箱,-w 允许写,-m 换模型,-e 换 effort)
    • ds → codex exec 挂 DeepSeek provider(DeepSeek API 原生支持 Responses 协议,Codex 当壳带完整工具;默认 v4-pro 只读,-f 换 flash,-w 可写;只需 DEEPSEEK_API_KEY)
    • grk → grok -p(默认 grok-4.7,需要先 grok login)
  • 三个 CLI 在终端里也可以直接用,不经过 Claude Code。
  • 子代理拿到的是自包含 prompt:外部模型看不到主会话的任何上下文,派发时必须把路径、要求、验收标准都写进去。

相对上一版的变更

  • 模型阵容从 gpt-5.5 / sonnet-5 / opus-4.8 / fable-5 升级为 fable-5.1 / opus-5.5 / sonnet-5.5 / haiku-5.5 / gpt-6-sol / deepseek-v4-pro / grok-4.7。
  • 「gpt-5.5 是免费劳动力」不再成立:ChatGPT 是 Plus 订阅且主要用于生图,Codex 的 cost 从 9 降到 6,默认模型降到 gpt-6-sol,astra 仅按需。
  • 新增 DeepSeek 承接原来 gpt-5.5 的「海量只读调查」角色,cost 10。
  • 新增 Grok 承接实时信息类任务。
  • 「不使用 Haiku」撤销:有了四档 Claude 模型后,haiku 低 effort 比起起一个 Codex 进程更适合纯机械编辑。
  • 「用 sonnet 包装代理跑 codex exec」的变通退役,改为专用 codex-worker 子代理。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment