@goodfoot/claude-code-hooks 1.0.11 → 1.0.16

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.
package/README.md CHANGED
@@ -107,7 +107,7 @@ npm test # Run tests
107
107
 
108
108
  ### Available Hook Types
109
109
 
110
- The `--hooks` argument accepts a comma-separated list of any of these 12 event types:
110
+ The `--hooks` argument accepts a comma-separated list of any of these 13 event types:
111
111
 
112
112
  | Hook Type | Description |
113
113
  | -------------------- | ------------------------------------------ |
@@ -123,6 +123,7 @@ The `--hooks` argument accepts a comma-separated list of any of these 12 event t
123
123
  | `SubagentStop` | When a Task tool completes |
124
124
  | `PreCompact` | Before context compaction |
125
125
  | `PermissionRequest` | When permission is requested |
126
+ | `Setup` | On init, install, or update events |
126
127
 
127
128
  Hook names are case-insensitive: `stop`, `Stop`, and `STOP` all work.
128
129
 
package/dist/cli.js CHANGED
@@ -691,6 +691,8 @@ function extractPreservedHooks(existingHooksJson) {
691
691
  const generatedFiles = new Set(existingHooksJson.__generated?.files ?? []);
692
692
  const preserved = {};
693
693
  for (const [eventType, entries] of Object.entries(existingHooksJson.hooks)) {
694
+ if (!entries)
695
+ continue;
694
696
  const preservedEntries = [];
695
697
  for (const entry of entries) {
696
698
  // Filter out hooks whose command matches a generated file
@@ -836,7 +838,7 @@ async function main() {
836
838
  preservedHooks = extractPreservedHooks(existingHooksJson);
837
839
  // Remove old generated files from disk
838
840
  removeOldGeneratedFiles(existingHooksJson, buildDir);
839
- const preservedCount = Object.values(preservedHooks).reduce((sum, entries) => sum + entries.reduce((s, e) => s + e.hooks.length, 0), 0);
841
+ const preservedCount = Object.values(preservedHooks).reduce((sum, entries) => sum + (entries?.reduce((s, e) => s + e.hooks.length, 0) ?? 0), 0);
840
842
  log("info", `Preserved ${preservedCount} hooks from other sources`);
841
843
  }
842
844
  // Compile all hooks
@@ -871,7 +873,7 @@ async function main() {
871
873
  // Output summary to stdout
872
874
  process.stdout.write(`Compiled ${compiledHooks.length} hooks to ${buildDir}\n`);
873
875
  if (Object.keys(preservedHooks).length > 0) {
874
- const preservedCount = Object.values(preservedHooks).reduce((sum, entries) => sum + entries.reduce((s, e) => s + e.hooks.length, 0), 0);
876
+ const preservedCount = Object.values(preservedHooks).reduce((sum, entries) => sum + (entries?.reduce((s, e) => s + e.hooks.length, 0) ?? 0), 0);
875
877
  process.stdout.write(`Preserved ${preservedCount} hooks from other sources\n`);
876
878
  }
877
879
  process.stdout.write(`Generated ${outputPath}\n`);
package/dist/constants.js CHANGED
@@ -18,4 +18,5 @@ export const HOOK_FACTORY_TO_EVENT = {
18
18
  subagentStopHook: "SubagentStop",
19
19
  preCompactHook: "PreCompact",
20
20
  permissionRequestHook: "PermissionRequest",
21
+ setupHook: "Setup",
21
22
  };
package/dist/hooks.js CHANGED
@@ -389,3 +389,43 @@ export function preCompactHook(config, handler) {
389
389
  export function permissionRequestHook(config, handler) {
390
390
  return createHookFunction("PermissionRequest", config, handler);
391
391
  }
392
+ // ============================================================================
393
+ // Setup Hook Factory
394
+ // ============================================================================
395
+ /**
396
+ * Creates a Setup hook handler.
397
+ *
398
+ * Setup hooks fire during initialization or maintenance, allowing you to:
399
+ * - Configure initial session state
400
+ * - Perform setup tasks before the session starts
401
+ * - Add context for maintenance operations
402
+ *
403
+ * **Matcher**: Matches against `trigger` ('init' or 'maintenance')
404
+ * @param config - Hook configuration with optional matcher and timeout
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 { setupHook, setupOutput } from '@goodfoot/claude-code-hooks';
410
+ *
411
+ * // Handle all setup events
412
+ * export default setupHook({}, async (input, { logger }) => {
413
+ * logger.info('Setup triggered', { trigger: input.trigger });
414
+ * return setupOutput({});
415
+ * });
416
+ *
417
+ * // Only handle initialization
418
+ * export default setupHook({ matcher: 'init' }, async (input, { logger }) => {
419
+ * logger.info('Initializing session');
420
+ * return setupOutput({
421
+ * hookSpecificOutput: {
422
+ * additionalContext: 'Session initialized with custom configuration'
423
+ * }
424
+ * });
425
+ * });
426
+ * ```
427
+ * @see https://code.claude.com/docs/en/hooks#setup
428
+ */
429
+ export function setupHook(config, handler) {
430
+ return createHookFunction("Setup", config, handler);
431
+ }
package/dist/index.js CHANGED
@@ -11,16 +11,16 @@ export {
11
11
  CLAUDE_ENV_VARS, getEnvFilePath,
12
12
  // Getters
13
13
  getProjectDir, isRemoteEnvironment, } from "./env.js";
14
- // Hook factory functions - all 12 hook types
15
- export { notificationHook, permissionRequestHook, postToolUseFailureHook, postToolUseHook, preCompactHook, preToolUseHook, sessionEndHook, sessionStartHook, stopHook, subagentStartHook, subagentStopHook, userPromptSubmitHook, } from "./hooks.js";
14
+ // Hook factory functions - all 13 hook types
15
+ export { notificationHook, permissionRequestHook, postToolUseFailureHook, postToolUseHook, preCompactHook, preToolUseHook, sessionEndHook, sessionStartHook, setupHook, stopHook, subagentStartHook, subagentStopHook, userPromptSubmitHook, } from "./hooks.js";
16
16
  // Logger exports
17
17
  export { LOG_LEVELS, Logger, logger } from "./logger.js";
18
18
  // Output builder functions
19
19
  export {
20
20
  // Exit codes
21
21
  EXIT_CODES, notificationOutput, permissionRequestOutput, postToolUseFailureOutput, postToolUseOutput, preCompactOutput,
22
- // All 12 output builder functions
23
- preToolUseOutput, sessionEndOutput, sessionStartOutput, stopOutput, subagentStartOutput, subagentStopOutput, userPromptSubmitOutput, } from "./outputs.js";
22
+ // All 13 output builder functions
23
+ preToolUseOutput, sessionEndOutput, sessionStartOutput, setupOutput, stopOutput, subagentStartOutput, subagentStopOutput, userPromptSubmitOutput, } from "./outputs.js";
24
24
  // Runtime exports - execute function
25
25
  export {
26
26
  // Main execute function for compiled hooks
package/dist/outputs.js CHANGED
@@ -279,3 +279,21 @@ export const preCompactOutput = /* @__PURE__ */ createSimpleOutputBuilder("PreCo
279
279
  * ```
280
280
  */
281
281
  export const permissionRequestOutput = /* @__PURE__ */ createHookSpecificOutputBuilder("PermissionRequest");
282
+ /**
283
+ * Creates an output for Setup hooks.
284
+ * @param options - Configuration options for the hook output
285
+ * @returns A SetupOutput object ready for the runtime
286
+ * @example
287
+ * ```typescript
288
+ * // Add context during setup
289
+ * setupOutput({
290
+ * hookSpecificOutput: {
291
+ * additionalContext: 'Project initialized with custom settings'
292
+ * }
293
+ * });
294
+ *
295
+ * // Simple passthrough
296
+ * setupOutput({});
297
+ * ```
298
+ */
299
+ export const setupOutput = /* @__PURE__ */ createHookSpecificOutputBuilder("Setup");
package/dist/scaffold.js CHANGED
@@ -49,6 +49,7 @@ const EVENT_TO_OUTPUT_FUNCTION = {
49
49
  SubagentStop: "subagentStopOutput",
50
50
  PreCompact: "preCompactOutput",
51
51
  PermissionRequest: "permissionRequestOutput",
52
+ Setup: "setupOutput",
52
53
  };
53
54
  // ============================================================================
54
55
  // Validation
@@ -116,7 +117,7 @@ function generatePackageJson(projectName, outputPath) {
116
117
  "@goodfoot/claude-code-hooks": "^1.0.9",
117
118
  },
118
119
  devDependencies: {
119
- "@biomejs/biome": "2.3.11",
120
+ "@biomejs/biome": "2.3.13",
120
121
  "@types/node": "^22.0.0",
121
122
  typescript: "^5.9.3",
122
123
  vitest: "^4.0.16",
@@ -159,7 +160,7 @@ function generateTsConfig() {
159
160
  */
160
161
  function generateBiomeConfig() {
161
162
  return `{
162
- "$schema": "https://biomejs.dev/schemas/2.3.11/schema.json",
163
+ "$schema": "https://biomejs.dev/schemas/2.3.13/schema.json",
163
164
  "formatter": {
164
165
  "enabled": true,
165
166
  "indentStyle": "space",
package/dist/types.js CHANGED
@@ -32,4 +32,5 @@ export const HOOK_EVENT_NAMES = [
32
32
  "SubagentStop",
33
33
  "PreCompact",
34
34
  "PermissionRequest",
35
+ "Setup",
35
36
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodfoot/claude-code-hooks",
3
- "version": "1.0.11",
3
+ "version": "1.0.16",
4
4
  "description": "Type-safe Claude Code hooks library with camelCase types and output builders",
5
5
  "homepage": "https://github.com/goodfoot-io/marketplace/tree/main/packages/claude-code-hooks",
6
6
  "repository": {
@@ -27,7 +27,9 @@
27
27
  "release": "bash ../../scripts/release-package.sh claude-code-hooks",
28
28
  "release:dry-run": "bash ../../scripts/release-package.sh claude-code-hooks --dry-run",
29
29
  "snapshot:sdk-types": "tsx scripts/snapshot-sdk-types.ts",
30
- "upgrade:deps": "./scripts/upgrade-deps.sh"
30
+ "upgrade:deps": "./scripts/upgrade-deps.sh",
31
+ "update:docs": "./scripts/update-docs.sh",
32
+ "update:docs:dry-run": "./scripts/update-docs.sh --dry-run"
31
33
  },
32
34
  "exports": {
33
35
  ".": {
@@ -51,8 +53,8 @@
51
53
  "typescript": "^5.9.3"
52
54
  },
53
55
  "devDependencies": {
54
- "@anthropic-ai/claude-agent-sdk": "^0.2.12",
55
- "@biomejs/biome": "2.3.11",
56
+ "@anthropic-ai/claude-agent-sdk": "^0.2.22",
57
+ "@biomejs/biome": "2.3.13",
56
58
  "@types/node": "^24",
57
59
  "ts-morph": "^25.0.0",
58
60
  "tsx": "^4.20.3",
package/types/hooks.d.ts CHANGED
@@ -22,8 +22,8 @@
22
22
  * @see https://code.claude.com/docs/en/hooks
23
23
  */
24
24
  import type { Logger } from "./logger.js";
25
- import type { NotificationOutput, PermissionRequestOutput, PostToolUseFailureOutput, PostToolUseOutput, PreCompactOutput, PreToolUseOutput, SessionEndOutput, SessionStartOutput, SpecificHookOutput, StopOutput, SubagentStartOutput, SubagentStopOutput, UserPromptSubmitOutput } from "./outputs.js";
26
- import type { HookEventName, KnownToolName, NotificationInput, PermissionRequestInput, PostToolUseFailureInput, PostToolUseInput, PreCompactInput, PreToolUseInput, SessionEndInput, SessionStartInput, StopInput, SubagentStartInput, SubagentStopInput, ToolInputMap, UserPromptSubmitInput } from "./types.js";
25
+ import type { NotificationOutput, PermissionRequestOutput, PostToolUseFailureOutput, PostToolUseOutput, PreCompactOutput, PreToolUseOutput, SessionEndOutput, SessionStartOutput, SetupOutput, SpecificHookOutput, StopOutput, SubagentStartOutput, SubagentStopOutput, UserPromptSubmitOutput } from "./outputs.js";
26
+ import type { HookEventName, KnownToolName, NotificationInput, PermissionRequestInput, PostToolUseFailureInput, PostToolUseInput, PreCompactInput, PreToolUseInput, SessionEndInput, SessionStartInput, SetupInput, StopInput, SubagentStartInput, SubagentStopInput, ToolInputMap, UserPromptSubmitInput } from "./types.js";
27
27
  /**
28
28
  * Configuration options for hook factories.
29
29
  *
@@ -763,3 +763,38 @@ export declare function preCompactHook(config: HookConfig, handler: HookHandler<
763
763
  */
764
764
  export declare function permissionRequestHook<T extends KnownToolName>(config: TypedHookConfig<T>, handler: HookHandler<TypedPermissionRequestInput<T>, PermissionRequestOutput>): HookFunction<TypedPermissionRequestInput<T>, PermissionRequestOutput>;
765
765
  export declare function permissionRequestHook(config: HookConfig, handler: HookHandler<PermissionRequestInput, PermissionRequestOutput>): HookFunction<PermissionRequestInput, PermissionRequestOutput>;
766
+ /**
767
+ * Creates a Setup hook handler.
768
+ *
769
+ * Setup hooks fire during initialization or maintenance, allowing you to:
770
+ * - Configure initial session state
771
+ * - Perform setup tasks before the session starts
772
+ * - Add context for maintenance operations
773
+ *
774
+ * **Matcher**: Matches against `trigger` ('init' or 'maintenance')
775
+ * @param config - Hook configuration with optional matcher and timeout
776
+ * @param handler - The handler function to execute
777
+ * @returns A hook function that can be exported as the default export
778
+ * @example
779
+ * ```typescript
780
+ * import { setupHook, setupOutput } from '@goodfoot/claude-code-hooks';
781
+ *
782
+ * // Handle all setup events
783
+ * export default setupHook({}, async (input, { logger }) => {
784
+ * logger.info('Setup triggered', { trigger: input.trigger });
785
+ * return setupOutput({});
786
+ * });
787
+ *
788
+ * // Only handle initialization
789
+ * export default setupHook({ matcher: 'init' }, async (input, { logger }) => {
790
+ * logger.info('Initializing session');
791
+ * return setupOutput({
792
+ * hookSpecificOutput: {
793
+ * additionalContext: 'Session initialized with custom configuration'
794
+ * }
795
+ * });
796
+ * });
797
+ * ```
798
+ * @see https://code.claude.com/docs/en/hooks#setup
799
+ */
800
+ export declare function setupHook(config: HookConfig, handler: HookHandler<SetupInput, SetupOutput>): HookFunction<SetupInput, SetupOutput>;
package/types/index.d.ts CHANGED
@@ -8,15 +8,15 @@
8
8
  export type * from "@anthropic-ai/claude-agent-sdk/sdk-tools.js";
9
9
  export { CLAUDE_ENV_VARS, getEnvFilePath, getProjectDir, isRemoteEnvironment, } from "./env.js";
10
10
  export type { HookConfig, HookContext, HookFunction, HookHandler, SessionStartContext, TypedHookConfig, TypedPermissionRequestInput, TypedPostToolUseFailureInput, TypedPostToolUseInput, TypedPreToolUseInput, } from "./hooks.js";
11
- export { notificationHook, permissionRequestHook, postToolUseFailureHook, postToolUseHook, preCompactHook, preToolUseHook, sessionEndHook, sessionStartHook, stopHook, subagentStartHook, subagentStopHook, userPromptSubmitHook, } from "./hooks.js";
11
+ export { notificationHook, permissionRequestHook, postToolUseFailureHook, postToolUseHook, preCompactHook, preToolUseHook, sessionEndHook, sessionStartHook, setupHook, stopHook, subagentStartHook, subagentStopHook, userPromptSubmitHook, } from "./hooks.js";
12
12
  export type { LogEvent, LogEventError, LogEventHandler, LoggerConfig, LogLevel, Unsubscribe } from "./logger.js";
13
13
  export { LOG_LEVELS, Logger, logger } from "./logger.js";
14
14
  export type {
15
15
  /** @deprecated Use CommonOptions instead */
16
- BaseOptions, CommonOptions, ExitCode, HookOutput, HookSpecificOutput, NotificationOptions, PermissionRequestAllowDecision, PermissionRequestDecision, PermissionRequestDenyDecision, PermissionRequestHookSpecificOutput, PermissionRequestOptions, PostToolUseFailureHookSpecificOutput, PostToolUseFailureOptions, PostToolUseHookSpecificOutput, PostToolUseOptions, PreCompactOptions, PreToolUseHookSpecificOutput, PreToolUseOptions, SessionEndOptions, SessionStartHookSpecificOutput, SessionStartOptions, StopOptions, SubagentStartHookSpecificOutput, SubagentStartOptions, SubagentStopOptions, SyncHookJSONOutput, UserPromptSubmitHookSpecificOutput, UserPromptSubmitOptions, } from "./outputs.js";
17
- export { EXIT_CODES, notificationOutput, permissionRequestOutput, postToolUseFailureOutput, postToolUseOutput, preCompactOutput, preToolUseOutput, sessionEndOutput, sessionStartOutput, stopOutput, subagentStartOutput, subagentStopOutput, userPromptSubmitOutput, } from "./outputs.js";
16
+ BaseOptions, CommonOptions, ExitCode, HookOutput, HookSpecificOutput, NotificationOptions, PermissionRequestAllowDecision, PermissionRequestDecision, PermissionRequestDenyDecision, PermissionRequestHookSpecificOutput, PermissionRequestOptions, PostToolUseFailureHookSpecificOutput, PostToolUseFailureOptions, PostToolUseHookSpecificOutput, PostToolUseOptions, PreCompactOptions, PreToolUseHookSpecificOutput, PreToolUseOptions, SessionEndOptions, SessionStartHookSpecificOutput, SessionStartOptions, SetupHookSpecificOutput, SetupOptions, StopOptions, SubagentStartHookSpecificOutput, SubagentStartOptions, SubagentStopOptions, SyncHookJSONOutput, UserPromptSubmitHookSpecificOutput, UserPromptSubmitOptions, } from "./outputs.js";
17
+ export { EXIT_CODES, notificationOutput, permissionRequestOutput, postToolUseFailureOutput, postToolUseOutput, preCompactOutput, preToolUseOutput, sessionEndOutput, sessionStartOutput, setupOutput, stopOutput, subagentStartOutput, subagentStopOutput, userPromptSubmitOutput, } from "./outputs.js";
18
18
  export { execute, } from "./runtime.js";
19
19
  export type { ContentContext, PatternCheckResult, ToolUseInput } from "./tool-helpers.js";
20
20
  export { checkContentForPattern, forEachContent, getFilePath, isAskUserQuestionTool, isBashTool, isEditTool, isExitPlanModeTool, isFileModifyingTool, isGlobTool, isGrepTool, isJsTsFile, isKillShellTool, isMultiEditTool, isNotebookEditTool, isReadTool, isTaskOutputTool, isTaskTool, isTodoWriteTool, isTsFile, isWebFetchTool, isWebSearchTool, isWriteTool, } from "./tool-helpers.js";
21
- export type { BaseHookInput, FileModifyingToolInput, FileModifyingToolName, HookEventName, HookInput, KnownToolInput, KnownToolName, MultiEditEntry, MultiEditToolInput, NotificationInput, PermissionMode, PermissionRequestInput, PermissionUpdate, PostToolUseFailureInput, PostToolUseInput, PreCompactInput, PreCompactTrigger, PreToolUseInput, SessionEndInput, SessionEndReason, SessionStartInput, SessionStartSource, StopInput, SubagentStartInput, SubagentStopInput, ToolInputMap, UserPromptSubmitInput, } from "./types.js";
21
+ export type { BaseHookInput, FileModifyingToolInput, FileModifyingToolName, HookEventName, HookInput, KnownToolInput, KnownToolName, MultiEditEntry, MultiEditToolInput, NotificationInput, PermissionMode, PermissionRequestInput, PermissionUpdate, PostToolUseFailureInput, PostToolUseInput, PreCompactInput, PreCompactTrigger, PreToolUseInput, SessionEndInput, SessionEndReason, SessionStartInput, SessionStartSource, SetupInput, SetupTrigger, StopInput, SubagentStartInput, SubagentStopInput, ToolInputMap, UserPromptSubmitInput, } from "./types.js";
22
22
  export { HOOK_EVENT_NAMES } from "./types.js";
@@ -7,7 +7,7 @@
7
7
  * @see https://code.claude.com/docs/en/hooks
8
8
  * @module
9
9
  */
10
- import type { PermissionRequestHookSpecificOutput as SDKPermissionRequestHookSpecificOutput, PostToolUseFailureHookSpecificOutput as SDKPostToolUseFailureHookSpecificOutput, PostToolUseHookSpecificOutput as SDKPostToolUseHookSpecificOutput, PreToolUseHookSpecificOutput as SDKPreToolUseHookSpecificOutput, SessionStartHookSpecificOutput as SDKSessionStartHookSpecificOutput, SubagentStartHookSpecificOutput as SDKSubagentStartHookSpecificOutput, SyncHookJSONOutput as SDKSyncHookJSONOutput, UserPromptSubmitHookSpecificOutput as SDKUserPromptSubmitHookSpecificOutput } from "@anthropic-ai/claude-agent-sdk/sdk.js";
10
+ import type { PermissionRequestHookSpecificOutput as SDKPermissionRequestHookSpecificOutput, PostToolUseFailureHookSpecificOutput as SDKPostToolUseFailureHookSpecificOutput, PostToolUseHookSpecificOutput as SDKPostToolUseHookSpecificOutput, PreToolUseHookSpecificOutput as SDKPreToolUseHookSpecificOutput, SessionStartHookSpecificOutput as SDKSessionStartHookSpecificOutput, SetupHookSpecificOutput as SDKSetupHookSpecificOutput, SubagentStartHookSpecificOutput as SDKSubagentStartHookSpecificOutput, SyncHookJSONOutput as SDKSyncHookJSONOutput, UserPromptSubmitHookSpecificOutput as SDKUserPromptSubmitHookSpecificOutput } from "@anthropic-ai/claude-agent-sdk/sdk.js";
11
11
  /**
12
12
  * Exit codes used by Claude Code hooks.
13
13
  *
@@ -36,7 +36,7 @@ export type { SDKSyncHookJSONOutput };
36
36
  /**
37
37
  * Re-export SDK hook-specific output types (includes hookEventName discriminator).
38
38
  */
39
- export type { SDKPreToolUseHookSpecificOutput, SDKPostToolUseHookSpecificOutput, SDKPostToolUseFailureHookSpecificOutput, SDKUserPromptSubmitHookSpecificOutput, SDKSessionStartHookSpecificOutput, SDKSubagentStartHookSpecificOutput, SDKPermissionRequestHookSpecificOutput, };
39
+ export type { SDKPreToolUseHookSpecificOutput, SDKPostToolUseHookSpecificOutput, SDKPostToolUseFailureHookSpecificOutput, SDKUserPromptSubmitHookSpecificOutput, SDKSessionStartHookSpecificOutput, SDKSetupHookSpecificOutput, SDKSubagentStartHookSpecificOutput, SDKPermissionRequestHookSpecificOutput, };
40
40
  /**
41
41
  * PreToolUse hook-specific output fields.
42
42
  * Omits `hookEventName` which is added automatically by the builder.
@@ -72,6 +72,11 @@ export type SubagentStartHookSpecificOutput = Omit<SDKSubagentStartHookSpecificO
72
72
  * Omits `hookEventName` which is added automatically by the builder.
73
73
  */
74
74
  export type PermissionRequestHookSpecificOutput = Omit<SDKPermissionRequestHookSpecificOutput, "hookEventName">;
75
+ /**
76
+ * Setup hook-specific output fields.
77
+ * Omits `hookEventName` which is added automatically by the builder.
78
+ */
79
+ export type SetupHookSpecificOutput = Omit<SDKSetupHookSpecificOutput, "hookEventName">;
75
80
  /**
76
81
  * Allow decision for permission requests.
77
82
  * Derived from SDK's PermissionRequestHookSpecificOutput.
@@ -102,7 +107,7 @@ export interface NotificationHookSpecificOutput {
102
107
  /**
103
108
  * Full hook-specific output with hookEventName discriminator.
104
109
  */
105
- export type HookSpecificOutput = SDKPreToolUseHookSpecificOutput | SDKPostToolUseHookSpecificOutput | SDKPostToolUseFailureHookSpecificOutput | SDKUserPromptSubmitHookSpecificOutput | SDKSessionStartHookSpecificOutput | SDKSubagentStartHookSpecificOutput | SDKPermissionRequestHookSpecificOutput | ({
110
+ export type HookSpecificOutput = SDKPreToolUseHookSpecificOutput | SDKPostToolUseHookSpecificOutput | SDKPostToolUseFailureHookSpecificOutput | SDKUserPromptSubmitHookSpecificOutput | SDKSessionStartHookSpecificOutput | SDKSetupHookSpecificOutput | SDKSubagentStartHookSpecificOutput | SDKPermissionRequestHookSpecificOutput | ({
106
111
  hookEventName: "Notification";
107
112
  } & NotificationHookSpecificOutput);
108
113
  /**
@@ -202,10 +207,14 @@ export type PreCompactOutput = BaseSpecificOutput<"PreCompact">;
202
207
  *
203
208
  */
204
209
  export type PermissionRequestOutput = BaseSpecificOutput<"PermissionRequest">;
210
+ /**
211
+ *
212
+ */
213
+ export type SetupOutput = BaseSpecificOutput<"Setup">;
205
214
  /**
206
215
  * Union of all specific output types.
207
216
  */
208
- export type SpecificHookOutput = PreToolUseOutput | PostToolUseOutput | PostToolUseFailureOutput | NotificationOutput | UserPromptSubmitOutput | SessionStartOutput | SessionEndOutput | StopOutput | SubagentStartOutput | SubagentStopOutput | PreCompactOutput | PermissionRequestOutput;
217
+ export type SpecificHookOutput = PreToolUseOutput | PostToolUseOutput | PostToolUseFailureOutput | NotificationOutput | UserPromptSubmitOutput | SessionStartOutput | SessionEndOutput | StopOutput | SubagentStartOutput | SubagentStopOutput | PreCompactOutput | PermissionRequestOutput | SetupOutput;
209
218
  /**
210
219
  * Options for decision-based hooks (Stop, SubagentStop).
211
220
  */
@@ -562,6 +571,36 @@ export declare const permissionRequestOutput: (options?: CommonOptions & {
562
571
  readonly _type: "PermissionRequest";
563
572
  stdout: SyncHookJSONOutput;
564
573
  };
574
+ /**
575
+ * Options for the Setup output builder.
576
+ */
577
+ export type SetupOptions = CommonOptions & {
578
+ /** Hook-specific output matching the wire format. */
579
+ hookSpecificOutput?: SetupHookSpecificOutput;
580
+ };
581
+ /**
582
+ * Creates an output for Setup hooks.
583
+ * @param options - Configuration options for the hook output
584
+ * @returns A SetupOutput object ready for the runtime
585
+ * @example
586
+ * ```typescript
587
+ * // Add context during setup
588
+ * setupOutput({
589
+ * hookSpecificOutput: {
590
+ * additionalContext: 'Project initialized with custom settings'
591
+ * }
592
+ * });
593
+ *
594
+ * // Simple passthrough
595
+ * setupOutput({});
596
+ * ```
597
+ */
598
+ export declare const setupOutput: (options?: CommonOptions & {
599
+ hookSpecificOutput?: SetupHookSpecificOutput | undefined;
600
+ }) => {
601
+ readonly _type: "Setup";
602
+ stdout: SyncHookJSONOutput;
603
+ };
565
604
  /**
566
605
  * @deprecated Use CommonOptions instead
567
606
  */
package/types/types.d.ts CHANGED
@@ -12,9 +12,9 @@
12
12
  * Re-exports types from @anthropic-ai/claude-agent-sdk with "SDK" prefix.
13
13
  * These are used as base types for extension, ensuring synchronization with the SDK.
14
14
  */
15
- export type { BaseHookInput as SDKBaseHookInput, HookEvent as SDKHookEvent, HookInput as SDKHookInput, NotificationHookInput as SDKNotificationHookInput, PermissionMode as SDKPermissionMode, PermissionRequestHookInput as SDKPermissionRequestHookInput, PermissionUpdate as SDKPermissionUpdate, PostToolUseFailureHookInput as SDKPostToolUseFailureHookInput, PostToolUseHookInput as SDKPostToolUseHookInput, PreCompactHookInput as SDKPreCompactHookInput, PreToolUseHookInput as SDKPreToolUseHookInput, SessionEndHookInput as SDKSessionEndHookInput, SessionStartHookInput as SDKSessionStartHookInput, StopHookInput as SDKStopHookInput, SubagentStartHookInput as SDKSubagentStartHookInput, SubagentStopHookInput as SDKSubagentStopHookInput, UserPromptSubmitHookInput as SDKUserPromptSubmitHookInput, } from "@anthropic-ai/claude-agent-sdk/entrypoints/agentSdkTypes.js";
16
- import type { BaseHookInput as SDKBaseHookInput, NotificationHookInput as SDKNotificationHookInput, PermissionMode as SDKPermissionMode, PermissionRequestHookInput as SDKPermissionRequestHookInput, PermissionUpdate as SDKPermissionUpdate, PostToolUseFailureHookInput as SDKPostToolUseFailureHookInput, PostToolUseHookInput as SDKPostToolUseHookInput, PreCompactHookInput as SDKPreCompactHookInput, PreToolUseHookInput as SDKPreToolUseHookInput, SessionEndHookInput as SDKSessionEndHookInput, SessionStartHookInput as SDKSessionStartHookInput, StopHookInput as SDKStopHookInput, SubagentStartHookInput as SDKSubagentStartHookInput, SubagentStopHookInput as SDKSubagentStopHookInput, UserPromptSubmitHookInput as SDKUserPromptSubmitHookInput } from "@anthropic-ai/claude-agent-sdk/entrypoints/agentSdkTypes.js";
17
- import type { AgentInput, AskUserQuestionInput, BashInput, ExitPlanModeInput, FileEditInput, FileReadInput, FileWriteInput, GlobInput, GrepInput, KillShellInput, NotebookEditInput, TaskOutputInput, TodoWriteInput, WebFetchInput, WebSearchInput } from "@anthropic-ai/claude-agent-sdk/sdk-tools.js";
15
+ export type { BaseHookInput as SDKBaseHookInput, HookEvent as SDKHookEvent, HookInput as SDKHookInput, NotificationHookInput as SDKNotificationHookInput, PermissionMode as SDKPermissionMode, PermissionRequestHookInput as SDKPermissionRequestHookInput, PermissionUpdate as SDKPermissionUpdate, PostToolUseFailureHookInput as SDKPostToolUseFailureHookInput, PostToolUseHookInput as SDKPostToolUseHookInput, PreCompactHookInput as SDKPreCompactHookInput, PreToolUseHookInput as SDKPreToolUseHookInput, SessionEndHookInput as SDKSessionEndHookInput, SessionStartHookInput as SDKSessionStartHookInput, SetupHookInput as SDKSetupHookInput, StopHookInput as SDKStopHookInput, SubagentStartHookInput as SDKSubagentStartHookInput, SubagentStopHookInput as SDKSubagentStopHookInput, UserPromptSubmitHookInput as SDKUserPromptSubmitHookInput, } from "@anthropic-ai/claude-agent-sdk";
16
+ import type { BaseHookInput as SDKBaseHookInput, NotificationHookInput as SDKNotificationHookInput, PermissionMode as SDKPermissionMode, PermissionRequestHookInput as SDKPermissionRequestHookInput, PermissionUpdate as SDKPermissionUpdate, PostToolUseFailureHookInput as SDKPostToolUseFailureHookInput, PostToolUseHookInput as SDKPostToolUseHookInput, PreCompactHookInput as SDKPreCompactHookInput, PreToolUseHookInput as SDKPreToolUseHookInput, SessionEndHookInput as SDKSessionEndHookInput, SessionStartHookInput as SDKSessionStartHookInput, SetupHookInput as SDKSetupHookInput, StopHookInput as SDKStopHookInput, SubagentStartHookInput as SDKSubagentStartHookInput, SubagentStopHookInput as SDKSubagentStopHookInput, UserPromptSubmitHookInput as SDKUserPromptSubmitHookInput } from "@anthropic-ai/claude-agent-sdk";
17
+ import type { AgentInput, AskUserQuestionInput, BashInput, ExitPlanModeInput, FileEditInput, FileReadInput, FileWriteInput, GlobInput, GrepInput, TaskStopInput as KillShellInput, NotebookEditInput, TaskOutputInput, TodoWriteInput, WebFetchInput, WebSearchInput } from "@anthropic-ai/claude-agent-sdk/sdk-tools.js";
18
18
  /**
19
19
  * Permission mode for controlling how tool executions are handled.
20
20
  * @see https://code.claude.com/docs/en/hooks#permission-modes
@@ -364,6 +364,39 @@ export interface PermissionRequestInput extends SDKPermissionRequestHookInput {
364
364
  */
365
365
  tool_use_id: string;
366
366
  }
367
+ /**
368
+ * Trigger type for Setup hooks.
369
+ */
370
+ export type SetupTrigger = "init" | "maintenance";
371
+ /**
372
+ * Input for Setup hooks.
373
+ *
374
+ * Fires during initialization or maintenance, allowing you to:
375
+ * - Configure initial session state
376
+ * - Perform setup tasks before the session starts
377
+ * - Add context for maintenance operations
378
+ *
379
+ * This hook uses `trigger` for matcher matching.
380
+ * @example
381
+ * ```typescript
382
+ * // Log setup events
383
+ * setupHook({}, async (input: SetupInput) => {
384
+ * console.log(`Setup triggered by: ${input.trigger}`);
385
+ * return setupOutput({});
386
+ * });
387
+ *
388
+ * // Only handle init triggers
389
+ * setupHook({ matcher: 'init' }, async (input: SetupInput) => {
390
+ * return setupOutput({
391
+ * hookSpecificOutput: {
392
+ * additionalContext: 'Initial setup complete'
393
+ * }
394
+ * });
395
+ * });
396
+ * ```
397
+ * @see https://code.claude.com/docs/en/hooks#setup
398
+ */
399
+ export type SetupInput = SDKSetupHookInput;
367
400
  /**
368
401
  * Discriminated union of all hook input types.
369
402
  *
@@ -388,7 +421,7 @@ export interface PermissionRequestInput extends SDKPermissionRequestHookInput {
388
421
  * ```
389
422
  * @see https://code.claude.com/docs/en/hooks
390
423
  */
391
- export type HookInput = PreToolUseInput | PostToolUseInput | PostToolUseFailureInput | NotificationInput | UserPromptSubmitInput | SessionStartInput | SessionEndInput | StopInput | SubagentStartInput | SubagentStopInput | PreCompactInput | PermissionRequestInput;
424
+ export type HookInput = PreToolUseInput | PostToolUseInput | PostToolUseFailureInput | NotificationInput | UserPromptSubmitInput | SessionStartInput | SessionEndInput | StopInput | SubagentStartInput | SubagentStopInput | PreCompactInput | PermissionRequestInput | SetupInput;
392
425
  /**
393
426
  * Hook event name literal union.
394
427
  *
@@ -406,7 +439,7 @@ export type HookEventName = HookInput["hook_event_name"];
406
439
  * }
407
440
  * ```
408
441
  */
409
- export declare const HOOK_EVENT_NAMES: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest"];
442
+ export declare const HOOK_EVENT_NAMES: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest", "Setup"];
410
443
  export type { SDKPermissionUpdate as PermissionUpdate };
411
444
  /**
412
445
  * Re-export all tool input types from the official Claude Agent SDK.
@@ -414,6 +447,11 @@ export type { SDKPermissionUpdate as PermissionUpdate };
414
447
  * @see {@link https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk | @anthropic-ai/claude-agent-sdk}
415
448
  */
416
449
  export type * from "@anthropic-ai/claude-agent-sdk/sdk-tools.js";
450
+ /**
451
+ * Backward compatibility alias for TaskStopInput (renamed in SDK 0.2.x).
452
+ * @deprecated Use TaskStopInput instead
453
+ */
454
+ export type { KillShellInput };
417
455
  /**
418
456
  * A single edit entry within a MultiEdit operation.
419
457
  */
package/types/inputs.d.ts DELETED
@@ -1,601 +0,0 @@
1
- /**
2
- * Input types for Claude Code hooks using wire format (snake_case).
3
- *
4
- * These types match the JSON format that Claude Code sends via stdin. Property names
5
- * use snake_case to match the wire protocol directly without transformation overhead.
6
- * Each hook input type includes comprehensive JSDoc documentation explaining when
7
- * the hook fires and how to use it.
8
- * @see https://code.claude.com/docs/en/hooks
9
- * @module
10
- */
11
- import type { PermissionUpdate } from '@anthropic-ai/claude-agent-sdk/entrypoints/agentSdkTypes.js';
12
- /**
13
- * Permission mode for controlling how tool executions are handled.
14
- * @see https://code.claude.com/docs/en/hooks#permission-modes
15
- */
16
- export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan' | 'delegate' | 'dontAsk';
17
- /**
18
- * Source that triggered a session start event.
19
- *
20
- * - `'startup'` - New session started from scratch
21
- * - `'resume'` - Resuming a previous session
22
- * - `'clear'` - Session cleared and restarted
23
- * - `'compact'` - Session restarted after context compaction
24
- */
25
- export type SessionStartSource = 'startup' | 'resume' | 'clear' | 'compact';
26
- /**
27
- * Trigger type for pre-compact events.
28
- *
29
- * - `'manual'` - User explicitly requested compaction
30
- * - `'auto'` - Automatic compaction due to context length
31
- */
32
- export type PreCompactTrigger = 'manual' | 'auto';
33
- /**
34
- * Reason for session end events.
35
- *
36
- * - `'clear'` - Session cleared by user
37
- * - `'logout'` - User logged out
38
- * - `'prompt_input_exit'` - User exited at prompt input
39
- * - `'other'` - Other reasons
40
- */
41
- export type SessionEndReason = 'clear' | 'logout' | 'prompt_input_exit' | 'other';
42
- /**
43
- * Common fields present in all hook inputs.
44
- *
45
- * Every hook receives these base fields providing session context.
46
- * Hook-specific inputs extend this base with additional fields.
47
- * @example
48
- * ```typescript
49
- * // All hook inputs include these fields
50
- * const handleAnyHook = (input: BaseHookInput) => {
51
- * console.log(`Session: ${input.session_id}`);
52
- * console.log(`Working directory: ${input.cwd}`);
53
- * console.log(`Transcript: ${input.transcript_path}`);
54
- * };
55
- * ```
56
- * @see https://code.claude.com/docs/en/hooks#hook-input-structure
57
- */
58
- export interface BaseHookInput {
59
- /**
60
- * Unique identifier for the current Claude Code session.
61
- * Persists across conversation turns within the same session.
62
- */
63
- session_id: string;
64
- /**
65
- * Absolute path to the session transcript file.
66
- * Contains the full conversation history in JSONL format.
67
- */
68
- transcript_path: string;
69
- /**
70
- * Current working directory for the Claude Code session.
71
- * All file operations are relative to this directory.
72
- */
73
- cwd: string;
74
- /**
75
- * Current permission mode for tool execution.
76
- * May be undefined if using default mode.
77
- */
78
- permission_mode?: PermissionMode;
79
- }
80
- /**
81
- * Input for PreToolUse hooks.
82
- *
83
- * Fires before any tool is executed, allowing you to:
84
- * - Inspect and validate tool inputs
85
- * - Allow, deny, or modify the tool execution
86
- * - Add custom permission logic
87
- *
88
- * This hook uses `tool_name` for matcher matching.
89
- * @example
90
- * ```typescript
91
- * // Block dangerous Bash commands
92
- * preToolUseHook({ matcher: 'Bash' }, async (input: PreToolUseInput) => {
93
- * const command = input.tool_input.command as string;
94
- * if (command.includes('rm -rf')) {
95
- * return preToolUseOutput({
96
- * deny: 'Destructive commands are not allowed'
97
- * });
98
- * }
99
- * return preToolUseOutput({ allow: true });
100
- * });
101
- * ```
102
- * @see https://code.claude.com/docs/en/hooks#pretooluse
103
- */
104
- export interface PreToolUseInput extends BaseHookInput {
105
- /** Discriminator for hook event type. */
106
- hook_event_name: 'PreToolUse';
107
- /**
108
- * Name of the tool being invoked.
109
- * Examples: 'Bash', 'Read', 'Edit', 'Write', 'Glob', 'Grep'
110
- */
111
- tool_name: string;
112
- /**
113
- * Input parameters being passed to the tool.
114
- * Structure varies by tool type.
115
- */
116
- tool_input: unknown;
117
- /**
118
- * Unique identifier for this specific tool invocation.
119
- * Use this to correlate with PostToolUse events.
120
- */
121
- tool_use_id: string;
122
- }
123
- /**
124
- * Input for PostToolUse hooks.
125
- *
126
- * Fires after a tool executes successfully, allowing you to:
127
- * - Inspect tool results
128
- * - Add additional context to the conversation
129
- * - Modify MCP tool output
130
- *
131
- * This hook uses `tool_name` for matcher matching.
132
- * @example
133
- * ```typescript
134
- * // Add context after file reads
135
- * postToolUseHook({ matcher: 'Read' }, async (input: PostToolUseInput) => {
136
- * const filePath = input.tool_input.file_path as string;
137
- * return postToolUseOutput({
138
- * additionalContext: `File ${filePath} was read successfully`
139
- * });
140
- * });
141
- * ```
142
- * @see https://code.claude.com/docs/en/hooks#posttooluse
143
- */
144
- export interface PostToolUseInput extends BaseHookInput {
145
- /** Discriminator for hook event type. */
146
- hook_event_name: 'PostToolUse';
147
- /**
148
- * Name of the tool that was invoked.
149
- */
150
- tool_name: string;
151
- /**
152
- * Input parameters that were passed to the tool.
153
- */
154
- tool_input: unknown;
155
- /**
156
- * Response returned by the tool.
157
- * Structure varies by tool type.
158
- */
159
- tool_response: unknown;
160
- /**
161
- * Unique identifier for this tool invocation.
162
- * Matches the tool_use_id from the corresponding PreToolUse event.
163
- */
164
- tool_use_id: string;
165
- }
166
- /**
167
- * Input for PostToolUseFailure hooks.
168
- *
169
- * Fires after a tool execution fails, allowing you to:
170
- * - Log or report tool failures
171
- * - Add context about the failure
172
- * - Take corrective action
173
- *
174
- * This hook uses `tool_name` for matcher matching.
175
- * @example
176
- * ```typescript
177
- * // Log tool failures
178
- * postToolUseFailureHook({ matcher: '.*' }, async (input: PostToolUseFailureInput) => {
179
- * console.error(`Tool ${input.tool_name} failed: ${input.error}`);
180
- * return postToolUseFailureOutput({
181
- * additionalContext: 'Please try an alternative approach'
182
- * });
183
- * });
184
- * ```
185
- * @see https://code.claude.com/docs/en/hooks#posttoolusefailure
186
- */
187
- export interface PostToolUseFailureInput extends BaseHookInput {
188
- /** Discriminator for hook event type. */
189
- hook_event_name: 'PostToolUseFailure';
190
- /**
191
- * Name of the tool that failed.
192
- */
193
- tool_name: string;
194
- /**
195
- * Input parameters that were passed to the tool.
196
- */
197
- tool_input: unknown;
198
- /**
199
- * Unique identifier for this tool invocation.
200
- */
201
- tool_use_id: string;
202
- /**
203
- * Error message describing why the tool failed.
204
- */
205
- error: string;
206
- /**
207
- * Whether this failure was caused by a user interrupt.
208
- */
209
- is_interrupt?: boolean;
210
- }
211
- /**
212
- * Input for Notification hooks.
213
- *
214
- * Fires when Claude Code sends a notification, allowing you to:
215
- * - Forward notifications to external systems
216
- * - Log important events
217
- * - Trigger custom alerting
218
- *
219
- * This hook uses `notification_type` for matcher matching.
220
- * @example
221
- * ```typescript
222
- * // Forward notifications to Slack
223
- * notificationHook({}, async (input: NotificationInput) => {
224
- * await sendSlackMessage(input.title, input.message);
225
- * return notificationOutput({});
226
- * });
227
- * ```
228
- * @see https://code.claude.com/docs/en/hooks#notification
229
- */
230
- export interface NotificationInput extends BaseHookInput {
231
- /** Discriminator for hook event type. */
232
- hook_event_name: 'Notification';
233
- /**
234
- * Main content of the notification.
235
- */
236
- message: string;
237
- /**
238
- * Optional title for the notification.
239
- */
240
- title?: string;
241
- /**
242
- * Type/category of the notification.
243
- */
244
- notification_type: string;
245
- }
246
- /**
247
- * Input for UserPromptSubmit hooks.
248
- *
249
- * Fires when a user submits a prompt, allowing you to:
250
- * - Add additional context or instructions
251
- * - Log user interactions
252
- * - Validate or transform prompts
253
- *
254
- * This hook does not support matchers; it fires on all prompt submissions.
255
- * @example
256
- * ```typescript
257
- * // Add project context to every prompt
258
- * userPromptSubmitHook({}, async (input: UserPromptSubmitInput) => {
259
- * return userPromptSubmitOutput({
260
- * additionalContext: await getProjectContext()
261
- * });
262
- * });
263
- * ```
264
- * @see https://code.claude.com/docs/en/hooks#userpromptsubmit
265
- */
266
- export interface UserPromptSubmitInput extends BaseHookInput {
267
- /** Discriminator for hook event type. */
268
- hook_event_name: 'UserPromptSubmit';
269
- /**
270
- * The prompt text submitted by the user.
271
- */
272
- prompt: string;
273
- }
274
- /**
275
- * Input for SessionStart hooks.
276
- *
277
- * Fires when a Claude Code session starts or restarts, allowing you to:
278
- * - Initialize session state
279
- * - Inject context or instructions
280
- * - Set up logging or monitoring
281
- *
282
- * This hook uses `source` for matcher matching.
283
- * @example
284
- * ```typescript
285
- * // Initialize context for new sessions
286
- * sessionStartHook({ matcher: 'startup' }, async (input: SessionStartInput) => {
287
- * return sessionStartOutput({
288
- * additionalContext: JSON.stringify({
289
- * project: 'my-project',
290
- * initialized: true
291
- * })
292
- * });
293
- * });
294
- * ```
295
- * @see https://code.claude.com/docs/en/hooks#sessionstart
296
- */
297
- export interface SessionStartInput extends BaseHookInput {
298
- /** Discriminator for hook event type. */
299
- hook_event_name: 'SessionStart';
300
- /**
301
- * How the session was started.
302
- *
303
- * - `'startup'` - New session started from scratch
304
- * - `'resume'` - Resuming a previous session
305
- * - `'clear'` - Session cleared and restarted
306
- * - `'compact'` - Session restarted after context compaction
307
- */
308
- source: SessionStartSource;
309
- }
310
- /**
311
- * Input for SessionEnd hooks.
312
- *
313
- * Fires when a Claude Code session ends, allowing you to:
314
- * - Clean up session resources
315
- * - Log session metrics
316
- * - Persist session state
317
- *
318
- * This hook uses `reason` for matcher matching.
319
- * @example
320
- * ```typescript
321
- * // Log session end
322
- * sessionEndHook({}, async (input: SessionEndInput) => {
323
- * console.log(`Session ended: ${input.reason}`);
324
- * return sessionEndOutput({});
325
- * });
326
- * ```
327
- * @see https://code.claude.com/docs/en/hooks#sessionend
328
- */
329
- export interface SessionEndInput extends BaseHookInput {
330
- /** Discriminator for hook event type. */
331
- hook_event_name: 'SessionEnd';
332
- /**
333
- * The reason the session ended.
334
- *
335
- * - `'clear'` - Session cleared by user
336
- * - `'logout'` - User logged out
337
- * - `'prompt_input_exit'` - User exited at prompt input
338
- * - `'other'` - Other reasons
339
- */
340
- reason: SessionEndReason;
341
- }
342
- /**
343
- * Input for Stop hooks.
344
- *
345
- * Fires when Claude Code is about to stop, allowing you to:
346
- * - Block the stop and require additional action
347
- * - Confirm the user wants to stop
348
- * - Clean up resources before stopping
349
- *
350
- * This hook does not support matchers; it fires on all stop events.
351
- * @example
352
- * ```typescript
353
- * // Require confirmation before stopping with pending changes
354
- * stopHook({}, async (input: StopInput) => {
355
- * const pendingChanges = await checkPendingChanges();
356
- * if (pendingChanges.length > 0) {
357
- * return stopOutput({
358
- * decision: 'block',
359
- * reason: 'There are uncommitted changes'
360
- * });
361
- * }
362
- * return stopOutput({ decision: 'approve' });
363
- * });
364
- * ```
365
- * @see https://code.claude.com/docs/en/hooks#stop
366
- */
367
- export interface StopInput extends BaseHookInput {
368
- /** Discriminator for hook event type. */
369
- hook_event_name: 'Stop';
370
- /**
371
- * Whether a stop hook is currently active.
372
- * Used to prevent recursive stop hook invocations.
373
- */
374
- stop_hook_active: boolean;
375
- }
376
- /**
377
- * Input for SubagentStart hooks.
378
- *
379
- * Fires when a subagent (Task tool) starts, allowing you to:
380
- * - Inject context for the subagent
381
- * - Log subagent invocations
382
- * - Configure subagent behavior
383
- *
384
- * This hook uses `agent_type` for matcher matching.
385
- * @example
386
- * ```typescript
387
- * // Add context for explore subagents
388
- * subagentStartHook({ matcher: 'explore' }, async (input: SubagentStartInput) => {
389
- * return subagentStartOutput({
390
- * additionalContext: 'Focus on finding patterns and conventions'
391
- * });
392
- * });
393
- * ```
394
- * @see https://code.claude.com/docs/en/hooks#subagentstart
395
- */
396
- export interface SubagentStartInput extends BaseHookInput {
397
- /** Discriminator for hook event type. */
398
- hook_event_name: 'SubagentStart';
399
- /**
400
- * Unique identifier for the subagent instance.
401
- */
402
- agent_id: string;
403
- /**
404
- * Type of subagent being started.
405
- * Examples: 'explore', 'codebase-analysis', custom agent types
406
- */
407
- agent_type: string;
408
- }
409
- /**
410
- * Input for SubagentStop hooks.
411
- *
412
- * Fires when a subagent completes or stops, allowing you to:
413
- * - Process subagent results
414
- * - Clean up subagent resources
415
- * - Log subagent completion
416
- * - Block subagent from stopping
417
- *
418
- * This hook uses `agent_type` for matcher matching.
419
- * @example
420
- * ```typescript
421
- * // Block explore subagent if task incomplete
422
- * subagentStopHook({ matcher: 'explore' }, async (input: SubagentStopInput) => {
423
- * console.log(`Subagent ${input.agent_id} (${input.agent_type}) stopping`);
424
- * return subagentStopOutput({
425
- * decision: 'block',
426
- * reason: 'Please verify all files were explored'
427
- * });
428
- * });
429
- * ```
430
- * @see https://code.claude.com/docs/en/hooks#subagentstop
431
- */
432
- export interface SubagentStopInput extends BaseHookInput {
433
- /** Discriminator for hook event type. */
434
- hook_event_name: 'SubagentStop';
435
- /**
436
- * Whether a stop hook is currently active.
437
- */
438
- stop_hook_active: boolean;
439
- /**
440
- * Unique identifier for the subagent instance.
441
- */
442
- agent_id: string;
443
- /**
444
- * Type of subagent that is stopping.
445
- * Examples: 'explore', 'codebase-analysis', custom agent types
446
- */
447
- agent_type: string;
448
- /**
449
- * Path to the subagent's transcript file.
450
- */
451
- agent_transcript_path: string;
452
- }
453
- /**
454
- * Input for PreCompact hooks.
455
- *
456
- * Fires before context compaction occurs, allowing you to:
457
- * - Preserve important information before compaction
458
- * - Log compaction events
459
- * - Modify custom instructions for the compacted context
460
- *
461
- * This hook uses `trigger` for matcher matching.
462
- * @example
463
- * ```typescript
464
- * // Log compaction events
465
- * preCompactHook({}, async (input: PreCompactInput) => {
466
- * console.log(`Compacting (${input.trigger})`);
467
- * return preCompactOutput({});
468
- * });
469
- * ```
470
- * @see https://code.claude.com/docs/en/hooks#precompact
471
- */
472
- export interface PreCompactInput extends BaseHookInput {
473
- /** Discriminator for hook event type. */
474
- hook_event_name: 'PreCompact';
475
- /**
476
- * What triggered the compaction.
477
- *
478
- * - `'manual'` - User explicitly requested compaction
479
- * - `'auto'` - Automatic compaction due to context length
480
- */
481
- trigger: PreCompactTrigger;
482
- /**
483
- * Custom instructions to include in the compacted context.
484
- * May be null if no custom instructions are set.
485
- */
486
- custom_instructions: string | null;
487
- }
488
- /**
489
- * Input for PermissionRequest hooks.
490
- *
491
- * Fires when a permission prompt would be shown, allowing you to:
492
- * - Auto-approve or deny tool executions
493
- * - Implement custom permission logic
494
- * - Modify tool inputs before approval
495
- *
496
- * This hook uses `tool_name` for matcher matching.
497
- * @example
498
- * ```typescript
499
- * // Auto-approve read operations in allowed directories
500
- * permissionRequestHook({ matcher: 'Read' }, async (input: PermissionRequestInput) => {
501
- * const filePath = input.tool_input.file_path as string;
502
- * if (filePath.startsWith('/allowed/')) {
503
- * return permissionRequestOutput({
504
- * allow: true
505
- * });
506
- * }
507
- * return permissionRequestOutput({}); // Fall through to normal permission prompt
508
- * });
509
- * ```
510
- * @see https://code.claude.com/docs/en/hooks#permissionrequest
511
- */
512
- export interface PermissionRequestInput extends BaseHookInput {
513
- /** Discriminator for hook event type. */
514
- hook_event_name: 'PermissionRequest';
515
- /**
516
- * Name of the tool requesting permission.
517
- */
518
- tool_name: string;
519
- /**
520
- * Input parameters for the tool.
521
- */
522
- tool_input: unknown;
523
- /**
524
- * Unique identifier for this specific tool invocation.
525
- */
526
- tool_use_id: string;
527
- /**
528
- * Suggested permission updates that would prevent future prompts.
529
- * Typically used for "always allow" functionality.
530
- */
531
- permission_suggestions?: PermissionUpdate[];
532
- }
533
- /**
534
- * Discriminated union of all hook input types.
535
- *
536
- * Use this type when handling multiple hook types in a single handler
537
- * or when the hook type is not known statically.
538
- * @example
539
- * ```typescript
540
- * // Handle any hook type with type narrowing
541
- * function handleHook(input: HookInput) {
542
- * switch (input.hook_event_name) {
543
- * case 'PreToolUse':
544
- * // TypeScript knows input is PreToolUseInput here
545
- * console.log(`Tool: ${input.tool_name}`);
546
- * break;
547
- * case 'SessionStart':
548
- * // TypeScript knows input is SessionStartInput here
549
- * console.log(`Source: ${input.source}`);
550
- * break;
551
- * // ... handle other hook types
552
- * }
553
- * }
554
- * ```
555
- * @see https://code.claude.com/docs/en/hooks
556
- */
557
- export type HookInput =
558
- | PreToolUseInput
559
- | PostToolUseInput
560
- | PostToolUseFailureInput
561
- | NotificationInput
562
- | UserPromptSubmitInput
563
- | SessionStartInput
564
- | SessionEndInput
565
- | StopInput
566
- | SubagentStartInput
567
- | SubagentStopInput
568
- | PreCompactInput
569
- | PermissionRequestInput;
570
- /**
571
- * Hook event name literal union.
572
- *
573
- * All valid hook event names that can appear in the `hook_event_name` field.
574
- */
575
- export type HookEventName = HookInput['hook_event_name'];
576
- /**
577
- * All hook event names as a readonly array.
578
- *
579
- * Useful for iteration and validation.
580
- * @example
581
- * ```typescript
582
- * for (const eventName of HOOK_EVENT_NAMES) {
583
- * console.log(`Supported hook: ${eventName}`);
584
- * }
585
- * ```
586
- */
587
- export declare const HOOK_EVENT_NAMES: readonly [
588
- 'PreToolUse',
589
- 'PostToolUse',
590
- 'PostToolUseFailure',
591
- 'Notification',
592
- 'UserPromptSubmit',
593
- 'SessionStart',
594
- 'SessionEnd',
595
- 'Stop',
596
- 'SubagentStart',
597
- 'SubagentStop',
598
- 'PreCompact',
599
- 'PermissionRequest'
600
- ];
601
- export type { PermissionUpdate };
@@ -1,228 +0,0 @@
1
- /**
2
- * Type definitions for well-known Claude Code tool inputs.
3
- *
4
- * These types define the structure of `toolInput` for common Claude Code tools.
5
- * Use them with type guards from `tool-helpers.ts` for safe type narrowing,
6
- * or with typed hook factory overloads for automatic typing.
7
- * @example
8
- * ```typescript
9
- * import { isWriteTool, getFilePath } from '@goodfoot/claude-code-hooks';
10
- *
11
- * preToolUseHook({ matcher: 'Write|Edit|MultiEdit' }, (input) => {
12
- * if (isWriteTool(input)) {
13
- * // input.tool_input is now typed as WriteToolInput
14
- * console.log(input.tool_input.file_path);
15
- * }
16
- * });
17
- * ```
18
- * @see https://code.claude.com/docs/en/hooks
19
- * @module
20
- */
21
- /**
22
- * Input structure for the Write tool.
23
- *
24
- * The Write tool creates or overwrites files with the specified content.
25
- * @example
26
- * ```typescript
27
- * // Example tool input
28
- * {
29
- * file_path: '/workspace/src/index.ts',
30
- * content: 'export const hello = "world";'
31
- * }
32
- * ```
33
- */
34
- export interface WriteToolInput {
35
- /** Absolute path to the file to write. */
36
- file_path: string;
37
- /** The content to write to the file. */
38
- content: string;
39
- }
40
- /**
41
- * Input structure for the Edit tool.
42
- *
43
- * The Edit tool performs search-and-replace operations on files.
44
- * @example
45
- * ```typescript
46
- * // Example tool input
47
- * {
48
- * file_path: '/workspace/src/index.ts',
49
- * old_string: 'const x = 1;',
50
- * new_string: 'const x = 2;',
51
- * replace_all: false
52
- * }
53
- * ```
54
- */
55
- export interface EditToolInput {
56
- /** Absolute path to the file to edit. */
57
- file_path: string;
58
- /** The text to search for (must be unique in the file unless replace_all is true). */
59
- old_string: string;
60
- /** The text to replace old_string with. */
61
- new_string: string;
62
- /** If true, replace all occurrences. If false, old_string must be unique. */
63
- replace_all?: boolean;
64
- }
65
- /**
66
- * A single edit entry within a MultiEdit operation.
67
- */
68
- export interface MultiEditEntry {
69
- /** The text to search for. */
70
- old_string: string;
71
- /** The text to replace old_string with. */
72
- new_string: string;
73
- }
74
- /**
75
- * Input structure for the MultiEdit tool.
76
- *
77
- * The MultiEdit tool performs multiple search-and-replace operations on a single file.
78
- * All edits are applied atomically.
79
- * @example
80
- * ```typescript
81
- * // Example tool input
82
- * {
83
- * file_path: '/workspace/src/index.ts',
84
- * edits: [
85
- * { old_string: 'const x = 1;', new_string: 'const x = 2;' },
86
- * { old_string: 'const y = 1;', new_string: 'const y = 2;' }
87
- * ]
88
- * }
89
- * ```
90
- */
91
- export interface MultiEditToolInput {
92
- /** Absolute path to the file to edit. */
93
- file_path: string;
94
- /** Array of edit operations to apply. */
95
- edits: MultiEditEntry[];
96
- }
97
- /**
98
- * Input structure for the Read tool.
99
- *
100
- * The Read tool reads file contents, optionally with offset and limit.
101
- * @example
102
- * ```typescript
103
- * // Example tool input
104
- * {
105
- * file_path: '/workspace/src/index.ts',
106
- * offset: 0,
107
- * limit: 100
108
- * }
109
- * ```
110
- */
111
- export interface ReadToolInput {
112
- /** Absolute path to the file to read. */
113
- file_path: string;
114
- /** Line offset to start reading from. */
115
- offset?: number;
116
- /** Maximum number of lines to read. */
117
- limit?: number;
118
- }
119
- /**
120
- * Input structure for the Bash tool.
121
- *
122
- * The Bash tool executes shell commands.
123
- * @example
124
- * ```typescript
125
- * // Example tool input
126
- * {
127
- * command: 'npm install',
128
- * timeout: 60000,
129
- * description: 'Install dependencies'
130
- * }
131
- * ```
132
- */
133
- export interface BashToolInput {
134
- /** The command to execute. */
135
- command: string;
136
- /** Optional timeout in milliseconds. */
137
- timeout?: number;
138
- /** Optional description of what the command does. */
139
- description?: string;
140
- }
141
- /**
142
- * Input structure for the Glob tool.
143
- *
144
- * The Glob tool finds files matching a glob pattern.
145
- * @example
146
- * ```typescript
147
- * // Example tool input
148
- * {
149
- * pattern: '**\/*.ts',
150
- * path: '/workspace/src'
151
- * }
152
- * ```
153
- */
154
- export interface GlobToolInput {
155
- /** Glob pattern to match files against. */
156
- pattern: string;
157
- /** Directory to search in (defaults to cwd). */
158
- path?: string;
159
- }
160
- /**
161
- * Input structure for the Grep tool.
162
- *
163
- * The Grep tool searches file contents using regex patterns.
164
- * @example
165
- * ```typescript
166
- * // Example tool input
167
- * {
168
- * pattern: 'function\\s+\\w+',
169
- * path: '/workspace/src',
170
- * glob: '*.ts'
171
- * }
172
- * ```
173
- */
174
- export interface GrepToolInput {
175
- /** Regular expression pattern to search for. */
176
- pattern: string;
177
- /** Directory to search in (defaults to cwd). */
178
- path?: string;
179
- /** Glob pattern to filter files. */
180
- glob?: string;
181
- }
182
- /**
183
- * Union of all file-modifying tool inputs.
184
- *
185
- * Use this type when you need to handle Write, Edit, or MultiEdit generically.
186
- */
187
- export type FileModifyingToolInput = WriteToolInput | EditToolInput | MultiEditToolInput;
188
- /**
189
- * Tool names for file-modifying tools.
190
- *
191
- * Use this type when you need to reference the tool name in type guards.
192
- */
193
- export type FileModifyingToolName = 'Write' | 'Edit' | 'MultiEdit';
194
- /**
195
- * Union of all known tool inputs.
196
- *
197
- * This includes all tool inputs that have well-defined type structures.
198
- */
199
- export type KnownToolInput =
200
- | WriteToolInput
201
- | EditToolInput
202
- | MultiEditToolInput
203
- | ReadToolInput
204
- | BashToolInput
205
- | GlobToolInput
206
- | GrepToolInput;
207
- /**
208
- * Tool names for all known tools with typed inputs.
209
- */
210
- export type KnownToolName = 'Write' | 'Edit' | 'MultiEdit' | 'Read' | 'Bash' | 'Glob' | 'Grep';
211
- /**
212
- * Type mapping from tool name to tool input type.
213
- *
214
- * Used by typed factory overloads to provide automatic typing.
215
- * @example
216
- * ```typescript
217
- * type WriteInput = ToolInputMap['Write']; // WriteToolInput
218
- * ```
219
- */
220
- export interface ToolInputMap {
221
- Write: WriteToolInput;
222
- Edit: EditToolInput;
223
- MultiEdit: MultiEditToolInput;
224
- Read: ReadToolInput;
225
- Bash: BashToolInput;
226
- Glob: GlobToolInput;
227
- Grep: GrepToolInput;
228
- }