OpenClaude

repository·main·Indexed 12 days ago

https://github.com/gitlawb/openclaude

An open-source, terminal-first coding agent CLI and VS Code extension that opens coding-agent workflows to any LLM, including OpenAI, Gemini, DeepSeek, Ollama, and 200+ other models. It provides a unified workflow for prompts, tools, agents, and Model Context Protocol (MCP) across cloud and local backends. Version 0.28.0.

Tokens
67.1K
Snippets
203
Records
288
Agent score
98%

What's inside OpenClaude

  1. What is Smart auto-routing?

    main

    Smart routing is an experimental, opt-in feature that classifies user turns as either simple or strong. It automatically routes trivial turns (e.g., "ok", "rename this") to a cheaper model and non-trivial turns to a stronger model to optimize costs.

    Key characteristics:

    • Heuristic-based: It uses a fast heuristic (prompt length, code blocks, reasoning keywords, etc.) to classify turns. It is designed to fail safely: if it is unsure, it routes to the strong model.
    • Provider-agnostic: It works by swapping models within your current provider. It does not support cross-provider routing (e.g., routing a simple turn to OpenAI and a strong turn to Anthropic).
    • One decision per turn: The model is selected at the start of the turn and remains the same for the entire turn, including tool calls.
    • Fallback mechanism: If a simple-routed model call fails due to a transport or server error, OpenClaude retries the turn once using the strong model.
  2. Choose an AI Provider for OpenClaude

    main

    OpenClaude supports multiple model providers. You can configure them using the /provider command inside the CLI.

    • OpenAI: Recommended for the easiest cloud setup if you have an OpenAI API key.
    • Ollama: Best for running models locally without depending on a cloud API. Requires Ollama to be installed and running.
    • Codex: Use this if you already use the Codex CLI or have Codex/ChatGPT authentication configured.
    • Other supported providers: DeepSeek, Gemini.
  3. Understand the OpenClaude Control Center

    main

    The Control Center is a status dashboard located in the VS Code Activity Bar. It provides real-time visibility into the OpenClaude environment, including:

    • Command Status: Whether the configured openclaude command is installed and which launch command is being used.
    • Shim Status: Whether the launch shim is injecting CLAUDE_CODE_USE_OPENAI=1.
    • Workspace Context: The current workspace folder and the launch cwd (current working directory) that will be used for terminal sessions.
    • Profile Detection: Whether a .openclaude-profile.json exists in the workspace root.
    • Provider Summary: A summary of the active provider, derived from the workspace profile or environment flags.

    Status Detection Logic:

    • The extension prioritizes the workspace .openclaude-profile.json file.
    • If no profile is found, it falls back to environment flags available to the VS Code extension host.
    • If the configuration is ambiguous, the status is displayed as unknown.
  4. Understand the Integration System Architecture

    main

    The OpenClaude integration system is divided into three distinct layers to maintain separation of concerns:

    1. Metadata (Descriptors): Files that declare labels, defaults, catalogs, setup requirements, validation hints, and request-shaping metadata. This is where you define what a route is.
    2. Routing: Helpers that map user configuration, presets, and environment state onto the active descriptor route.
    3. Transport: Runtime execution code that performs the actual request using a specific transport family. This is where you define how a request is executed against an external API.

    When making changes, determine if the change affects the route definition (Metadata) or the execution logic (Transport).

  5. Configure Context Windows for LiteLLM Models

    main

    OpenClaude attempts to discover model context limits via LiteLLM's /v1/models endpoint. If your LiteLLM alias does not automatically expose the correct context length, you can configure it in two ways:

    Add model_info to your litellm_config.yaml for the specific model alias. This allows LiteLLM to expose the metadata to OpenClaude.

    model_list:
      - model_name: long-context-model
        litellm_params:
          model: openai/gpt-4.1
          api_key: os.environ/OPENAI_API_KEY
        model_info:
          context_length: 1000000
          max_input_tokens: 1000000

    Method 2: OpenClaude Environment Override

    If you cannot modify the LiteLLM config, you can force an override in OpenClaude using the CLAUDE_CODE_OPENAI_CONTEXT_WINDOWS environment variable with a JSON mapping of model aliases to context sizes.

    export CLAUDE_CODE_OPENAI_CONTEXT_WINDOWS='{"long-context-model":1000000}'
  6. Select the correct descriptor type for integrations

    main

    When modeling a new route, choose the descriptor type based on the nature of the endpoint to ensure correct routing and behavior:

    • VendorDescriptor: Use when the route is the canonical direct vendor API.
    • GatewayDescriptor: Use when the route hosts, proxies, or aggregates models behind its own endpoint contract.
    • AnthropicProxyDescriptor: Use when the route accepts Anthropic-native traffic through its own Anthropic-style environment contract.
    • ModelDescriptor: Use for shared model metadata (what a model is), not for defining route availability (where a model is offered).
    // Use define* helpers from src/integrations/define.ts
    // and default-export the descriptor.
    
    // Example conceptual usage:
    export default defineVendorDescriptor({
      // ... descriptor config
    });
  7. Use `transportConfig.kind` for Routing

    main

    For gateways and custom routes, the transportConfig.kind field is the authoritative routing contract used by the runtime to select the correct transport family.

    Do not use the category field for routing decisions. The category field is purely descriptive metadata used for grouping or display (e.g., local, hosted, aggregating).

    Common values for transportConfig.kind include:

    • 'openai-compatible'
    • 'local'
    • 'anthropic-proxy'
    • 'bedrock'
    • 'vertex'
  8. Describe reasoning capabilities in model descriptors

    main

    To indicate that a model is capable of reasoning or 'thinking', use the following metadata:

    • classification: ['reasoning']
    • capabilities.supportsReasoning: true

    Warning: Adding these fields does not automatically enable /effort request mutation. You must verify the model's exact control surface (accepted/rejected levels and thinking-disable formats) for the specific route before adding this metadata.

  9. Understand model lookup and fallback precedence

    main

    When looking up model information, the system follows this precedence order:

    1. Route-owned catalog metadata: The primary source for what a specific route offers.
    2. Shared model-descriptor enrichment: Metadata pulled from a shared descriptor when a catalog entry references a modelDescriptorId.
    3. Global shared model descriptors: Found in src/integrations/models/ (used for legacy or custom OpenAI-compatible names).
    4. User overrides:
      • Environment variables: CLAUDE_CODE_OPENAI_CONTEXT_WINDOWS and CLAUDE_CODE_OPENAI_MAX_OUTPUT_TOKENS.
      • settings.json: The modelLimits map.
  10. Configure discovery cache TTL and refresh modes

    main

    Control how frequently discovered models are refreshed using discoveryCacheTtl and discoveryRefreshMode.

    Discovery Cache TTL (discoveryCacheTtl)

    Use human-readable strings:

    • 30m: For fast-changing catalogs.
    • 1h: For moderately active hosted routes.
    • 1d: For stable hosted or local routes with low churn.

    Discovery Refresh Mode (discoveryRefreshMode)

    • manual: For flaky or rate-limited providers; refresh only on demand.
    • on-open: The picker always attempts a fresh list when opened.
    • background-if-stale: The standard choice for hosted gateways; cached models appear immediately while refreshing in the background.
    • startup: For fast local routes where probing at startup is cheap and useful.
  11. Configure reasoning control metadata for models

    main

    OpenClaude manages reasoning (thinking) capabilities on a per-model basis. To enable control over reasoning effort via the /effort command, you must provide a reasoning object in the model's metadata.

    Key Concepts:

    • capabilities.supportsReasoning: A boolean flag indicating the model is capable of reasoning. This does not automatically enable request mutation (like changing effort levels).
    • reasoning: The control surface that defines how OpenClaude interacts with the model's reasoning parameters.

    Metadata Schema:

    reasoning: {
      mode: 'levels' | 'toggle' | 'always-on'
      levels?: ReasoningEffortLevel[] // e.g., ['high', 'xhigh']
      defaultLevel?: 'low' | 'medium' | 'high' | 'xhigh' | 'max'
      wireFormat?: 'reasoning_effort' | 'deepseek_compatible' | 'zai_compatible' | 'none'
      disableFormat?: 'thinking_type_disabled'
    }
    reasoning: {
      mode: 'levels' | 'toggle' | 'always-on'
      levels?: ReasoningEffortLevel[]
      defaultLevel?: 'low' | 'medium' | 'high' | 'xhigh' | 'max'
      wireFormat?: 'reasoning_effort' | 'deepseek_compatible' | 'zai_compatible' | 'none'
      disableFormat?: 'thinking_type_disabled'
    }
  12. Identify the transport mechanism using `transportConfig.kind`

    main

    The transportConfig.kind field on a route descriptor is the authoritative selector for the transport family. If you need to determine how a route executes requests or if the underlying protocol differs, inspect transportConfig.kind.

    Common transport examples include:

    • Anthropic-native
    • Anthropic-proxy
    • OpenAI-compatible
    • local
    • Gemini-native
    • Bedrock
    • Vertex

    Note that an Anthropic Proxy is a specific descriptor type for third-party endpoints that accept Anthropic-native requests through a non-Anthropic endpoint/auth contract, and is distinct from an OpenAI-compatible gateway.