- Notifications
You must be signed in to change notification settings - Fork 3
fix: prevent BOM in JSON files written by install-hooks.ps1 #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Commit Message Format IssueYour commit messages don't follow the Conventional Commits specification. Required Format:Valid Types:
Examples:Breaking Changes:Add Please amend your commit messages to follow this format. Learn more: Conventional Commits |
1 similar comment
Commit Message Format IssueYour commit messages don't follow the Conventional Commits specification. Required Format:Valid Types:
Examples:Breaking Changes:Add Please amend your commit messages to follow this format. Learn more: Conventional Commits |
| Warning Rate limit exceeded@ooples has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 59 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
Summary by CodeRabbit
WalkthroughThe changes refactor JSON output handling in install-hooks.ps1 to write files without UTF-8 Byte Order Mark (BOM) using Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Comment |
Performance Benchmark Results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test-bom-fix.ps1 (1)
105-107: Consider using try-finally for guaranteed cleanup.The cleanup code won't run if any test fails and exits early (lines 53, 68, 72, 99). While not critical for a test script, wrapping the tests in a try-finally block would ensure the temp directory is always removed.
Example structure:
try { # All tests here } finally { if (Test-Path $testDir) { Remove-Item $testDir -Recurse -Force } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
install-hooks.ps1(7 hunks)test-bom-fix.ps1(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test (Node 18)
- GitHub Check: Test (Node 20)
🔇 Additional comments (1)
install-hooks.ps1 (1)
218-220: Excellent fix for the BOM issue!The implementation correctly uses
[System.IO.File]::WriteAllTextwithUTF8Encoding($false)to write JSON files without a Byte Order Mark. The$falseparameter disablesencoderShouldEmitUTF8Identifier, ensuring BOM-free UTF-8 output that JSON parsers can handle correctly.All seven locations follow a consistent pattern:
- Serialize the object to JSON with
ConvertTo-Json- Write using
WriteAllTextwith BOM-free UTF-8 encoding- Properly guarded by DryRun checks and wrapped in try-catch blocks where appropriate
This resolves the critical issue where
Set-Content -Encoding UTF8was adding a BOM (EF BB BF) that broke Claude Code settings.Also applies to: 259-260, 288-289, 311-312, 340-341, 363-364, 386-387
**Problem**: PowerShell's `Set-Content -Encoding UTF8` adds a UTF-8 BOM (Byte Order Mark: EF BB BF) to files, which breaks JSON parsers and causes Claude Code to show "Invalid or malformed JSON" errors. **Impact**: Users cannot use Claude Code after running install-hooks because settings.json becomes unparseable. **Root Cause**: 7 locations in install-hooks.ps1 used: ```powershell $settings | ConvertTo-Json -Depth 10 | Set-Content $file -Encoding UTF8 ``` **Solution**: Replace all instances with BOM-free write method: ```powershell $json = $settings | ConvertTo-Json -Depth 10 [System.IO.File]::WriteAllText($file, $json, (New-Object System.Text.UTF8Encoding $false)) ``` The third parameter `$false` prevents BOM from being added. **Changes**: - Fixed 7 JSON write operations in install-hooks.ps1 - Added test-bom-fix.ps1 to verify no BOM is added - All tests pass confirming the fix works **Testing**: Run `pwsh test-bom-fix.ps1` to verify: - NEW method does NOT add BOM (7B 0D 0A...) - OLD method DOES add BOM (EF BB BF 7B...) - JSON remains valid and parseable Fixes: Users unable to use Claude Code after hook installation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
af0463e to a86391a Compare Performance Benchmark Results |
CodeRabbit correctly identified that Test 4 was only reading the file as a Buffer and would pass even if JSON was malformed. **Changes**: - Added JSON.parse() to actually parse the file content - Added 'utf8' encoding parameter to readFileSync() - Test now properly verifies JSON parsability, not just file readability This ensures the test catches malformed JSON that would break Claude Code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Performance Benchmark Results |
| This PR is included in version 3.0.2. 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Problem
PowerShell's
Set-Content -Encoding UTF8adds a UTF-8 BOM (Byte Order Mark:EF BB BF) to files, which breaks JSON parsers and causes Claude Code to show this error:This makes Claude Code completely unusable after running the hook installation script.
Impact
Any user who runs
install-hooks.ps1will have their Claude Code settings corrupted with UTF-8 BOM, preventing Claude Code from starting.Affected files:
C:\Users\username\.claude\settings.json(Claude Code main config)C:\Users\username\.claude\state.json(workspace trust state)Solution
Replace all instances of
Set-Content -Encoding UTF8with a BOM-free write method:Before (adds BOM):
After (no BOM):
The
$falseparameter prevents the BOM from being added.Changes
Fixed 7 locations in
install-hooks.ps1:$CLAUDE_SETTINGS(Claude Code main config)$CLAUDE_STATE(workspace trust state)$claudeDesktopConfig(Claude Desktop)$cursorConfig(Cursor IDE)$clineConfig(Cline/VS Code)$vscodeWorkspaceConfig(VS Code workspace)$windsurfConfig(Windsurf IDE)Testing
Added
test-bom-fix.ps1with comprehensive verification:Test Results
Hex Dump Comparison
OLD method (with BOM) - BREAKS JSON:
NEW method (no BOM) - WORKS:
Verification
To verify this fix locally:
All tests should pass with
[PASS]status.Priority
CRITICAL - This bug prevents Claude Code from functioning after hook installation.