Skip to main content

CLAUDE

Constant CLAUDE 

Source
pub const CLAUDE: &str = "// Claude Code configuration script\n// Generates .claude/settings.json and other required files\n\n// Determine if we\'re using a proxy\nlet using_proxy = ctx.profile.proxy_url != ();\n\n// Build settings.json content\n// When using proxy, always use anthropic-compatible with proxy URL\n// For self-auth or native anthropic (without proxy), use \"anthropic\" type so Claude Code handles auth\nlet settings = #{\n    model: ctx.profile.model,\n    customApiKeyResponsibleParty: \"user\",\n    hasCompletedOnboarding: true,\n    hasAcknowledgedCostThreshold: true,\n    primaryProvider: #{\n        type: if using_proxy {\n            // Proxy routes to multiple backends, use compatible mode\n            \"anthropic-compatible\"\n        } else if ctx.provider.type == \"anthropic\" || ctx.provider.type == \"self\" {\n            \"anthropic\"\n        } else {\n            \"anthropic-compatible\"\n        },\n        baseUrl: if using_proxy {\n            ctx.profile.proxy_url\n        } else if ctx.provider.type == \"anthropic\" || ctx.provider.type == \"self\" {\n            ()\n        } else {\n            ctx.profile.endpoint\n        }\n    }\n};\n\n// Add hooks configuration if present\n// hooks_config is the full Claude Code hooks format (PreToolUse, PostToolUse, etc.)\nif ctx.profile.hooks_config != () {\n    settings.hooks = ctx.profile.hooks_config;\n}\n\n// Legacy: Add simple hooks if enabled (for backwards compatibility)\nlet hooks = ();\nif ctx.profile.hooks.len() > 0 {\n    hooks = #{};\n    for hook in ctx.profile.hooks {\n        hooks[hook] = true;\n    }\n}\n\n// Add MCP servers if enabled\nlet mcp_servers = ();\nif ctx.profile.mcp_servers.len() > 0 {\n    mcp_servers = [];\n    for server in ctx.profile.mcp_servers {\n        mcp_servers.push(#{\n            name: server,\n            enabled: true\n        });\n    }\n}\n\n// Build environment variables\nlet env = #{};\n\n// Only set API key env var if not self-authenticating\nif ctx.provider.type != \"self\" {\n    // Set the provider\'s auth key for API key retrieval\n    env[ctx.provider.auth_env_key] = \"${API_KEY}\";\n\n    if using_proxy {\n        // When using proxy, set ANTHROPIC_AUTH_TOKEN and proxy URL\n        // The proxy will handle routing to the actual provider\n        env[\"ANTHROPIC_AUTH_TOKEN\"] = \"${API_KEY}\";\n        env[\"ANTHROPIC_BASE_URL\"] = ctx.profile.proxy_url;\n    } else if ctx.provider.type == \"anthropic\" {\n        // For native Anthropic, use ANTHROPIC_API_KEY\n        env[\"ANTHROPIC_API_KEY\"] = \"${API_KEY}\";\n    } else {\n        // For anthropic-compatible providers (like MiniMax),\n        // Claude Code expects ANTHROPIC_AUTH_TOKEN and ANTHROPIC_BASE_URL\n        env[\"ANTHROPIC_AUTH_TOKEN\"] = \"${API_KEY}\";\n        env[\"ANTHROPIC_BASE_URL\"] = ctx.profile.endpoint;\n    }\n}\n\n// Return the output\n#{\n    files: #{\n        \".claude/settings.json\": json::encode_pretty(settings)\n    },\n    env: env,\n    hooks: hooks,\n    mcp_servers: mcp_servers\n}\n";