Skip to content

ccproxy.cli.helpers

ccproxy.cli.helpers

CLI helper utilities for CCProxy API.

merge_claude_code_options

merge_claude_code_options(base_options, **overrides)

Create a new ClaudeCodeOptions instance by merging base options with overrides.

Parameters:

Name Type Description Default
base_options Any

Base ClaudeCodeOptions instance to copy from

required
**overrides Any

Dictionary of option overrides

{}

Returns:

Type Description
Any

New ClaudeCodeOptions instance with merged options

Source code in ccproxy/cli/helpers.py
def merge_claude_code_options(base_options: Any, **overrides: Any) -> Any:
    """
    Create a new ClaudeCodeOptions instance by merging base options with overrides.

    Args:
        base_options: Base ClaudeCodeOptions instance to copy from
        **overrides: Dictionary of option overrides

    Returns:
        New ClaudeCodeOptions instance with merged options
    """
    with patched_typing():
        from claude_code_sdk import ClaudeCodeOptions

    # Create a new options instance with the base values
    options = ClaudeCodeOptions()

    # Copy all attributes from base_options
    if base_options:
        for attr in [
            "model",
            "max_thinking_tokens",
            "max_turns",
            "cwd",
            "system_prompt",
            "append_system_prompt",
            "permission_mode",
            "permission_prompt_tool_name",
            "continue_conversation",
            "resume",
            "allowed_tools",
            "disallowed_tools",
            "mcp_servers",
            "mcp_tools",
            # Anthropic API fields
            "temperature",
            "top_p",
            "top_k",
            "stop_sequences",
            "tools",
            "metadata",
            "service_tier",
        ]:
            if hasattr(base_options, attr):
                base_value = getattr(base_options, attr)
                if base_value is not None:
                    setattr(options, attr, base_value)

    # Apply overrides
    for key, value in overrides.items():
        if value is not None and hasattr(options, key):
            # Handle special type conversions for specific fields
            if key == "cwd" and not isinstance(value, str):
                value = str(value)
            setattr(options, key, value)

    return options