cc-hooks-ts 2.1.94 → 2.1.121

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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as v from "valibot";
2
- import { AgentInput, AgentOutput, AskUserQuestionInput, AskUserQuestionOutput, BashInput, BashOutput, ConfigInput, ConfigOutput, EnterWorktreeInput, EnterWorktreeOutput, ExitPlanModeInput, ExitPlanModeOutput, ExitWorktreeInput, ExitWorktreeOutput, FileEditInput, FileEditOutput, FileReadInput, FileReadOutput, FileWriteInput, FileWriteOutput, GlobInput, GlobOutput, GrepInput, GrepOutput, ListMcpResourcesInput, ListMcpResourcesOutput, McpInput, McpOutput, NotebookEditInput, NotebookEditOutput, ReadMcpResourceInput, ReadMcpResourceOutput, TaskOutputInput, TaskStopInput, TaskStopOutput, TodoWriteInput, TodoWriteOutput, WebFetchInput, WebFetchOutput, WebSearchInput, WebSearchOutput } from "@anthropic-ai/claude-agent-sdk/sdk-tools";
2
+ import { AgentInput, AgentOutput, AskUserQuestionInput, AskUserQuestionOutput, BashInput, BashOutput, EnterWorktreeInput, EnterWorktreeOutput, ExitPlanModeInput, ExitPlanModeOutput, ExitWorktreeInput, ExitWorktreeOutput, FileEditInput, FileEditOutput, FileReadInput, FileReadOutput, FileWriteInput, FileWriteOutput, GlobInput, GlobOutput, GrepInput, GrepOutput, ListMcpResourcesInput, ListMcpResourcesOutput, McpInput, McpOutput, NotebookEditInput, NotebookEditOutput, ReadMcpResourceInput, ReadMcpResourceOutput, TaskOutputInput, TaskStopInput, TaskStopOutput, TodoWriteInput, TodoWriteOutput, WebFetchInput, WebFetchOutput, WebSearchInput, WebSearchOutput } from "@anthropic-ai/claude-agent-sdk/sdk-tools";
3
3
 
4
4
  //#region src/utils/types.d.ts
5
5
  type Awaitable<T> = Promise<T> | T;
@@ -33,6 +33,7 @@ declare const HookInputSchemas: {
33
33
  readonly hook_event_name: v.LiteralSchema<"PostToolUse", undefined>;
34
34
  } & {
35
35
  tool_name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.GuardAction<string, (s: string) => s is AutoComplete<string>, undefined>]>;
36
+ duration_ms: v.ExactOptionalSchema<v.NumberSchema<undefined>, undefined>;
36
37
  tool_input: v.UnknownSchema;
37
38
  tool_response: v.UnknownSchema;
38
39
  tool_use_id: v.StringSchema<undefined>;
@@ -47,11 +48,28 @@ declare const HookInputSchemas: {
47
48
  readonly hook_event_name: v.LiteralSchema<"PostToolUseFailure", undefined>;
48
49
  } & {
49
50
  tool_name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.GuardAction<string, (s: string) => s is AutoComplete<string>, undefined>]>;
51
+ duration_ms: v.ExactOptionalSchema<v.NumberSchema<undefined>, undefined>;
50
52
  error: v.StringSchema<undefined>;
51
53
  is_interrupt: v.ExactOptionalSchema<v.BooleanSchema<undefined>, undefined>;
52
54
  tool_input: v.UnknownSchema;
53
55
  tool_use_id: v.StringSchema<undefined>;
54
56
  }, undefined>;
