@goodfoot/agent-hooks 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +137 -0
  2. package/dist/agents/antigravity/events.js +42 -0
  3. package/dist/agents/antigravity/hooks.js +59 -0
  4. package/dist/agents/antigravity/index.js +28 -0
  5. package/dist/agents/antigravity/outputs.js +81 -0
  6. package/dist/agents/antigravity/transport.js +84 -0
  7. package/dist/agents/antigravity/types.js +11 -0
  8. package/dist/agents/claude-code/env.js +27 -0
  9. package/dist/agents/claude-code/events.js +87 -0
  10. package/dist/agents/claude-code/hooks.js +1000 -0
  11. package/dist/agents/claude-code/index.js +57 -0
  12. package/dist/agents/claude-code/outputs.js +579 -0
  13. package/dist/agents/claude-code/tool-helpers.js +840 -0
  14. package/dist/agents/claude-code/transport.js +254 -0
  15. package/dist/agents/claude-code/types.js +11 -0
  16. package/dist/agents/codex/cli-support.js +318 -0
  17. package/dist/agents/codex/constants.js +29 -0
  18. package/dist/agents/codex/events.js +68 -0
  19. package/dist/agents/codex/hooks.js +93 -0
  20. package/dist/agents/codex/index.js +21 -0
  21. package/dist/agents/codex/outputs.js +189 -0
  22. package/dist/agents/codex/scaffold.js +273 -0
  23. package/dist/agents/codex/transport.js +139 -0
  24. package/dist/agents/codex/types.js +1 -0
  25. package/dist/cli.js +1357 -0
  26. package/dist/constants.js +39 -0
  27. package/dist/core/define-hook.js +61 -0
  28. package/dist/core/env.js +186 -0
  29. package/dist/core/logger.js +508 -0
  30. package/dist/core/stdin.js +38 -0
  31. package/dist/core/transport.js +231 -0
  32. package/dist/core/types.js +10 -0
  33. package/dist/index.js +17 -0
  34. package/dist/scaffold.js +512 -0
  35. package/package.json +61 -0
  36. package/types/agents/antigravity/events.d.ts +50 -0
  37. package/types/agents/antigravity/hooks.d.ts +76 -0
  38. package/types/agents/antigravity/index.d.ts +27 -0
  39. package/types/agents/antigravity/outputs.d.ts +107 -0
  40. package/types/agents/antigravity/transport.d.ts +47 -0
  41. package/types/agents/antigravity/types.d.ts +58 -0
  42. package/types/agents/claude-code/env.d.ts +27 -0
  43. package/types/agents/claude-code/events.d.ts +69 -0
  44. package/types/agents/claude-code/hooks.d.ts +1182 -0
  45. package/types/agents/claude-code/index.d.ts +23 -0
  46. package/types/agents/claude-code/outputs.d.ts +1160 -0
  47. package/types/agents/claude-code/tool-helpers.d.ts +807 -0
  48. package/types/agents/claude-code/transport.d.ts +119 -0
  49. package/types/agents/claude-code/types.d.ts +557 -0
  50. package/types/agents/codex/cli-support.d.ts +105 -0
  51. package/types/agents/codex/constants.d.ts +10 -0
  52. package/types/agents/codex/events.d.ts +63 -0
  53. package/types/agents/codex/hooks.d.ts +135 -0
  54. package/types/agents/codex/index.d.ts +19 -0
  55. package/types/agents/codex/outputs.d.ts +190 -0
  56. package/types/agents/codex/scaffold.d.ts +14 -0
  57. package/types/agents/codex/transport.d.ts +74 -0
  58. package/types/agents/codex/types.d.ts +131 -0
  59. package/types/cli.d.ts +315 -0
  60. package/types/constants.d.ts +9 -0
  61. package/types/core/define-hook.d.ts +39 -0
  62. package/types/core/env.d.ts +150 -0
  63. package/types/core/logger.d.ts +476 -0
  64. package/types/core/stdin.d.ts +21 -0
  65. package/types/core/transport.d.ts +131 -0
  66. package/types/core/types.d.ts +137 -0
  67. package/types/index.d.ts +18 -0
  68. package/types/scaffold.d.ts +46 -0
