@@ -53,13 +53,15 @@ type EnvBuilder<TInput, TOutput> = (
5353 /**
5454 * Wrap a tool to fire its post-hook (if one exists) after each successful execute.
5555 * Hooks are looked up via the session-scoped cache — no filesystem access per call.
56- * Hooks are fire-and-forget; errors are always swallowed.
56+ * Errors are always swallowed. onHook is called with the result so the caller can
57+ * render a UI line.
5758 */
5859 function withHooks<TInput extends { cwd?: string }, TOutput>(
5960 tool: ToolDef<TInput, TOutput>,
6061 lookupHook: (toolName: string) => string | null,
6162 cwd: string,
6263 buildEnv: EnvBuilder<TInput, TOutput>,
64+ onHook: (toolName: string, scriptPath: string, success: boolean) => void,
6365 ): ToolDef<TInput, TOutput> {
6466 const originalExecute = tool.execute;
6567 return {
@@ -69,7 +71,8 @@ function withHooks<TInput extends { cwd?: string }, TOutput>(
6971 const hookScript = lookupHook(tool.name);
7072 if (hookScript) {
7173 const env = buildEnv(result, input);
72- await runHook(hookScript, env, cwd);
74+ const success = await runHook(hookScript, env, cwd);
75+ onHook(tool.name, hookScript, success);
7376 }
7477 return result;
7578 },
@@ -102,8 +105,9 @@ export function buildToolSet(opts: {
102105 inputTokens: number;
103106 outputTokens: number;
104107 }>;
108+ onHook: (toolName: string, scriptPath: string, success: boolean) => void;
105109 }): ToolDef[] {
106- const { cwd } = opts;
110+ const { cwd, onHook } = opts;
107111 const depth = opts.depth ?? 0;
108112 const lookupHook = createHookCache(HOOKABLE_TOOLS, cwd);
109113
@@ -117,6 +121,7 @@ export function buildToolSet(opts: {
117121 lookupHook,
118122 cwd,
119123 (_, input) => hookEnvForGlob(input, cwd),
124+ onHook,
120125 ) as ToolDef,
121126 withHooks(
122127 withCwdDefault(grepTool as ToolDef, cwd) as ToolDef<
@@ -126,6 +131,7 @@ export function buildToolSet(opts: {
126131 lookupHook,
127132 cwd,
128133 (_, input) => hookEnvForGrep(input, cwd),
134+ onHook,
129135 ) as ToolDef,
130136 withHooks(
131137 withCwdDefault(readTool as ToolDef, cwd) as ToolDef<
@@ -135,6 +141,7 @@ export function buildToolSet(opts: {
135141 lookupHook,
136142 cwd,
137143 (_, input) => hookEnvForRead(input, cwd),
144+ onHook,
138145 ) as ToolDef,
139146 // Write: create/overwrite, replace/delete, insert
140147 withHooks(
@@ -145,6 +152,7 @@ export function buildToolSet(opts: {
145152 lookupHook,
146153 cwd,
147154 (result) => hookEnvForCreate(result, cwd),
155+ onHook,
148156 ) as ToolDef,
149157 withHooks(
150158 withCwdDefault(replaceTool as ToolDef, cwd) as ToolDef<
@@ -154,6 +162,7 @@ export function buildToolSet(opts: {
154162 lookupHook,
155163 cwd,
156164 (result) => hookEnvForReplace(result, cwd),
165+ onHook,
157166 ) as ToolDef,
158167 withHooks(
159168 withCwdDefault(insertTool as ToolDef, cwd) as ToolDef<
@@ -163,6 +172,7 @@ export function buildToolSet(opts: {
163172 lookupHook,
164173 cwd,
165174 (result) => hookEnvForInsert(result, cwd),
175+ onHook,
166176 ) as ToolDef,
167177 // Shell and subagent
168178 withHooks(
@@ -173,6 +183,7 @@ export function buildToolSet(opts: {
173183 lookupHook,
174184 cwd,
175185 (result, input) => hookEnvForShell(result, input, cwd),
186+ onHook,
176187 ) as ToolDef,
177188 createSubagentTool(async (prompt) => {
178189 if (depth >= MAX_SUBAGENT_DEPTH) {