57
+ readonly PostToolBatch: v.ObjectSchema<{
58
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
59
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
60
+ readonly cwd: v.StringSchema<undefined>;
61
+ readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
62
+ readonly session_id: v.StringSchema<undefined>;
63
+ readonly transcript_path: v.StringSchema<undefined>;
64
+ readonly hook_event_name: v.LiteralSchema<"PostToolBatch", undefined>;
65
+ } & {
66
+ tool_calls: v.ArraySchema<v.ObjectSchema<{
67
+ readonly tool_input: v.UnknownSchema;
68
+ readonly tool_name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.GuardAction<string, (s: string) => s is AutoComplete<string>, undefined>]>;
69
+ readonly tool_response: v.ExactOptionalSchema<v.UnknownSchema, undefined>;
70
+ readonly tool_use_id: v.StringSchema<undefined>;
71
+ }, undefined>, undefined>;
72
+ }, undefined>;
55
73
  readonly Notification: v.ObjectSchema<{
56
74
  readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
57
75
  readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -77,6 +95,21 @@ declare const HookInputSchemas: {
77
95
  prompt: v.StringSchema<undefined>;
78
96
  session_title: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
79
97
  }, undefined>;
98
+ readonly UserPromptExpansion: v.ObjectSchema<{
99
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
100
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
101
+ readonly cwd: v.StringSchema<undefined>;
102
+ readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
103
+ readonly session_id: v.StringSchema<undefined>;
104
+ readonly transcript_path: v.StringSchema<undefined>;
105
+ readonly hook_event_name: v.LiteralSchema<"UserPromptExpansion", undefined>;
106
+ } & {
107
+ command_args: v.StringSchema<undefined>;
108
+ command_name: v.StringSchema<undefined>;
109
+ command_source: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
110
+ expansion_type: v.PicklistSchema<["slash_command", "mcp_prompt"], undefined>;
111
+ prompt: v.StringSchema<undefined>;
112
+ }, undefined>;
80
113
  readonly Stop: v.ObjectSchema<{
81
114
  readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
82
115
  readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -407,7 +440,7 @@ declare const HookInputSchemas: {
407
440
  *
408
441
  * @package
409
442
  */
410
- type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "Notification" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "StopFailure" | "SubagentStart" | "SubagentStop" | "PreCompact" | "PostCompact" | "PermissionRequest" | "PermissionDenied" | "Setup" | "TeammateIdle" | "TaskCreated" | "TaskCompleted" | "ConfigChange" | "WorktreeCreate" | "WorktreeRemove" | "Elicitation" | "ElicitationResult" | "InstructionsLoaded" | "CwdChanged" | "FileChanged";
443
+ type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "PostToolBatch" | "Notification" | "UserPromptSubmit" | "UserPromptExpansion" | "SessionStart" | "SessionEnd" | "Stop" | "StopFailure" | "SubagentStart" | "SubagentStop" | "PreCompact" | "PostCompact" | "PermissionRequest" | "PermissionDenied" | "Setup" | "TeammateIdle" | "TaskCreated" | "TaskCompleted" | "ConfigChange" | "WorktreeCreate" | "WorktreeRemove" | "Elicitation" | "ElicitationResult" | "InstructionsLoaded" | "CwdChanged" | "FileChanged";
411
444
  //#endregion
412
445
  //#region src/hooks/input/types.d.ts
413
446
  /**
@@ -431,6 +464,8 @@ type HookInput = { [EventKey in SupportedHookEvent]: EventKey extends "PreToolUs
431
464
  default: BaseHookInputs["PermissionRequest"];
432
465
  } : EventKey extends "PermissionDenied" ? ToolSpecificPermissionDeniedInput & {
433
466
  default: BaseHookInputs["PermissionDenied"];
467
+ } : EventKey extends "PostToolBatch" ? {
468
+ default: PostToolBatchInput;
434
469
  } : {
435
470
  default: BaseHookInputs[EventKey];
436
471
  } };
@@ -499,6 +534,15 @@ type ToolSpecificPermissionDeniedInput = { [K in keyof ToolSchema]: Omit<BaseHoo
499
534
  tool_input: ToolSchema[K]["input"];
500
535
  tool_name: K;
501
536
  } };
537
+ type BatchedToolCall = { [K in keyof ToolSchema]: {
538
+ tool_input: ToolSchema[K]["input"];
539
+ tool_name: K;
540
+ tool_response?: ToolSchema[K]["response"];
541
+ tool_use_id: string;
542
+ } }[keyof ToolSchema];
543
+ type PostToolBatchInput = Omit<BaseHookInputs["PostToolBatch"], "tool_calls"> & {
544
+ tool_calls: BatchedToolCall[];
545
+ };
502
546
  //#endregion
503
547
  //#region src/hooks/permission.d.ts
504
548
  /**
@@ -551,6 +595,8 @@ type HookOutput = {
551
595
  PreToolUse: PreToolUseHookOutput;
552
596
  PostToolUse: PostToolUseHookOutput;
553
597
  PostToolUseFailure: PostToolUseFailureHookOutput;
598
+ PostToolBatch: PostToolBatchHookOutput;
599
+ UserPromptExpansion: UserPromptExpansionHookOutput;
554
600
  UserPromptSubmit: UserPromptSubmitHookOutput;
555
601
  Stop: StopHookOutput;
556
602
  StopFailure: CommonHookOutputs;
@@ -676,6 +722,13 @@ interface PostToolUseHookOutput extends CommonHookOutputs {
676
722
  * Adds context for Claude to consider.
677
723
  */
678
724
  additionalContext?: string;
725
+ /**
726
+ * Replaces the tool output before it is sent to the model.
727
+ */
728
+ updatedToolOutput?: unknown;
729
+ /**
730
+ * Replaces the output for MCP tools only. Prefer `updatedToolOutput`, which works for all tools.
731
+ */
679
732
  updatedMCPToolOutput?: unknown;
680
733
  };
681
734
  reason?: string;
@@ -689,6 +742,27 @@ interface PostToolUseFailureHookOutput extends CommonHookOutputs {
689
742
  additionalContext?: string;
690
743
  };
691
744
  }
745
+ interface PostToolBatchHookOutput extends CommonHookOutputs {
746
+ hookSpecificOutput?: {
747
+ hookEventName: "PostToolBatch";
748
+ /**
749
+ * Adds context for Claude to consider.
750
+ */
751
+ additionalContext?: string;
752
+ };
753
+ }
754
+ /**
755
+ * @see {@link https://docs.anthropic.com/en/docs/claude-code/hooks#userpromptsubmit-decision-control}
756
+ */
757
+ interface UserPromptExpansionHookOutput extends CommonHookOutputs {
758
+ hookSpecificOutput?: {
759
+ hookEventName: "UserPromptExpansion";
760
+ /**
761
+ * Adds the string to the context.
762
+ */
763
+ additionalContext?: string;
764
+ };
765
+ }
692
766
  /**
693
767
  * @see {@link https://docs.anthropic.com/en/docs/claude-code/hooks#userpromptsubmit-decision-control}
694
768
  */
@@ -1213,10 +1287,6 @@ interface ToolSchema {
1213
1287
  input: BashInput;
1214
1288
  response: BashOutput;
1215
1289
  };
1216
- Config: {
1217
- input: ConfigInput;
1218
- response: ConfigOutput;
1219
- };
1220
1290
  Edit: {
1221
1291
  input: FileEditInput;
1222
1292
  response: FileEditOutput;
package/dist/index.mjs CHANGED
@@ -186,17 +186,25 @@ const HookInputSchemas = {
186
186
  }),
187
187
  PostToolUse: buildHookInputSchema("PostToolUse", {
188
188
  tool_name: v.pipe(v.string(), v.guard((s) => true)),
189
+ duration_ms: v.exactOptional(v.number()),
189
190
  tool_input: v.unknown(),
190
191
  tool_response: v.unknown(),
191
192
  tool_use_id: v.string()
192
193
  }),
193
194
  PostToolUseFailure: buildHookInputSchema("PostToolUseFailure", {
194
195
  tool_name: v.pipe(v.string(), v.guard((s) => true)),
196
+ duration_ms: v.exactOptional(v.number()),
195
197
  error: v.string(),
196
198
  is_interrupt: v.exactOptional(v.boolean()),
197
199
  tool_input: v.unknown(),
198
200
  tool_use_id: v.string()
199
201
  }),
202
+ PostToolBatch: buildHookInputSchema("PostToolBatch", { tool_calls: v.array(v.object({
203
+ tool_input: v.unknown(),
204
+ tool_name: v.pipe(v.string(), v.guard((s) => true)),
205
+ tool_response: v.exactOptional(v.unknown()),
206
+ tool_use_id: v.string()
207
+ })) }),
200
208
  Notification: buildHookInputSchema("Notification", {
201
209
  message: v.string(),
202
210
  notification_type: v.string(),
@@ -206,6 +214,13 @@ const HookInputSchemas = {
206
214
  prompt: v.string(),
207
215
  session_title: v.exactOptional(v.string())
208
216
  }),
217
+ UserPromptExpansion: buildHookInputSchema("UserPromptExpansion", {
218
+ command_args: v.string(),
219
+ command_name: v.string(),
220
+ command_source: v.exactOptional(v.string()),
221
+ expansion_type: v.picklist(["slash_command", "mcp_prompt"]),
222
+ prompt: v.string()
223
+ }),
209
224
  Stop: buildHookInputSchema("Stop", {
210
225
  last_assistant_message: v.exactOptional(v.string()),
211
226
  stop_hook_active: v.boolean()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-hooks-ts",
3
- "version": "2.1.94",
3
+ "version": "2.1.121",
4
4
  "type": "module",
5
5
  "description": "Write claude code hooks with type safety",
6
6
  "sideEffects": false,
@@ -62,7 +62,7 @@
62
62
  "vitest": "4.1.2"
63
63
  },
64
64
  "dependencies": {
65
- "@anthropic-ai/claude-agent-sdk": "0.2.94",
65
+ "@anthropic-ai/claude-agent-sdk": "0.2.121",
66
66
  "get-stdin": "10.0.0",
67
67
  "valibot": "^1.1.0"
68
68
  },