chenhg5/cc-connect · error

parse %s: %w

Error message

parse %s: %w

What it means

readSettingsFile in agent/claudecode/cc_hooks.go loads Claude Code settings (config.toml sibling JSON that may contain comments) and unmarshals them into ccSettings. This error wraps a json.Unmarshal failure on the stripped content of the file at path, meaning the settings file is not parseable as JSON after JSONC comment removal.

Source

Thrown at agent/claudecode/cc_hooks.go:155

	if workDir != "" {
		paths = append(paths,
			filepath.Join(workDir, ".claude", "settings.json"),
			filepath.Join(workDir, ".claude", "settings.local.json"),
		)
	}
	return paths
}

// readSettingsFile reads a single settings.json, stripping JSONC comments.
func readSettingsFile(path string) (*ccSettings, error) {
	data, err := os.ReadFile(path)
	if err != nil {
		return nil, err
	}
	cleaned := stripJSONC(data)
	var s ccSettings
	if err := json.Unmarshal(cleaned, &s); err != nil {
		return nil, fmt.Errorf("parse %s: %w", path, err)
	}
	return &s, nil
}

// stripJSONC removes // and /* */ comments from JSONC, preserving strings.
func stripJSONC(data []byte) []byte {
	var out bytes.Buffer
	inString := false
	escaped := false
	i := 0
	for i < len(data) {
		ch := data[i]

		if escaped {
			out.WriteByte(ch)
			escaped = false
			i++
			continue

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Open the file named in the error at path and fix the JSON syntax error at the offset given by the wrapped encoding/json error
  2. Validate the file with a JSON linter (e.g. `jq . <path>` or `python -m json.tool`) before retrying
  3. Move comments into JSONC-safe positions (// at line starts or /* */ between values) — stripJSONC only removes those forms
  4. Restore the file from backup or reinstall/re-run claude's onboarding to regenerate defaults
Defensive patterns

Strategy: validation

Validate before calling

data, _ := os.ReadFile(path)
if !json.Valid(stripJSONC(data)) { return fmt.Errorf("settings file %s is not valid JSON", path) }

Try / catch

s, err := readSettingsFile(path)
if err != nil {
    var se *json.SyntaxError
    if errors.As(err, &se) {
        log.Errorf("settings JSON syntax error at offset %d: %v", se.Offset, se.Error())
    }
    return err
}

Prevention

When it happens

Trigger: loadSettings → readSettingsFile → json.Unmarshal(stripJSONC(data), &s) fails when the settings file at path contains a JSON syntax error: trailing commas, unquoted keys, unbalanced braces, or comments inside strings that stripJSONC mishandles.

Common situations: User hand-edited ~/.claude/settings.json and left a trailing comma or truncated the file; an editor auto-formatted the settings into JSON5 syntax; a partially-written file from a crashed update.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/d9c3d742ef19c7c3. Report an issue: GitHub.