Created
February 10, 2026 16:54
-
-
Save schpet/4618709d04cbbfc238dc233cb3a1fb49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Copy Claude Code credentials from the repoman server to the VM. | |
| * This allows the VM to use Claude Code without manual login. | |
| * Uses CLAUDE_CODE_OAUTH_TOKEN from server environment to set up OAuth authentication. | |
| * Silently skips if OAuth token is not available. | |
| */ | |
| async function copyClaudeCredentials(sshCommand: string): Promise<void> { | |
| const sshTarget = extractSshTarget(sshCommand); | |
| // Get OAuth token from environment | |
| const oauthToken = Deno.env.get("CLAUDE_CODE_OAUTH_TOKEN"); | |
| if (!oauthToken) { | |
| console.log( | |
| "[bootstrap] CLAUDE_CODE_OAUTH_TOKEN not set, skipping Claude credential copy", | |
| ); | |
| return; | |
| } | |
| console.log( | |
| `[bootstrap] Setting up Claude OAuth credentials on ${sshTarget}`, | |
| ); | |
| // Create credentials JSON with OAuth token | |
| const credentials = { | |
| claudeAiOauth: { | |
| accessToken: oauthToken, | |
| refreshToken: "", | |
| expiresAt: 1900000000000, | |
| scopes: ["user:inference", "user:profile"], | |
| }, | |
| }; | |
| // Create .claude.json with onboarding skipped | |
| const config = { | |
| hasCompletedOnboarding: true, | |
| theme: "dark", | |
| autoUpdaterStatus: "disabled", | |
| }; | |
| // Escape JSON for shell | |
| const credentialsJson = JSON.stringify(credentials).replace(/'/g, "'\\''"); | |
| const configJson = JSON.stringify(config).replace(/'/g, "'\\''"); | |
| // Setup credentials via SSH - create directory, write files, set permissions | |
| const setupScript = ` | |
| mkdir -p ~/.claude | |
| echo '${credentialsJson}' > ~/.claude/.credentials.json | |
| chmod 600 ~/.claude/.credentials.json | |
| echo '${configJson}' > ~/.claude.json | |
| chmod 644 ~/.claude.json | |
| `.trim(); | |
| const setupCmd = new Deno.Command("ssh", { | |
| args: [ | |
| "-o", | |
| "StrictHostKeyChecking=no", | |
| "-o", | |
| "UserKnownHostsFile=/dev/null", | |
| sshTarget, | |
| setupScript, | |
| ], | |
| stdout: "piped", | |
| stderr: "piped", | |
| }); | |
| const setupResult = await setupCmd.output(); | |
| if (setupResult.code !== 0) { | |
| const stderr = new TextDecoder().decode(setupResult.stderr); | |
| throw new Error(`Failed to setup Claude credentials: ${stderr}`); | |
| } | |
| console.log("[bootstrap] Claude OAuth credentials configured successfully"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment