Skip to content

# Feature Request: Support for Custom Claude Code Execution Command and Environment Variables #400

@jiang-yuan

Description

@jiang-yuan

Problem Description

I'm using claude-code-router (CCR), a proxy tool that routes Claude Code requests to different AI models and providers. However, opcode currently doesn't support integration with CCR due to the following limitations:

  1. Hardcoded claude command: opcode directly calls the claude binary without allowing customization
  2. Environment variable whitelist: The code (src-tauri/src/commands/claude.rs) only inherits specific environment variables (PATH, HOME, NODE_*, etc.) and filters out critical ones needed by CCR like:
    • ANTHROPIC_BASE_URL
    • CLAUDE_CODE_MAX_OUTPUT_TOKENS
    • MAX_THINKING_TOKENS

Current Workaround Attempts

I tried creating a wrapper script to intercept claude calls, but ran into issues:

  • Direct call + environment variables: Doesn't work because CCR's managed authentication requires going through ccr code command
  • Wrapper calling ccr code: Creates infinite loop (claudeccr codeclaude → ...)

Proposed Solutions

Option 1: Custom Claude Binary Path (Recommended)

Add a setting in opcode UI to specify a custom Claude Code launch command:

UI Example:

Settings → General → Claude Code Command
[ccr code                                    ] (default: claude)

Implementation:

// In src-tauri/src/commands/claude.rs
let claude_command = get_custom_claude_command().unwrap_or("claude".to_string());
let mut cmd = Command::new(claude_command);

Option 2: Custom Environment Variables

Add a setting to specify additional environment variables:

UI Example:

Settings → Advanced → Custom Environment Variables
┌──────────────────────────────────────────────┐
│ ANTHROPIC_BASE_URL=https://my-proxy.com/    │
│ CLAUDE_CODE_MAX_OUTPUT_TOKENS=20000         │
└──────────────────────────────────────────────┘

Implementation:

// In create_command_with_env()
let custom_envs = get_custom_environment_variables();
for (key, value) in custom_envs {
    cmd.env(key, value);
}

Option 3: Whitelist Configuration

Allow users to extend the environment variable whitelist via config file or UI.

Use Cases

This feature would benefit users who:

  • Use CCR to route requests to different AI models (e.g., Gemini, DeepSeek, Ollama)
  • Run Claude Code through custom proxy servers
  • Need to set custom API endpoints for enterprise deployments
  • Want to modify Claude Code behavior via environment variables

Related Code

The relevant code is in src-tauri/src/commands/claude.rs:

fn create_command_with_env() {
    // Current whitelist only includes:
    if key == "PATH" || key == "HOME" || key == "USER" || key == "SHELL"
        || key == "LANG" || key == "LC_ALL" || key.starts_with("LC_")
        || key == "NODE_PATH" || key == "NVM_DIR" || key == "NVM_BIN"
        || key == "HOMEBREW_PREFIX" || key == "HOMEBREW_CELLAR"
    {
        // Only these variables are inherited
    }
}

Additional Context

Expected Behavior

After implementing one of the proposed solutions, users should be able to:

  1. Configure opcode to use ccr code instead of claude
  2. Pass custom environment variables to Claude Code
  3. Successfully integrate opcode with CCR and similar proxy tools

Thank you for considering this feature! opcode is an excellent tool, and this enhancement would make it compatible with the broader Claude Code ecosystem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions