Skip to content

Commit 2f01c1b

Browse files
committed
fix: prevent unicode escaping in settings.local.json
Go's json.Marshal escapes `>` as `\u003e` by default (HTML escaping). Use json.Encoder.SetEscapeHTML(false) to preserve literal characters in hook commands like `2>/dev/null`. Fixes hook creation bug where Claude Code rejected the settings file due to unicode-escaped characters in command strings. Signed-off-by: Jose Alekhinne <alekhinejose@gmail.com>
1 parent b9d4fde commit 2f01c1b

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

internal/cli/initialize/hook.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package initialize
88

99
import (
10+
"bytes"
1011
"encoding/json"
1112
"fmt"
1213
"os"
@@ -163,13 +164,16 @@ func mergeSettingsHooks(
163164
return fmt.Errorf("failed to create %s: %w", config.DirClaude, err)
164165
}
165166

166-
// Write settings with pretty formatting
167-
output, err := json.MarshalIndent(settings, "", " ")
168-
if err != nil {
167+
// Write settings with pretty formatting (disable HTML escaping to avoid \u003e for >)
168+
var buf bytes.Buffer
169+
encoder := json.NewEncoder(&buf)
170+
encoder.SetEscapeHTML(false)
171+
encoder.SetIndent("", " ")
172+
if err := encoder.Encode(settings); err != nil {
169173
return fmt.Errorf("failed to marshal settings: %w", err)
170174
}
171175

172-
if err := os.WriteFile(config.FileSettings, output, 0644); err != nil {
176+
if err := os.WriteFile(config.FileSettings, buf.Bytes(), 0644); err != nil {
173177
return fmt.Errorf("failed to write %s: %w", config.FileSettings, err)
174178
}
175179

0 commit comments

Comments
 (0)