Skip to content

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

Open
Nimraakram22 wants to merge 3 commits intogithub:mainfrom
Nimraakram22:fix/powershell-utf8-bom
Open

fix(powershell): ensure UTF-8 templates are written without BOM#2280
Nimraakram22 wants to merge 3 commits 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 thread scripts/powershell/create-new-feature.ps1 Outdated
Comment thread scripts/powershell/setup-plan.ps1 Outdated
Comment thread scripts/powershell/setup-plan.ps1 Outdated
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

@Nimraakram22
Copy link
Copy Markdown
Author

@mnriem Done! I have updated both setup-plan.ps1 and create-new-feature.ps1 to:

Use -Encoding UTF8 when reading templates to ensure character integrity.

Use lower camelCase for the $utf8NoBom variable.

Fix the indentation of the .NET write method calls.

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.

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/create-new-feature.ps1:355

  • The PR description says the write is hardened "regardless of the source template's encoding", but Get-Content -Encoding UTF8 forces UTF-8 decoding. If a resolved template is UTF-16/UTF-32 (common for Windows-authored files) this will corrupt content. Consider reading via a BOM-detecting API (e.g., [System.IO.File]::ReadAllText($template) / StreamReader with BOM detection) and then writing with UTF8Encoding($false).
            $content = Get-Content -Raw -Encoding UTF8 -Path $template
            $utf8NoBom = New-Object System.Text.UTF8Encoding($false)

scripts/powershell/setup-plan.ps1:41

  • Get-Content -Encoding UTF8 forces UTF-8 decoding, so this doesn't fully meet the stated goal of being robust to template encoding (e.g., UTF-16 templates with a BOM would be mis-decoded). Prefer a BOM-detecting read (such as [System.IO.File]::ReadAllText($template)) before writing out with UTF8Encoding($false).
    $content = Get-Content -Raw -Encoding UTF8 -Path $template
    $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
    [System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $utf8NoBom)
  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread scripts/powershell/create-new-feature.ps1 Outdated
Comment thread scripts/powershell/setup-plan.ps1
@mnriem
Copy link
Copy Markdown
Collaborator

mnriem commented Apr 21, 2026

Please address Copilot feedback. If not applicable please explain why

@Nimraakram22
Copy link
Copy Markdown
Author

@mnriem "Fixed! I have updated the scripts based on Copilot's feedback:

Switched to [System.IO.File]::ReadAllText() for more robust template encoding detection.

Corrected the variable name from $targetPath to $specFile in create-new-feature.ps1.

Cleaned up the duplicate comments and indentation.

Ready for another look!"

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.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new

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