fix(powershell): ensure UTF-8 templates are written without BOM#2280
fix(powershell): ensure UTF-8 templates are written without BOM#2280Nimraakram22 wants to merge 1 commit intogithub:mainfrom
Conversation
There was a problem hiding this comment.
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-Itemtemplate 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.ps1andcreate-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
$Utf8NoBomis 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$Utf8NoBomis 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
| # Read the template content and write it to the spec file with UTF-8 encoding without BOM | ||
| $content = Get-Content -Raw -Path $template |
There was a problem hiding this comment.
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.
| # 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 |
| # 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) |
There was a problem hiding this comment.
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.
| # 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) |
| # 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) |
There was a problem hiding this comment.
[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.
| [System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $Utf8NoBom) | |
| [System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $Utf8NoBom) |
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback. If not appicable, please explain why
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.