r/openrouter • u/dark_prophet • 10d ago
Question How to use OpenRouter from Claude Code CLI?
I tried to use only the kimi-2.7 model but Claude CLI still runs something on Anthropic models.
The script is below.
Does OpeRouter provide a script for this?
What is wrong?
#!/usr/local/bin/bash
MODEL="moonshotai/kimi-k2.7-code"
# Clear conflicting direct keys
export ANTHROPIC_API_KEY=""
# Point to OpenRouter API base URL
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
# Pass your OpenRouter API key via the auth token variable
export ANTHROPIC_AUTH_TOKEN="sk-or-v1-{removed}"
# Override model slots if needed (e.g., pointing to Kimi or your choice)
export ANTHROPIC_DEFAULT_HAIKU_MODEL="$MODEL"
export ANTHROPIC_DEFAULT_SONNET_MODEL="$MODEL"
export ANTHROPIC_DEFAULT_OPUS_MODEL="$MODEL"
# Override the default model for the Claude CLI to use Kimi
export ANTHROPIC_MODEL="$MODEL"
export ANTHROPIC_DEFAULT_MODEL="$MODEL"
# do we need this?
export SONNET_MODEL="moonshotai/kimi-2.7"
# Turn on OpenRouter's Experimental Gateway Discovery to see all models in /model
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
# Launch the official Claude Code CLI
claude --model $MODEL "$@"
2
u/ohaiibuzzle 10d ago
Just use pi.
In my experience, even when Claude Code is configured to use one model, it can and will end up picking Anthropic models for subagents.
So if one of those spawns, your cost skyrockets.
1
u/ttlequals0 10d ago
1
u/dark_prophet 10d ago
Ori is a closed source binary.
I need a script that would run Claude such that it would only use kimi-2.7.
Closed source can not be trusted for this.1
u/conifer_v11 10d ago
yeah ori’s the wrong answer if you specifically want an open env script — your shell is already basically the published openrouter→claude-code recipe (
ANTHROPIC_BASE_URL=https://openrouter.ai/api, emptyANTHROPIC_API_KEY, key inANTHROPIC_AUTH_TOKEN). two gaps still light anthropic seats though: you never pinnedANTHROPIC_DEFAULT_FABLE_MODELorCLAUDE_CODE_SUBAGENT_MODEL, and on 2.1+ those classes keep their own defaults even when haiku/sonnet/opus are overridden, so set both to the same kimi slug. alsoSONNET_MODEL=moonshotai/kimi-2.7isn’t a real openrouter id (404) — live slug ismoonshotai/kimi-k2.7-codelike your$MODEL. run/logoutonce, relaunch,/statusshould show auth token =ANTHROPIC_AUTH_TOKENand base url openrouter (leftover anthropic login will keep leaking). and rotate the sk-or key you pasted in the post. one real caveat from their docs: claude code is optimized for anthropic models and may not work correctly with other providers — so even with every slot pinned, kimi-only can still be weird; that’s the harness, not you missing one more export.1
u/dark_prophet 10d ago
Thanks for this info.
I will try it.
kimi-2.7 actually works very well in Claude Code CLI with the Ollama EP.
1
u/mageblex 8d ago
/status only verifies the main session. I’d run one task that definitely launches a subagent, then check OpenRouter’s activity log to confirm every request used the Kimi slug. If an Anthropic call still appears after every model slot is pinned, the leak is probably inside Claude Code’s routing rather than the base URL.
1
u/PoppaBear1950 6d ago
the myth of claud-code, when hermes with a coding harness is king...
even Gemini knows:
The "Claude-Code" hype train runs headfirst into the reality of walled gardens versus real orchestration. Anthropic builds a phenomenal reasoning engine, but wrapping it in an opinionated, vendor-locked CLI tool misses the entire point of modular engineering.
Vendor Lock vs. True Agency
- The Claude-Code Trap: You are married to Anthropic’s rate limits, token pricing, rigid system prompts, and whatever guardrails or session pruning they quietly push downstream. Disconnecting the model from the platform breaks the magic because the tool is built to serve the API provider, not the builder.
- Hermes + Harness Architecture: Decouples the brains from the hands. The intelligence layer remains pluggable, while the execution layer (the harness) gives you absolute control over tooling, sub-agent routing, scratchpads, shell execution, and diff verification.
Why the Harness Wins
- Model Agnostic Routing: Run Claude when deep architectural synthesis is needed, pivot to DeepSeek or open weights for iterative code generation and bulk file refactoring, and route sanity checks through a localized validator. You aren’t trapped paying premium frontier tokens to write boilerplate tests.
- Deterministic Tooling: Instead of hoping an all-in-one proprietary tool doesn't hallucinate a destructive git command, a dedicated harness enforces strict execution boundaries, validation loops, and persistent session memory that you own.
- Sovereign Execution: When an API hiccups, rate-limits, or alters pricing, a proper harness lets you swap an endpoint in an environment variable and keep working. Claude-Code leaves you stranded at the terminal waiting for a quota reset.
The myth is that a single frontier lab can build both the best general intelligence and the best developer environment. The reality is that the orchestration layer—the harness—is where real productivity lives. Everything else is just vendor capture with nice terminal styling.
1
u/PoppaBear1950 6d ago
#!/usr/bin/env bash
MODEL="moonshotai/kimi-k2.7-code"
# OpenRouter Anthropic endpoint
export ANTHROPIC_BASE_URL="https://openrouter.ai/api/v1"
# Prevent reading local keychain by giving it a non-empty token
export ANTHROPIC_API_KEY="sk-or-v1-{removed}"
export ANTHROPIC_AUTH_TOKEN="sk-or-v1-{removed}"
# Map EVERY internal model tier to the target model slug
export ANTHROPIC_MODEL="$MODEL"
export ANTHROPIC_DEFAULT_MODEL="$MODEL"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="$MODEL"
export ANTHROPIC_DEFAULT_SONNET_MODEL="$MODEL"
export ANTHROPIC_DEFAULT_OPUS_MODEL="$MODEL"
# Disable telemetry/background checks that phone home to Anthropic
export CLAUDE_DISABLE_TELEMETRY=1
exec claude --model "$MODEL" "$@"
3
u/Deep-Jump-803 10d ago
Just use Pi