Skip to content

runtime-switch: switch.js shell syntax error — 'then;' invalid in bash if-statement #481

@Nanyan

Description

@Nanyan

Problem

In skills/runtime-switch/scripts/switch.js, the writeTokenCmd is constructed by joining shell command fragments with '; ':

```js
const writeTokenCmd = [
"source ~/.nvm/nvm.sh",
`if grep -q '^CLAUDE_CODE_OAUTH_TOKEN=' ~/zylos/.env 2>/dev/null; then`,
` sed -i 's|^CLAUDE_CODE_OAUTH_TOKEN=.*|CLAUDE_CODE_OAUTH_TOKEN=${token}|' ~/zylos/.env`,
`else`,
` echo 'CLAUDE_CODE_OAUTH_TOKEN=${token}' >> ~/zylos/.env`,
`fi`,
"echo 'token_written'"
].join('; ');
```

When joined with '; ', the resulting string becomes:

```bash
source ~/.nvm/nvm.sh; if grep -q ...; then; sed -i ...; else; echo ...; fi; echo 'token_written'
```

The then; (semicolon immediately after then) is invalid bash syntax. In bash, then cannot be followed by a semicolon — it must be followed by a newline or a command directly.

Expected Behavior

The command should execute without a shell syntax error. The if/then/else block should be correctly formed.

Fix

Join with '\n' instead of '; ' for multi-line shell constructs, or restructure to a single-line form:

```js
// Option A: join with newline
].join('\n');

// Option B: single-line if
`if grep -q '^CLAUDE_CODE_OAUTH_TOKEN=' ~/zylos/.env 2>/dev/null; then sed -i ...; else echo ...; fi`
```

Impact

All Claude runtime switches via switch.js fail at step 2.1 (writing CLAUDE_CODE_OAUTH_TOKEN to .env) on VMs where the token does NOT already exist in .env. Manual SSH workaround is currently in use.

Related

  • Discovered during zylos310 / avere / melody runtime switches on 2026-04-02

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions