s1d1-router / tutorials /03-claude-code.md
scombat's picture
Integrations: policy, server, LiteLLM, tutorials (untested parts labelled)
7783834 verified
|
Raw History Blame Contribute Delete
2.89 kB

Claude Code

Facts from the Claude Code documentation (2026-10-15):

  • Model: --model, /model, ANTHROPIC_MODEL, model in settings; aliases haiku, sonnet, opus, fable, opusplan (Opus in plan mode, Sonnet to execute); CLAUDE_CODE_SUBAGENT_MODEL; a sub-agent can pin model and effort in its frontmatter.
  • Effort: --effort, /effort, CLAUDE_CODE_EFFORT_LEVEL, effortLevel in settings; levels low, medium, high, xhigh, max (max not accepted in effortLevel); ultrathink in a prompt raises depth for one turn.
  • Gateway: ANTHROPIC_BASE_URL + ANTHROPIC_AUTH_TOKEN. Anthropic does not support routing Claude Code to non-Claude models through a gateway: keep the pool to Claude models.
  • With CLAUDE_CODE_GATEWAY_HINT_HEADERS=1 (v2.1.273+) a custom gateway receives x-claude-code-session-id, x-claude-code-prompt-id (one id per user prompt), x-claude-code-request-class (main, subagent, workflow, compaction, auxiliary).

1. Simplest: choose at launch (documented flags, router untested)

python integrations/serve.py --model scombat/s1d1-router --policy integrations/policy.example.yaml &
python integrations/routed.py claude "refactor the parser and add tests"

routed.py asks the router about your first prompt and starts claude --model <model> --effort <effort> "<prompt>". The session keeps that model; use /model and /effort to change it. Nothing is intercepted.

2. Per request, through a gateway (untested end to end)

export ANTHROPIC_BASE_URL=http://localhost:4000
export ANTHROPIC_AUTH_TOKEN=<litellm key>
export CLAUDE_CODE_GATEWAY_HINT_HEADERS=1
claude --model s1d1-auto

with the LiteLLM hook of 02-litellm.md (A). The hook routes on the last human text of the request (tool results are skipped), remembers one decision per x-claude-code-prompt-id, and leaves auxiliary requests alone. Cautions from the gateway guide:

  • keep forwarding anthropic-beta/anthropic-version and the system array unchanged; do not rewrite bodies except model and the effort field;
  • changing the model between turns can make the API reject old thinking blocks ("bound to a different conversation"); Claude Code then drops earlier thinking and retries, at the price of the cache. This is why the policy is escalate-only per session;
  • a rejected output_config.effort is retried without it by Claude Code.

3. No router at all: the same policy as static settings

{
  "model": "sonnet",
  "effortLevel": "medium",
  "availableModels": ["haiku", "sonnet", "opus", "fable"]
}

plus CLAUDE_CODE_SUBAGENT_MODEL=haiku for exploration sub-agents, a sub-agent frontmatter with model: haiku and effort: low for cheap searches, and opusplan to plan with Opus and execute with Sonnet. The router replaces these fixed choices with a choice per prompt.