Skip to content

[BUG] Write tool produces LF-only line endings on Windows, breaking batch (.bat) files #31224

Closed

Description

Description

The write tool produces LF-only (\n) line endings on Windows when writing .bat/.cmd files. Cmd.exe requires CRLF (\r\n) line endings; LF-only causes the batch file to exit immediately with no visible error.

Root Cause

packages/opencode/src/tool/write.ts passes content directly to writeWithDirs() 鈫?writeFileString() in packages/core/src/fs-util.ts with no line ending conversion. Contrast with edit.ts:46-56 which already has detectLineEnding()/convertToLineEnding() helpers.

Expected Behavior

  • Windows .bat/.cmd files: CRLF line endings, UTF-8 without BOM
  • Other files: no transformation needed

Suggested Fix

In write.ts, detect .bat/.cmd extensions on process.platform === 'win32' and normalize line endings to CRLF before writing. For encoding, write UTF-8 without BOM (BOM before @echo off causes cmd.exe to crash on some Windows configurations).

See also the companion discussion in #31275 (closed as out-of-scope 鈥?AGENTS.md rules are user/AI-authored, not program-bundled).

Activity

  1. github-actions commented on Jun 7, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is distinct from these, please add a comment explaining how it differs.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions