You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
{env:} substitution breaks on Windows paths due to unescaped backslashes in JSON #35536
{env:VAR} substitution on Windows produces InvalidEscapeCharacter errors. Environment variables like USERPROFILE expand to paths containing backslashes (e.g. C:\Users\licat). After raw string replace, sequences like \U appear in the JSON text, which the JSONC parser rejects.
Root cause: substitute() in packages/opencode/src/config/variable.ts does a plain replace() for {env:} values, unlike {file:} which wraps with JSON.stringify() to escape backslashes.
Previous report (#20640) was closed as "incorrect root cause attribution" but a corrected issue was never filed.
If your issue is distinct from #20640 (e.g., you believe the correct fix is JSON.stringify()-based escaping rather than the slash-replacement workaround), please clarify the difference in this issue so maintainers can evaluate it separately.
#20640 was closed by the author as "incorrect root cause attribution" (it cited a non-existent file paths.ts). The corrected issue was never filed, so the bug still exists.
This report differs in two ways:
Correct file path: the actual code is in packages/opencode/src/config/variable.ts, not paths.ts.
// variable.ts - current (broken)text.replace(/\{env:([^}]+)\}/g,(_,v)=>process.env[v]||'')// should be (like {file:} already does)text.replace(/\{env:([^}]+)\}/g,(_,v)=>JSON.stringify(process.env[v]||'').slice(1,-1))
The slash-replacement approach would also break cases where a literal backslash is intentional in a non-path context.
Duplicate of #32695 — same underlying bug in variable.ts: unescaped {env:} values producing invalid JSON on Windows. #32695 has an open PR with the fix (#32786).
Activity
github-actions commentedon Jul 6, 2026
This issue might be a duplicate of an existing issue. Please check:
{env:VAR}substitution breaking on Windows with backslash paths causingInvalidEscapeCharacter. That issue was closed with a different proposed fix (forward-slash replacement), but the symptom and affected code path are the same.If your issue is distinct from #20640 (e.g., you believe the correct fix is
JSON.stringify()-based escaping rather than the slash-replacement workaround), please clarify the difference in this issue so maintainers can evaluate it separately.licat2023 commentedon Jul 6, 2026
#20640 was closed by the author as "incorrect root cause attribution" (it cited a non-existent file
paths.ts). The corrected issue was never filed, so the bug still exists.This report differs in two ways:
Correct file path: the actual code is in
packages/opencode/src/config/variable.ts, notpaths.ts.Correct fix: {env:VAR} substitutions break on Windows (backslashes in paths produce InvalidEscapeCharacter) #20640 proposed
replaceAll("\", "/")as a fix, but that is a workaround that only papers over the real problem. The right fix is to make{env:}consistent with{file:}— the latter already wraps withJSON.stringify()to escape backslashes properly. The{env:}path should do the same.The slash-replacement approach would also break cases where a literal backslash is intentional in a non-path context.
licat2023 commentedon Jul 6, 2026
Duplicate of #32695 — same underlying bug in
variable.ts: unescaped{env:}values producing invalid JSON on Windows. #32695 has an open PR with the fix (#32786).