Skip to content

{env:VAR} in permission keys expands to native Windows backslashes, producing invalid JSON on Windows #32695

@ple-4js

Description

@ple-4js

Description

When an environment variable is set with a native Windows path (backslashes), using{env:VAR}as a permission key causes opencode to fail with a JSON parse error on startup.

Plugins

No response

OpenCode version

1.14.33

Steps to reproduce

  1. Set an environment variable with a native Windows path:

    set MYDIR=C:\Users\me\AppData\Roaming\MyApp\config

  2. Add it as a permission key in opencode.json:

    "permission": {
    "external_directory": {
    "{env:MYDIR}/**": "allow"
    }
    }

  3. Run opencode .

Expected behavior

opencode normalizes the expanded path to forward slashes before using it as a JSON key, or accepts backslashes in permission key paths on Windows.

Actual behavior

opencode expands {env:MYDIR} literally and treats the backslashes as JSON escape sequences, producing a parse error:

--- Errors ---
InvalidEscapeCharacter at line N, column 7
   Line N:       "C:\Users\me\AppData\Roaming\MyApp\config/**": "allow"
                ^
--- End ---

Workaround

Set the environment variable with forward slashes before launching opencode:

set MYDIR=C:/Users/me/AppData/Roaming/MyApp/config

This is not always possible when the variable is set by a third-party application that uses native Windows path separators.

Suggested fix

Normalize {env:...} expanded values to forward slashes before inserting them as permission key paths.

Screenshot and/or share link

No response

Operating System

Windows 11

Terminal

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions