Zum Inhalt

OpenCode Setup fuer Windows

Stand: 2026-05-27

Ziel

Windows-Clients nutzen OpenCode ueber zentrale HTTPS-Endpunkte. Es werden keine direkten 10.x-, VLAN70-, GB10- oder Ollama-Ziele in der Client-Konfiguration verwendet.

Installation

OpenCode gemaess Lanstyle-Softwareverteilung oder offizieller Installationsanleitung installieren. Danach einmal starten und wieder beenden.

Config-Verzeichnis

PowerShell:

$OpenCodeConfig = Join-Path $env:USERPROFILE ".config\\opencode"
New-Item -ItemType Directory -Force $OpenCodeConfig | Out-Null

Kopiere die Operator-Konfiguration nach:

%USERPROFILE%\.config\opencode\opencode.jsonc

Quelle:

agent-runtime/configs/opencode.operator.jsonc

Secrets-Datei

Pfad:

%USERPROFILE%\.config\opencode\secrets.env

Beispiel:

@'
LITELLM_API_KEY="PASTE_LITELLM_USER_KEY_HERE"
LANSTYLE_MCPHUB_TOKEN="PASTE_MCP_USER_TOKEN_HERE"
CONTEXT7_API_KEY="OPTIONAL_CONTEXT7_KEY_HERE"
'@ | Set-Content -Path "$env:USERPROFILE\\.config\\opencode\\secrets.env" -Encoding UTF8

Rechte haerten:

icacls "$env:USERPROFILE\\.config\\opencode\\secrets.env" /inheritance:r
icacls "$env:USERPROFILE\\.config\\opencode\\secrets.env" /grant:r "$($env:USERNAME):(R,W)"

ENV fuer aktuelle Sitzung laden

$SecretFile = "$env:USERPROFILE\\.config\\opencode\\secrets.env"
Get-Content $SecretFile | ForEach-Object {
    if ($_ -match '^\\s*([^#][^=]+)=(.*)$') {
        $name = $matches[1].Trim()
        $value = $matches[2].Trim().Trim('"')
        [Environment]::SetEnvironmentVariable($name, $value, 'Process')
    }
}

Dann OpenCode aus derselben PowerShell-Sitzung starten.

ENV persistent fuer Benutzer setzen

Nur wenn der Benutzer das akzeptiert:

$SecretFile = "$env:USERPROFILE\\.config\\opencode\\secrets.env"
Get-Content $SecretFile | ForEach-Object {
    if ($_ -match '^\\s*([^#][^=]+)=(.*)$') {
        $name = $matches[1].Trim()
        $value = $matches[2].Trim().Trim('"')
        [Environment]::SetEnvironmentVariable($name, $value, 'User')
    }
}

Danach abmelden/anmelden oder OpenCode aus einer neuen Sitzung starten.

Optional: Task Scheduler

Wenn OpenCode automatisch mit gesetzten Umgebungsvariablen starten soll, kann ein Benutzer-Task verwendet werden. Beispielskript:

agent-runtime/configs/opencode-windows-env-setup.example.ps1

Der Task darf keine Tokenwerte protokollieren.

Pruefung

Test-Path "$env:USERPROFILE\\.config\\opencode\\opencode.jsonc"
Test-Path "$env:USERPROFILE\\.config\\opencode\\secrets.env"
[Environment]::GetEnvironmentVariable('LITELLM_API_KEY', 'User') -ne $null
[Environment]::GetEnvironmentVariable('LANSTYLE_MCPHUB_TOKEN', 'User') -ne $null

Erwartung:

  • OpenCode nutzt https://litellm.lanstyle.de/v1.
  • MCP nutzt https://mcphub.lanstyle.de/lanstyle-mcp.
  • Kein OAuth-Popup.
  • bash und edit sind im Operator-Profil nicht erlaubt.