Skip to content

Commit d04e00d

Browse files
committed
fix: auto-cleanup old flat hook format in init command
init now detects and removes old flat-format hooks from previous versions that cause Claude Code settings validation errors. Re-adds in correct nested format automatically.
1 parent 77953f6 commit d04e00d

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/cli/init.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,22 @@ fi
144144
try { settings = JSON.parse(readFileSync(settingsPath, 'utf8')); } catch { /* ignore */ }
145145
}
146146
const hooks = (settings.hooks || {}) as Record<string, unknown[]>;
147-
// Check if our hook already exists (nested format: [{hooks:[{command:...}]}])
148-
const existing = hooks.UserPromptSubmit as Array<{ hooks?: Array<{ command?: string }> }> | undefined;
149-
const hasOurHook = existing?.some(entry =>
147+
if (!hooks.UserPromptSubmit) hooks.UserPromptSubmit = [];
148+
const items = hooks.UserPromptSubmit as Array<Record<string, unknown>>;
149+
150+
// Remove old flat-format entries from previous codebase-pilot versions
151+
// (flat format causes Claude Code settings validation error)
152+
hooks.UserPromptSubmit = items.filter(entry => {
153+
if (Array.isArray(entry.hooks)) return true; // correct nested format — keep
154+
if ((entry as { command?: string }).command?.includes('codebase-pilot-log-prompt')) return false; // our old broken format — remove
155+
return true; // other hooks — keep
156+
});
157+
158+
// Check if our hook exists in correct nested format
159+
const hasOurHook = (hooks.UserPromptSubmit as Array<{ hooks?: Array<{ command?: string }> }>).some(entry =>
150160
entry.hooks?.some(h => h.command?.includes('codebase-pilot-log-prompt'))
151161
);
152162
if (!hasOurHook) {
153-
if (!hooks.UserPromptSubmit) hooks.UserPromptSubmit = [];
154163
// Claude Code schema requires { hooks: [...] } wrapper
155164
(hooks.UserPromptSubmit as unknown[]).push({
156165
hooks: [{

0 commit comments

Comments
 (0)