chenhg5/cc-connect · error

parse existing Agy hooks %s: %w

Error message

parse existing Agy hooks %s: %w

What it means

When building the overlay, createAgyConfigOverlay reads the existing ~/.gemini/config/hooks.json and unmarshals it into a map of raw JSON messages so the bridge hook can be merged. If the file exists but is not valid JSON (or not a JSON object), this wrapped error is returned.

Source

Thrown at agent/antigravity/permission_bridge.go:123

	overlayConfigRoot := filepath.Join(rootDir, "agy-config")
	overlayConfigDir := filepath.Join(overlayConfigRoot, "config")
	if err := os.MkdirAll(overlayConfigDir, 0o700); err != nil {
		return "", fmt.Errorf("create Agy permission overlay: %w", err)
	}

	if err := mirrorDirectoryEntries(realConfigRoot, overlayConfigRoot, map[string]bool{"config": true}); err != nil {
		return "", err
	}
	realConfigDir := filepath.Join(realConfigRoot, "config")
	if err := mirrorDirectoryEntries(realConfigDir, overlayConfigDir, map[string]bool{"hooks.json": true}); err != nil {
		return "", err
	}

	hooks := make(map[string]json.RawMessage)
	hooksPath := filepath.Join(realConfigDir, "hooks.json")
	if data, err := os.ReadFile(hooksPath); err == nil {
		if err := json.Unmarshal(data, &hooks); err != nil {
			return "", fmt.Errorf("parse existing Agy hooks %s: %w", hooksPath, err)
		}
		if hooks == nil {
			hooks = make(map[string]json.RawMessage)
		}
	} else if !os.IsNotExist(err) {
		return "", fmt.Errorf("read existing Agy hooks %s: %w", hooksPath, err)
	}

	executable, err := os.Executable()
	if err != nil {
		return "", fmt.Errorf("resolve cc-connect executable for Agy hook: %w", err)
	}
	bridgeHook, err := json.Marshal(map[string]any{
		"PreToolUse": []any{
			map[string]any{
				"matcher": "*",
				"hooks": []any{
					map[string]any{

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Validate the file: `python3 -m json.tool ~/.gemini/config/hooks.json` and fix any syntax errors.
  2. If the content is not recoverable, remove or rename hooks.json so the bridge recreates a fresh overlay (note: existing hooks in it will be lost).
  3. Back up the file, then restore only valid hook entries.
  4. Ensure no other process concurrently rewrites hooks.json while a session starts.

Example fix

// before: ~/.gemini/config/hooks.json
{ "PreToolUse": [ }, // trailing comma → invalid
// after
{ "PreToolUse": [ { "matcher": "*", "hooks": [] } ] }
Defensive patterns

Strategy: validation

Validate before calling

// shell: validate existing hooks.json before starting cc-connect
python3 -m json.tool "$HOME/.gemini/config/hooks.json" > /dev/null \
  || echo "hooks.json is not valid JSON"

Try / catch

if err := startAntigravitySession(); err != nil && strings.Contains(err.Error(), "parse existing Agy hooks") {
    // back up ~/.gemini/config/hooks.json, fix or remove it, retry
}

Prevention

When it happens

Trigger: newAgyPermissionBridge → createAgyConfigOverlay with a pre-existing <home>/.gemini/config/hooks.json containing malformed JSON, JSON arrays, or other non-object top-level values.

Common situations: Hand-edited hooks.json with syntax errors, a partial/truncated write from a crashed process, or a hooks.json written by a different tool version with an incompatible schema.

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/93e372d15493e491. Report an issue: GitHub.