Skip to content

fix(powershell): ensure UTF-8 templates are written without BOM#2280

Open
Nimraakram22 wants to merge 1 commit intogithub:mainfrom
Nimraakram22:fix/powershell-utf8-bom
Open

fix(powershell): ensure UTF-8 templates are written without BOM#2280
Nimraakram22 wants to merge 1 commit intogithub:mainfrom
Nimraakram22:fix/powershell-utf8-bom

Conversation

@Nimraakram22
Copy link
Copy Markdown

Description
This PR fixes an issue where PowerShell 5.1 (default on Windows) writes files like CLAUDE.md with a UTF-8 Byte Order Mark (BOM). This invisible prefix causes parsing errors in modern tools like Claude Code and other Unix-style CLI utilities.

Changes
Stripped BOM from existing templates: Found and removed the BOM from all .md files in the templates/ and presets/ directories.

Hardened PowerShell logic: Replaced Copy-Item with a .NET based write method ([System.IO.File]::WriteAllText) in setup-plan.ps1 and create-new-feature.ps1 to force "UTF-8 No BOM" output, regardless of the source template's encoding.

Verification
Verified using the file command in MINGW64 to ensure output files now show as UTF-8 Unicode text instead of UTF-8 Unicode (with BOM) text.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the PowerShell feature/setup scripts to ensure generated markdown files are written as UTF-8 without BOM (avoiding BOM-related parsing issues in Unix-style tooling).

Changes:

  • Replaced Copy-Item template copying with a read + [System.IO.File]::WriteAllText(...) flow to force UTF-8 no BOM output.
  • Applied the same UTF-8 no BOM write approach in both setup-plan.ps1 and create-new-feature.ps1.
Show a summary per file
File Description
scripts/powershell/setup-plan.ps1 Writes plan.md from the template using UTF-8 no BOM instead of Copy-Item.
scripts/powershell/create-new-feature.ps1 Writes spec.md from the template using UTF-8 no BOM instead of Copy-Item.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (2)

scripts/powershell/setup-plan.ps1:39

  • Variable $Utf8NoBom is PascalCase while other local variables in this file are lower camelCase (e.g., $paths, $template, $content). Consider renaming to match the local variable naming convention (e.g., $utf8NoBom).
    $Utf8NoBom = New-Object System.Text.UTF8Encoding($false)

scripts/powershell/create-new-feature.ps1:355

  • Local variables in this script use lower camelCase (e.g., $featureDesc, $branchName), but $Utf8NoBom is PascalCase. Consider renaming to match the file's convention (e.g., $utf8NoBom).
            $Utf8NoBom = New-Object System.Text.UTF8Encoding($false)
  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Comment on lines +353 to +354
# Read the template content and write it to the spec file with UTF-8 encoding without BOM
$content = Get-Content -Raw -Path $template
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows PowerShell 5.1, Get-Content without -Encoding will treat UTF-8 without BOM as the system ANSI code page, which can corrupt non-ASCII characters in templates. Since you're normalizing output to UTF-8 no BOM, please also read the template using an explicit UTF-8 encoding (e.g., Get-Content -Raw -Encoding UTF8 or .NET ReadAllText).

This issue also appears on line 355 of the same file.

Suggested change
# Read the template content and write it to the spec file with UTF-8 encoding without BOM
$content = Get-Content -Raw -Path $template
# Read the template content as UTF-8 and write it to the spec file with UTF-8 encoding without BOM
$content = Get-Content -Raw -Encoding UTF8 -Path $template

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +40
# Read the template content and write it to the implementation plan file with UTF-8 encoding without BOM
$content = Get-Content -Raw -Path $template
$Utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $Utf8NoBom)
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows PowerShell 5.1, Get-Content without -Encoding will treat UTF-8 without BOM as the system ANSI code page, which can corrupt non-ASCII characters in templates (especially now that templates are expected to be UTF-8 no BOM). Read with an explicit UTF-8 encoding (e.g., Get-Content -Raw -Encoding UTF8 or a .NET ReadAllText overload) before writing.

This issue also appears on line 39 of the same file.

Suggested change
# Read the template content and write it to the implementation plan file with UTF-8 encoding without BOM
$content = Get-Content -Raw -Path $template
$Utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $Utf8NoBom)
# Read the template content as UTF-8 and write it to the implementation plan file with UTF-8 encoding without BOM
$content = Get-Content -Raw -Encoding UTF8 -Path $template
$Utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $Utf8NoBom)

Copilot uses AI. Check for mistakes.
# Read the template content and write it to the implementation plan file with UTF-8 encoding without BOM
$content = Get-Content -Raw -Path $template
$Utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $Utf8NoBom)
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[System.IO.File]::WriteAllText(...) is not indented like the rest of the if block, which makes the block harder to read and looks accidental. Please align its indentation with the surrounding statements.

Suggested change
[System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $Utf8NoBom)
[System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $Utf8NoBom)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

@mnriem mnriem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback. If not appicable, please explain why

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants