Claudish Documentation
repository·main·Indexed 21 days ago
https://github.com/madappgang/claudishA CLI tool and proxy server that allows users to run Claude Code with any AI model, including OpenRouter, Gemini, OpenAI, and local models via Ollama, by providing an Anthropic-compatible API interface. It features capabilities for intercepting and modifying API traffic, replacing server tools, and implementing advisor replacement architectures.
What's inside Claudish
- Claudish is a CLI proxy tool that allows you to run Claude Code using any AI model instead of being restricted to Anthropic's models. It uses prefix-based routing to connect to various backends, including OpenRouter (100+ models), Google Gemini, OpenAI, and local providers like Ollama or LM Studio. It supports 100% of Claude Code features and provides cost tracking and model selection.
Manage Context Packaging Levels for Advisors
mainWhen consulting an advisor, the amount of context sent is critical for performance and cost. There are three defined levels of context packaging:
- Level 1 (default): Summary only. Includes the objective, known facts, constraints, proposed plan, and the specific question.
- Level 2: Summary + artifacts. Includes file snippets, tool outputs, error traces, and diff hunks.
- Level 3: Near-full transcript. Used only when necessary and when the token budget allows.
Performance and Security best practices for Claudish automation
mainPerformance
- Model Selection: Use cheaper/faster models like
minimax/minimax-m2for quick tasks and more capable models likeGrokorCodexfor complex logic. - Parallelization: Run multiple instances simultaneously; each gets its own proxy port.
- Defaults: Set
export CLAUDISH_MODEL='<model_name>'in your environment to avoid repeating the--modelflag.
Security
- Never hardcode API keys. Use environment variables or secrets management (GitHub Secrets, GitLab CI/CD variables, or local
.envfiles). - Example of secure key loading:
export OPENROUTER_API_KEY=$(vault read secret/openrouter)
- Model Selection: Use cheaper/faster models like
How Claudish MCP Server Mode works
mainClaudish can run as an MCP (Model Context Protocol) server, allowing Claude Code to interact with other models via OpenRouter.
There are two primary interaction flows:
Standard Tool Call Flow: Claude Code sends a tool call via MCP (stdio) $\rightarrow$ Claudish MCP server receives it $\rightarrow$ Server calls the target model via the proxy engine $\rightarrow$ Response is returned to Claude Code.
Channel Session Flow (Async/Long-running): Claude Code calls
create_session$\rightarrow$ Claudish spawns a child process $\rightarrow$ A Session Manager monitors the process and fires channel notifications $\rightarrow$ Claude Code receives<channel>tags at each state change $\rightarrow$ On completion, Claude Code callsget_output.
Route models using Claudish prefixes
mainClaudish uses prefixes to determine which backend to use for a model request. If no prefix is provided, it defaults to OpenRouter.
Prefix Backend Example (none) OpenRouter openai/gpt-5.3g/orgemini/Google Gemini g/gemini-2.0-flashoai/oropenai/OpenAI oai/gpt-4oollama/Ollama ollama/llama3.2lmstudio/LM Studio lmstudio/modelhttp://...Custom http://localhost:8000/modelUnderstand the Advisor Tool Request Structure
mainWhen the Advisor tool is enabled, every subsequent
/v1/messagesrequest sent by Claude Code includes a specific tool definition in thetoolsarray. This allows the Anthropic server to run the advisor as a sub-inference at the executor's discretion.Tool Definition Schema:
{ "type": "advisor_20260301", "name": "advisor", "model": "claude-opus-4-6" }Observed Behavior in Response Stream: When the advisor is triggered, the response stream will contain:
- A
server_tool_useblock withtype=advisor_20260301. - An
advisor_tool_resultblock containing the advice text. - A continuation block where the main executor model processes the advice to produce the final response.
- A
Extend Claude Code capabilities via API Proxy
mainYou can extend Claude Code's tool capabilities by routing its API traffic through a
claudishmonitor-mode proxy using theANTHROPIC_BASE_URLenvironment variable. This technique allows you to intercept and modify the communication between the Claude Code client and the Anthropic API.Key capabilities include:
- Replacing server tools: Swapping native server-side tools with regular tools that the executor can still call.
- Intercepting
tool_resultblocks: Rewriting tool results (including error messages) before they reach Claude Code. - Injecting custom tools: Adding new tool definitions to the request's
toolsarray that the client runtime doesn't natively implement. - Modifying system prompts: Guiding tool invocation behavior via prompt injection.
Claude Code ──ANTHROPIC_BASE_URL──▸ Claudish Monitor Proxy │ ┌─────┴──────┐ │ Transform: │ │ 1. Swap tool│ │ type │ │ 2. Strip │ │ beta hdr │ │ 3. Rewrite │ │ tool_ │ │ result │ └─────┬──────┘ │ ▼ Anthropic API (or OpenRouter)Intercept and replace Claude Code tools via proxy
mainYou can extend Claude Code's capabilities by using a transparent proxy. Instead of injecting new MCP tools, a more effective pattern for replacing native features (like the advisor) is to intercept the tool loop via an API proxy.
The Tool Replacement Pattern
- Tool Swap: Patch the proxy to intercept the native tool name (e.g.,
advisor_20260301) and map it to a regular tool. You should also strip the specific beta header (e.g.,advisor-tool-2026-03-01) to prevent client-side conflicts. - Tool Result Rewrite: When the model calls the swapped tool, Claude Code will receive an error (e.g.,
No such tool available). The proxy should intercept this inboundtool_result, identify thetool_useID, and rewrite the error content with your own stubbed advice or data.
This allows the model to receive injected advice as if it came from the native provider, and the model will treat the proxy-injected content identically to native responses.
- Tool Swap: Patch the proxy to intercept the native tool name (e.g.,
Understand the Three-Layer Adapter Architecture
mainClaudish uses a three-layer architecture to compose requests for different AI models and providers. This separation allows the system to handle the same model through different routes (e.g., via a direct API vs. an aggregator like OpenRouter) by mixing and matching layers.
The Three Layers
- Layer 1: APIFormat (
FormatConverter) - Handles wire format translation. It reshapes messages, converts tool schemas, and assembles the final request body (e.g., converting OpenAI Chat Completions to Anthropic Messages format). - Layer 2: ModelDialect (
ModelTranslator) - Handles model parameter translation. It manages model-specific quirks like renamed parameters (e.g.,thinkingvsreasoning_effort), context window sizes, and vision support. - Layer 3: ProviderTransport (
ProviderTransport) - Handles HTTP transport. It manages endpoints, authentication headers, and can override the stream parsing format.
Request Flow
When a request is made, it follows this sequence:
- Normalize: Incoming OpenAI-format request is normalized to Claude's internal format.
- L1 (APIFormat): Messages are reshaped, tools are converted, and the payload is built.
- L2 (ModelDialect): Per-model parameter quirks are applied to the payload.
- L3 (ProviderTransport): Auth headers and endpoints are added.
- Execute: The HTTP request is sent.
- Parse: The response stream is parsed based on a 3-tier priority (Transport override > Model dialect > APIFormat declaration).
ComposedHandler = APIFormat (explicit) + ModelDialect (auto-selected) + ProviderTransport- Layer 1: APIFormat (
Use Provider Routing Syntax
mainClaudish uses a specific syntax to route requests to different AI providers and models.
Preferred Syntax:
provider@model[:concurrency]The
@separator identifies the provider. You can optionally specify concurrency for local providers.Examples:
google@gemini-3-pro: Direct Google Gemini API.openrouter@deepseek/deepseek-r1: Explicit OpenRouter with vendor prefix.ollama@llama3.2:3: Local Ollama with up to 3 concurrent requests.ollama@llama3.2:0: Local Ollama with no concurrency limit (bypass queue).ll@my-model: LiteLLM proxy with auto catalog resolution.
Native Auto-Detection
If you omit the
provider@prefix, Claudish routes based on the model name pattern:google/*orgemini-*$\rightarrow$ Google Geminiopenai/*orgpt-*$\rightarrow$ OpenAImoonshot/*orkimi-*$\rightarrow$ Kimianthropic/*orclaude-*$\rightarrow$ Native Anthropicbare name(no/) $\rightarrow$ Native Anthropic (treated as Claude model)
Custom URL Syntax
You can pass a full URL directly as a model spec to treat it as a local custom endpoint:
http://localhost:11434/llama3.2google@gemini-3-pro ollama@llama3.2:3 http://localhost:11434/llama3.2Configure Model Role Mappings
mainClaude Code uses specific models for different internal roles (
opus,sonnet,haiku,subagent). You can override these mappings to control which models handle specific task types.Resolution Priority (Highest to Lowest):
- CLI flags:
--model-opus,--model-sonnet,--model-haiku,--model-subagent. - Environment variables:
CLAUDISH_MODEL_OPUS,CLAUDISH_MODEL_SONNET,CLAUDISH_MODEL_HAIKU,CLAUDISH_MODEL_SUBAGENT. - Anthropic/Claude Code defaults:
ANTHROPIC_DEFAULT_OPUS_MODEL, etc. - Profile
modelsfields in.claudish.jsonor~/.claudish/config.json.
Note: The primary model (set via
--modelorCLAUDISH_MODEL) is distinct from these role mappings and determines the main conversation provider.- CLI flags:
Provider slug renames: xai to x-ai and zai to z-ai
mainThe canonical names for certain providers have been updated to align with the model catalog.
xaiis nowx-ai(shortcuts:xai,grok)zaiis nowz-ai(shortcut:zai)
Impact on Credentials: Existing credentials remain functional. The following mappings are unchanged:
- Environment variables:
XAI_API_KEYandZAI_API_KEYstill work. config.json: Keys referencingXAI_API_KEYorZAI_API_KEYremain valid.
Users should use the new canonical slugs (
x-ai,z-ai) when interacting with theproviders --jsoncommand or configuring models.