Skip to content

{env:VAR} substitutions break on Windows (backslashes in paths produce InvalidEscapeCharacter) #20640

Closed

Description

@mynameistito

Description

{env:VAR} substitutions are broken on Windows. Paths in opencode.jsonc using {env:XDG_CONFIG_HOME} or {env:HOME} trigger InvalidEscapeCharacter errors and prevent the config from loading.

The issue is in packages/opencode/src/config/paths.ts. The substitute function performs a raw string replacement before the JSONC parser runs:

text = text.replace(/\{env:([^}]+)\}/g, (_, varName) => {
  return process.env[varName] || ""
})

On Windows, HOME contains backslashes (e.g., C:\Users\name). After substitution, the JSON contains sequences like \U, which are invalid escape characters, causing the parser to crash.

The Fix:
Swap backslashes for forward slashes after expanding the variable:

return (process.env[varName] || "").replaceAll("\\", "/")

Steps to reproduce

  1. Run OpenCode on Windows.
  2. Add a path using {env:HOME} in opencode.jsonc:
    "file:///{env:HOME}/opencode/plugins/myplugin.ts"
  3. OpenCode reports InvalidEscapeCharacter.

Workaround

Hardcode paths with forward slashes:

"file:///C:/Users/username/.config/opencode/plugins/myplugin.ts"

Operating System

Windows 11

Terminal

Windows Terminal

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 2, 2026
  2. mynameistito commented on Apr 2, 2026

    @mynameistito
    ContributorAuthor

    sorry for the ping kmdr, but it my agent cooked the wrong commit there, but it seems like it has been an issue since yesterday*

  3. mynameistito commented on Apr 2, 2026

    @mynameistito
    ContributorAuthor

    Closing - incorrect root cause attribution. Filing a corrected issue.

  4. Social-Mean commented on Apr 2, 2026

    @Social-Mean

    Hi @mynameistito , I encountered the same problem on Windows. How did you solve it?

  5. mynameistito commented on Apr 2, 2026

    @mynameistito
    ContributorAuthor

    I didn't, I just reaped remapped it without the var @Social-Mean. Will kick off an agent later to try find an accurate location of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)windows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions