@goodfoot/claude-code-hooks 1.1.0 → 1.2.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.
- package/dist/cli.js +3 -3
- package/dist/constants.js +6 -0
- package/dist/hooks.js +177 -0
- package/dist/index.js +6 -6
- package/dist/outputs.js +69 -0
- package/dist/scaffold.js +22 -2
- package/dist/types.js +6 -0
- package/package.json +3 -3
- package/types/hooks.d.ts +149 -2
- package/types/index.d.ts +4 -4
- package/types/outputs.d.ts +162 -3
- package/types/types.d.ts +72 -4
package/dist/cli.js
CHANGED
|
@@ -863,7 +863,7 @@ async function main() {
|
|
|
863
863
|
const hookFiles = await discoverHookFiles(args.input, cwd);
|
|
864
864
|
log("info", `Discovered ${hookFiles.length} hook files`, { files: hookFiles });
|
|
865
865
|
if (hookFiles.length === 0) {
|
|
866
|
-
process.stderr.write(`No hook files found matching pattern: ${args.input}\n`);
|
|
866
|
+
process.stderr.write(`Error: No hook files found matching pattern: ${args.input}\n`);
|
|
867
867
|
process.exit(1);
|
|
868
868
|
}
|
|
869
869
|
// Read existing hooks.json to preserve non-generated hooks
|
|
@@ -880,8 +880,8 @@ async function main() {
|
|
|
880
880
|
}
|
|
881
881
|
// Compile all hooks
|
|
882
882
|
const compiledHooks = await compileAllHooks({ hookFiles, outputDir: buildDir, logFilePath });
|
|
883
|
-
if (compiledHooks.length === 0) {
|
|
884
|
-
process.stderr.write("No valid hooks found in discovered files.\n");
|
|
883
|
+
if (compiledHooks.length === 0 && hookFiles.length > 0) {
|
|
884
|
+
process.stderr.write("Error: No valid hooks found in discovered files.\n");
|
|
885
885
|
process.exit(1);
|
|
886
886
|
}
|
|
887
887
|
// Auto-detect hook context based on output path
|
package/dist/constants.js
CHANGED
|
@@ -21,4 +21,10 @@ export const HOOK_FACTORY_TO_EVENT = {
|
|
|
21
21
|
setupHook: "Setup",
|
|
22
22
|
teammateIdleHook: "TeammateIdle",
|
|
23
23
|
taskCompletedHook: "TaskCompleted",
|
|
24
|
+
elicitationHook: "Elicitation",
|
|
25
|
+
elicitationResultHook: "ElicitationResult",
|
|
26
|
+
configChangeHook: "ConfigChange",
|
|
27
|
+
instructionsLoadedHook: "InstructionsLoaded",
|
|
28
|
+
worktreeCreateHook: "WorktreeCreate",
|
|
29
|
+
worktreeRemoveHook: "WorktreeRemove",
|
|
24
30
|
};
|
package/dist/hooks.js
CHANGED
|
@@ -499,3 +499,180 @@ export function teammateIdleHook(config, handler) {
|
|
|
499
499
|
export function taskCompletedHook(config, handler) {
|
|
500
500
|
return createHookFunction("TaskCompleted", config, handler);
|
|
501
501
|
}
|
|
502
|
+
// ============================================================================
|
|
503
|
+
// Elicitation Hook Factory
|
|
504
|
+
// ============================================================================
|
|
505
|
+
/**
|
|
506
|
+
* Creates an Elicitation hook handler.
|
|
507
|
+
*
|
|
508
|
+
* Elicitation hooks fire when an MCP server requests user input, allowing you to:
|
|
509
|
+
* - Accept, decline, or cancel elicitation requests programmatically
|
|
510
|
+
* - Provide structured form input or URL-based auth responses
|
|
511
|
+
* - Log or audit elicitation requests
|
|
512
|
+
*
|
|
513
|
+
* **Matcher**: No matcher support - fires on all elicitation events
|
|
514
|
+
* @param config - Hook configuration with optional timeout
|
|
515
|
+
* @param handler - The handler function to execute
|
|
516
|
+
* @returns A hook function that can be exported as the default export
|
|
517
|
+
* @example
|
|
518
|
+
* ```typescript
|
|
519
|
+
* import { elicitationHook, elicitationOutput } from '@goodfoot/claude-code-hooks';
|
|
520
|
+
*
|
|
521
|
+
* export default elicitationHook({}, async (input, { logger }) => {
|
|
522
|
+
* logger.info('Elicitation request', { server: input.mcp_server_name });
|
|
523
|
+
* return elicitationOutput({
|
|
524
|
+
* hookSpecificOutput: { action: 'accept', content: { approved: true } }
|
|
525
|
+
* });
|
|
526
|
+
* });
|
|
527
|
+
* ```
|
|
528
|
+
* @see https://code.claude.com/docs/en/hooks#elicitation
|
|
529
|
+
*/
|
|
530
|
+
export function elicitationHook(config, handler) {
|
|
531
|
+
return createHookFunction("Elicitation", config, handler);
|
|
532
|
+
}
|
|
533
|
+
// ============================================================================
|
|
534
|
+
// ElicitationResult Hook Factory
|
|
535
|
+
// ============================================================================
|
|
536
|
+
/**
|
|
537
|
+
* Creates an ElicitationResult hook handler.
|
|
538
|
+
*
|
|
539
|
+
* ElicitationResult hooks fire with the result of an MCP elicitation request,
|
|
540
|
+
* allowing you to:
|
|
541
|
+
* - Observe elicitation outcomes
|
|
542
|
+
* - Modify the result before it is returned to the MCP server
|
|
543
|
+
* - Log elicitation completions
|
|
544
|
+
*
|
|
545
|
+
* **Matcher**: No matcher support - fires on all elicitation result events
|
|
546
|
+
* @param config - Hook configuration with optional timeout
|
|
547
|
+
* @param handler - The handler function to execute
|
|
548
|
+
* @returns A hook function that can be exported as the default export
|
|
549
|
+
* @example
|
|
550
|
+
* ```typescript
|
|
551
|
+
* import { elicitationResultHook, elicitationResultOutput } from '@goodfoot/claude-code-hooks';
|
|
552
|
+
*
|
|
553
|
+
* export default elicitationResultHook({}, async (input, { logger }) => {
|
|
554
|
+
* logger.info('Elicitation result', { action: input.action });
|
|
555
|
+
* return elicitationResultOutput({});
|
|
556
|
+
* });
|
|
557
|
+
* ```
|
|
558
|
+
* @see https://code.claude.com/docs/en/hooks#elicitationresult
|
|
559
|
+
*/
|
|
560
|
+
export function elicitationResultHook(config, handler) {
|
|
561
|
+
return createHookFunction("ElicitationResult", config, handler);
|
|
562
|
+
}
|
|
563
|
+
// ============================================================================
|
|
564
|
+
// ConfigChange Hook Factory
|
|
565
|
+
// ============================================================================
|
|
566
|
+
/**
|
|
567
|
+
* Creates a ConfigChange hook handler.
|
|
568
|
+
*
|
|
569
|
+
* ConfigChange hooks fire when Claude Code configuration changes, allowing you to:
|
|
570
|
+
* - React to settings file changes
|
|
571
|
+
* - Log or audit configuration changes
|
|
572
|
+
* - Apply custom logic when settings are updated
|
|
573
|
+
*
|
|
574
|
+
* **Matcher**: Matches against `source` ('user_settings', 'project_settings', etc.)
|
|
575
|
+
* @param config - Hook configuration with optional matcher and timeout
|
|
576
|
+
* @param handler - The handler function to execute
|
|
577
|
+
* @returns A hook function that can be exported as the default export
|
|
578
|
+
* @example
|
|
579
|
+
* ```typescript
|
|
580
|
+
* import { configChangeHook, configChangeOutput } from '@goodfoot/claude-code-hooks';
|
|
581
|
+
*
|
|
582
|
+
* export default configChangeHook({}, async (input, { logger }) => {
|
|
583
|
+
* logger.info('Config changed', { source: input.source, file: input.file_path });
|
|
584
|
+
* return configChangeOutput({});
|
|
585
|
+
* });
|
|
586
|
+
* ```
|
|
587
|
+
* @see https://code.claude.com/docs/en/hooks#configchange
|
|
588
|
+
*/
|
|
589
|
+
export function configChangeHook(config, handler) {
|
|
590
|
+
return createHookFunction("ConfigChange", config, handler);
|
|
591
|
+
}
|
|
592
|
+
// ============================================================================
|
|
593
|
+
// InstructionsLoaded Hook Factory
|
|
594
|
+
// ============================================================================
|
|
595
|
+
/**
|
|
596
|
+
* Creates an InstructionsLoaded hook handler.
|
|
597
|
+
*
|
|
598
|
+
* InstructionsLoaded hooks fire when a CLAUDE.md or similar instructions file
|
|
599
|
+
* is loaded, allowing you to:
|
|
600
|
+
* - React to instructions being applied
|
|
601
|
+
* - Log which instruction files are active
|
|
602
|
+
* - Observe the instruction loading hierarchy
|
|
603
|
+
*
|
|
604
|
+
* **Matcher**: No matcher support - fires on all instruction load events
|
|
605
|
+
* @param config - Hook configuration with optional timeout
|
|
606
|
+
* @param handler - The handler function to execute
|
|
607
|
+
* @returns A hook function that can be exported as the default export
|
|
608
|
+
* @example
|
|
609
|
+
* ```typescript
|
|
610
|
+
* import { instructionsLoadedHook, instructionsLoadedOutput } from '@goodfoot/claude-code-hooks';
|
|
611
|
+
*
|
|
612
|
+
* export default instructionsLoadedHook({}, async (input, { logger }) => {
|
|
613
|
+
* logger.info('Instructions loaded', { file: input.file_path, type: input.memory_type });
|
|
614
|
+
* return instructionsLoadedOutput({});
|
|
615
|
+
* });
|
|
616
|
+
* ```
|
|
617
|
+
* @see https://code.claude.com/docs/en/hooks#instructionsloaded
|
|
618
|
+
*/
|
|
619
|
+
export function instructionsLoadedHook(config, handler) {
|
|
620
|
+
return createHookFunction("InstructionsLoaded", config, handler);
|
|
621
|
+
}
|
|
622
|
+
// ============================================================================
|
|
623
|
+
// WorktreeCreate Hook Factory
|
|
624
|
+
// ============================================================================
|
|
625
|
+
/**
|
|
626
|
+
* Creates a WorktreeCreate hook handler.
|
|
627
|
+
*
|
|
628
|
+
* WorktreeCreate hooks fire when a git worktree is created, allowing you to:
|
|
629
|
+
* - Set up worktree-specific configuration
|
|
630
|
+
* - Log worktree creation events
|
|
631
|
+
* - Initialize worktree resources
|
|
632
|
+
*
|
|
633
|
+
* **Matcher**: No matcher support - fires on all worktree creation events
|
|
634
|
+
* @param config - Hook configuration with optional timeout
|
|
635
|
+
* @param handler - The handler function to execute
|
|
636
|
+
* @returns A hook function that can be exported as the default export
|
|
637
|
+
* @example
|
|
638
|
+
* ```typescript
|
|
639
|
+
* import { worktreeCreateHook, worktreeCreateOutput } from '@goodfoot/claude-code-hooks';
|
|
640
|
+
*
|
|
641
|
+
* export default worktreeCreateHook({}, async (input, { logger }) => {
|
|
642
|
+
* logger.info('Worktree created', { name: input.name });
|
|
643
|
+
* return worktreeCreateOutput({});
|
|
644
|
+
* });
|
|
645
|
+
* ```
|
|
646
|
+
* @see https://code.claude.com/docs/en/hooks#worktreecreate
|
|
647
|
+
*/
|
|
648
|
+
export function worktreeCreateHook(config, handler) {
|
|
649
|
+
return createHookFunction("WorktreeCreate", config, handler);
|
|
650
|
+
}
|
|
651
|
+
// ============================================================================
|
|
652
|
+
// WorktreeRemove Hook Factory
|
|
653
|
+
// ============================================================================
|
|
654
|
+
/**
|
|
655
|
+
* Creates a WorktreeRemove hook handler.
|
|
656
|
+
*
|
|
657
|
+
* WorktreeRemove hooks fire when a git worktree is removed, allowing you to:
|
|
658
|
+
* - Clean up worktree-specific resources
|
|
659
|
+
* - Log worktree removal events
|
|
660
|
+
*
|
|
661
|
+
* **Matcher**: No matcher support - fires on all worktree removal events
|
|
662
|
+
* @param config - Hook configuration with optional timeout
|
|
663
|
+
* @param handler - The handler function to execute
|
|
664
|
+
* @returns A hook function that can be exported as the default export
|
|
665
|
+
* @example
|
|
666
|
+
* ```typescript
|
|
667
|
+
* import { worktreeRemoveHook, worktreeRemoveOutput } from '@goodfoot/claude-code-hooks';
|
|
668
|
+
*
|
|
669
|
+
* export default worktreeRemoveHook({}, async (input, { logger }) => {
|
|
670
|
+
* logger.info('Worktree removed', { path: input.worktree_path });
|
|
671
|
+
* return worktreeRemoveOutput({});
|
|
672
|
+
* });
|
|
673
|
+
* ```
|
|
674
|
+
* @see https://code.claude.com/docs/en/hooks#worktreeremove
|
|
675
|
+
*/
|
|
676
|
+
export function worktreeRemoveHook(config, handler) {
|
|
677
|
+
return createHookFunction("WorktreeRemove", config, handler);
|
|
678
|
+
}
|
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
|
|
15
|
-
export { notificationHook, permissionRequestHook, postToolUseFailureHook, postToolUseHook, preCompactHook, preToolUseHook, sessionEndHook, sessionStartHook, setupHook, stopHook, subagentStartHook, subagentStopHook, taskCompletedHook, teammateIdleHook, userPromptSubmitHook, } from "./hooks.js";
|
|
14
|
+
// Hook factory functions - all 21 hook types
|
|
15
|
+
export { configChangeHook, elicitationHook, elicitationResultHook, instructionsLoadedHook, notificationHook, permissionRequestHook, postToolUseFailureHook, postToolUseHook, preCompactHook, preToolUseHook, sessionEndHook, sessionStartHook, setupHook, stopHook, subagentStartHook, subagentStopHook, taskCompletedHook, teammateIdleHook, userPromptSubmitHook, worktreeCreateHook, worktreeRemoveHook, } from "./hooks.js";
|
|
16
16
|
// Logger exports
|
|
17
17
|
export { LOG_LEVELS, Logger, logger } from "./logger.js";
|
|
18
18
|
// Output builder functions
|
|
19
|
-
export {
|
|
19
|
+
export { configChangeOutput,
|
|
20
20
|
// Exit codes
|
|
21
|
-
EXIT_CODES, notificationOutput, permissionRequestOutput, postToolUseFailureOutput, postToolUseOutput, preCompactOutput,
|
|
22
|
-
// All
|
|
23
|
-
preToolUseOutput, sessionEndOutput, sessionStartOutput, setupOutput, stopOutput, subagentStartOutput, subagentStopOutput, taskCompletedOutput, teammateIdleOutput, userPromptSubmitOutput, } from "./outputs.js";
|
|
21
|
+
EXIT_CODES, elicitationOutput, elicitationResultOutput, instructionsLoadedOutput, notificationOutput, permissionRequestOutput, postToolUseFailureOutput, postToolUseOutput, preCompactOutput,
|
|
22
|
+
// All 21 output builder functions
|
|
23
|
+
preToolUseOutput, sessionEndOutput, sessionStartOutput, setupOutput, stopOutput, subagentStartOutput, subagentStopOutput, taskCompletedOutput, teammateIdleOutput, userPromptSubmitOutput, worktreeCreateOutput, worktreeRemoveOutput, } 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
|
@@ -342,3 +342,72 @@ export const teammateIdleOutput = /* @__PURE__ */ createExitCodeOutputBuilder("T
|
|
|
342
342
|
* ```
|
|
343
343
|
*/
|
|
344
344
|
export const taskCompletedOutput = /* @__PURE__ */ createExitCodeOutputBuilder("TaskCompleted");
|
|
345
|
+
/**
|
|
346
|
+
* Creates an output for Elicitation hooks.
|
|
347
|
+
* @param options - Configuration options for the hook output
|
|
348
|
+
* @returns An ElicitationOutput object ready for the runtime
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* // Accept the elicitation
|
|
352
|
+
* elicitationOutput({
|
|
353
|
+
* hookSpecificOutput: { action: 'accept', content: { username: 'alice' } }
|
|
354
|
+
* });
|
|
355
|
+
*
|
|
356
|
+
* // Decline the elicitation
|
|
357
|
+
* elicitationOutput({
|
|
358
|
+
* hookSpecificOutput: { action: 'decline' }
|
|
359
|
+
* });
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
export const elicitationOutput = /* @__PURE__ */ createHookSpecificOutputBuilder("Elicitation");
|
|
363
|
+
/**
|
|
364
|
+
* Creates an output for ElicitationResult hooks.
|
|
365
|
+
* @param options - Configuration options for the hook output
|
|
366
|
+
* @returns An ElicitationResultOutput object ready for the runtime
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* elicitationResultOutput({});
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
export const elicitationResultOutput = /* @__PURE__ */ createHookSpecificOutputBuilder("ElicitationResult");
|
|
373
|
+
/**
|
|
374
|
+
* Creates an output for ConfigChange hooks.
|
|
375
|
+
* @param options - Configuration options for the hook output
|
|
376
|
+
* @returns A ConfigChangeOutput object ready for the runtime
|
|
377
|
+
* @example
|
|
378
|
+
* ```typescript
|
|
379
|
+
* configChangeOutput({});
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
export const configChangeOutput = /* @__PURE__ */ createSimpleOutputBuilder("ConfigChange");
|
|
383
|
+
/**
|
|
384
|
+
* Creates an output for InstructionsLoaded hooks.
|
|
385
|
+
* @param options - Configuration options for the hook output
|
|
386
|
+
* @returns An InstructionsLoadedOutput object ready for the runtime
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* instructionsLoadedOutput({});
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
export const instructionsLoadedOutput =
|
|
393
|
+
/* @__PURE__ */ createSimpleOutputBuilder("InstructionsLoaded");
|
|
394
|
+
/**
|
|
395
|
+
* Creates an output for WorktreeCreate hooks.
|
|
396
|
+
* @param options - Configuration options for the hook output
|
|
397
|
+
* @returns A WorktreeCreateOutput object ready for the runtime
|
|
398
|
+
* @example
|
|
399
|
+
* ```typescript
|
|
400
|
+
* worktreeCreateOutput({});
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
export const worktreeCreateOutput = /* @__PURE__ */ createSimpleOutputBuilder("WorktreeCreate");
|
|
404
|
+
/**
|
|
405
|
+
* Creates an output for WorktreeRemove hooks.
|
|
406
|
+
* @param options - Configuration options for the hook output
|
|
407
|
+
* @returns A WorktreeRemoveOutput object ready for the runtime
|
|
408
|
+
* @example
|
|
409
|
+
* ```typescript
|
|
410
|
+
* worktreeRemoveOutput({});
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
export const worktreeRemoveOutput = /* @__PURE__ */ createSimpleOutputBuilder("WorktreeRemove");
|
package/dist/scaffold.js
CHANGED
|
@@ -52,6 +52,12 @@ const EVENT_TO_OUTPUT_FUNCTION = {
|
|
|
52
52
|
Setup: "setupOutput",
|
|
53
53
|
TeammateIdle: "teammateIdleOutput",
|
|
54
54
|
TaskCompleted: "taskCompletedOutput",
|
|
55
|
+
Elicitation: "elicitationOutput",
|
|
56
|
+
ElicitationResult: "elicitationResultOutput",
|
|
57
|
+
ConfigChange: "configChangeOutput",
|
|
58
|
+
InstructionsLoaded: "instructionsLoadedOutput",
|
|
59
|
+
WorktreeCreate: "worktreeCreateOutput",
|
|
60
|
+
WorktreeRemove: "worktreeRemoveOutput",
|
|
55
61
|
};
|
|
56
62
|
// ============================================================================
|
|
57
63
|
// Validation
|
|
@@ -119,7 +125,7 @@ function generatePackageJson(projectName, outputPath) {
|
|
|
119
125
|
"@goodfoot/claude-code-hooks": "^1.0.9",
|
|
120
126
|
},
|
|
121
127
|
devDependencies: {
|
|
122
|
-
"@biomejs/biome": "2.4.
|
|
128
|
+
"@biomejs/biome": "2.4.6",
|
|
123
129
|
"@types/node": "^22.0.0",
|
|
124
130
|
typescript: "^5.9.3",
|
|
125
131
|
vitest: "^4.0.16",
|
|
@@ -162,7 +168,7 @@ function generateTsConfig() {
|
|
|
162
168
|
*/
|
|
163
169
|
function generateBiomeConfig() {
|
|
164
170
|
return `{
|
|
165
|
-
"$schema": "https://biomejs.dev/schemas/2.4.
|
|
171
|
+
"$schema": "https://biomejs.dev/schemas/2.4.6/schema.json",
|
|
166
172
|
"formatter": {
|
|
167
173
|
"enabled": true,
|
|
168
174
|
"indentStyle": "space",
|
|
@@ -313,6 +319,20 @@ function generateHookTemplate(eventName) {
|
|
|
313
319
|
systemMessage: "Permission request processed.",
|
|
314
320
|
});`;
|
|
315
321
|
break;
|
|
322
|
+
case "Elicitation":
|
|
323
|
+
returnStatement = `return ${outputName}({
|
|
324
|
+
hookSpecificOutput: { action: "accept" },
|
|
325
|
+
});`;
|
|
326
|
+
break;
|
|
327
|
+
case "ElicitationResult":
|
|
328
|
+
returnStatement = `return ${outputName}({});`;
|
|
329
|
+
break;
|
|
330
|
+
case "ConfigChange":
|
|
331
|
+
case "InstructionsLoaded":
|
|
332
|
+
case "WorktreeCreate":
|
|
333
|
+
case "WorktreeRemove":
|
|
334
|
+
returnStatement = `return ${outputName}({});`;
|
|
335
|
+
break;
|
|
316
336
|
default:
|
|
317
337
|
// SessionEnd, Notification, SubagentStart use simple output with systemMessage
|
|
318
338
|
returnStatement = `return ${outputName}({
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodfoot/claude-code-hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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": {
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"typescript": "^5.9.3"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@anthropic-ai/claude-agent-sdk": "^0.2.
|
|
57
|
-
"@biomejs/biome": "2.4.
|
|
56
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.69",
|
|
57
|
+
"@biomejs/biome": "2.4.6",
|
|
58
58
|
"@types/node": "^24",
|
|
59
59
|
"ts-morph": "^25.0.0",
|
|
60
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, SetupOutput, SpecificHookOutput, StopOutput, SubagentStartOutput, SubagentStopOutput, TaskCompletedOutput, TeammateIdleOutput, UserPromptSubmitOutput } from "./outputs.js";
|
|
26
|
-
import type { HookEventName, KnownToolName, NotificationInput, PermissionRequestInput, PostToolUseFailureInput, PostToolUseInput, PreCompactInput, PreToolUseInput, SessionEndInput, SessionStartInput, SetupInput, StopInput, SubagentStartInput, SubagentStopInput, TaskCompletedInput, TeammateIdleInput, ToolInputMap, UserPromptSubmitInput } from "./types.js";
|
|
25
|
+
import type { ConfigChangeOutput, ElicitationOutput, ElicitationResultOutput, InstructionsLoadedOutput, NotificationOutput, PermissionRequestOutput, PostToolUseFailureOutput, PostToolUseOutput, PreCompactOutput, PreToolUseOutput, SessionEndOutput, SessionStartOutput, SetupOutput, SpecificHookOutput, StopOutput, SubagentStartOutput, SubagentStopOutput, TaskCompletedOutput, TeammateIdleOutput, UserPromptSubmitOutput, WorktreeCreateOutput, WorktreeRemoveOutput } from "./outputs.js";
|
|
26
|
+
import type { ConfigChangeInput, ElicitationInput, ElicitationResultInput, HookEventName, InstructionsLoadedInput, KnownToolName, NotificationInput, PermissionRequestInput, PostToolUseFailureInput, PostToolUseInput, PreCompactInput, PreToolUseInput, SessionEndInput, SessionStartInput, SetupInput, StopInput, SubagentStartInput, SubagentStopInput, TaskCompletedInput, TeammateIdleInput, ToolInputMap, UserPromptSubmitInput, WorktreeCreateInput, WorktreeRemoveInput } from "./types.js";
|
|
27
27
|
/**
|
|
28
28
|
* Configuration options for hook factories.
|
|
29
29
|
*
|
|
@@ -870,4 +870,151 @@ export declare function teammateIdleHook(config: HookConfig, handler: HookHandle
|
|
|
870
870
|
* @see https://code.claude.com/docs/en/hooks#taskcompleted
|
|
871
871
|
*/
|
|
872
872
|
export declare function taskCompletedHook(config: HookConfig, handler: HookHandler<TaskCompletedInput, TaskCompletedOutput>): HookFunction<TaskCompletedInput, TaskCompletedOutput>;
|
|
873
|
+
/**
|
|
874
|
+
* Creates an Elicitation hook handler.
|
|
875
|
+
*
|
|
876
|
+
* Elicitation hooks fire when an MCP server requests user input, allowing you to:
|
|
877
|
+
* - Accept, decline, or cancel elicitation requests programmatically
|
|
878
|
+
* - Provide structured form input or URL-based auth responses
|
|
879
|
+
* - Log or audit elicitation requests
|
|
880
|
+
*
|
|
881
|
+
* **Matcher**: No matcher support - fires on all elicitation events
|
|
882
|
+
* @param config - Hook configuration with optional timeout
|
|
883
|
+
* @param handler - The handler function to execute
|
|
884
|
+
* @returns A hook function that can be exported as the default export
|
|
885
|
+
* @example
|
|
886
|
+
* ```typescript
|
|
887
|
+
* import { elicitationHook, elicitationOutput } from '@goodfoot/claude-code-hooks';
|
|
888
|
+
*
|
|
889
|
+
* export default elicitationHook({}, async (input, { logger }) => {
|
|
890
|
+
* logger.info('Elicitation request', { server: input.mcp_server_name });
|
|
891
|
+
* return elicitationOutput({
|
|
892
|
+
* hookSpecificOutput: { action: 'accept', content: { approved: true } }
|
|
893
|
+
* });
|
|
894
|
+
* });
|
|
895
|
+
* ```
|
|
896
|
+
* @see https://code.claude.com/docs/en/hooks#elicitation
|
|
897
|
+
*/
|
|
898
|
+
export declare function elicitationHook(config: HookConfig, handler: HookHandler<ElicitationInput, ElicitationOutput>): HookFunction<ElicitationInput, ElicitationOutput>;
|
|
899
|
+
/**
|
|
900
|
+
* Creates an ElicitationResult hook handler.
|
|
901
|
+
*
|
|
902
|
+
* ElicitationResult hooks fire with the result of an MCP elicitation request,
|
|
903
|
+
* allowing you to:
|
|
904
|
+
* - Observe elicitation outcomes
|
|
905
|
+
* - Modify the result before it is returned to the MCP server
|
|
906
|
+
* - Log elicitation completions
|
|
907
|
+
*
|
|
908
|
+
* **Matcher**: No matcher support - fires on all elicitation result events
|
|
909
|
+
* @param config - Hook configuration with optional timeout
|
|
910
|
+
* @param handler - The handler function to execute
|
|
911
|
+
* @returns A hook function that can be exported as the default export
|
|
912
|
+
* @example
|
|
913
|
+
* ```typescript
|
|
914
|
+
* import { elicitationResultHook, elicitationResultOutput } from '@goodfoot/claude-code-hooks';
|
|
915
|
+
*
|
|
916
|
+
* export default elicitationResultHook({}, async (input, { logger }) => {
|
|
917
|
+
* logger.info('Elicitation result', { action: input.action });
|
|
918
|
+
* return elicitationResultOutput({});
|
|
919
|
+
* });
|
|
920
|
+
* ```
|
|
921
|
+
* @see https://code.claude.com/docs/en/hooks#elicitationresult
|
|
922
|
+
*/
|
|
923
|
+
export declare function elicitationResultHook(config: HookConfig, handler: HookHandler<ElicitationResultInput, ElicitationResultOutput>): HookFunction<ElicitationResultInput, ElicitationResultOutput>;
|
|
924
|
+
/**
|
|
925
|
+
* Creates a ConfigChange hook handler.
|
|
926
|
+
*
|
|
927
|
+
* ConfigChange hooks fire when Claude Code configuration changes, allowing you to:
|
|
928
|
+
* - React to settings file changes
|
|
929
|
+
* - Log or audit configuration changes
|
|
930
|
+
* - Apply custom logic when settings are updated
|
|
931
|
+
*
|
|
932
|
+
* **Matcher**: Matches against `source` ('user_settings', 'project_settings', etc.)
|
|
933
|
+
* @param config - Hook configuration with optional matcher and timeout
|
|
934
|
+
* @param handler - The handler function to execute
|
|
935
|
+
* @returns A hook function that can be exported as the default export
|
|
936
|
+
* @example
|
|
937
|
+
* ```typescript
|
|
938
|
+
* import { configChangeHook, configChangeOutput } from '@goodfoot/claude-code-hooks';
|
|
939
|
+
*
|
|
940
|
+
* export default configChangeHook({}, async (input, { logger }) => {
|
|
941
|
+
* logger.info('Config changed', { source: input.source, file: input.file_path });
|
|
942
|
+
* return configChangeOutput({});
|
|
943
|
+
* });
|
|
944
|
+
* ```
|
|
945
|
+
* @see https://code.claude.com/docs/en/hooks#configchange
|
|
946
|
+
*/
|
|
947
|
+
export declare function configChangeHook(config: HookConfig, handler: HookHandler<ConfigChangeInput, ConfigChangeOutput>): HookFunction<ConfigChangeInput, ConfigChangeOutput>;
|
|
948
|
+
/**
|
|
949
|
+
* Creates an InstructionsLoaded hook handler.
|
|
950
|
+
*
|
|
951
|
+
* InstructionsLoaded hooks fire when a CLAUDE.md or similar instructions file
|
|
952
|
+
* is loaded, allowing you to:
|
|
953
|
+
* - React to instructions being applied
|
|
954
|
+
* - Log which instruction files are active
|
|
955
|
+
* - Observe the instruction loading hierarchy
|
|
956
|
+
*
|
|
957
|
+
* **Matcher**: No matcher support - fires on all instruction load 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 { instructionsLoadedHook, instructionsLoadedOutput } from '@goodfoot/claude-code-hooks';
|
|
964
|
+
*
|
|
965
|
+
* export default instructionsLoadedHook({}, async (input, { logger }) => {
|
|
966
|
+
* logger.info('Instructions loaded', { file: input.file_path, type: input.memory_type });
|
|
967
|
+
* return instructionsLoadedOutput({});
|
|
968
|
+
* });
|
|
969
|
+
* ```
|
|
970
|
+
* @see https://code.claude.com/docs/en/hooks#instructionsloaded
|
|
971
|
+
*/
|
|
972
|
+
export declare function instructionsLoadedHook(config: HookConfig, handler: HookHandler<InstructionsLoadedInput, InstructionsLoadedOutput>): HookFunction<InstructionsLoadedInput, InstructionsLoadedOutput>;
|
|
973
|
+
/**
|
|
974
|
+
* Creates a WorktreeCreate hook handler.
|
|
975
|
+
*
|
|
976
|
+
* WorktreeCreate hooks fire when a git worktree is created, allowing you to:
|
|
977
|
+
* - Set up worktree-specific configuration
|
|
978
|
+
* - Log worktree creation events
|
|
979
|
+
* - Initialize worktree resources
|
|
980
|
+
*
|
|
981
|
+
* **Matcher**: No matcher support - fires on all worktree creation events
|
|
982
|
+
* @param config - Hook configuration with optional timeout
|
|
983
|
+
* @param handler - The handler function to execute
|
|
984
|
+
* @returns A hook function that can be exported as the default export
|
|
985
|
+
* @example
|
|
986
|
+
* ```typescript
|
|
987
|
+
* import { worktreeCreateHook, worktreeCreateOutput } from '@goodfoot/claude-code-hooks';
|
|
988
|
+
*
|
|
989
|
+
* export default worktreeCreateHook({}, async (input, { logger }) => {
|
|
990
|
+
* logger.info('Worktree created', { name: input.name });
|
|
991
|
+
* return worktreeCreateOutput({});
|
|
992
|
+
* });
|
|
993
|
+
* ```
|
|
994
|
+
* @see https://code.claude.com/docs/en/hooks#worktreecreate
|
|
995
|
+
*/
|
|
996
|
+
export declare function worktreeCreateHook(config: HookConfig, handler: HookHandler<WorktreeCreateInput, WorktreeCreateOutput>): HookFunction<WorktreeCreateInput, WorktreeCreateOutput>;
|
|
997
|
+
/**
|
|
998
|
+
* Creates a WorktreeRemove hook handler.
|
|
999
|
+
*
|
|
1000
|
+
* WorktreeRemove hooks fire when a git worktree is removed, allowing you to:
|
|
1001
|
+
* - Clean up worktree-specific resources
|
|
1002
|
+
* - Log worktree removal events
|
|
1003
|
+
*
|
|
1004
|
+
* **Matcher**: No matcher support - fires on all worktree removal events
|
|
1005
|
+
* @param config - Hook configuration with optional timeout
|
|
1006
|
+
* @param handler - The handler function to execute
|
|
1007
|
+
* @returns A hook function that can be exported as the default export
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```typescript
|
|
1010
|
+
* import { worktreeRemoveHook, worktreeRemoveOutput } from '@goodfoot/claude-code-hooks';
|
|
1011
|
+
*
|
|
1012
|
+
* export default worktreeRemoveHook({}, async (input, { logger }) => {
|
|
1013
|
+
* logger.info('Worktree removed', { path: input.worktree_path });
|
|
1014
|
+
* return worktreeRemoveOutput({});
|
|
1015
|
+
* });
|
|
1016
|
+
* ```
|
|
1017
|
+
* @see https://code.claude.com/docs/en/hooks#worktreeremove
|
|
1018
|
+
*/
|
|
1019
|
+
export declare function worktreeRemoveHook(config: HookConfig, handler: HookHandler<WorktreeRemoveInput, WorktreeRemoveOutput>): HookFunction<WorktreeRemoveInput, WorktreeRemoveOutput>;
|
|
873
1020
|
export {};
|
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, TypedPostToolUseFailureHookInput, TypedPostToolUseHookInput, TypedPreToolUseHookInput, } from "./hooks.js";
|
|
11
|
-
export { notificationHook, permissionRequestHook, postToolUseFailureHook, postToolUseHook, preCompactHook, preToolUseHook, sessionEndHook, sessionStartHook, setupHook, stopHook, subagentStartHook, subagentStopHook, taskCompletedHook, teammateIdleHook, userPromptSubmitHook, } from "./hooks.js";
|
|
11
|
+
export { configChangeHook, elicitationHook, elicitationResultHook, instructionsLoadedHook, notificationHook, permissionRequestHook, postToolUseFailureHook, postToolUseHook, preCompactHook, preToolUseHook, sessionEndHook, sessionStartHook, setupHook, stopHook, subagentStartHook, subagentStopHook, taskCompletedHook, teammateIdleHook, userPromptSubmitHook, worktreeCreateHook, worktreeRemoveHook, } 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, ExitCodeOptions, HookOutput, HookSpecificOutput, NotificationHookSpecificOutput, NotificationOptions, PermissionRequestAllowDecision, PermissionRequestDecision, PermissionRequestDenyDecision, PermissionRequestHookSpecificOutput, PermissionRequestOptions, PostToolUseFailureHookSpecificOutput, PostToolUseFailureOptions, PostToolUseHookSpecificOutput, PostToolUseOptions, PreCompactOptions, PreToolUseHookSpecificOutput, PreToolUseOptions, SessionEndOptions, SessionStartHookSpecificOutput, SessionStartOptions, SetupHookSpecificOutput, SetupOptions, StopOptions, SubagentStartHookSpecificOutput, SubagentStartOptions, SubagentStopOptions, SyncHookJSONOutput, TaskCompletedOptions, TeammateIdleOptions, UserPromptSubmitHookSpecificOutput, UserPromptSubmitOptions, } from "./outputs.js";
|
|
17
|
-
export { EXIT_CODES, notificationOutput, permissionRequestOutput, postToolUseFailureOutput, postToolUseOutput, preCompactOutput, preToolUseOutput, sessionEndOutput, sessionStartOutput, setupOutput, stopOutput, subagentStartOutput, subagentStopOutput, taskCompletedOutput, teammateIdleOutput, userPromptSubmitOutput, } from "./outputs.js";
|
|
16
|
+
BaseOptions, CommonOptions, ConfigChangeOptions, ElicitationHookSpecificOutput, ElicitationOptions, ElicitationResultHookSpecificOutput, ElicitationResultOptions, ExitCode, ExitCodeOptions, HookOutput, HookSpecificOutput, InstructionsLoadedOptions, NotificationHookSpecificOutput, NotificationOptions, PermissionRequestAllowDecision, PermissionRequestDecision, PermissionRequestDenyDecision, PermissionRequestHookSpecificOutput, PermissionRequestOptions, PostToolUseFailureHookSpecificOutput, PostToolUseFailureOptions, PostToolUseHookSpecificOutput, PostToolUseOptions, PreCompactOptions, PreToolUseHookSpecificOutput, PreToolUseOptions, SessionEndOptions, SessionStartHookSpecificOutput, SessionStartOptions, SetupHookSpecificOutput, SetupOptions, StopOptions, SubagentStartHookSpecificOutput, SubagentStartOptions, SubagentStopOptions, SyncHookJSONOutput, TaskCompletedOptions, TeammateIdleOptions, UserPromptSubmitHookSpecificOutput, UserPromptSubmitOptions, WorktreeCreateOptions, WorktreeRemoveOptions, } from "./outputs.js";
|
|
17
|
+
export { configChangeOutput, EXIT_CODES, elicitationOutput, elicitationResultOutput, instructionsLoadedOutput, notificationOutput, permissionRequestOutput, postToolUseFailureOutput, postToolUseOutput, preCompactOutput, preToolUseOutput, sessionEndOutput, sessionStartOutput, setupOutput, stopOutput, subagentStartOutput, subagentStopOutput, taskCompletedOutput, teammateIdleOutput, userPromptSubmitOutput, worktreeCreateOutput, worktreeRemoveOutput, } 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, isConfigTool, isEditTool, isExitPlanModeTool, isFileModifyingTool, isGlobTool, isGrepTool, isJsTsFile, isKillShellTool, isListMcpResourcesTool, isMcpTool, isMultiEditTool, isNotebookEditTool, isReadMcpResourceTool, isReadTool, isTaskOutputTool, isTaskTool, isTodoWriteTool, isTsFile, isWebFetchTool, isWebSearchTool, isWriteTool, } from "./tool-helpers.js";
|
|
21
|
-
export type { BaseHookInput, ConfigInput, FileModifyingToolInput, FileModifyingToolName, HookEventName, HookInput, KnownToolInput, KnownToolName, ListMcpResourcesInput, McpInput, MultiEditEntry, MultiEditToolInput, NotificationInput, PermissionMode, PermissionRequestInput, PermissionUpdate, PostToolUseFailureInput, PostToolUseInput, PreCompactInput, PreCompactTrigger, PreToolUseInput, ReadMcpResourceInput, SessionEndInput, SessionEndReason, SessionStartInput, SessionStartSource, SetupInput, SetupTrigger, StopInput, SubagentStartInput, SubagentStopInput, TaskCompletedInput, TeammateIdleInput, ToolInputMap, UserPromptSubmitInput, } from "./types.js";
|
|
21
|
+
export type { BaseHookInput, ConfigChangeInput, ConfigInput, ElicitationInput, ElicitationResultInput, FileModifyingToolInput, FileModifyingToolName, HookEventName, HookInput, InstructionsLoadedInput, KnownToolInput, KnownToolName, ListMcpResourcesInput, McpInput, MultiEditEntry, MultiEditToolInput, NotificationInput, PermissionMode, PermissionRequestInput, PermissionUpdate, PostToolUseFailureInput, PostToolUseInput, PreCompactInput, PreCompactTrigger, PreToolUseInput, ReadMcpResourceInput, SessionEndInput, SessionEndReason, SessionStartInput, SessionStartSource, SetupInput, SetupTrigger, StopInput, SubagentStartInput, SubagentStopInput, TaskCompletedInput, TeammateIdleInput, ToolInputMap, UserPromptSubmitInput, WorktreeCreateInput, WorktreeRemoveInput, } from "./types.js";
|
|
22
22
|
export { HOOK_EVENT_NAMES } from "./types.js";
|
package/types/outputs.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @see https://code.claude.com/docs/en/hooks
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
|
+
import type { ElicitationHookSpecificOutput as SDKElicitationHookSpecificOutput, ElicitationResultHookSpecificOutput as SDKElicitationResultHookSpecificOutput } from "@anthropic-ai/claude-agent-sdk";
|
|
10
11
|
import type { NotificationHookSpecificOutput as SDKNotificationHookSpecificOutput, 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
12
|
/**
|
|
12
13
|
* Exit codes used by Claude Code hooks.
|
|
@@ -36,7 +37,7 @@ export type { SDKSyncHookJSONOutput };
|
|
|
36
37
|
/**
|
|
37
38
|
* Re-export SDK hook-specific output types (includes hookEventName discriminator).
|
|
38
39
|
*/
|
|
39
|
-
export type { SDKNotificationHookSpecificOutput, SDKPreToolUseHookSpecificOutput, SDKPostToolUseHookSpecificOutput, SDKPostToolUseFailureHookSpecificOutput, SDKUserPromptSubmitHookSpecificOutput, SDKSessionStartHookSpecificOutput, SDKSetupHookSpecificOutput, SDKSubagentStartHookSpecificOutput, SDKPermissionRequestHookSpecificOutput, };
|
|
40
|
+
export type { SDKElicitationHookSpecificOutput, SDKElicitationResultHookSpecificOutput, SDKNotificationHookSpecificOutput, SDKPreToolUseHookSpecificOutput, SDKPostToolUseHookSpecificOutput, SDKPostToolUseFailureHookSpecificOutput, SDKUserPromptSubmitHookSpecificOutput, SDKSessionStartHookSpecificOutput, SDKSetupHookSpecificOutput, SDKSubagentStartHookSpecificOutput, SDKPermissionRequestHookSpecificOutput, };
|
|
40
41
|
/**
|
|
41
42
|
* PreToolUse hook-specific output fields.
|
|
42
43
|
* Omits `hookEventName` which is added automatically by the builder.
|
|
@@ -77,6 +78,16 @@ export type PermissionRequestHookSpecificOutput = Omit<SDKPermissionRequestHookS
|
|
|
77
78
|
* Omits `hookEventName` which is added automatically by the builder.
|
|
78
79
|
*/
|
|
79
80
|
export type SetupHookSpecificOutput = Omit<SDKSetupHookSpecificOutput, "hookEventName">;
|
|
81
|
+
/**
|
|
82
|
+
* Elicitation hook-specific output fields.
|
|
83
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
84
|
+
*/
|
|
85
|
+
export type ElicitationHookSpecificOutput = Omit<SDKElicitationHookSpecificOutput, "hookEventName">;
|
|
86
|
+
/**
|
|
87
|
+
* ElicitationResult hook-specific output fields.
|
|
88
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
89
|
+
*/
|
|
90
|
+
export type ElicitationResultHookSpecificOutput = Omit<SDKElicitationResultHookSpecificOutput, "hookEventName">;
|
|
80
91
|
/**
|
|
81
92
|
* Allow decision for permission requests.
|
|
82
93
|
* Derived from SDK's PermissionRequestHookSpecificOutput.
|
|
@@ -104,7 +115,7 @@ export type NotificationHookSpecificOutput = Omit<SDKNotificationHookSpecificOut
|
|
|
104
115
|
/**
|
|
105
116
|
* Full hook-specific output with hookEventName discriminator.
|
|
106
117
|
*/
|
|
107
|
-
export type HookSpecificOutput = SDKPreToolUseHookSpecificOutput | SDKPostToolUseHookSpecificOutput | SDKPostToolUseFailureHookSpecificOutput | SDKUserPromptSubmitHookSpecificOutput | SDKSessionStartHookSpecificOutput | SDKSetupHookSpecificOutput | SDKSubagentStartHookSpecificOutput | SDKPermissionRequestHookSpecificOutput | SDKNotificationHookSpecificOutput;
|
|
118
|
+
export type HookSpecificOutput = SDKPreToolUseHookSpecificOutput | SDKPostToolUseHookSpecificOutput | SDKPostToolUseFailureHookSpecificOutput | SDKUserPromptSubmitHookSpecificOutput | SDKSessionStartHookSpecificOutput | SDKSetupHookSpecificOutput | SDKSubagentStartHookSpecificOutput | SDKPermissionRequestHookSpecificOutput | SDKNotificationHookSpecificOutput | SDKElicitationHookSpecificOutput | SDKElicitationResultHookSpecificOutput;
|
|
108
119
|
/**
|
|
109
120
|
* The JSON output format expected by Claude Code (sync hooks only).
|
|
110
121
|
* Extends SDK's SyncHookJSONOutput to include Notification hook support.
|
|
@@ -228,10 +239,34 @@ export type TeammateIdleOutput = BaseSpecificOutput<"TeammateIdle">;
|
|
|
228
239
|
*
|
|
229
240
|
*/
|
|
230
241
|
export type TaskCompletedOutput = BaseSpecificOutput<"TaskCompleted">;
|
|
242
|
+
/**
|
|
243
|
+
*
|
|
244
|
+
*/
|
|
245
|
+
export type ElicitationOutput = BaseSpecificOutput<"Elicitation">;
|
|
246
|
+
/**
|
|
247
|
+
*
|
|
248
|
+
*/
|
|
249
|
+
export type ElicitationResultOutput = BaseSpecificOutput<"ElicitationResult">;
|
|
250
|
+
/**
|
|
251
|
+
*
|
|
252
|
+
*/
|
|
253
|
+
export type ConfigChangeOutput = BaseSpecificOutput<"ConfigChange">;
|
|
254
|
+
/**
|
|
255
|
+
*
|
|
256
|
+
*/
|
|
257
|
+
export type InstructionsLoadedOutput = BaseSpecificOutput<"InstructionsLoaded">;
|
|
258
|
+
/**
|
|
259
|
+
*
|
|
260
|
+
*/
|
|
261
|
+
export type WorktreeCreateOutput = BaseSpecificOutput<"WorktreeCreate">;
|
|
262
|
+
/**
|
|
263
|
+
*
|
|
264
|
+
*/
|
|
265
|
+
export type WorktreeRemoveOutput = BaseSpecificOutput<"WorktreeRemove">;
|
|
231
266
|
/**
|
|
232
267
|
* Union of all specific output types.
|
|
233
268
|
*/
|
|
234
|
-
export type SpecificHookOutput = PreToolUseOutput | PostToolUseOutput | PostToolUseFailureOutput | NotificationOutput | UserPromptSubmitOutput | SessionStartOutput | SessionEndOutput | StopOutput | SubagentStartOutput | SubagentStopOutput | PreCompactOutput | PermissionRequestOutput | SetupOutput | TeammateIdleOutput | TaskCompletedOutput;
|
|
269
|
+
export type SpecificHookOutput = PreToolUseOutput | PostToolUseOutput | PostToolUseFailureOutput | NotificationOutput | UserPromptSubmitOutput | SessionStartOutput | SessionEndOutput | StopOutput | SubagentStartOutput | SubagentStopOutput | PreCompactOutput | PermissionRequestOutput | SetupOutput | TeammateIdleOutput | TaskCompletedOutput | ElicitationOutput | ElicitationResultOutput | ConfigChangeOutput | InstructionsLoadedOutput | WorktreeCreateOutput | WorktreeRemoveOutput;
|
|
235
270
|
/**
|
|
236
271
|
* Options for decision-based hooks (Stop, SubagentStop).
|
|
237
272
|
*/
|
|
@@ -664,6 +699,130 @@ export declare const taskCompletedOutput: ({ stderr }?: ExitCodeOptions) => {
|
|
|
664
699
|
stdout: SyncHookJSONOutput;
|
|
665
700
|
stderr?: string;
|
|
666
701
|
};
|
|
702
|
+
/**
|
|
703
|
+
* Options for the Elicitation output builder.
|
|
704
|
+
*/
|
|
705
|
+
export type ElicitationOptions = CommonOptions & {
|
|
706
|
+
/** Hook-specific output matching the wire format. */
|
|
707
|
+
hookSpecificOutput?: ElicitationHookSpecificOutput;
|
|
708
|
+
};
|
|
709
|
+
/**
|
|
710
|
+
* Creates an output for Elicitation hooks.
|
|
711
|
+
* @param options - Configuration options for the hook output
|
|
712
|
+
* @returns An ElicitationOutput object ready for the runtime
|
|
713
|
+
* @example
|
|
714
|
+
* ```typescript
|
|
715
|
+
* // Accept the elicitation
|
|
716
|
+
* elicitationOutput({
|
|
717
|
+
* hookSpecificOutput: { action: 'accept', content: { username: 'alice' } }
|
|
718
|
+
* });
|
|
719
|
+
*
|
|
720
|
+
* // Decline the elicitation
|
|
721
|
+
* elicitationOutput({
|
|
722
|
+
* hookSpecificOutput: { action: 'decline' }
|
|
723
|
+
* });
|
|
724
|
+
* ```
|
|
725
|
+
*/
|
|
726
|
+
export declare const elicitationOutput: (options?: CommonOptions & {
|
|
727
|
+
hookSpecificOutput?: ElicitationHookSpecificOutput | undefined;
|
|
728
|
+
}) => {
|
|
729
|
+
readonly _type: "Elicitation";
|
|
730
|
+
stdout: SyncHookJSONOutput;
|
|
731
|
+
};
|
|
732
|
+
/**
|
|
733
|
+
* Options for the ElicitationResult output builder.
|
|
734
|
+
*/
|
|
735
|
+
export type ElicitationResultOptions = CommonOptions & {
|
|
736
|
+
/** Hook-specific output matching the wire format. */
|
|
737
|
+
hookSpecificOutput?: ElicitationResultHookSpecificOutput;
|
|
738
|
+
};
|
|
739
|
+
/**
|
|
740
|
+
* Creates an output for ElicitationResult hooks.
|
|
741
|
+
* @param options - Configuration options for the hook output
|
|
742
|
+
* @returns An ElicitationResultOutput object ready for the runtime
|
|
743
|
+
* @example
|
|
744
|
+
* ```typescript
|
|
745
|
+
* elicitationResultOutput({});
|
|
746
|
+
* ```
|
|
747
|
+
*/
|
|
748
|
+
export declare const elicitationResultOutput: (options?: CommonOptions & {
|
|
749
|
+
hookSpecificOutput?: ElicitationResultHookSpecificOutput | undefined;
|
|
750
|
+
}) => {
|
|
751
|
+
readonly _type: "ElicitationResult";
|
|
752
|
+
stdout: SyncHookJSONOutput;
|
|
753
|
+
};
|
|
754
|
+
/**
|
|
755
|
+
* Options for the ConfigChange output builder.
|
|
756
|
+
* ConfigChange hooks only support common options.
|
|
757
|
+
*/
|
|
758
|
+
export type ConfigChangeOptions = CommonOptions;
|
|
759
|
+
/**
|
|
760
|
+
* Creates an output for ConfigChange hooks.
|
|
761
|
+
* @param options - Configuration options for the hook output
|
|
762
|
+
* @returns A ConfigChangeOutput object ready for the runtime
|
|
763
|
+
* @example
|
|
764
|
+
* ```typescript
|
|
765
|
+
* configChangeOutput({});
|
|
766
|
+
* ```
|
|
767
|
+
*/
|
|
768
|
+
export declare const configChangeOutput: (options?: CommonOptions) => {
|
|
769
|
+
readonly _type: "ConfigChange";
|
|
770
|
+
stdout: SyncHookJSONOutput;
|
|
771
|
+
};
|
|
772
|
+
/**
|
|
773
|
+
* Options for the InstructionsLoaded output builder.
|
|
774
|
+
* InstructionsLoaded hooks only support common options.
|
|
775
|
+
*/
|
|
776
|
+
export type InstructionsLoadedOptions = CommonOptions;
|
|
777
|
+
/**
|
|
778
|
+
* Creates an output for InstructionsLoaded hooks.
|
|
779
|
+
* @param options - Configuration options for the hook output
|
|
780
|
+
* @returns An InstructionsLoadedOutput object ready for the runtime
|
|
781
|
+
* @example
|
|
782
|
+
* ```typescript
|
|
783
|
+
* instructionsLoadedOutput({});
|
|
784
|
+
* ```
|
|
785
|
+
*/
|
|
786
|
+
export declare const instructionsLoadedOutput: (options?: CommonOptions) => {
|
|
787
|
+
readonly _type: "InstructionsLoaded";
|
|
788
|
+
stdout: SyncHookJSONOutput;
|
|
789
|
+
};
|
|
790
|
+
/**
|
|
791
|
+
* Options for the WorktreeCreate output builder.
|
|
792
|
+
* WorktreeCreate hooks only support common options.
|
|
793
|
+
*/
|
|
794
|
+
export type WorktreeCreateOptions = CommonOptions;
|
|
795
|
+
/**
|
|
796
|
+
* Creates an output for WorktreeCreate hooks.
|
|
797
|
+
* @param options - Configuration options for the hook output
|
|
798
|
+
* @returns A WorktreeCreateOutput object ready for the runtime
|
|
799
|
+
* @example
|
|
800
|
+
* ```typescript
|
|
801
|
+
* worktreeCreateOutput({});
|
|
802
|
+
* ```
|
|
803
|
+
*/
|
|
804
|
+
export declare const worktreeCreateOutput: (options?: CommonOptions) => {
|
|
805
|
+
readonly _type: "WorktreeCreate";
|
|
806
|
+
stdout: SyncHookJSONOutput;
|
|
807
|
+
};
|
|
808
|
+
/**
|
|
809
|
+
* Options for the WorktreeRemove output builder.
|
|
810
|
+
* WorktreeRemove hooks only support common options.
|
|
811
|
+
*/
|
|
812
|
+
export type WorktreeRemoveOptions = CommonOptions;
|
|
813
|
+
/**
|
|
814
|
+
* Creates an output for WorktreeRemove hooks.
|
|
815
|
+
* @param options - Configuration options for the hook output
|
|
816
|
+
* @returns A WorktreeRemoveOutput object ready for the runtime
|
|
817
|
+
* @example
|
|
818
|
+
* ```typescript
|
|
819
|
+
* worktreeRemoveOutput({});
|
|
820
|
+
* ```
|
|
821
|
+
*/
|
|
822
|
+
export declare const worktreeRemoveOutput: (options?: CommonOptions) => {
|
|
823
|
+
readonly _type: "WorktreeRemove";
|
|
824
|
+
stdout: SyncHookJSONOutput;
|
|
825
|
+
};
|
|
667
826
|
/**
|
|
668
827
|
* @deprecated Use CommonOptions instead
|
|
669
828
|
*/
|
package/types/types.d.ts
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
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, SetupHookInput as SDKSetupHookInput, StopHookInput as SDKStopHookInput, SubagentStartHookInput as SDKSubagentStartHookInput, SubagentStopHookInput as SDKSubagentStopHookInput, TaskCompletedHookInput as SDKTaskCompletedHookInput, TeammateIdleHookInput as SDKTeammateIdleHookInput, 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, TaskCompletedHookInput as SDKTaskCompletedHookInput, TeammateIdleHookInput as SDKTeammateIdleHookInput, UserPromptSubmitHookInput as SDKUserPromptSubmitHookInput } from "@anthropic-ai/claude-agent-sdk";
|
|
15
|
+
export type { BaseHookInput as SDKBaseHookInput, ConfigChangeHookInput as SDKConfigChangeHookInput, ElicitationHookInput as SDKElicitationHookInput, ElicitationResultHookInput as SDKElicitationResultHookInput, HookEvent as SDKHookEvent, HookInput as SDKHookInput, InstructionsLoadedHookInput as SDKInstructionsLoadedHookInput, 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, TaskCompletedHookInput as SDKTaskCompletedHookInput, TeammateIdleHookInput as SDKTeammateIdleHookInput, UserPromptSubmitHookInput as SDKUserPromptSubmitHookInput, WorktreeCreateHookInput as SDKWorktreeCreateHookInput, WorktreeRemoveHookInput as SDKWorktreeRemoveHookInput, } from "@anthropic-ai/claude-agent-sdk";
|
|
16
|
+
import type { BaseHookInput as SDKBaseHookInput, ConfigChangeHookInput as SDKConfigChangeHookInput, ElicitationHookInput as SDKElicitationHookInput, ElicitationResultHookInput as SDKElicitationResultHookInput, InstructionsLoadedHookInput as SDKInstructionsLoadedHookInput, 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, TaskCompletedHookInput as SDKTaskCompletedHookInput, TeammateIdleHookInput as SDKTeammateIdleHookInput, UserPromptSubmitHookInput as SDKUserPromptSubmitHookInput, WorktreeCreateHookInput as SDKWorktreeCreateHookInput, WorktreeRemoveHookInput as SDKWorktreeRemoveHookInput } from "@anthropic-ai/claude-agent-sdk";
|
|
17
17
|
import type { AgentInput, AskUserQuestionInput, BashInput, ConfigInput, ExitPlanModeInput, FileEditInput, FileReadInput, FileWriteInput, GlobInput, GrepInput, TaskStopInput as KillShellInput, ListMcpResourcesInput, McpInput, NotebookEditInput, ReadMcpResourceInput, 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.
|
|
@@ -165,6 +165,74 @@ export type TeammateIdleInput = {
|
|
|
165
165
|
export type TaskCompletedInput = {
|
|
166
166
|
[K in keyof SDKTaskCompletedHookInput]: SDKTaskCompletedHookInput[K];
|
|
167
167
|
} & {};
|
|
168
|
+
/**
|
|
169
|
+
* Input for Elicitation hooks.
|
|
170
|
+
*
|
|
171
|
+
* Fires when an MCP server requests user input (elicitation), allowing you to:
|
|
172
|
+
* - Intercept and handle MCP server prompts programmatically
|
|
173
|
+
* - Accept, decline, or cancel elicitation requests
|
|
174
|
+
* - Provide structured form input or URL-based auth responses
|
|
175
|
+
* @see https://code.claude.com/docs/en/hooks#elicitation
|
|
176
|
+
*/
|
|
177
|
+
export type ElicitationInput = {
|
|
178
|
+
[K in keyof SDKElicitationHookInput]: SDKElicitationHookInput[K];
|
|
179
|
+
} & {};
|
|
180
|
+
/**
|
|
181
|
+
* Input for ElicitationResult hooks.
|
|
182
|
+
*
|
|
183
|
+
* Fires with the result of an elicitation request, allowing you to:
|
|
184
|
+
* - Observe and log elicitation outcomes
|
|
185
|
+
* - Modify the result before it is returned to the MCP server
|
|
186
|
+
* @see https://code.claude.com/docs/en/hooks#elicitationresult
|
|
187
|
+
*/
|
|
188
|
+
export type ElicitationResultInput = {
|
|
189
|
+
[K in keyof SDKElicitationResultHookInput]: SDKElicitationResultHookInput[K];
|
|
190
|
+
} & {};
|
|
191
|
+
/**
|
|
192
|
+
* Input for ConfigChange hooks.
|
|
193
|
+
*
|
|
194
|
+
* Fires when Claude Code configuration changes (settings files, skills), allowing you to:
|
|
195
|
+
* - React to configuration changes
|
|
196
|
+
* - Log or audit configuration changes
|
|
197
|
+
* - Apply custom logic when settings are updated
|
|
198
|
+
* @see https://code.claude.com/docs/en/hooks#configchange
|
|
199
|
+
*/
|
|
200
|
+
export type ConfigChangeInput = {
|
|
201
|
+
[K in keyof SDKConfigChangeHookInput]: SDKConfigChangeHookInput[K];
|
|
202
|
+
} & {};
|
|
203
|
+
/**
|
|
204
|
+
* Input for InstructionsLoaded hooks.
|
|
205
|
+
*
|
|
206
|
+
* Fires when a CLAUDE.md (or similar instructions file) is loaded, allowing you to:
|
|
207
|
+
* - React to instructions being loaded
|
|
208
|
+
* - Log which instruction files are active for the session
|
|
209
|
+
* @see https://code.claude.com/docs/en/hooks#instructionsloaded
|
|
210
|
+
*/
|
|
211
|
+
export type InstructionsLoadedInput = {
|
|
212
|
+
[K in keyof SDKInstructionsLoadedHookInput]: SDKInstructionsLoadedHookInput[K];
|
|
213
|
+
} & {};
|
|
214
|
+
/**
|
|
215
|
+
* Input for WorktreeCreate hooks.
|
|
216
|
+
*
|
|
217
|
+
* Fires when a git worktree is created, allowing you to:
|
|
218
|
+
* - React to new worktree creation
|
|
219
|
+
* - Set up worktree-specific configuration
|
|
220
|
+
* @see https://code.claude.com/docs/en/hooks#worktreecreate
|
|
221
|
+
*/
|
|
222
|
+
export type WorktreeCreateInput = {
|
|
223
|
+
[K in keyof SDKWorktreeCreateHookInput]: SDKWorktreeCreateHookInput[K];
|
|
224
|
+
} & {};
|
|
225
|
+
/**
|
|
226
|
+
* Input for WorktreeRemove hooks.
|
|
227
|
+
*
|
|
228
|
+
* Fires when a git worktree is removed, allowing you to:
|
|
229
|
+
* - React to worktree removal
|
|
230
|
+
* - Clean up worktree-specific resources
|
|
231
|
+
* @see https://code.claude.com/docs/en/hooks#worktreeremove
|
|
232
|
+
*/
|
|
233
|
+
export type WorktreeRemoveInput = {
|
|
234
|
+
[K in keyof SDKWorktreeRemoveHookInput]: SDKWorktreeRemoveHookInput[K];
|
|
235
|
+
} & {};
|
|
168
236
|
/**
|
|
169
237
|
* Input for SessionEnd hooks.
|
|
170
238
|
*
|
|
@@ -259,7 +327,7 @@ export type SetupTrigger = "init" | "maintenance";
|
|
|
259
327
|
* ```
|
|
260
328
|
* @see https://code.claude.com/docs/en/hooks
|
|
261
329
|
*/
|
|
262
|
-
export type HookInput = PreToolUseInput | PostToolUseInput | PostToolUseFailureInput | NotificationInput | UserPromptSubmitInput | SessionStartInput | SessionEndInput | StopInput | SubagentStartInput | SubagentStopInput | PreCompactInput | PermissionRequestInput | SetupInput | TeammateIdleInput | TaskCompletedInput;
|
|
330
|
+
export type HookInput = PreToolUseInput | PostToolUseInput | PostToolUseFailureInput | NotificationInput | UserPromptSubmitInput | SessionStartInput | SessionEndInput | StopInput | SubagentStartInput | SubagentStopInput | PreCompactInput | PermissionRequestInput | SetupInput | TeammateIdleInput | TaskCompletedInput | ElicitationInput | ElicitationResultInput | ConfigChangeInput | InstructionsLoadedInput | WorktreeCreateInput | WorktreeRemoveInput;
|
|
263
331
|
/**
|
|
264
332
|
* Hook event name literal union.
|
|
265
333
|
*
|
|
@@ -277,7 +345,7 @@ export type HookEventName = HookInput["hook_event_name"];
|
|
|
277
345
|
* }
|
|
278
346
|
* ```
|
|
279
347
|
*/
|
|
280
|
-
export declare const HOOK_EVENT_NAMES: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest", "Setup", "TeammateIdle", "TaskCompleted"];
|
|
348
|
+
export declare const HOOK_EVENT_NAMES: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest", "Setup", "TeammateIdle", "TaskCompleted", "Elicitation", "ElicitationResult", "ConfigChange", "InstructionsLoaded", "WorktreeCreate", "WorktreeRemove"];
|
|
281
349
|
export type { SDKPermissionUpdate as PermissionUpdate };
|
|
282
350
|
/**
|
|
283
351
|
* Re-export all tool input types from the official Claude Agent SDK.
|