deepclaude

repository·main·Indexed 24 days ago

https://github.com/aattaran/deepclaude

A proxy tool that enables Claude Code's autonomous agent loop to work with Anthropic-compatible backends such as DeepSeek V4 Pro, OpenRouter, and Fireworks AI. It splits traffic between the hardcoded Anthropic Bridge WebSocket for authentication and a local proxy for model API calls. Features include a CLI for backend switching, support for `claude remote-control` mode, and integration options for VS Code and Cursor.

Tokens
1.9K
Snippets
6
Records
8
Agent score
31%

What's inside deepclaude

  1. How the Model Proxy works for Claude Remote Control

    main

    When using claude remote-control, the system requires two different authentication paths: Bridge authentication must go to Anthropic, while model API calls are routed to DeepSeek. This proxy splits the traffic:

    1. Bridge WebSocket: Connects to wss://bridge.claudeusercontent.com (Anthropic, hardcoded).
    2. Model API calls: Routed to http://localhost:3200 (the proxy).
      • /v1/messages requests are forwarded to api.deepseek.com using your DeepSeek API key.
      • All other requests are passed through to api.anthropic.com.
  2. Use Remote Control mode

    main

    You can run a Claude Code session in a web browser (phone, tablet, etc.) using the --remote flag. This uses Anthropic's bridge for WebSockets but routes model calls through the deepclaude proxy.

    Prerequisites:

    • Must be logged into Claude Code: claude auth login.
    • Must have a claude.ai subscription.
    • Node.js 18+ installed.

    Usage:

    deepclaude --remote                # Remote control + DeepSeek
    deepclaude --remote -b or          # Remote control + OpenRouter
    deepclaude --remote -b anthropic   # Remote control + Anthropic

    This will print a URL (e.g., https://claude.ai/code/session_...) to open in your browser.

    deepclaude --remote
  3. Switch backends mid-session (Live switching)

    main

    You can switch between Anthropic and other backends (like DeepSeek) without restarting your session.

    Create custom command files in ~/.claude/commands/ to trigger the proxy's control endpoint via curl.

    Example deepseek.md:

    Switch the model proxy to DeepSeek. Run this command silently and report the result:
    curl -sX POST http://127.0.0.1:3200/_proxy/mode -d "backend=deepseek"
    If successful, say: "Switched to DeepSeek."

    Example anthropic.md:

    Switch the model proxy back to Anthropic. Run this command silently and report the result:
    curl -sX POST http://127.0.0.1:3200/_proxy/mode -d "backend=anthropic"
    If successful, say: "Switched to Anthropic."

    Option 2: CLI Flag

    Start a session with a specific backend:

    deepclaude --switch deepseek
    deepclaude -s anthropic

    Option 3: VS Code Tasks

    Add tasks to .vscode/tasks.json and bind them to keys in keybindings.json using Invoke-RestMethod (Windows) to hit http://127.0.0.1:3200/_proxy/mode.

    curl -sX POST http://127.0.0.1:3200/_proxy/mode -d "backend=deepseek"
  4. Use the Model Proxy to route Claude calls to DeepSeek

    main

    You can programmatically start the model proxy using startModelProxy. This allows you to intercept model API calls and redirect them to a DeepSeek endpoint while maintaining the necessary Anthropic bridge connection.

    To use the proxy with claude remote-control, you must set the following environment variables:

    • ANTHROPIC_BASE_URL: Set this to http://127.0.0.1:${proxy.port}
    • ANTHROPIC_DEFAULT_OPUS_MODEL: Set this to your desired DeepSeek model (e.g., deepseek-v4-pro)

    Important: Do NOT set ANTHROPIC_AUTH_TOKEN. The bridge authentication is handled via OAuth, and setting this variable to a DeepSeek key will break the bridge connection.

    import { startModelProxy } from './model-proxy.js';
    
    const proxy = await startModelProxy({
        targetUrl: 'https://api.deepseek.com/anthropic',
        apiKey: process.env.DEEPSEEK_API_KEY,
    });
    
    console.log(`Proxy on port ${proxy.port}`);
    
    // Set env vars for claude remote-control:
    // ANTHROPIC_BASE_URL=http://127.0.0.1:${proxy.port}
    // ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-v4-pro
    // (do NOT set ANTHROPIC_AUTH_TOKEN — OAuth handles bridge auth)
    
    // When done:
    proxy.close();
  5. Integrate deepclaude with VS Code / Cursor

    main

    To launch deepclaude directly from your IDE terminal, add a custom terminal profile.

    Windows (Settings > JSON):

    {
      "terminal.integrated.profiles.windows": {
        "DeepSeek Agent": {
          "path": "powershell.exe",
          "args": ["-ExecutionPolicy", "Bypass", "-NoExit", "-File", "C:\\path\\to\\deepclaude.ps1"]
        }
      }
    }

    macOS/Linux (Settings > JSON):

    {
      "terminal.integrated.profiles.linux": {
        "DeepSeek Agent": {
          "path": "/usr/local/bin/deepclaude"
        }
      }
    }
    {
      "terminal.integrated.profiles.windows": {
        "DeepSeek Agent": {
          "path": "powershell.exe",
          "args": ["-ExecutionPolicy", "Bypass", "-NoExit", "-File", "C:\\path\\to\\deepclaude.ps1"]
        }
      }
    }
  6. Quick start with deepclaude

    main

    To use deepclaude to run Claude Code with cheaper backends like DeepSeek, follow these steps:

    1. Get a DeepSeek API key: Sign up at platform.deepseek.com and copy your key.
    2. Set environment variables:
      • Windows (PowerShell): setx DEEPSEEK_API_KEY "sk-your-key-here"
      • macOS/Linux: echo 'export DEEPSEEK_API_KEY="sk-your-key-here"' >> ~/.bashrc && source ~/.bashrc
    3. Install:
      • Windows: Copy the script to your PATH:
        Copy-Item deepclaude.ps1 "$env:USERPROFILE\.local\bin\deepclaude.ps1"
        Or add the repo directory to PATH:
        setx PATH "$env:PATH;C:\path\to\deepclaude"
      • macOS/Linux: Make executable and symlink to /usr/local/bin:
        chmod +x deepclaude.sh
        sudo ln -s "$(pwd)/deepclaude.sh" /usr/local/bin/deepclaude
    4. Use it: Run deepclaude to launch with the default DeepSeek backend.
    deepclaude
  7. Configure backends and environment variables

    main

    The deepclaude proxy intercepts API calls by setting specific Anthropic environment variables. You can configure different backends by setting their respective API keys:

    Supported Backends

    BackendFlagNotes
    DeepSeek--backend dsDefault. Supports auto context caching.
    OpenRouter--backend orCheapest, lowest latency from US/EU.
    Fireworks AI--backend fwFastest inference.
    Anthropic--backend anthropicOriginal Claude Opus.

    Required Environment Variables

    VariableDescription
    DEEPSEEK_API_KEYKey for DeepSeek backend.
    OPENROUTER_API_KEYKey for OpenRouter backend.
    FIREWORKS_API_KEYKey for Fireworks AI backend.

    Proxy-controlled Variables

    deepclaude manages these per-session to redirect Claude Code:

    • ANTHROPIC_BASE_URL: The API endpoint.
    • ANTHROPIC_AUTH_TOKEN: The API key for the chosen backend.
    • ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL: Model names for different tiers.
    • CLAUDE_CODE_SUBAGENT_MODEL: Model for spawned subagents.
  8. Use deepclaude CLI commands

    main

    The deepclaude CLI provides several flags to control the backend and view status:

    • deepclaude: Launch Claude Code with DeepSeek V4 Pro (default).
    • deepclaude --status: Show available backends and keys.
    • deepclaude --backend <name>: Specify a backend. Supported values: or (OpenRouter), fw (Fireworks AI), anthropic (Original Claude).
    • deepclaude --cost: Show pricing comparison.
    • deepclaude --benchmark: Run a latency test across all providers.
    • deepclaude --switch <name>: Switch backend mid-session (e.g., deepclaude --switch ds).
    deepclaude --backend or
    deepclaude --backend fw
    deepclaude --backend anthropic
    deepclaude --cost
    deepclaude --benchmark
    deepclaude --switch ds