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
import fails on UTF-16 files with BOM (Windows PowerShell redirection) #54306
readJson in packages/core/src/fs-util.ts decodes every file as UTF-8 (fs.readFileString), so the UTF-16 bytes turn into replacement characters before JSON.parse runs. Files with a BOM have an unambiguous encoding and could be decoded accordingly; UTF-16 without a BOM can stay unsupported.
This was previously diagnosed in #21941, which the inactivity bot auto-closed without a fix. Still reproducible on dev. I have a fix for BOM-prefixed UTF-16LE/BE in readJson and will open a PR referencing this issue.
Thanks for the detailed report and for tracking down the cause!
This was reproduced on the dev branch, which is OpenCode v1 (0.x/1.x). v1 now only gets fixes for critical bugs such as data loss, security problems or breakage with no workaround. This one has a straightforward workaround, so it's unlikely to be fixed in v1:
opencode export <session-id>|Out-File-Encoding utf8 session.json
# or convert an existing file:Get-Content session.json |Set-Content-Encoding utf8 session-utf8.json
We'd encourage moving to v2 (npm package @opencode/cli), where the equivalent command is opencode session import <file>. From reading the v2 code, it also decodes local files as UTF-8, so the same PowerShell 5.1 round-trip may well fail there too. If you can confirm it happens on v2, or if you think this is critical for v1, please reply here and we'll take another look.
UTF-8 without BOM: SchemaError: Missing key ["info"]["location"]
Both inputs reach schema validation with the identical error (the known v1-export/v2-schema difference, #49314), so v2 parses the UTF-16 file correctly.
Why: v2's session import reads the file with Bun.file(input.file).text() (packages/cli/src/commands/handlers/session/import.ts), and Bun.file().text() decodes a UTF-16 BOM. FSUtil.readJson (packages/util/src/fs-util.ts) is not in that code path, so it never sees this file.
So this is v1-only, and v1 has the workaround you posted. Closing as not planned — thanks for the triage.
Thanks for testing on v2 and for the correction. You're right: Bun.file().text() decodes the UTF-16 BOM, so v2's opencode session import reads the file fine. I was wrong to say v2 might have the same problem. Since v2 gives the same error for the UTF-16LE and UTF-8 files, this only affects v1, and v1 has the Out-File -Encoding utf8 workaround.
The Missing key ["info"]["location"] error you got when importing a v1 export into v2 is a separate problem, tracked in #49314.
This issue will be closed as not planned. Thanks again for the thorough report.
Closing as not planned. Your test on @opencode/cli@2.0.26 showed that v2 reads UTF-16 files with a BOM correctly, so this only affects v1. v1 only gets critical fixes, and this one has a workaround: in PowerShell 5.1, use Out-File -Encoding utf8 or Set-Content -Encoding utf8 instead of >. The schema error you hit when importing a v1 export into v2 is tracked in #49314. Thanks for the detailed report and for checking v2. If this shows up again on v2, please open a new issue.
Activity
opencode-agent commentedon Oct 10, 2026
Thanks for the detailed report and for tracking down the cause!
This was reproduced on the
devbranch, which is OpenCode v1 (0.x/1.x). v1 now only gets fixes for critical bugs such as data loss, security problems or breakage with no workaround. This one has a straightforward workaround, so it's unlikely to be fixed in v1:We'd encourage moving to v2 (npm package
@opencode/cli), where the equivalent command isopencode session import <file>. From reading the v2 code, it also decodes local files as UTF-8, so the same PowerShell 5.1 round-trip may well fail there too. If you can confirm it happens on v2, or if you think this is critical for v1, please reply here and we'll take another look.Related:
readJsonreynold-hu commentedon Oct 10, 2026
Confirmed on v2 — this does not reproduce there.
Tested
@opencode/cli@2.0.26on Windows 10 with PowerShell 5.1, importing the same session export twice:opencode export <id> > session.json):SchemaError: Missing key ["info"]["location"]SchemaError: Missing key ["info"]["location"]Both inputs reach schema validation with the identical error (the known v1-export/v2-schema difference, #49314), so v2 parses the UTF-16 file correctly.
Why: v2's
session importreads the file withBun.file(input.file).text()(packages/cli/src/commands/handlers/session/import.ts), andBun.file().text()decodes a UTF-16 BOM.FSUtil.readJson(packages/util/src/fs-util.ts) is not in that code path, so it never sees this file.So this is v1-only, and v1 has the workaround you posted. Closing as not planned — thanks for the triage.
opencode-agent commentedon Oct 10, 2026
Thanks for testing on v2 and for the correction. You're right:
Bun.file().text()decodes the UTF-16 BOM, so v2'sopencode session importreads the file fine. I was wrong to say v2 might have the same problem. Since v2 gives the same error for the UTF-16LE and UTF-8 files, this only affects v1, and v1 has theOut-File -Encoding utf8workaround.The
Missing key ["info"]["location"]error you got when importing a v1 export into v2 is a separate problem, tracked in #49314.This issue will be closed as not planned. Thanks again for the thorough report.
opencode-agent commentedon Oct 11, 2026
Closing as not planned. Your test on
@opencode/cli@2.0.26showed that v2 reads UTF-16 files with a BOM correctly, so this only affects v1. v1 only gets critical fixes, and this one has a workaround: in PowerShell 5.1, useOut-File -Encoding utf8orSet-Content -Encoding utf8instead of>. The schema error you hit when importing a v1 export into v2 is tracked in #49314. Thanks for the detailed report and for checking v2. If this shows up again on v2, please open a new issue.