Claudish Documentation

repository·main·Indexed 21 days ago

https://github.com/madappgang/claudish

A 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.

Tokens
116.8K
Snippets
335
Records
471
Agent score
72%

What's inside Claudish

  1. What is Claudish?

    main
    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.
  2. Manage Context Packaging Levels for Advisors

    main

    When 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.
  3. Performance and Security best practices for Claudish automation

    main

    Performance

    • Model Selection: Use cheaper/faster models like minimax/minimax-m2 for quick tasks and more capable models like Grok or Codex for 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 --model flag.

    Security

    • Never hardcode API keys. Use environment variables or secrets management (GitHub Secrets, GitLab CI/CD variables, or local .env files).
    • Example of secure key loading: export OPENROUTER_API_KEY=$(vault read secret/openrouter)
  4. How Claudish MCP Server Mode works

    main

    Claudish 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:

    1. 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.

    2. 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 calls get_output.

  5. Route models using Claudish prefixes

    main

    Claudish uses prefixes to determine which backend to use for a model request. If no prefix is provided, it defaults to OpenRouter.

    PrefixBackendExample
    (none)OpenRouteropenai/gpt-5.3
    g/ or gemini/Google Geminig/gemini-2.0-flash
    oai/ or openai/OpenAIoai/gpt-4o
    ollama/Ollamaollama/llama3.2
    lmstudio/LM Studiolmstudio/model
    http://...Customhttp://localhost:8000/model
  6. Understand the Advisor Tool Request Structure

    main

    When the Advisor tool is enabled, every subsequent /v1/messages request sent by Claude Code includes a specific tool definition in the tools array. 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:

    1. A server_tool_use block with type=advisor_20260301.
    2. An advisor_tool_result block containing the advice text.
    3. A continuation block where the main executor model processes the advice to produce the final response.
  7. Extend Claude Code capabilities via API Proxy

    main

    You can extend Claude Code's tool capabilities by routing its API traffic through a claudish monitor-mode proxy using the ANTHROPIC_BASE_URL environment 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_result blocks: Rewriting tool results (including error messages) before they reach Claude Code.
    • Injecting custom tools: Adding new tool definitions to the request's tools array 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)
  8. Intercept and replace Claude Code tools via proxy

    main

    You 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

    1. 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.
    2. 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 inbound tool_result, identify the tool_use ID, 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.

  9. Understand the Three-Layer Adapter Architecture

    main

    Claudish 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

    1. 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).
    2. Layer 2: ModelDialect (ModelTranslator) - Handles model parameter translation. It manages model-specific quirks like renamed parameters (e.g., thinking vs reasoning_effort), context window sizes, and vision support.
    3. 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:

    1. Normalize: Incoming OpenAI-format request is normalized to Claude's internal format.
    2. L1 (APIFormat): Messages are reshaped, tools are converted, and the payload is built.
    3. L2 (ModelDialect): Per-model parameter quirks are applied to the payload.
    4. L3 (ProviderTransport): Auth headers and endpoints are added.
    5. Execute: The HTTP request is sent.
    6. 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
  10. Use Provider Routing Syntax

    main

    Claudish 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/* or gemini-* $\rightarrow$ Google Gemini
    • openai/* or gpt-* $\rightarrow$ OpenAI
    • moonshot/* or kimi-* $\rightarrow$ Kimi
    • anthropic/* or claude-* $\rightarrow$ Native Anthropic
    • bare 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.2

    google@gemini-3-pro
    ollama@llama3.2:3
    http://localhost:11434/llama3.2
  11. Configure Model Role Mappings

    main

    Claude 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):

    1. CLI flags: --model-opus, --model-sonnet, --model-haiku, --model-subagent.
    2. Environment variables: CLAUDISH_MODEL_OPUS, CLAUDISH_MODEL_SONNET, CLAUDISH_MODEL_HAIKU, CLAUDISH_MODEL_SUBAGENT.
    3. Anthropic/Claude Code defaults: ANTHROPIC_DEFAULT_OPUS_MODEL, etc.
    4. Profile models fields in .claudish.json or ~/.claudish/config.json.

    Note: The primary model (set via --model or CLAUDISH_MODEL) is distinct from these role mappings and determines the main conversation provider.

  12. Provider slug renames: xai to x-ai and zai to z-ai

    main

    The canonical names for certain providers have been updated to align with the model catalog.

    • xai is now x-ai (shortcuts: xai, grok)
    • zai is now z-ai (shortcut: zai)

    Impact on Credentials: Existing credentials remain functional. The following mappings are unchanged:

    • Environment variables: XAI_API_KEY and ZAI_API_KEY still work.
    • config.json: Keys referencing XAI_API_KEY or ZAI_API_KEY remain valid.

    Users should use the new canonical slugs (x-ai, z-ai) when interacting with the providers --json command or configuring models.