cc-hooks-ts 2.1.63 → 2.1.76

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, ExitPlanModeInput, ExitPlanModeOutput, FileEditInput, FileEditOutput, FileReadInput, FileReadOutput, FileWriteInput, FileWriteOutput, GlobInput, GlobOutput, GrepInput, GrepOutput, ListMcpResourcesInput, ListMcpResourcesOutput, 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, 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, SubscribeMcpResourceInput, SubscribeMcpResourceOutput, SubscribePollingInput, SubscribePollingOutput, TaskOutputInput, TaskStopInput, TaskStopOutput, TodoWriteInput, TodoWriteOutput, UnsubscribeMcpResourceInput, UnsubscribeMcpResourceOutput, UnsubscribePollingInput, UnsubscribePollingOutput, 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;
@@ -11,6 +11,8 @@ type AutoComplete<T extends string> = Record<string, never> & T;
11
11
  */
12
12
  declare const HookInputSchemas: {
13
13
  readonly PreToolUse: v.ObjectSchema<{
14
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
15
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
14
16
  readonly cwd: v.StringSchema<undefined>;
15
17
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
16
18
  readonly session_id: v.StringSchema<undefined>;
@@ -22,6 +24,8 @@ declare const HookInputSchemas: {
22
24
  tool_use_id: v.StringSchema<undefined>;
23
25
  }, undefined>;
24
26
  readonly PostToolUse: v.ObjectSchema<{
27
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
28
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
25
29
  readonly cwd: v.StringSchema<undefined>;
26
30
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
27
31
  readonly session_id: v.StringSchema<undefined>;
@@ -34,6 +38,8 @@ declare const HookInputSchemas: {
34
38
  tool_use_id: v.StringSchema<undefined>;
35
39
  }, undefined>;
36
40
  readonly PostToolUseFailure: v.ObjectSchema<{
41
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
42
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
37
43
  readonly cwd: v.StringSchema<undefined>;
38
44
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
39
45
  readonly session_id: v.StringSchema<undefined>;
@@ -47,6 +53,8 @@ declare const HookInputSchemas: {
47
53
  tool_use_id: v.StringSchema<undefined>;
48
54
  }, undefined>;
49
55
  readonly Notification: v.ObjectSchema<{
56
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
57
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
50
58
  readonly cwd: v.StringSchema<undefined>;
51
59
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
52
60
  readonly session_id: v.StringSchema<undefined>;
@@ -58,6 +66,8 @@ declare const HookInputSchemas: {
58
66
  title: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
59
67
  }, undefined>;
60
68
  readonly UserPromptSubmit: v.ObjectSchema<{
69
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
70
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
61
71
  readonly cwd: v.StringSchema<undefined>;
62
72
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
63
73
  readonly session_id: v.StringSchema<undefined>;
@@ -67,6 +77,8 @@ declare const HookInputSchemas: {
67
77
  prompt: v.StringSchema<undefined>;
68
78
  }, undefined>;
69
79
  readonly Stop: v.ObjectSchema<{
80
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
81
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
70
82
  readonly cwd: v.StringSchema<undefined>;
71
83
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
72
84
  readonly session_id: v.StringSchema<undefined>;
@@ -76,30 +88,37 @@ declare const HookInputSchemas: {
76
88
  last_assistant_message: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
77
89
  stop_hook_active: v.BooleanSchema<undefined>;
78
90
  }, undefined>;
79
- readonly SubagentStart: v.ObjectSchema<{
91
+ readonly SubagentStart: v.ObjectSchema<Omit<{
92
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
93
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
80
94
  readonly cwd: v.StringSchema<undefined>;
81
95
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
82
96
  readonly session_id: v.StringSchema<undefined>;
83
97
  readonly transcript_path: v.StringSchema<undefined>;
84
98
  readonly hook_event_name: v.LiteralSchema<"SubagentStart", undefined>;
85
- } & {
86
- agent_id: v.StringSchema<undefined>;
87
- agent_type: v.StringSchema<undefined>;
99
+ }, "agent_id" | "agent_type"> & {
100
+ readonly agent_id: v.StringSchema<undefined>;
101
+ readonly agent_type: v.StringSchema<undefined>;
88
102
  }, undefined>;
89
- readonly SubagentStop: v.ObjectSchema<{
103
+ readonly SubagentStop: v.ObjectSchema<Omit<{
104
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
105
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
90
106
  readonly cwd: v.StringSchema<undefined>;
91
107
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
92
108
  readonly session_id: v.StringSchema<undefined>;
93
109
  readonly transcript_path: v.StringSchema<undefined>;
94
110
  readonly hook_event_name: v.LiteralSchema<"SubagentStop", undefined>;
95
111
  } & {
96
- agent_id: v.StringSchema<undefined>;
97
112
  agent_transcript_path: v.StringSchema<undefined>;
98
- agent_type: v.StringSchema<undefined>;
99
113
  last_assistant_message: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
100
114
  stop_hook_active: v.BooleanSchema<undefined>;
115
+ }, "agent_id" | "agent_type"> & {
116
+ readonly agent_id: v.StringSchema<undefined>;
117
+ readonly agent_type: v.StringSchema<undefined>;
101
118
  }, undefined>;
102
119
  readonly PreCompact: v.ObjectSchema<{
120
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
121
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
103
122
  readonly cwd: v.StringSchema<undefined>;
104
123
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
105
124
  readonly session_id: v.StringSchema<undefined>;
@@ -109,7 +128,21 @@ declare const HookInputSchemas: {
109
128
  custom_instructions: v.NullableSchema<v.StringSchema<undefined>, undefined>;
110
129
  trigger: v.PicklistSchema<["manual", "auto"], undefined>;
111
130
  }, undefined>;
131
+ readonly PostCompact: v.ObjectSchema<{
132
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
133
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
134
+ readonly cwd: v.StringSchema<undefined>;
135
+ readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
136
+ readonly session_id: v.StringSchema<undefined>;
137
+ readonly transcript_path: v.StringSchema<undefined>;
138
+ readonly hook_event_name: v.LiteralSchema<"PostCompact", undefined>;
139
+ } & {
140
+ compact_summary: v.StringSchema<undefined>;
141
+ trigger: v.PicklistSchema<["manual", "auto"], undefined>;
142
+ }, undefined>;
112
143
  readonly SessionStart: v.ObjectSchema<{
144
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
145
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
113
146
  readonly cwd: v.StringSchema<undefined>;
114
147
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
115
148
  readonly session_id: v.StringSchema<undefined>;
@@ -121,6 +154,8 @@ declare const HookInputSchemas: {
121
154
  source: v.PicklistSchema<["startup", "resume", "clear", "compact"], undefined>;
122
155
  }, undefined>;
123
156
  readonly SessionEnd: v.ObjectSchema<{
157
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
158
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
124
159
  readonly cwd: v.StringSchema<undefined>;
125
160
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
126
161
  readonly session_id: v.StringSchema<undefined>;
@@ -130,6 +165,8 @@ declare const HookInputSchemas: {
130
165
  reason: v.PicklistSchema<["clear", "logout", "prompt_input_exit", "other", "bypass_permissions_disabled"], undefined>;
131
166
  }, undefined>;
132
167
  readonly PermissionRequest: v.ObjectSchema<{
168
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
169
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
133
170
  readonly cwd: v.StringSchema<undefined>;
134
171
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
135
172
  readonly session_id: v.StringSchema<undefined>;
@@ -177,6 +214,8 @@ declare const HookInputSchemas: {
177
214
  tool_name: v.StringSchema<undefined>;
178
215
  }, undefined>;
179
216
  readonly Setup: v.ObjectSchema<{
217
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
218
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
180
219
  readonly cwd: v.StringSchema<undefined>;
181
220
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
182
221
  readonly session_id: v.StringSchema<undefined>;
@@ -186,6 +225,8 @@ declare const HookInputSchemas: {
186
225
  trigger: v.PicklistSchema<["init", "maintenance"], undefined>;
187
226
  }, undefined>;
188
227
  readonly TeammateIdle: v.ObjectSchema<{
228
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
229
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
189
230
  readonly cwd: v.StringSchema<undefined>;
190
231
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
191
232
  readonly session_id: v.StringSchema<undefined>;
@@ -196,6 +237,8 @@ declare const HookInputSchemas: {
196
237
  teammate_name: v.StringSchema<undefined>;
197
238
  }, undefined>;
198
239
  readonly TaskCompleted: v.ObjectSchema<{
240
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
241
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
199
242
  readonly cwd: v.StringSchema<undefined>;
200
243
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
201
244
  readonly session_id: v.StringSchema<undefined>;
@@ -209,6 +252,8 @@ declare const HookInputSchemas: {
209
252
  teammate_name: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
210
253
  }, undefined>;
211
254
  readonly ConfigChange: v.ObjectSchema<{
255
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
256
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
212
257
  readonly cwd: v.StringSchema<undefined>;
213
258
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
214
259
  readonly session_id: v.StringSchema<undefined>;
@@ -219,6 +264,8 @@ declare const HookInputSchemas: {
219
264
  source: v.PicklistSchema<["local_settings", "policy_settings", "project_settings", "skills", "user_settings"], undefined>;
220
265
  }, undefined>;
221
266
  readonly WorktreeCreate: v.ObjectSchema<{
267
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
268
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
222
269
  readonly cwd: v.StringSchema<undefined>;
223
270
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
224
271
  readonly session_id: v.StringSchema<undefined>;
@@ -228,6 +275,8 @@ declare const HookInputSchemas: {
228
275
  name: v.StringSchema<undefined>;
229
276
  }, undefined>;
230
277
  readonly WorktreeRemove: v.ObjectSchema<{
278
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
279
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
231
280
  readonly cwd: v.StringSchema<undefined>;
232
281
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
233
282
  readonly session_id: v.StringSchema<undefined>;
@@ -237,6 +286,8 @@ declare const HookInputSchemas: {
237
286
  worktree_path: v.StringSchema<undefined>;
238
287
  }, undefined>;
239
288
  readonly Elicitation: v.ObjectSchema<{
289
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
290
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
240
291
  readonly cwd: v.StringSchema<undefined>;
241
292
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
242
293
  readonly session_id: v.StringSchema<undefined>;
@@ -251,6 +302,8 @@ declare const HookInputSchemas: {
251
302
  url: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
252
303
  }, undefined>;
253
304
  readonly ElicitationResult: v.ObjectSchema<{
305
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
306
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
254
307
  readonly cwd: v.StringSchema<undefined>;
255
308
  readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
256
309
  readonly session_id: v.StringSchema<undefined>;
@@ -263,6 +316,22 @@ declare const HookInputSchemas: {
263
316
  mcp_server_name: v.StringSchema<undefined>;
264
317
  mode: v.ExactOptionalSchema<v.PicklistSchema<["form", "url"], undefined>, undefined>;
265
318
  }, undefined>;
319
+ readonly InstructionsLoaded: v.ObjectSchema<{
320
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
321
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
322
+ readonly cwd: v.StringSchema<undefined>;
323
+ readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
324
+ readonly session_id: v.StringSchema<undefined>;
325
+ readonly transcript_path: v.StringSchema<undefined>;
326
+ readonly hook_event_name: v.LiteralSchema<"InstructionsLoaded", undefined>;
327
+ } & {
328
+ file_path: v.StringSchema<undefined>;
329
+ globs: v.ExactOptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
330
+ load_reason: v.PicklistSchema<["session_start", "nested_traversal", "path_glob_match", "include"], undefined>;
331
+ memory_type: v.PicklistSchema<["User", "Project", "Local", "Managed"], undefined>;
332
+ parent_file_path: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
333
+ trigger_file_path: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
334
+ }, undefined>;
266
335
  };
267
336
  //#endregion
268
337
  //#region src/hooks/event.d.ts
@@ -271,7 +340,7 @@ declare const HookInputSchemas: {
271
340
  *
272
341
  * @package
273
342
  */
274
- type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "Notification" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "SubagentStart" | "SubagentStop" | "PreCompact" | "PermissionRequest" | "Setup" | "TeammateIdle" | "TaskCompleted" | "ConfigChange" | "WorktreeCreate" | "WorktreeRemove" | "Elicitation" | "ElicitationResult";
343
+ type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "Notification" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "SubagentStart" | "SubagentStop" | "PreCompact" | "PostCompact" | "PermissionRequest" | "Setup" | "TeammateIdle" | "TaskCompleted" | "ConfigChange" | "WorktreeCreate" | "WorktreeRemove" | "Elicitation" | "ElicitationResult" | "InstructionsLoaded";
275
344
  //#endregion
276
345
  //#region src/hooks/input/types.d.ts
277
346
  /**
@@ -414,6 +483,8 @@ type HookOutput = {
414
483
  Elicitation: ElicitationHookOutput;
415
484
  ElicitationResult: ElicitationResultHookOutput;
416
485
  ConfigChange: CommonHookOutputs;
486
+ InstructionsLoaded: CommonHookOutputs;
487
+ PostCompact: CommonHookOutputs;
417
488
  PreCompact: CommonHookOutputs;
418
489
  SessionEnd: CommonHookOutputs;
419
490
  TaskCompleted: CommonHookOutputs;
@@ -1030,14 +1101,26 @@ interface ToolSchema {
1030
1101
  input: BashInput;
1031
1102
  response: BashOutput;
1032
1103
  };
1104
+ Config: {
1105
+ input: ConfigInput;
1106
+ response: ConfigOutput;
1107
+ };
1033
1108
  Edit: {
1034
1109
  input: FileEditInput;
1035
1110
  response: FileEditOutput;
1036
1111
  };
1112
+ EnterWorktree: {
1113
+ input: EnterWorktreeInput;
1114
+ response: EnterWorktreeOutput;
1115
+ };
1037
1116
  ExitPlanMode: {
1038
1117
  input: ExitPlanModeInput;
1039
1118
  response: ExitPlanModeOutput;
1040
1119
  };
1120
+ ExitWorktree: {
1121
+ input: ExitWorktreeInput;
1122
+ response: ExitWorktreeOutput;
1123
+ };
1041
1124
  Glob: {
1042
1125
  input: GlobInput;
1043
1126
  response: GlobOutput;
@@ -1050,6 +1133,10 @@ interface ToolSchema {
1050
1133
  input: ListMcpResourcesInput;
1051
1134
  response: ListMcpResourcesOutput;
1052
1135
  };
1136
+ Mcp: {
1137
+ input: McpInput;
1138
+ response: McpOutput;
1139
+ };
1053
1140
  NotebookEdit: {
1054
1141
  input: NotebookEditInput;
1055
1142
  response: NotebookEditOutput;
@@ -1062,6 +1149,14 @@ interface ToolSchema {
1062
1149
  input: ReadMcpResourceInput;
1063
1150
  response: ReadMcpResourceOutput;
1064
1151
  };
1152
+ SubscribeMcpResource: {
1153
+ input: SubscribeMcpResourceInput;
1154
+ response: SubscribeMcpResourceOutput;
1155
+ };
1156
+ SubscribePolling: {
1157
+ input: SubscribePollingInput;
1158
+ response: SubscribePollingOutput;
1159
+ };
1065
1160
  Task: {
1066
1161
  input: AgentInput;
1067
1162
  response: AgentOutput;
@@ -1078,6 +1173,14 @@ interface ToolSchema {
1078
1173
  input: TodoWriteInput;
1079
1174
  response: TodoWriteOutput;
1080
1175
  };
1176
+ UnsubscribeMcpResource: {
1177
+ input: UnsubscribeMcpResourceInput;
1178
+ response: UnsubscribeMcpResourceOutput;
1179
+ };
1180
+ UnsubscribePolling: {
1181
+ input: UnsubscribePollingInput;
1182
+ response: UnsubscribePollingOutput;
1183
+ };
1081
1184
  WebFetch: {
1082
1185
  input: WebFetchInput;
1083
1186
  response: WebFetchOutput;
package/dist/index.mjs CHANGED
@@ -1,9 +1,63 @@
1
1
  import getStdin from "get-stdin";
2
2
  import process from "node:process";
3
3
  import * as v from "valibot";
4
+ //#region src/define.ts
5
+ /**
6
+ * Creates a type-safe Claude Code hook definition.
7
+ *
8
+ * This function provides a way to define hooks with full TypeScript type safety,
9
+ * including input validation using Valibot schemas and strongly typed context.
10
+ *
11
+ * @param definition - The hook definition object containing trigger events and handler function
12
+ * @returns The same hook definition, but with enhanced type safety
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * // Basic session start hook
17
+ * const sessionHook = defineHook({
18
+ * trigger: { SessionStart: true },
19
+ * run: (context) => {
20
+ * console.log(`Session started: ${context.input.session_id}`);
21
+ * return context.success({
22
+ * messageForUser: "Welcome to your coding session!"
23
+ * });
24
+ * }
25
+ * });
26
+ *
27
+ * // Tool-specific PreToolUse hook
28
+ * const readHook = defineHook({
29
+ * trigger: { PreToolUse: { Read: true } },
30
+ * run: (context) => {
31
+ * // context.input.tool_input is typed as { file_path: string }
32
+ * const { file_path } = context.input.tool_input;
33
+ *
34
+ * if (file_path.includes('.env')) {
35
+ * return context.blockingError('Cannot read environment files');
36
+ * }
37
+ *
38
+ * return context.success();
39
+ * }
40
+ * });
41
+ *
42
+ * // Multiple event triggers with conditional logic
43
+ * const multiEventHook = defineHook({
44
+ * trigger: {
45
+ * PreToolUse: { Read: true, WebFetch: true },
46
+ * PostToolUse: { Read: true }
47
+ * },
48
+ * shouldRun: () => process.env.NODE_ENV === 'development',
49
+ * run: (context) => {
50
+ * // Handle different events and tools based on context.input
51
+ * return context.success();
52
+ * }
53
+ * });
54
+ * ```
55
+ */
4
56
  function defineHook(definition) {
5
57
  return definition;
6
58
  }
59
+ //#endregion
60
+ //#region src/context.ts
7
61
  function createContext(input) {
8
62
  return {
9
63
  defer: (handler, options) => ({
@@ -33,6 +87,8 @@ function createContext(input) {
33
87
  })
34
88
  };
35
89
  }
90
+ //#endregion
91
+ //#region src/hooks/permission.ts
36
92
  const permissionBehaviorSchema = v.picklist([
37
93
  "allow",
38
94
  "deny",
@@ -49,6 +105,9 @@ const permissionRuleValueSchema = v.object({
49
105
  ruleContent: v.exactOptional(v.string()),
50
106
  toolName: v.string()
51
107
  });
108
+ /**
109
+ * @package
110
+ */
52
111
  const permissionUpdateSchema = v.variant("type", [
53
112
  v.object({
54
113
  behavior: permissionBehaviorSchema,
@@ -90,7 +149,11 @@ const permissionUpdateSchema = v.variant("type", [
90
149
  type: v.literal("removeDirectories")
91
150
  })
92
151
  ]);
152
+ //#endregion
153
+ //#region src/hooks/input/schemas.ts
93
154
  const baseHookInputSchema = v.object({
155
+ agent_id: v.exactOptional(v.string()),
156
+ agent_type: v.exactOptional(v.string()),
94
157
  cwd: v.string(),
95
158
  permission_mode: v.exactOptional(v.string()),
96
159
  session_id: v.string(),
@@ -103,6 +166,17 @@ function buildHookInputSchema(hook_event_name, entries) {
103
166
  ...entries
104
167
  });
105
168
  }
169
+ function buildSubagentInputSchema(hook_event_name, entries) {
170
+ const base = buildHookInputSchema(hook_event_name, entries);
171
+ return v.object({
172
+ ...v.omit(base, ["agent_id", "agent_type"]).entries,
173
+ agent_id: v.string(),
174
+ agent_type: v.string()
175
+ });
176
+ }
177
+ /**
178
+ * @package
179
+ */
106
180
  const HookInputSchemas = {
107
181
  PreToolUse: buildHookInputSchema("PreToolUse", {
108
182
  tool_name: v.pipe(v.string(), v.transform((s) => s)),
@@ -132,14 +206,9 @@ const HookInputSchemas = {
132
206
  last_assistant_message: v.exactOptional(v.string()),
133
207
  stop_hook_active: v.boolean()
134
208
  }),
135
- SubagentStart: buildHookInputSchema("SubagentStart", {
136
- agent_id: v.string(),
137
- agent_type: v.string()
138
- }),
139
- SubagentStop: buildHookInputSchema("SubagentStop", {
140
- agent_id: v.string(),
209
+ SubagentStart: buildSubagentInputSchema("SubagentStart", {}),
210
+ SubagentStop: buildSubagentInputSchema("SubagentStop", {
141
211
  agent_transcript_path: v.string(),
142
- agent_type: v.string(),
143
212
  last_assistant_message: v.exactOptional(v.string()),
144
213
  stop_hook_active: v.boolean()
145
214
  }),
@@ -147,6 +216,10 @@ const HookInputSchemas = {
147
216
  custom_instructions: v.nullable(v.string()),
148
217
  trigger: v.picklist(["manual", "auto"])
149
218
  }),
219
+ PostCompact: buildHookInputSchema("PostCompact", {
220
+ compact_summary: v.string(),
221
+ trigger: v.picklist(["manual", "auto"])
222
+ }),
150
223
  SessionStart: buildHookInputSchema("SessionStart", {
151
224
  agent_type: v.exactOptional(v.string()),
152
225
  model: v.exactOptional(v.string()),
@@ -211,11 +284,77 @@ const HookInputSchemas = {
211
284
  elicitation_id: v.exactOptional(v.string()),
212
285
  mcp_server_name: v.string(),
213
286
  mode: v.exactOptional(v.picklist(["form", "url"]))
287
+ }),
288
+ InstructionsLoaded: buildHookInputSchema("InstructionsLoaded", {
289
+ file_path: v.string(),
290
+ globs: v.exactOptional(v.array(v.string())),
291
+ load_reason: v.picklist([
292
+ "session_start",
293
+ "nested_traversal",
294
+ "path_glob_match",
295
+ "include"
296
+ ]),
297
+ memory_type: v.picklist([
298
+ "User",
299
+ "Project",
300
+ "Local",
301
+ "Managed"
302
+ ]),
303
+ parent_file_path: v.exactOptional(v.string()),
304
+ trigger_file_path: v.exactOptional(v.string())
214
305
  })
215
306
  };
307
+ //#endregion
308
+ //#region src/utils/string.ts
216
309
  function isNonEmptyString(value) {
217
310
  return typeof value === "string" && value.length > 0;
218
311
  }
312
+ //#endregion
313
+ //#region src/run.ts
314
+ /**
315
+ * Executes a Claude Code hook with runtime input validation and error handling.
316
+ *
317
+ * This function handles the complete lifecycle of hook execution including:
318
+ * - Reading input from stdin
319
+ * - Validating input against Valibot schemas
320
+ * - Creating typed context
321
+ * - Executing the hook handler
322
+ * - Formatting and outputting results
323
+ *
324
+ * @param definition - The hook definition to execute
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * // CLI usage: echo '{"hook_event_name":"SessionStart",...}' | node hook.js
329
+ * const hook = defineHook({
330
+ * trigger: { SessionStart: true },
331
+ * run: (context) => context.success()
332
+ * });
333
+ *
334
+ * // Execute the hook (typically called from CLI)
335
+ * await runHook(hook);
336
+ *
337
+ * // Hook with error handling
338
+ * const validationHook = defineHook({
339
+ * trigger: { PreToolUse: { Read: true } },
340
+ * run: (context) => {
341
+ * try {
342
+ * const { file_path } = context.input.tool_input;
343
+ *
344
+ * if (!file_path.endsWith('.ts')) {
345
+ * return context.nonBlockingError('Warning: Non-TypeScript file detected');
346
+ * }
347
+ *
348
+ * return context.success();
349
+ * } catch (error) {
350
+ * return context.blockingError(`Validation failed: ${error.message}`);
351
+ * }
352
+ * }
353
+ * });
354
+ *
355
+ * await runHook(validationHook);
356
+ * ```
357
+ */
219
358
  async function runHook(def) {
220
359
  const { run, shouldRun = true, trigger } = def;
221
360
  let eventName = null;
@@ -296,4 +435,5 @@ function extractInputSchemaFromTrigger(trigger) {
296
435
  });
297
436
  return v.union(schemas);
298
437
  }
438
+ //#endregion
299
439
  export { defineHook, runHook };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-hooks-ts",
3
- "version": "2.1.63",
3
+ "version": "2.1.76",
4
4
  "type": "module",
5
5
  "description": "Write claude code hooks with type safety",
6
6
  "sideEffects": false,
@@ -43,26 +43,26 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@arethetypeswrong/core": "0.18.2",
46
- "@types/node": "25.2.1",
47
- "@typescript/native-preview": "^7.0.0-dev.20251108.1",
46
+ "@types/node": "25.4.0",
47
+ "@typescript/native-preview": "7.0.0-dev.20260311.1",
48
48
  "@virtual-live-lab/eslint-config": "2.3.1",
49
49
  "@virtual-live-lab/tsconfig": "2.1.21",
50
50
  "eslint": "9.39.2",
51
51
  "eslint-plugin-import-access": "3.1.0",
52
52
  "oxfmt": "0.28.0",
53
- "pkg-pr-new": "0.0.63",
54
- "publint": "0.3.17",
53
+ "pkg-pr-new": "0.0.65",
54
+ "publint": "0.3.18",
55
55
  "release-it": "19.2.4",
56
56
  "release-it-pnpm": "4.6.6",
57
- "tsdown": "0.20.3",
58
- "type-fest": "5.4.3",
57
+ "tsdown": "0.21.2",
58
+ "type-fest": "5.4.4",
59
59
  "typescript": "5.9.3",
60
- "typescript-eslint": "8.54.0",
60
+ "typescript-eslint": "8.57.0",
61
61
  "unplugin-unused": "0.5.7",
62
62
  "vitest": "4.0.18"
63
63
  },
64
64
  "dependencies": {
65
- "@anthropic-ai/claude-agent-sdk": "0.2.63",
65
+ "@anthropic-ai/claude-agent-sdk": "0.2.76",
66
66
  "get-stdin": "10.0.0",
67
67
  "valibot": "^1.1.0"
68
68
  },