@@ -0,0 +1,1182 @@
1
+ /**
2
+ * Hook factory functions for Claude Code hooks.
3
+ *
4
+ * Provides typed factory functions for all 30 hook types that handle:
5
+ * - Input type narrowing based on hook event type
6
+ * - Output type enforcement via return types
7
+ * - Error wrapping with automatic logging
8
+ * - Logger context injection
9
+ *
10
+ * Each factory accepts a HookConfig with optional matcher and timeout settings,
11
+ * and returns a function that the runtime invokes when the hook file executes.
12
+ * @module
13
+ * @example
14
+ * ```typescript
15
+ * import { preToolUseHook, preToolUseOutput } from '@goodfoot/agent-hooks/claude-code';
16
+ *
17
+ * export default preToolUseHook({ matcher: 'Bash' }, async (input, { logger }) => {
18
+ * logger.info('Processing Bash command');
19
+ * return preToolUseOutput({ allow: true });
20
+ * });
21
+ * ```
22
+ * @see https://code.claude.com/docs/en/hooks
23
+ */
24
+ import type { HookConfig, HookContext, HookFunction, UnexpectedErrorHandler, UnexpectedErrorPolicy } from "../../core/types.js";
25
+ import { type AllowedUnexpectedErrorPolicy } from "./events.js";
26
+ import type { ConfigChangeOutput, CwdChangedOutput, ElicitationOutput, ElicitationResultOutput, FileChangedOutput, InstructionsLoadedOutput, MessageDisplayOutput, NotificationOutput, PermissionDeniedOutput, PermissionRequestOutput, PostCompactOutput, PostToolBatchOutput, PostToolUseFailureOutput, PostToolUseOutput, PreCompactOutput, PreToolUseOutput, SessionEndOutput, SessionStartOutput, SetupOutput, SpecificHookOutput, StopFailureOutput, StopOutput, SubagentStartOutput, SubagentStopOutput, TaskCompletedOutput, TaskCreatedOutput, TeammateIdleOutput, UserPromptExpansionOutput, UserPromptSubmitOutput, WorktreeCreateOutput, WorktreeRemoveOutput } from "./outputs.js";
27
+ import type { ConfigChangeInput, CwdChangedInput, ElicitationInput, ElicitationResultInput, FileChangedInput, HookEventName, InstructionsLoadedInput, KnownToolName, MessageDisplayInput, NotificationInput, PermissionDeniedInput, PermissionRequestInput, PostCompactInput, PostToolBatchInput, PostToolUseFailureInput, PostToolUseInput, PreCompactInput, PreToolUseInput, SessionEndInput, SessionStartInput, SetupInput, StopFailureInput, StopInput, SubagentStartInput, SubagentStopInput, TaskCompletedInput, TaskCreatedInput, TeammateIdleInput, ToolInputMap, UserPromptExpansionInput, UserPromptSubmitInput, WorktreeCreateInput, WorktreeRemoveInput } from "./types.js";
28
+ /**
29
+ * The policy, phase, and diagnostic vocabulary is shared across agents and
30
+ * owned by the core; re-exported here so the Claude Code surface keeps its
31
+ * historical import site (`hooks.js`).
32
+ *
33
+ * `"error"` (default) preserves existing behavior: an unhandled exception
34
+ * anywhere in the runtime writes a stack trace to stderr and exits non-zero.
35
+ *
36
+ * `"continue"` is an opt-in fail-open policy for advisory hooks whose only
37
+ * purpose is to enrich context (e.g. UserPromptSubmit additionalContext).
38
+ * Under this policy, unexpected runtime failures are swallowed, the empty
39
+ * output (`{}`) is emitted if no response was already produced, and the
40
+ * process exits 0 instead of surfacing a failed-hook banner to the user.
41
+ * An explicit `stderr`/blocking response returned by the handler itself is
42
+ * unaffected: it always writes that message and exits with code 2 (BLOCK).
43
+ * Do not use "continue" for hooks that enforce permission, safety, or
44
+ * policy decisions — see {@link ADVISORY_EVENTS} and the per-event config
45
+ * narrowing ({@link HookConfigFor}), which reject it at factory-call time
46
+ * and at compile time for every excluded event.
47
+ */
48
+ export type { HookConfig, HookContext, HookErrorPhase, HookFunction, UnexpectedErrorHandler, UnexpectedErrorPolicy, } from "../../core/types.js";
49
+ /**
50
+ * Per-event hook configuration: the shared {@link HookConfig} with the
51
+ * fail-open policy narrowed by the advisory allow-list. On excluded events
52
+ * (`PreToolUse`, `PermissionRequest`, blocking `Stop`/`SubagentStop`,
53
+ * `WorktreeCreate`/`WorktreeRemove`) the `unexpectedError` field collapses
54
+ * to `"error"` only, so `unexpectedError: "continue"` fails the type check;
55
+ * the same rule is enforced at factory-call time by the runtime policy gate.
56
+ * @template TEventName - The event the factory binds.
57
+ */
58
+ export type HookConfigFor<TEventName extends HookEventName> = Omit<HookConfig, "unexpectedError"> & {
59
+ unexpectedError?: AllowedUnexpectedErrorPolicy<TEventName>;
60
+ };
61
+ /**
62
+ * Typed-single-tool-matcher variant of {@link HookConfigFor}: narrows both
63
+ * the tool input (via `matcher: T`) and the allowed fail-open policy for the
64
+ * bound event. See {@link HookConfigFor}.
65
+ * @template T - The known tool name to match
66
+ * @template TEventName - The event the factory binds.
67
+ */
68
+ export type TypedHookConfigFor<T extends KnownToolName, TEventName extends HookEventName> = Omit<TypedHookConfig<T>, "unexpectedError"> & {
69
+ unexpectedError?: AllowedUnexpectedErrorPolicy<TEventName>;
70
+ };
71
+ /**
72
+ * Configuration for hooks with a known single-tool matcher.
73
+ *
74
+ * When the matcher is a single known tool name, the handler receives
75
+ * automatically typed toolInput based on the tool type.
76
+ * @template T - The known tool name
77
+ * @example
78
+ * ```typescript
79
+ * // tool_input is automatically typed as FileWriteInput
80
+ * preToolUseHook({ matcher: 'Write' }, (input) => {
81
+ * console.log(input.tool_input.file_path); // Typed!
82
+ * console.log(input.tool_input.content); // Typed!
83
+ * });
84
+ * ```
85
+ */
86
+ export interface TypedHookConfig<T extends KnownToolName> {
87
+ /**
88
+ * The single tool name to match.
89
+ * When this is a known tool name, toolInput will be automatically typed.
90
+ */
91
+ matcher: T;
92
+ /**
93
+ * Handler execution timeout in milliseconds.
94
+ */
95
+ timeout?: number;
96
+ /**
97
+ * Opt-in fail-open policy for unexpected runtime failures. See
98
+ * {@link UnexpectedErrorPolicy}.
99
+ */
100
+ unexpectedError?: UnexpectedErrorPolicy;
101
+ /**
102
+ * Best-effort diagnostic callback for the "continue" policy. See
103
+ * {@link UnexpectedErrorHandler}.
104
+ */
105
+ onUnexpectedError?: UnexpectedErrorHandler;
106
+ }
107
+ /**
108
+ * PreToolUseHookInput with typed tool_input for a specific tool.
109
+ * @template T - The known tool name
110
+ */
111
+ type _TypedPreToolUseHookInputBase<T extends KnownToolName> = Omit<PreToolUseInput, "tool_name" | "tool_input"> & {
112
+ tool_name: T;
113
+ tool_input: ToolInputMap[T];
114
+ };
115
+ export type TypedPreToolUseHookInput<T extends KnownToolName> = {
116
+ [K in keyof _TypedPreToolUseHookInputBase<T>]: _TypedPreToolUseHookInputBase<T>[K];
117
+ } & {};
118
+ /**
119
+ * PostToolUseHookInput with typed tool_input for a specific tool.
120
+ * @template T - The known tool name
121
+ */
122
+ type _TypedPostToolUseHookInputBase<T extends KnownToolName> = Omit<PostToolUseInput, "tool_name" | "tool_input"> & {
123
+ tool_name: T;
124
+ tool_input: ToolInputMap[T];
125
+ };
126
+ export type TypedPostToolUseHookInput<T extends KnownToolName> = {
127
+ [K in keyof _TypedPostToolUseHookInputBase<T>]: _TypedPostToolUseHookInputBase<T>[K];
128
+ } & {};
129
+ /**
130
+ * PostToolUseFailureHookInput with typed tool_input for a specific tool.
131
+ * @template T - The known tool name
132
+ */
133
+ type _TypedPostToolUseFailureHookInputBase<T extends KnownToolName> = Omit<PostToolUseFailureInput, "tool_name" | "tool_input"> & {
134
+ tool_name: T;
135
+ tool_input: ToolInputMap[T];
136
+ };
137
+ export type TypedPostToolUseFailureHookInput<T extends KnownToolName> = {
138
+ [K in keyof _TypedPostToolUseFailureHookInputBase<T>]: _TypedPostToolUseFailureHookInputBase<T>[K];
139
+ } & {};
140
+ /**
141
+ * PermissionRequestInput with typed tool_input for a specific tool.
142
+ * @template T - The known tool name
143
+ */
144
+ type _TypedPermissionRequestInputBase<T extends KnownToolName> = Omit<PermissionRequestInput, "tool_name" | "tool_input"> & {
145
+ tool_name: T;
146
+ tool_input: ToolInputMap[T];
147
+ };
148
+ export type TypedPermissionRequestInput<T extends KnownToolName> = {
149
+ [K in keyof _TypedPermissionRequestInputBase<T>]: _TypedPermissionRequestInputBase<T>[K];
150
+ } & {};
151
+ /**
152
+ * Extended context for SessionStart hooks.
153
+ *
154
+ * SessionStart hooks have additional capabilities for persisting environment
155
+ * variables that will be available in all subsequent bash commands.
156
+ * @example
157
+ * ```typescript
158
+ * export default sessionStartHook({}, async (input, { logger, persistEnvVar }) => {
159
+ * // Set environment variables for the session
160
+ * persistEnvVar('NODE_ENV', 'development');
161
+ * persistEnvVar('DEBUG', 'true');
162
+ *
163
+ * return sessionStartOutput({});
164
+ * });
165
+ * ```
166
+ */
167
+ export interface SessionStartContext extends HookContext {
168
+ /**
169
+ * Persists an environment variable for use in subsequent bash commands.
170
+ *
171
+ * This function writes a shell export statement to the `CLAUDE_ENV_FILE`,
172
+ * which Claude Code sources before running bash commands. This allows
173
+ * SessionStart hooks to configure the environment for the entire session.
174
+ * @param name - The environment variable name
175
+ * @param value - The environment variable value (will be shell-escaped)
176
+ * @example
177
+ * ```typescript
178
+ * persistEnvVar('NODE_ENV', 'production');
179
+ * persistEnvVar('API_KEY', 'secret-key');
180
+ * ```
181
+ */
182
+ persistEnvVar: (name: string, value: string) => void;
183
+ /**
184
+ * Persists multiple environment variables at once.
185
+ *
186
+ * This is a convenience wrapper around `persistEnvVar` for setting
187
+ * multiple variables in a single call.
188
+ * @param vars - Object mapping variable names to values
189
+ * @example
190
+ * ```typescript
191
+ * persistEnvVars({
192
+ * NODE_ENV: 'production',
193
+ * API_KEY: 'secret',
194
+ * DEBUG: 'false'
195
+ * });
196
+ * ```
197
+ */
198
+ persistEnvVars: (vars: Record<string, string>) => void;
199
+ }
200
+ /**
201
+ * Handler function for a specific hook type.
202
+ *
203
+ * Receives the typed input and context, returns a specific output type.
204
+ * Can be async for operations that require awaiting.
205
+ * @template TInput - The input type for this hook
206
+ * @template TOutput - The specific output type for this hook
207
+ * @template TContext - The context type (defaults to HookContext)
208
+ */
209
+ export type HookHandler<TInput, TOutput extends SpecificHookOutput, TContext extends HookContext = HookContext> = (input: TInput, context: TContext) => TOutput | null | Promise<TOutput | null>;
210
+ /**
211
+ * Creates a PreToolUse hook handler.
212
+ *
213
+ * PreToolUse hooks fire before any tool is executed, allowing you to:
214
+ * - Inspect and validate tool inputs
215
+ * - Allow, deny, or modify the tool execution
216
+ * - Add custom permission logic
217
+ *
218
+ * **Matcher**: Matches against `tool_name` (e.g., 'Bash', 'Read', 'Write')
219
+ *
220
+ * **Typed Overload**: When the matcher is a single known tool name (Write, Edit,
221
+ * MultiEdit, Read, Bash, Glob, Grep), the handler receives automatically typed
222
+ * `toolInput` based on the tool type.
223
+ * @param config - Hook configuration with optional matcher and timeout
224
+ * @param handler - The handler function to execute
225
+ * @returns A hook function that can be exported as the default export
226
+ * @example
227
+ * ```typescript
228
+ * import { preToolUseHook, preToolUseOutput } from '@goodfoot/agent-hooks/claude-code';
229
+ *
230
+ * // Typed overload: tool_input is automatically typed as BashInput
231
+ * export default preToolUseHook({ matcher: 'Bash' }, async (input, { logger }) => {
232
+ * // input.tool_input.command is typed as string - no cast needed!
233
+ * if (input.tool_input.command.includes('rm -rf')) {
234
+ * logger.warn('Blocking destructive command', { command: input.tool_input.command });
235
+ * return preToolUseOutput({
236
+ * hookSpecificOutput: {
237
+ * permissionDecision: 'deny',
238
+ * permissionDecisionReason: 'Destructive commands are not allowed'
239
+ * }
240
+ * });
241
+ * }
242
+ *
243
+ * return preToolUseOutput({
244
+ * hookSpecificOutput: { permissionDecision: 'allow' }
245
+ * });
246
+ * });
247
+ * ```
248
+ * @example
249
+ * ```typescript
250
+ * // Typed overload: tool_input is automatically typed as FileWriteInput
251
+ * export default preToolUseHook({ matcher: 'Write' }, (input) => {
252
+ * const { file_path, content } = input.tool_input; // Full autocomplete!
253
+ * // ...
254
+ * });
255
+ * ```
256
+ * @see https://code.claude.com/docs/en/hooks#pretooluse
257
+ */
258
+ export declare function preToolUseHook<T extends KnownToolName>(config: TypedHookConfigFor<T, "PreToolUse">, handler: HookHandler<TypedPreToolUseHookInput<T>, PreToolUseOutput>): HookFunction<TypedPreToolUseHookInput<T>, PreToolUseOutput>;
259
+ export declare function preToolUseHook(config: HookConfigFor<"PreToolUse">, handler: HookHandler<PreToolUseInput, PreToolUseOutput>): HookFunction<PreToolUseInput, PreToolUseOutput>;
260
+ /**
261
+ * Creates a PostToolUse hook handler.
262
+ *
263
+ * PostToolUse hooks fire after a tool executes successfully, allowing you to:
264
+ * - Inspect tool results
265
+ * - Add additional context to the conversation
266
+ * - Modify MCP tool output
267
+ *
268
+ * **Matcher**: Matches against `tool_name`
269
+ *
270
+ * **Typed Overload**: When the matcher is a single known tool name, the handler
271
+ * receives automatically typed `toolInput` based on the tool type.
272
+ * @param config - Hook configuration with optional matcher and timeout
273
+ * @param handler - The handler function to execute
274
+ * @returns A hook function that can be exported as the default export
275
+ * @example
276
+ * ```typescript
277
+ * import { postToolUseHook, postToolUseOutput } from '@goodfoot/agent-hooks/claude-code';
278
+ *
279
+ * // Typed overload: tool_input is automatically typed as FileReadInput
280
+ * export default postToolUseHook({ matcher: 'Read' }, async (input, { logger }) => {
281
+ * // input.tool_input.file_path is typed as string - no cast needed!
282
+ * logger.info('File read completed', { filePath: input.tool_input.file_path });
283
+ *
284
+ * return postToolUseOutput({
285
+ * hookSpecificOutput: {
286
+ * additionalContext: `File ${input.tool_input.file_path} was read successfully`
287
+ * }
288
+ * });
289
+ * });
290
+ * ```
291
+ * @see https://code.claude.com/docs/en/hooks#posttooluse
292
+ */
293
+ export declare function postToolUseHook<T extends KnownToolName>(config: TypedHookConfig<T>, handler: HookHandler<TypedPostToolUseHookInput<T>, PostToolUseOutput>): HookFunction<TypedPostToolUseHookInput<T>, PostToolUseOutput>;
294
+ export declare function postToolUseHook(config: HookConfig, handler: HookHandler<PostToolUseInput, PostToolUseOutput>): HookFunction<PostToolUseInput, PostToolUseOutput>;
295
+ /**
296
+ * Creates a PostToolUseFailure hook handler.
297
+ *
298
+ * PostToolUseFailure hooks fire after a tool execution fails, allowing you to:
299
+ * - Log or report tool failures
300
+ * - Add context about the failure
301
+ * - Take corrective action
302
+ *
303
+ * **Matcher**: Matches against `tool_name`
304
+ *
305
+ * **Typed Overload**: When the matcher is a single known tool name, the handler
306
+ * receives automatically typed `toolInput` based on the tool type.
307
+ * @param config - Hook configuration with optional matcher and timeout
308
+ * @param handler - The handler function to execute
309
+ * @returns A hook function that can be exported as the default export
310
+ * @example
311
+ * ```typescript
312
+ * import { postToolUseFailureHook, postToolUseFailureOutput } from '@goodfoot/agent-hooks/claude-code';
313
+ *
314
+ * // Log tool failures and suggest alternatives
315
+ * export default postToolUseFailureHook({ matcher: 'Bash' }, async (input, { logger }) => {
316
+ * // input.tool_input.command is typed as string
317
+ * logger.error('Bash command failed', {
318
+ * command: input.tool_input.command,
319
+ * error: input.error
320
+ * });
321
+ *
322
+ * return postToolUseFailureOutput({
323
+ * hookSpecificOutput: {
324
+ * additionalContext: 'Please try an alternative approach'
325
+ * }
326
+ * });
327
+ * });
328
+ * ```
329
+ * @see https://code.claude.com/docs/en/hooks#posttoolusefailure
330
+ */
331
+ export declare function postToolUseFailureHook<T extends KnownToolName>(config: TypedHookConfig<T>, handler: HookHandler<TypedPostToolUseFailureHookInput<T>, PostToolUseFailureOutput>): HookFunction<TypedPostToolUseFailureHookInput<T>, PostToolUseFailureOutput>;
332
+ export declare function postToolUseFailureHook(config: HookConfig, handler: HookHandler<PostToolUseFailureInput, PostToolUseFailureOutput>): HookFunction<PostToolUseFailureInput, PostToolUseFailureOutput>;
333
+ /**
334
+ * Creates a PostToolBatch hook handler.
335
+ *
336
+ * PostToolBatch hooks fire exactly once after every tool call in a batch has
337
+ * resolved, before the next model request. Unlike PostToolUse — which fires per
338
+ * tool and may run concurrently for parallel tool calls — PostToolBatch receives
339
+ * the full batch via `input.tool_calls`, allowing you to:
340
+ * - Inspect or summarize all tool calls in a single turn together
341
+ * - Inject additional context once per batch instead of once per tool
342
+ *
343
+ * **Matcher**: No matcher support - fires once per batch
344
+ * @param config - Hook configuration with optional timeout (matcher is ignored)
345
+ * @param handler - The handler function to execute
346
+ * @returns A hook function that can be exported as the default export
347
+ * @example
348
+ * ```typescript
349
+ * import { postToolBatchHook, postToolBatchOutput } from '@goodfoot/agent-hooks/claude-code';
350
+ *
351
+ * export default postToolBatchHook({}, async (input, { logger }) => {
352
+ * logger.info('Tool batch completed', { count: input.tool_calls.length });
353
+ *
354
+ * return postToolBatchOutput({
355
+ * hookSpecificOutput: {
356
+ * additionalContext: `Reviewed ${input.tool_calls.length} tool calls`
357
+ * }
358
+ * });
359
+ * });
360
+ * ```
361
+ * @see https://code.claude.com/docs/en/hooks#posttoolbatch
362
+ */
363
+ export declare function postToolBatchHook(config: HookConfig, handler: HookHandler<PostToolBatchInput, PostToolBatchOutput>): HookFunction<PostToolBatchInput, PostToolBatchOutput>;
364
+ /**
365
+ * Creates a Notification hook handler.
366
+ *
367
+ * Notification hooks fire when Claude Code sends a notification, allowing you to:
368
+ * - Forward notifications to external systems
369
+ * - Log important events
370
+ * - Trigger custom alerting
371
+ *
372
+ * **Matcher**: Matches against `notification_type`
373
+ * @param config - Hook configuration with optional matcher and timeout
374
+ * @param handler - The handler function to execute
375
+ * @returns A hook function that can be exported as the default export
376
+ * @example
377
+ * ```typescript
378
+ * import { notificationHook, notificationOutput } from '@goodfoot/agent-hooks/claude-code';
379
+ *
380
+ * // Forward notifications to Slack
381
+ * export default notificationHook({}, async (input, { logger }) => {
382
+ * logger.info('Notification received', {
383
+ * type: input.notification_type,
384
+ * title: input.title
385
+ * });
386
+ *
387
+ * await sendSlackMessage(input.title ?? 'Notification', input.message);
388
+ *
389
+ * return notificationOutput({});
390
+ * });
391
+ * ```
392
+ * @see https://code.claude.com/docs/en/hooks#notification
393
+ */
394
+ export declare function notificationHook(config: HookConfig, handler: HookHandler<NotificationInput, NotificationOutput>): HookFunction<NotificationInput, NotificationOutput>;
395
+ /**
396
+ * Creates a UserPromptSubmit hook handler.
397
+ *
398
+ * UserPromptSubmit hooks fire when a user submits a prompt, allowing you to:
399
+ * - Add additional context or instructions
400
+ * - Log user interactions
401
+ * - Validate or transform prompts
402
+ *
403
+ * **Matcher**: No matcher support - fires on all prompt submissions
404
+ * @param config - Hook configuration with optional timeout (matcher is ignored)
405
+ * @param handler - The handler function to execute
406
+ * @returns A hook function that can be exported as the default export
407
+ * @example
408
+ * ```typescript
409
+ * import { userPromptSubmitHook, userPromptSubmitOutput } from '@goodfoot/agent-hooks/claude-code';
410
+ *
411
+ * // Add project context to every prompt
412
+ * export default userPromptSubmitHook({}, async (input, { logger }) => {
413
+ * logger.debug('User prompt submitted', { promptLength: input.prompt.length });
414
+ *
415
+ * const projectContext = await getProjectContext();
416
+ *
417
+ * return userPromptSubmitOutput({
418
+ * additionalContext: projectContext
419
+ * });
420
+ * });
421
+ * ```
422
+ * @see https://code.claude.com/docs/en/hooks#userpromptsubmit
423
+ */
424
+ export declare function userPromptSubmitHook(config: HookConfig, handler: HookHandler<UserPromptSubmitInput, UserPromptSubmitOutput>): HookFunction<UserPromptSubmitInput, UserPromptSubmitOutput>;
425
+ /**
426
+ * Creates a UserPromptExpansion hook handler.
427
+ *
428
+ * UserPromptExpansion hooks fire when a user prompt is expanded from a slash
429
+ * command or MCP prompt, allowing you to:
430
+ * - Add context based on the command being invoked
431
+ * - Log slash command and MCP prompt usage
432
+ * - Observe prompt expansion events
433
+ *
434
+ * **Matcher**: No matcher support - fires on all prompt expansions
435
+ * @param config - Hook configuration with optional timeout (matcher is ignored)
436
+ * @param handler - The handler function to execute
437
+ * @returns A hook function that can be exported as the default export
438
+ * @example
439
+ * ```typescript
440
+ * import { userPromptExpansionHook, userPromptExpansionOutput } from '@goodfoot/agent-hooks/claude-code';
441
+ *
442
+ * // Add context when a slash command is invoked
443
+ * export default userPromptExpansionHook({}, async (input, { logger }) => {
444
+ * logger.debug('Prompt expanded', { type: input.expansion_type, command: input.command_name });
445
+ *
446
+ * return userPromptExpansionOutput({
447
+ * hookSpecificOutput: {
448
+ * additionalContext: `Command: ${input.command_name}`
449
+ * }
450
+ * });
451
+ * });
452
+ * ```
453
+ * @see https://code.claude.com/docs/en/hooks#userpromptexpansion
454
+ */
455
+ export declare function userPromptExpansionHook(config: HookConfig, handler: HookHandler<UserPromptExpansionInput, UserPromptExpansionOutput>): HookFunction<UserPromptExpansionInput, UserPromptExpansionOutput>;
456
+ /**
457
+ * Creates a SessionStart hook handler.
458
+ *
459
+ * SessionStart hooks fire when a Claude Code session starts or restarts,
460
+ * allowing you to:
461
+ * - Initialize session state
462
+ * - Inject context or instructions
463
+ * - Persist environment variables for subsequent bash commands
464
+ * - Set up logging or monitoring
465
+ *
466
+ * **Matcher**: Matches against `source` ('startup', 'resume', 'clear', 'compact')
467
+ *
468
+ * **Context**: SessionStart hooks receive an extended context with `persistEnvVar`
469
+ * and `persistEnvVars` functions for setting environment variables.
470
+ * @param config - Hook configuration with optional matcher and timeout
471
+ * @param handler - The handler function to execute
472
+ * @returns A hook function that can be exported as the default export
473
+ * @example
474
+ * ```typescript
475
+ * import { sessionStartHook, sessionStartOutput } from '@goodfoot/agent-hooks/claude-code';
476
+ *
477
+ * // Persist environment variables for the session
478
+ * export default sessionStartHook({ matcher: 'startup' }, async (input, { logger, persistEnvVar }) => {
479
+ * logger.info('New session started', {
480
+ * sessionId: input.session_id,
481
+ * cwd: input.cwd
482
+ * });
483
+ *
484
+ * // Set environment variables for all subsequent bash commands
485
+ * persistEnvVar('NODE_ENV', 'development');
486
+ * persistEnvVar('DEBUG', 'true');
487
+ *
488
+ * return sessionStartOutput({});
489
+ * });
490
+ * ```
491
+ * @example
492
+ * ```typescript
493
+ * // Set multiple environment variables at once
494
+ * export default sessionStartHook({}, async (input, { persistEnvVars }) => {
495
+ * persistEnvVars({
496
+ * NODE_ENV: 'production',
497
+ * API_KEY: 'secret',
498
+ * DEBUG: 'false'
499
+ * });
500
+ *
501
+ * return sessionStartOutput({});
502
+ * });
503
+ * ```
504
+ * @see https://code.claude.com/docs/en/hooks#sessionstart
505
+ */
506
+ export declare function sessionStartHook(config: HookConfig, handler: HookHandler<SessionStartInput, SessionStartOutput, SessionStartContext>): HookFunction<SessionStartInput, SessionStartOutput, SessionStartContext>;
507
+ /**
508
+ * Creates a SessionEnd hook handler.
509
+ *
510
+ * SessionEnd hooks fire when a Claude Code session ends, allowing you to:
511
+ * - Clean up session resources
512
+ * - Log session metrics
513
+ * - Persist session state
514
+ *
515
+ * **Matcher**: Matches against `reason` (the exit reason string)
516
+ * @param config - Hook configuration with optional matcher and timeout
517
+ * @param handler - The handler function to execute
518
+ * @returns A hook function that can be exported as the default export
519
+ * @example
520
+ * ```typescript
521
+ * import { sessionEndHook, sessionEndOutput } from '@goodfoot/agent-hooks/claude-code';
522
+ *
523
+ * // Log session end and clean up
524
+ * export default sessionEndHook({}, async (input, { logger }) => {
525
+ * logger.info('Session ended', {
526
+ * sessionId: input.session_id,
527
+ * reason: input.reason
528
+ * });
529
+ *
530
+ * await cleanupSessionResources(input.session_id);
531
+ *
532
+ * return sessionEndOutput({});
533
+ * });
534
+ * ```
535
+ * @see https://code.claude.com/docs/en/hooks#sessionend
536
+ */
537
+ export declare function sessionEndHook(config: HookConfig, handler: HookHandler<SessionEndInput, SessionEndOutput>): HookFunction<SessionEndInput, SessionEndOutput>;
538
+ /**
539
+ * Creates a Stop hook handler.
540
+ *
541
+ * Stop hooks fire when Claude Code is about to stop, allowing you to:
542
+ * - Block the stop and require additional action
543
+ * - Confirm the user wants to stop
544
+ * - Clean up resources before stopping
545
+ *
546
+ * **Matcher**: No matcher support - fires on all stop events
547
+ * @param config - Hook configuration with optional timeout (matcher is ignored)
548
+ * @param handler - The handler function to execute
549
+ * @returns A hook function that can be exported as the default export
550
+ * @example
551
+ * ```typescript
552
+ * import { stopHook, stopOutput } from '@goodfoot/agent-hooks/claude-code';
553
+ *
554
+ * // Block stop if there are pending changes
555
+ * export default stopHook({}, async (input, { logger }) => {
556
+ * const pendingChanges = await checkPendingChanges();
557
+ *
558
+ * if (pendingChanges.length > 0) {
559
+ * logger.warn('Blocking stop due to pending changes', {
560
+ * count: pendingChanges.length
561
+ * });
562
+ *
563
+ * return stopOutput({
564
+ * decision: 'block',
565
+ * reason: `There are ${pendingChanges.length} uncommitted changes`,
566
+ * systemMessage: 'Please commit or discard changes before stopping'
567
+ * });
568
+ * }
569
+ *
570
+ * logger.info('Approving stop');
571
+ * return stopOutput({ decision: 'approve' });
572
+ * });
573
+ * ```
574
+ * @see https://code.claude.com/docs/en/hooks#stop
575
+ */
576
+ export declare function stopHook(config: HookConfigFor<"Stop">, handler: HookHandler<StopInput, StopOutput>): HookFunction<StopInput, StopOutput>;
577
+ /**
578
+ * Creates a StopFailure hook handler.
579
+ *
580
+ * StopFailure hooks fire when Claude Code encounters an error while stopping
581
+ * (e.g., API errors, authentication failures, rate limits), allowing you to:
582
+ * - Log stop failure events and error details
583
+ * - Alert on unexpected session termination errors
584
+ * - Observe what error caused the failure
585
+ *
586
+ * **Matcher**: No matcher support - fires on all stop failure events
587
+ * @param config - Hook configuration with optional timeout (matcher is ignored)
588
+ * @param handler - The handler function to execute
589
+ * @returns A hook function that can be exported as the default export
590
+ * @example
591
+ * ```typescript
592
+ * import { stopFailureHook, stopFailureOutput } from '@goodfoot/agent-hooks/claude-code';
593
+ *
594
+ * export default stopFailureHook({}, async (input, { logger }) => {
595
+ * logger.error('Session stopped due to error', {
596
+ * error: input.error,
597
+ * details: input.error_details
598
+ * });
599
+ * return stopFailureOutput({});
600
+ * });
601
+ * ```
602
+ * @see https://code.claude.com/docs/en/hooks#stopfailure
603
+ */
604
+ export declare function stopFailureHook(config: HookConfig, handler: HookHandler<StopFailureInput, StopFailureOutput>): HookFunction<StopFailureInput, StopFailureOutput>;
605
+ /**
606
+ * Creates a SubagentStart hook handler.
607
+ *
608
+ * SubagentStart hooks fire when a subagent (Agent tool) starts, allowing you to:
609
+ * - Inject context for the subagent
610
+ * - Log subagent invocations
611
+ * - Configure subagent behavior
612
+ *
613
+ * **Matcher**: Matches against `agent_type` (e.g., 'explore', 'codebase-analysis')
614
+ * @param config - Hook configuration with optional matcher and timeout
615
+ * @param handler - The handler function to execute
616
+ * @returns A hook function that can be exported as the default export
617
+ * @example
618
+ * ```typescript
619
+ * import { subagentStartHook, subagentStartOutput } from '@goodfoot/agent-hooks/claude-code';
620
+ *
621
+ * // Add context for explore subagents
622
+ * export default subagentStartHook({ matcher: 'explore' }, async (input, { logger }) => {
623
+ * logger.info('Explore subagent starting', {
624
+ * agentId: input.agent_id,
625
+ * agentType: input.agent_type
626
+ * });
627
+ *
628
+ * return subagentStartOutput({
629
+ * additionalContext: 'Focus on finding patterns and conventions'
630
+ * });
631
+ * });
632
+ * ```
633
+ * @see https://code.claude.com/docs/en/hooks#subagentstart
634
+ */
635
+ export declare function subagentStartHook(config: HookConfig, handler: HookHandler<SubagentStartInput, SubagentStartOutput>): HookFunction<SubagentStartInput, SubagentStartOutput>;
636
+ /**
637
+ * Creates a SubagentStop hook handler.
638
+ *
639
+ * SubagentStop hooks fire when a subagent completes or stops, allowing you to:
640
+ * - Block the subagent from stopping
641
+ * - Process subagent results
642
+ * - Clean up subagent resources
643
+ * - Log subagent completion
644
+ *
645
+ * **Matcher**: Matches against `agent_type` (e.g., 'explore', 'codebase-analysis')
646
+ * @param config - Hook configuration with optional matcher and timeout
647
+ * @param handler - The handler function to execute
648
+ * @returns A hook function that can be exported as the default export
649
+ * @example
650
+ * ```typescript
651
+ * import { subagentStopHook, subagentStopOutput } from '@goodfoot/agent-hooks/claude-code';
652
+ *
653
+ * // Block explore subagents if task incomplete
654
+ * export default subagentStopHook({ matcher: 'explore' }, async (input, { logger }) => {
655
+ * logger.info('Subagent stopping', {
656
+ * agentId: input.agent_id,
657
+ * agentType: input.agent_type
658
+ * });
659
+ *
660
+ * // Block if transcript shows incomplete work
661
+ * return subagentStopOutput({
662
+ * decision: 'block',
663
+ * reason: 'Please verify exploration is complete'
664
+ * });
665
+ * });
666
+ * ```
667
+ * @see https://code.claude.com/docs/en/hooks#subagentstop
668
+ */
669
+ export declare function subagentStopHook(config: HookConfigFor<"SubagentStop">, handler: HookHandler<SubagentStopInput, SubagentStopOutput>): HookFunction<SubagentStopInput, SubagentStopOutput>;
670
+ /**
671
+ * Creates a PreCompact hook handler.
672
+ *
673
+ * PreCompact hooks fire before context compaction occurs, allowing you to:
674
+ * - Preserve important information before compaction
675
+ * - Log compaction events
676
+ * - Modify custom instructions for the compacted context
677
+ *
678
+ * **Matcher**: Matches against `trigger` ('manual', 'auto')
679
+ * @param config - Hook configuration with optional matcher and timeout
680
+ * @param handler - The handler function to execute
681
+ * @returns A hook function that can be exported as the default export
682
+ * @example
683
+ * ```typescript
684
+ * import { preCompactHook, preCompactOutput } from '@goodfoot/agent-hooks/claude-code';
685
+ *
686
+ * // Log compaction events and preserve context
687
+ * export default preCompactHook({}, async (input, { logger }) => {
688
+ * logger.info('Context compaction triggered', {
689
+ * trigger: input.trigger,
690
+ * hasCustomInstructions: input.custom_instructions !== null
691
+ * });
692
+ *
693
+ * return preCompactOutput({
694
+ * systemMessage: 'Remember: strict mode is enabled'
695
+ * });
696
+ * });
697
+ * ```
698
+ * @example
699
+ * ```typescript
700
+ * // Only handle manual compaction
701
+ * export default preCompactHook({ matcher: 'manual' }, async (input, { logger }) => {
702
+ * logger.info('Manual compaction requested');
703
+ * return preCompactOutput({});
704
+ * });
705
+ * ```
706
+ * @see https://code.claude.com/docs/en/hooks#precompact
707
+ */
708
+ export declare function preCompactHook(config: HookConfig, handler: HookHandler<PreCompactInput, PreCompactOutput>): HookFunction<PreCompactInput, PreCompactOutput>;
709
+ /**
710
+ * Creates a PostCompact hook handler.
711
+ *
712
+ * PostCompact hooks fire after context compaction completes, allowing you to:
713
+ * - Observe the compaction summary and details
714
+ * - Log compaction events
715
+ * - React to the new compacted state
716
+ *
717
+ * **Matcher**: Matches against `trigger` ('manual', 'auto')
718
+ * @param config - Hook configuration with optional matcher and timeout
719
+ * @param handler - The handler function to execute
720
+ * @returns A hook function that can be exported as the default export
721
+ * @example
722
+ * ```typescript
723
+ * import { postCompactHook, postCompactOutput } from '@goodfoot/agent-hooks/claude-code';
724
+ *
725
+ * export default postCompactHook({}, async (input, { logger }) => {
726
+ * logger.info('Context compaction completed', {
727
+ * trigger: input.trigger,
728
+ * summary: input.compact_summary
729
+ * });
730
+ * return postCompactOutput({});
731
+ * });
732
+ * ```
733
+ * @see https://code.claude.com/docs/en/hooks#postcompact
734
+ */
735
+ export declare function postCompactHook(config: HookConfig, handler: HookHandler<PostCompactInput, PostCompactOutput>): HookFunction<PostCompactInput, PostCompactOutput>;
736
+ /**
737
+ * Creates a PermissionRequest hook handler.
738
+ *
739
+ * PermissionRequest hooks fire when a permission prompt would be shown,
740
+ * allowing you to:
741
+ * - Auto-approve or deny tool executions
742
+ * - Implement custom permission logic
743
+ * - Modify tool inputs before approval
744
+ *
745
+ * **Matcher**: Matches against `tool_name`
746
+ *
747
+ * **Typed Overload**: When the matcher is a single known tool name, the handler
748
+ * receives automatically typed `toolInput` based on the tool type.
749
+ * @param config - Hook configuration with optional matcher and timeout
750
+ * @param handler - The handler function to execute
751
+ * @returns A hook function that can be exported as the default export
752
+ * @example
753
+ * ```typescript
754
+ * import { permissionRequestHook, permissionRequestOutput } from '@goodfoot/agent-hooks/claude-code';
755
+ *
756
+ * // Typed overload: tool_input is automatically typed as FileReadInput
757
+ * export default permissionRequestHook({ matcher: 'Read' }, async (input, { logger }) => {
758
+ * // input.tool_input.file_path is typed as string - no cast needed!
759
+ * if (input.tool_input.file_path.startsWith('/allowed/')) {
760
+ * logger.info('Auto-approving read in allowed directory', { filePath: input.tool_input.file_path });
761
+ * return permissionRequestOutput({
762
+ * hookSpecificOutput: { decision: { behavior: 'allow' } }
763
+ * });
764
+ * }
765
+ *
766
+ * // Fall through to normal permission prompt
767
+ * return permissionRequestOutput({});
768
+ * });
769
+ * ```
770
+ * @example
771
+ * ```typescript
772
+ * // Typed overload: tool_input is automatically typed as BashInput
773
+ * export default permissionRequestHook({ matcher: 'Bash' }, async (input, { logger }) => {
774
+ * // input.tool_input.command is typed as string - no cast needed!
775
+ * if (input.tool_input.command.includes('sudo')) {
776
+ * logger.warn('Denying sudo command', { command: input.tool_input.command });
777
+ * return permissionRequestOutput({
778
+ * hookSpecificOutput: {
779
+ * decision: {
780
+ * behavior: 'deny',
781
+ * message: 'sudo commands are not allowed',
782
+ * interrupt: true
783
+ * }
784
+ * }
785
+ * });
786
+ * }
787
+ *
788
+ * return permissionRequestOutput({});
789
+ * });
790
+ * ```
791
+ * @see https://code.claude.com/docs/en/hooks#permissionrequest
792
+ */
793
+ export declare function permissionRequestHook<T extends KnownToolName>(config: TypedHookConfigFor<T, "PermissionRequest">, handler: HookHandler<TypedPermissionRequestInput<T>, PermissionRequestOutput>): HookFunction<TypedPermissionRequestInput<T>, PermissionRequestOutput>;
794
+ export declare function permissionRequestHook(config: HookConfigFor<"PermissionRequest">, handler: HookHandler<PermissionRequestInput, PermissionRequestOutput>): HookFunction<PermissionRequestInput, PermissionRequestOutput>;
795
+ /**
796
+ * Creates a PermissionDenied hook handler.
797
+ *
798
+ * PermissionDenied hooks fire when a permission request is denied (either by the
799
+ * user or by a PermissionRequest hook), allowing you to:
800
+ * - Log permission denials for auditing
801
+ * - React to denied tool executions
802
+ * - Optionally request a retry via the output
803
+ *
804
+ * **Matcher**: Matches against `tool_name`
805
+ * @param config - Hook configuration with optional matcher and timeout
806
+ * @param handler - The handler function to execute
807
+ * @returns A hook function that can be exported as the default export
808
+ * @example
809
+ * ```typescript
810
+ * import { permissionDeniedHook, permissionDeniedOutput } from '@goodfoot/agent-hooks/claude-code';
811
+ *
812
+ * // Log all permission denials
813
+ * export default permissionDeniedHook({}, async (input, { logger }) => {
814
+ * logger.warn('Permission denied', {
815
+ * toolName: input.tool_name,
816
+ * reason: input.reason
817
+ * });
818
+ * return permissionDeniedOutput({});
819
+ * });
820
+ * ```
821
+ * @see https://code.claude.com/docs/en/hooks#permissiondenied
822
+ */
823
+ export declare function permissionDeniedHook(config: HookConfig, handler: HookHandler<PermissionDeniedInput, PermissionDeniedOutput>): HookFunction<PermissionDeniedInput, PermissionDeniedOutput>;
824
+ /**
825
+ * Creates a Setup hook handler.
826
+ *
827
+ * Setup hooks fire during initialization or maintenance, allowing you to:
828
+ * - Configure initial session state
829
+ * - Perform setup tasks before the session starts
830
+ * - Add context for maintenance operations
831
+ *
832
+ * **Matcher**: Matches against `trigger` ('init' or 'maintenance')
833
+ * @param config - Hook configuration with optional matcher and timeout
834
+ * @param handler - The handler function to execute
835
+ * @returns A hook function that can be exported as the default export
836
+ * @example
837
+ * ```typescript
838
+ * import { setupHook, setupOutput } from '@goodfoot/agent-hooks/claude-code';
839
+ *
840
+ * // Handle all setup events
841
+ * export default setupHook({}, async (input, { logger }) => {
842
+ * logger.info('Setup triggered', { trigger: input.trigger });
843
+ * return setupOutput({});
844
+ * });
845
+ *
846
+ * // Only handle initialization
847
+ * export default setupHook({ matcher: 'init' }, async (input, { logger }) => {
848
+ * logger.info('Initializing session');
849
+ * return setupOutput({
850
+ * hookSpecificOutput: {
851
+ * additionalContext: 'Session initialized with custom configuration'
852
+ * }
853
+ * });
854
+ * });
855
+ * ```
856
+ * @see https://code.claude.com/docs/en/hooks#setup
857
+ */
858
+ export declare function setupHook(config: HookConfig, handler: HookHandler<SetupInput, SetupOutput>): HookFunction<SetupInput, SetupOutput>;
859
+ /**
860
+ * Creates a TeammateIdle hook handler.
861
+ *
862
+ * TeammateIdle hooks fire when a teammate in a team is about to go idle,
863
+ * allowing you to:
864
+ * - Assign work to idle teammates
865
+ * - Log team activity
866
+ * - Coordinate multi-agent workflows
867
+ *
868
+ * **Matcher**: No matcher support - fires on all teammate idle events
869
+ * @param config - Hook configuration with optional timeout (matcher is ignored)
870
+ * @param handler - The handler function to execute
871
+ * @returns A hook function that can be exported as the default export
872
+ * @example
873
+ * ```typescript
874
+ * import { teammateIdleHook, teammateIdleOutput } from '@goodfoot/agent-hooks/claude-code';
875
+ *
876
+ * // Log when teammates go idle
877
+ * export default teammateIdleHook({}, async (input, { logger }) => {
878
+ * logger.info('Teammate going idle', {
879
+ * teammateName: input.teammate_name,
880
+ * teamName: input.team_name
881
+ * });
882
+ *
883
+ * return teammateIdleOutput({});
884
+ * });
885
+ * ```
886
+ * @see https://code.claude.com/docs/en/hooks#teammateidle
887
+ */
888
+ export declare function teammateIdleHook(config: HookConfig, handler: HookHandler<TeammateIdleInput, TeammateIdleOutput>): HookFunction<TeammateIdleInput, TeammateIdleOutput>;
889
+ /**
890
+ * Creates a TaskCreated hook handler.
891
+ *
892
+ * TaskCreated hooks fire when a new task is created and assigned to a teammate,
893
+ * allowing you to:
894
+ * - Observe task creation events
895
+ * - Log task assignments for auditing
896
+ * - React to new work being assigned
897
+ *
898
+ * **Matcher**: No matcher support - fires on all task creation events
899
+ * @param config - Hook configuration with optional timeout (matcher is ignored)
900
+ * @param handler - The handler function to execute
901
+ * @returns A hook function that can be exported as the default export
902
+ * @example
903
+ * ```typescript
904
+ * import { taskCreatedHook, taskCreatedOutput } from '@goodfoot/agent-hooks/claude-code';
905
+ *
906
+ * // Log task creation
907
+ * export default taskCreatedHook({}, async (input, { logger }) => {
908
+ * logger.info('Task created', {
909
+ * taskId: input.task_id,
910
+ * taskSubject: input.task_subject
911
+ * });
912
+ *
913
+ * return taskCreatedOutput({});
914
+ * });
915
+ * ```
916
+ * @see https://code.claude.com/docs/en/hooks#taskcreated
917
+ */
918
+ export declare function taskCreatedHook(config: HookConfig, handler: HookHandler<TaskCreatedInput, TaskCreatedOutput>): HookFunction<TaskCreatedInput, TaskCreatedOutput>;
919
+ /**
920
+ * Creates a TaskCompleted hook handler.
921
+ *
922
+ * TaskCompleted hooks fire when a task is being marked as completed,
923
+ * allowing you to:
924
+ * - Verify task completion
925
+ * - Log task metrics
926
+ * - Trigger follow-up actions
927
+ *
928
+ * **Matcher**: No matcher support - fires on all task completion events
929
+ * @param config - Hook configuration with optional timeout (matcher is ignored)
930
+ * @param handler - The handler function to execute
931
+ * @returns A hook function that can be exported as the default export
932
+ * @example
933
+ * ```typescript
934
+ * import { taskCompletedHook, taskCompletedOutput } from '@goodfoot/agent-hooks/claude-code';
935
+ *
936
+ * // Log task completion
937
+ * export default taskCompletedHook({}, async (input, { logger }) => {
938
+ * logger.info('Task completed', {
939
+ * taskId: input.task_id,
940
+ * taskSubject: input.task_subject
941
+ * });
942
+ *
943
+ * return taskCompletedOutput({});
944
+ * });
945
+ * ```
946
+ * @see https://code.claude.com/docs/en/hooks#taskcompleted
947
+ */
948
+ export declare function taskCompletedHook(config: HookConfig, handler: HookHandler<TaskCompletedInput, TaskCompletedOutput>): HookFunction<TaskCompletedInput, TaskCompletedOutput>;
949
+ /**
950
+ * Creates an Elicitation hook handler.
951
+ *
952
+ * Elicitation hooks fire when an MCP server requests user input, allowing you to:
953
+ * - Accept, decline, or cancel elicitation requests programmatically
954
+ * - Provide structured form input or URL-based auth responses
955
+ * - Log or audit elicitation requests
956
+ *
957
+ * **Matcher**: No matcher support - fires on all elicitation events
958
+ * @param config - Hook configuration with optional timeout
959
+ * @param handler - The handler function to execute
960
+ * @returns A hook function that can be exported as the default export
961
+ * @example
962
+ * ```typescript
963
+ * import { elicitationHook, elicitationOutput } from '@goodfoot/agent-hooks/claude-code';
964
+ *
965
+ * export default elicitationHook({}, async (input, { logger }) => {
966
+ * logger.info('Elicitation request', { server: input.mcp_server_name });
967
+ * return elicitationOutput({
968
+ * hookSpecificOutput: { action: 'accept', content: { approved: true } }
969
+ * });
970
+ * });
971
+ * ```
972
+ * @see https://code.claude.com/docs/en/hooks#elicitation
973
+ */
974
+ export declare function elicitationHook(config: HookConfig, handler: HookHandler<ElicitationInput, ElicitationOutput>): HookFunction<ElicitationInput, ElicitationOutput>;
975
+ /**
976
+ * Creates an ElicitationResult hook handler.
977
+ *
978
+ * ElicitationResult hooks fire with the result of an MCP elicitation request,
979
+ * allowing you to:
980
+ * - Observe elicitation outcomes
981
+ * - Modify the result before it is returned to the MCP server
982
+ * - Log elicitation completions
983
+ *
984
+ * **Matcher**: No matcher support - fires on all elicitation result events
985
+ * @param config - Hook configuration with optional timeout
986
+ * @param handler - The handler function to execute
987
+ * @returns A hook function that can be exported as the default export
988
+ * @example
989
+ * ```typescript
990
+ * import { elicitationResultHook, elicitationResultOutput } from '@goodfoot/agent-hooks/claude-code';
991
+ *
992
+ * export default elicitationResultHook({}, async (input, { logger }) => {
993
+ * logger.info('Elicitation result', { action: input.action });
994
+ * return elicitationResultOutput({});
995
+ * });
996
+ * ```
997
+ * @see https://code.claude.com/docs/en/hooks#elicitationresult
998
+ */
999
+ export declare function elicitationResultHook(config: HookConfig, handler: HookHandler<ElicitationResultInput, ElicitationResultOutput>): HookFunction<ElicitationResultInput, ElicitationResultOutput>;
1000
+ /**
1001
+ * Creates a ConfigChange hook handler.
1002
+ *
1003
+ * ConfigChange hooks fire when Claude Code configuration changes, allowing you to:
1004
+ * - React to settings file changes
1005
+ * - Log or audit configuration changes
1006
+ * - Apply custom logic when settings are updated
1007
+ *
1008
+ * **Matcher**: Matches against `source` ('user_settings', 'project_settings', etc.)
1009
+ * @param config - Hook configuration with optional matcher and timeout
1010
+ * @param handler - The handler function to execute
1011
+ * @returns A hook function that can be exported as the default export
1012
+ * @example
1013
+ * ```typescript
1014
+ * import { configChangeHook, configChangeOutput } from '@goodfoot/agent-hooks/claude-code';
1015
+ *
1016
+ * export default configChangeHook({}, async (input, { logger }) => {
1017
+ * logger.info('Config changed', { source: input.source, file: input.file_path });
1018
+ * return configChangeOutput({});
1019
+ * });
1020
+ * ```
1021
+ * @see https://code.claude.com/docs/en/hooks#configchange
1022
+ */
1023
+ export declare function configChangeHook(config: HookConfig, handler: HookHandler<ConfigChangeInput, ConfigChangeOutput>): HookFunction<ConfigChangeInput, ConfigChangeOutput>;
1024
+ /**
1025
+ * Creates an InstructionsLoaded hook handler.
1026
+ *
1027
+ * InstructionsLoaded hooks fire when a CLAUDE.md or similar instructions file
1028
+ * is loaded, allowing you to:
1029
+ * - React to instructions being applied
1030
+ * - Log which instruction files are active
1031
+ * - Observe the instruction loading hierarchy
1032
+ *
1033
+ * **Matcher**: No matcher support - fires on all instruction load events
1034
+ * @param config - Hook configuration with optional timeout
1035
+ * @param handler - The handler function to execute
1036
+ * @returns A hook function that can be exported as the default export
1037
+ * @example
1038
+ * ```typescript
1039
+ * import { instructionsLoadedHook, instructionsLoadedOutput } from '@goodfoot/agent-hooks/claude-code';
1040
+ *
1041
+ * export default instructionsLoadedHook({}, async (input, { logger }) => {
1042
+ * logger.info('Instructions loaded', { file: input.file_path, type: input.memory_type });
1043
+ * return instructionsLoadedOutput({});
1044
+ * });
1045
+ * ```
1046
+ * @see https://code.claude.com/docs/en/hooks#instructionsloaded
1047
+ */
1048
+ export declare function instructionsLoadedHook(config: HookConfig, handler: HookHandler<InstructionsLoadedInput, InstructionsLoadedOutput>): HookFunction<InstructionsLoadedInput, InstructionsLoadedOutput>;
1049
+ /**
1050
+ * Creates a WorktreeCreate hook handler.
1051
+ *
1052
+ * WorktreeCreate hooks fire when a git worktree is created, allowing you to:
1053
+ * - Set up worktree-specific configuration
1054
+ * - Log worktree creation events
1055
+ * - Initialize worktree resources
1056
+ *
1057
+ * **Matcher**: No matcher support - fires on all worktree creation events
1058
+ * @param config - Hook configuration with optional timeout
1059
+ * @param handler - The handler function to execute
1060
+ * @returns A hook function that can be exported as the default export
1061
+ * @example
1062
+ * ```typescript
1063
+ * import { worktreeCreateHook, worktreeCreateOutput } from '@goodfoot/agent-hooks/claude-code';
1064
+ *
1065
+ * export default worktreeCreateHook({}, async (input, { logger }) => {
1066
+ * const worktreePath = `${input.cwd}/.worktrees/${input.name}`;
1067
+ * logger.info('Worktree created', { name: input.name, worktreePath });
1068
+ * // WorktreeCreate is a command hook: the path is written to stdout as plain text.
1069
+ * return worktreeCreateOutput({ worktreePath });
1070
+ * });
1071
+ * ```
1072
+ * @see https://code.claude.com/docs/en/hooks#worktreecreate
1073
+ */
1074
+ export declare function worktreeCreateHook(config: HookConfigFor<"WorktreeCreate">, handler: HookHandler<WorktreeCreateInput, WorktreeCreateOutput>): HookFunction<WorktreeCreateInput, WorktreeCreateOutput>;
1075
+ /**
1076
+ * Creates a WorktreeRemove hook handler.
1077
+ *
1078
+ * WorktreeRemove hooks fire when a git worktree is removed, allowing you to:
1079
+ * - Clean up worktree-specific resources
1080
+ * - Log worktree removal events
1081
+ *
1082
+ * **Matcher**: No matcher support - fires on all worktree removal events
1083
+ * @param config - Hook configuration with optional timeout
1084
+ * @param handler - The handler function to execute
1085
+ * @returns A hook function that can be exported as the default export
1086
+ * @example
1087
+ * ```typescript
1088
+ * import { worktreeRemoveHook, worktreeRemoveOutput } from '@goodfoot/agent-hooks/claude-code';
1089
+ *
1090
+ * export default worktreeRemoveHook({}, async (input, { logger }) => {
1091
+ * logger.info('Worktree removed', { path: input.worktree_path });
1092
+ * return worktreeRemoveOutput({});
1093
+ * });
1094
+ * ```
1095
+ * @see https://code.claude.com/docs/en/hooks#worktreeremove
1096
+ */
1097
+ export declare function worktreeRemoveHook(config: HookConfigFor<"WorktreeRemove">, handler: HookHandler<WorktreeRemoveInput, WorktreeRemoveOutput>): HookFunction<WorktreeRemoveInput, WorktreeRemoveOutput>;
1098
+ /**
1099
+ * Creates a CwdChanged hook handler.
1100
+ *
1101
+ * CwdChanged hooks fire when Claude Code's current working directory changes,
1102
+ * allowing you to:
1103
+ * - React to directory changes within a session
1104
+ * - Update file watchers or environment state
1105
+ * - Return `watchPaths` via `hookSpecificOutput` to register paths for FileChanged events
1106
+ *
1107
+ * **Matcher**: No matcher support - fires on all cwd change events
1108
+ * @param config - Hook configuration with optional timeout
1109
+ * @param handler - The handler function to execute
1110
+ * @returns A hook function that can be exported as the default export
1111
+ * @example
1112
+ * ```typescript
1113
+ * import { cwdChangedHook, cwdChangedOutput } from '@goodfoot/agent-hooks/claude-code';
1114
+ *
1115
+ * export default cwdChangedHook({}, async (input, { logger }) => {
1116
+ * logger.info('Working directory changed', { from: input.old_cwd, to: input.new_cwd });
1117
+ * return cwdChangedOutput({});
1118
+ * });
1119
+ * ```
1120
+ * @see https://code.claude.com/docs/en/hooks#cwdchanged
1121
+ */
1122
+ export declare function cwdChangedHook(config: HookConfig, handler: HookHandler<CwdChangedInput, CwdChangedOutput>): HookFunction<CwdChangedInput, CwdChangedOutput>;
1123
+ /**
1124
+ * Creates a FileChanged hook handler.
1125
+ *
1126
+ * FileChanged hooks fire when a watched file changes on disk, allowing you to:
1127
+ * - React to file system changes during a session
1128
+ * - Invalidate caches or reload configuration
1129
+ * - Return `watchPaths` via `hookSpecificOutput` to update the set of watched paths
1130
+ *
1131
+ * The input `event` field indicates the type of change:
1132
+ * - `'change'` - File contents changed
1133
+ * - `'add'` - File was created
1134
+ * - `'unlink'` - File was deleted
1135
+ *
1136
+ * **Matcher**: No matcher support - fires on all file change events
1137
+ * @param config - Hook configuration with optional timeout
1138
+ * @param handler - The handler function to execute
1139
+ * @returns A hook function that can be exported as the default export
1140
+ * @example
1141
+ * ```typescript
1142
+ * import { fileChangedHook, fileChangedOutput } from '@goodfoot/agent-hooks/claude-code';
1143
+ *
1144
+ * export default fileChangedHook({}, async (input, { logger }) => {
1145
+ * logger.info('File changed', { path: input.file_path, event: input.event });
1146
+ * return fileChangedOutput({});
1147
+ * });
1148
+ * ```
1149
+ * @see https://code.claude.com/docs/en/hooks#filechanged
1150
+ */
1151
+ export declare function fileChangedHook(config: HookConfig, handler: HookHandler<FileChangedInput, FileChangedOutput>): HookFunction<FileChangedInput, FileChangedOutput>;
1152
+ /**
1153
+ * Creates a MessageDisplay hook handler.
1154
+ *
1155
+ * MessageDisplay hooks fire with each batch of newly completed lines while an
1156
+ * assistant message streams. Display-only: the stored message and what the model
1157
+ * sees are untouched. Allows you to:
1158
+ * - Replace the delta shown on screen with custom content via `displayContent`
1159
+ * - Observe and log message streaming events
1160
+ *
1161
+ * The input carries `turn_id`, `message_id`, `index`, `final`, and `delta` fields.
1162
+ * The `final` flag indicates the last flush of a message — its `delta` is empty
1163
+ * when the message ends on a newline; treat `final` as the end-of-message signal.
1164
+ *
1165
+ * **Matcher**: No matcher support - fires on all message display events
1166
+ * @param config - Hook configuration with optional timeout
1167
+ * @param handler - The handler function to execute
1168
+ * @returns A hook function that can be exported as the default export
1169
+ * @example
1170
+ * ```typescript
1171
+ * import { messageDisplayHook, messageDisplayOutput } from '@goodfoot/agent-hooks/claude-code';
1172
+ *
1173
+ * export default messageDisplayHook({}, async (input, { logger }) => {
1174
+ * if (input.final) {
1175
+ * logger.info('Message complete', { messageId: input.message_id });
1176
+ * }
1177
+ * return messageDisplayOutput({});
1178
+ * });
1179
+ * ```
1180
+ * @see https://code.claude.com/docs/en/hooks#messagedisplay
1181
+ */
1182
+ export declare function messageDisplayHook(config: HookConfig, handler: HookHandler<MessageDisplayInput, MessageDisplayOutput>): HookFunction<MessageDisplayInput, MessageDisplayOutput>;