Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const HOOK_SETTINGS = {
type: "command",
command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/session-start.js"',
timeout: 5,
_managedBy: "openwolf",
},
],
},
Expand All @@ -67,6 +68,7 @@ const HOOK_SETTINGS = {
type: "command",
command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/pre-read.js"',
timeout: 5,
_managedBy: "openwolf",
},
],
},
Expand All @@ -77,6 +79,7 @@ const HOOK_SETTINGS = {
type: "command",
command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/pre-write.js"',
timeout: 5,
_managedBy: "openwolf",
},
],
},
Expand All @@ -89,6 +92,7 @@ const HOOK_SETTINGS = {
type: "command",
command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/post-read.js"',
timeout: 5,
_managedBy: "openwolf",
},
],
},
Expand All @@ -99,6 +103,7 @@ const HOOK_SETTINGS = {
type: "command",
command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/post-write.js"',
timeout: 10,
_managedBy: "openwolf",
},
],
},
Expand All @@ -111,6 +116,7 @@ const HOOK_SETTINGS = {
type: "command",
command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/stop.js"',
timeout: 10,
_managedBy: "openwolf",
},
],
},
Expand Down Expand Up @@ -480,17 +486,22 @@ function replaceOpenWolfHooks(
if (!merged.hooks) {
merged.hooks = {};
}
const hooks = merged.hooks as Record<string, Array<{ matcher: string; hooks: Array<{ command?: string; type: string }> }>>;
const hooks = merged.hooks as Record<string, Array<{ matcher: string; hooks: Array<{ command?: string; type: string; _managedBy?: string }> }>>;

for (const [event, newMatchers] of Object.entries(hookSettings.hooks)) {
if (!hooks[event]) {
hooks[event] = [];
}

// Remove any existing OpenWolf hook entries (match by .wolf/hooks/ in command)
// Remove any existing OpenWolf hook entries. Prefer the explicit
// `_managedBy: "openwolf"` tag, fall back to the legacy
// `.wolf/hooks/` substring match so we still clean up entries
// installed by versions before the tag existed.
hooks[event] = hooks[event].filter((entry) => {
const isOpenWolfHook = entry.hooks?.some(
(h) => h.command && h.command.includes(".wolf/hooks/")
(h) =>
h._managedBy === "openwolf" ||
(h.command && h.command.includes(".wolf/hooks/"))
);
return !isOpenWolfHook;
});
Expand Down
27 changes: 18 additions & 9 deletions src/cli/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@ const BACKUP_FILES = [
...USER_DATA_FILES,
];

// Every hook entry carries `_managedBy: "openwolf"`. Claude Code's
// settings round-tripper preserves entries with this provenance tag
// across `/effort`, `/config`, and similar rewrites; untagged entries
// get silently dropped. See cytostack/openwolf#31.
const HOOK_SETTINGS = {
hooks: {
SessionStart: [{ matcher: "", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/session-start.js"', timeout: 5 }] }],
SessionStart: [{ matcher: "", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/session-start.js"', timeout: 5, _managedBy: "openwolf" }] }],
PreToolUse: [
{ matcher: "Read", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/pre-read.js"', timeout: 5 }] },
{ matcher: "Write|Edit|MultiEdit", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/pre-write.js"', timeout: 5 }] },
{ matcher: "Read", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/pre-read.js"', timeout: 5, _managedBy: "openwolf" }] },
{ matcher: "Write|Edit|MultiEdit", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/pre-write.js"', timeout: 5, _managedBy: "openwolf" }] },
],
PostToolUse: [
{ matcher: "Read", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/post-read.js"', timeout: 5 }] },
{ matcher: "Write|Edit|MultiEdit", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/post-write.js"', timeout: 10 }] },
{ matcher: "Read", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/post-read.js"', timeout: 5, _managedBy: "openwolf" }] },
{ matcher: "Write|Edit|MultiEdit", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/post-write.js"', timeout: 10, _managedBy: "openwolf" }] },
],
Stop: [{ matcher: "", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/stop.js"', timeout: 10 }] }],
Stop: [{ matcher: "", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.wolf/hooks/stop.js"', timeout: 10, _managedBy: "openwolf" }] }],
},
};

Expand Down Expand Up @@ -358,15 +362,20 @@ function replaceOpenWolfHooks(
): Record<string, unknown> {
const merged = { ...existing };
if (!merged.hooks) merged.hooks = {};
const hooks = merged.hooks as Record<string, Array<{ matcher: string; hooks: Array<{ command?: string; type: string }> }>>;
const hooks = merged.hooks as Record<string, Array<{ matcher: string; hooks: Array<{ command?: string; type: string; _managedBy?: string }> }>>;

for (const [event, newMatchers] of Object.entries(hookSettings.hooks)) {
if (!hooks[event]) hooks[event] = [];

// Remove existing OpenWolf hook entries
// Remove existing OpenWolf hook entries. Prefer the explicit
// `_managedBy: "openwolf"` tag, fall back to the legacy
// `.wolf/hooks/` substring match so we still clean up entries
// installed by versions before the tag existed.
hooks[event] = hooks[event].filter((entry) => {
const isOpenWolfHook = entry.hooks?.some(
(h) => h.command && h.command.includes(".wolf/hooks/")
(h) =>
h._managedBy === "openwolf" ||
(h.command && h.command.includes(".wolf/hooks/"))
);
return !isOpenWolfHook;
});
Expand Down