cc-hooks-ts 2.1.86 → 2.1.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,6 +20,8 @@ See [examples](./examples) for more usage examples.
20
20
  - [Documentation](#documentation)
21
21
  - [Development](#development)
22
22
  - [How to follow the upstream changes](#how-to-follow-the-upstream-changes)
23
+ - [If a Dependabot PR already exists](#if-a-dependabot-pr-already-exists)
24
+ - [If no Dependabot PR exists](#if-no-dependabot-pr-exists)
23
25
  - [License](#license)
24
26
  - [Contributing](#contributing)
25
27
 
@@ -100,7 +102,7 @@ Then, load defined hooks in your Claude Code settings at `~/.claude/settings.jso
100
102
 
101
103
  ## Tool Specific Hooks
102
104
 
103
- In `PreToolUse`, `PostToolUse`, and `PostToolUseFailure` events, you can define hooks specific to tools by specifying tool names in the trigger configuration.
105
+ In `PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `PermissionRequest`, and `PermissionDenied` events, you can define hooks specific to tools by specifying tool names in the trigger configuration.
104
106
 
105
107
  For example, you can create a hook that only runs before the `Read` tool is used:
106
108
 
@@ -145,6 +147,24 @@ Then configure it in Claude Code settings:
145
147
  }
146
148
  ```
147
149
 
150
+ The same trigger shape also works for permission hooks:
151
+
152
+ ```typescript
153
+ const permissionRequestHook = defineHook({
154
+ trigger: { PermissionRequest: { Bash: true } },
155
+ run: (context) => {
156
+ // context.input.tool_input is typed as BashInput
157
+ const { command } = context.input.tool_input;
158
+
159
+ if (command.includes("rm -rf")) {
160
+ return context.blockingError("Refusing destructive command");
161
+ }
162
+
163
+ return context.success();
164
+ },
165
+ });
166
+ ```
167
+
148
168
  ### Custom Tool Types Support
149
169
 
150
170
  You can add support for custom tools by extending the tool type definitions.
@@ -277,38 +297,52 @@ pnpm typecheck
277
297
 
278
298
  ### How to follow the upstream changes
279
299
 
280
- 1. Check installed version of `@anthropic-ai/claude-agent-sdk`:
300
+ Dependabot automatically creates PRs to bump `@anthropic-ai/claude-agent-sdk`. The CI bot posts a type diff comment on each PR.
281
301
 
282
- ```bash
283
- npm list @anthropic-ai/claude-agent-sdk
302
+ #### If a Dependabot PR already exists
303
+
304
+ 1. Find the Dependabot PR that bumps `@anthropic-ai/claude-agent-sdk` and check out its branch.
305
+
306
+ 2. Read the type diff posted as a PR comment, then reflect the changes.
307
+ - Edit `src/hooks/` for changed hook input / output types.
308
+ - No need for adding tests in most cases since we are testing the whole type definitions in these files:
309
+ - `src/hooks/input/schemas.test-d.ts`
310
+ - `src/hooks/output/index.test-d.ts`
311
+ - `src/hooks/event.test-d.ts`
312
+ - `src/hooks/permission.test-d.ts`
313
+ - Edit `src/index.ts` for changed tool input / output types.
314
+ - YOU SHOULD NOT MODIFY `version` in `package.json` manually.
315
+
316
+ 3. Push to the Dependabot PR branch.
317
+
318
+ 4. Update the PR title to:
319
+
320
+ ```plaintext
321
+ fix: update to parity with Claude Code v$(npm info @anthropic-ai/claude-agent-sdk claudeCodeVersion)
284
322
  ```
285
323
 
286
- 2. Check the latest version of `@anthropic-ai/claude-agent-sdk`:
324
+ #### If no Dependabot PR exists
325
+
326
+ 1. Create a new branch and bump `@anthropic-ai/claude-agent-sdk` to the latest version:
287
327
 
288
328
  ```bash
289
- npm view @anthropic-ai/claude-agent-sdk version
329
+ git switch -c bump-claude-agent-sdk
330
+ pnpm add @anthropic-ai/claude-agent-sdk@latest
290
331
  ```
291
332
 
292
- - If the latest version is the same as your installed version, then there is no upstream change and you are good to go!
293
-
294
- 3. Get diff of the types.
333
+ 2. Get the type diff between the old and new versions:
295
334
 
296
335
  ```bash
297
336
  npm diff --diff=@anthropic-ai/claude-agent-sdk@<old_version> --diff=@anthropic-ai/claude-agent-sdk@<new_version> '**/*.d.ts'
298
-
299
- # Only for humans, You can use dandavison/delta for better diff visualization
300
- npm diff --diff=@anthropic-ai/claude-agent-sdk@<old_version> --diff=@anthropic-ai/claude-agent-sdk@<new_version> '**/*.d.ts' | delta --side-by-side
301
337
  ```
302
338
 
303
- 4. Reflect the changes.
304
- - Edit `src/hooks/` for changed hook input / output types.
305
- - No need for adding tests in most cases since we are testing the whole type definitions in these files:
306
- - `src/hooks/input/schemas.test-d.ts`
307
- - `src/hooks/output/index.test-d.ts`
308
- - `src/hooks/event.test-d.ts`
309
- - `src/hooks/permission.test-d.ts`
310
- - Edit `src/index.ts` for changed tool input / output types.
311
- - YOU SHOULD NOT MODIFY `version` in `package.json` manually.
339
+ 3. Reflect the changes (same as step 2 above).
340
+
341
+ 4. Commit, push, and create a PR with the title:
342
+
343
+ ```plaintext
344
+ fix: update to parity with Claude Code v$(npm info @anthropic-ai/claude-agent-sdk claudeCodeVersion)
345
+ ```
312
346
 
313
347
  ## License
314
348
 
package/dist/index.d.mts CHANGED
@@ -226,6 +226,20 @@ declare const HookInputSchemas: {
226
226
  tool_input: v.UnknownSchema;
227
227
  tool_name: v.StringSchema<undefined>;
228
228
  }, undefined>;
229
+ readonly PermissionDenied: v.ObjectSchema<{
230
+ readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
231
+ readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
232
+ readonly cwd: v.StringSchema<undefined>;
233
+ readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
234
+ readonly session_id: v.StringSchema<undefined>;
235
+ readonly transcript_path: v.StringSchema<undefined>;
236
+ readonly hook_event_name: v.LiteralSchema<"PermissionDenied", undefined>;
237
+ } & {
238
+ reason: v.StringSchema<undefined>;
239
+ tool_input: v.UnknownSchema;
240
+ tool_name: v.StringSchema<undefined>;
241
+ tool_use_id: v.StringSchema<undefined>;
242
+ }, undefined>;
229
243
  readonly Setup: v.ObjectSchema<{
230
244
  readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
231
245
  readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -392,12 +406,12 @@ declare const HookInputSchemas: {
392
406
  *
393
407
  * @package
394
408
  */
395
- type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "Notification" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "StopFailure" | "SubagentStart" | "SubagentStop" | "PreCompact" | "PostCompact" | "PermissionRequest" | "Setup" | "TeammateIdle" | "TaskCreated" | "TaskCompleted" | "ConfigChange" | "WorktreeCreate" | "WorktreeRemove" | "Elicitation" | "ElicitationResult" | "InstructionsLoaded" | "CwdChanged" | "FileChanged";
409
+ 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";
396
410
  //#endregion
397
411
  //#region src/hooks/input/types.d.ts
398
412
  /**
399
- * Internal type that combines base hook inputs with tool-specific inputs for PreToolUse events.
400
- * For non-PreToolUse events, this is equivalent to BaseHookInputs.
413
+ * Internal type that combines base hook inputs with tool-specific inputs for tool-aware events.
414
+ * For all other events, this is equivalent to BaseHookInputs.
401
415
  *
402
416
  * @example
403
417
  * ```ts
@@ -412,13 +426,17 @@ type HookInput = { [EventKey in SupportedHookEvent]: EventKey extends "PreToolUs
412
426
  default: BaseHookInputs["PostToolUse"];
413
427
  } : EventKey extends "PostToolUseFailure" ? ToolSpecificPostToolUseFailureInput & {
414
428
  default: BaseHookInputs["PostToolUseFailure"];
429
+ } : EventKey extends "PermissionRequest" ? ToolSpecificPermissionRequestInput & {
430
+ default: BaseHookInputs["PermissionRequest"];
431
+ } : EventKey extends "PermissionDenied" ? ToolSpecificPermissionDeniedInput & {
432
+ default: BaseHookInputs["PermissionDenied"];
415
433
  } : {
416
434
  default: BaseHookInputs[EventKey];
417
435
  } };
418
436
  /**
419
437
  * Extracts all possible hook input types for a specific event type.
420
438
  * For non-tool-specific events, this returns only the default input type.
421
- * For tool-specific events (PreToolUse/PostToolUse), this returns a union of all possible inputs including default and tool-specific variants.
439
+ * For tool-specific events, this returns a union of all possible inputs including default and tool-specific variants.
422
440
  *
423
441
  * @example
424
442
  * ```ts
@@ -472,6 +490,14 @@ type ToolSpecificPostToolUseFailureInput = { [K in keyof ToolSchema]: Omit<BaseH
472
490
  tool_input: ToolSchema[K]["input"];
473
491
  tool_name: K;
474
492
  } };
493
+ type ToolSpecificPermissionRequestInput = { [K in keyof ToolSchema]: Omit<BaseHookInputs["PermissionRequest"], "tool_input" | "tool_name"> & {
494
+ tool_input: ToolSchema[K]["input"];
495
+ tool_name: K;
496
+ } };
497
+ type ToolSpecificPermissionDeniedInput = { [K in keyof ToolSchema]: Omit<BaseHookInputs["PermissionDenied"], "tool_input" | "tool_name"> & {
498
+ tool_input: ToolSchema[K]["input"];
499
+ tool_name: K;
500
+ } };
475
501
  //#endregion
476
502
  //#region src/hooks/permission.d.ts
477
503
  /**
@@ -530,6 +556,7 @@ type HookOutput = {
530
556
  SubagentStart: SubagentStartHookOutput;
531
557
  SubagentStop: SubagentStopHookOutput;
532
558
  SessionStart: SessionStartHookOutput;
559
+ PermissionDenied: PermissionDeniedHookOutput;
533
560
  PermissionRequest: PermissionRequestHookOutput;
534
561
  Setup: SetupHookOutput;
535
562
  Notification: NotificationHookOutput;
@@ -625,8 +652,9 @@ interface PreToolUseHookOutput extends CommonHookOutputs {
625
652
  * - `allow` bypasses the permission system. `permissionDecisionReason` is shown to the user but not to Claude.
626
653
  * - `deny` prevents the tool call from executing. `permissionDecisionReason` is shown to Claude.
627
654
  * - `ask` asks the user to confirm the tool call in the UI. `permissionDecisionReason` is shown to the user but not to Claude.
655
+ * - `defer` exits gracefully so the tool can be resumed later.
628
656
  */
629
- permissionDecision?: "allow" | "ask" | "deny";
657
+ permissionDecision?: "allow" | "ask" | "deny" | "defer";
630
658
  permissionDecisionReason?: string;
631
659
  updatedInput?: Record<string, unknown>;
632
660
  additionalContext?: string;
@@ -772,6 +800,12 @@ interface PermissionRequestHookOutput extends CommonHookOutputs {
772
800
  };
773
801
  };
774
802
  }
803
+ interface PermissionDeniedHookOutput extends CommonHookOutputs {
804
+ hookSpecificOutput?: {
805
+ hookEventName: "PermissionDenied";
806
+ retry?: boolean;
807
+ };
808
+ }
775
809
  interface ElicitationHookOutput extends CommonHookOutputs {
776
810
  hookSpecificOutput?: {
777
811
  action?: "accept" | "decline" | "cancel";
package/dist/index.mjs CHANGED
@@ -256,6 +256,12 @@ const HookInputSchemas = {
256
256
  tool_input: v.unknown(),
257
257
  tool_name: v.string()
258
258
  }),
259
+ PermissionDenied: buildHookInputSchema("PermissionDenied", {
260
+ reason: v.string(),
261
+ tool_input: v.unknown(),
262
+ tool_name: v.string(),
263
+ tool_use_id: v.string()
264
+ }),
259
265
  Setup: buildHookInputSchema("Setup", { trigger: v.picklist(["init", "maintenance"]) }),
260
266
  TeammateIdle: buildHookInputSchema("TeammateIdle", {
261
267
  team_name: v.string(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-hooks-ts",
3
- "version": "2.1.86",
3
+ "version": "2.1.90",
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.86",
65
+ "@anthropic-ai/claude-agent-sdk": "0.2.90",
66
66
  "get-stdin": "10.0.0",
67
67
  "valibot": "^1.1.0"
68
68
  },