Skip to main content

OPENCODE

Constant OPENCODE 

Source
pub const OPENCODE: &str = "// OpenCode configuration script\n// Generates config files for OpenCode CLI agent\n\n// OpenCode uses Anthropic-compatible API\n// For self-auth, use native anthropic provider (OpenCode handles auth)\nlet config = #{\n    model: ctx.profile.model,\n    provider: if ctx.provider.type == \"anthropic\" || ctx.provider.type == \"self\" {\n        \"anthropic\"\n    } else {\n        \"anthropic-compatible\"\n    }\n};\n\n// Build environment variables\nlet env = #{};\n\n// Only set API key env vars if not self-authenticating\nif ctx.provider.type != \"self\" {\n    env[ctx.provider.auth_env_key] = \"${API_KEY}\";\n\n    // If using a custom endpoint, set it\n    if ctx.provider.type != \"anthropic\" {\n        config.api_base = ctx.profile.endpoint;\n        env[\"ANTHROPIC_BASE_URL\"] = ctx.profile.endpoint;\n    }\n}\n\n// Return the output\n#{\n    files: #{\n        \".opencode/config.json\": json::encode_pretty(config)\n    },\n    env: env,\n    hooks: (),\n    mcp_servers: ()\n}\n";