cc-hooks-ts 2.1.87 → 2.1.91

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
@@ -102,7 +102,7 @@ Then, load defined hooks in your Claude Code settings at `~/.claude/settings.jso
102
102
 
103
103
  ## Tool Specific Hooks
104
104
 
105
- 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.
106
106
 
107
107
  For example, you can create a hook that only runs before the `Read` tool is used:
108
108
 
@@ -147,6 +147,24 @@ Then configure it in Claude Code settings:
147
147
  }
148
148
  ```
149
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
+
150
168
  ### Custom Tool Types Support
151
169
 
152
170
  You can add support for custom tools by extending the tool type definitions.
package/dist/index.d.mts CHANGED
@@ -212,7 +212,7 @@ declare const HookInputSchemas: {
212
212
  readonly type: v.LiteralSchema<"removeRules", undefined>;
213
213
  }, undefined>, v.ObjectSchema<{
214
214
  readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
215
- readonly mode: v.PicklistSchema<["acceptEdits", "bypassPermissions", "default", "dontAsk", "plan"], undefined>;
215
+ readonly mode: v.PicklistSchema<["acceptEdits", "bypassPermissions", "default", "dontAsk", "plan", "auto"], undefined>;
216
216
  readonly type: v.LiteralSchema<"setMode", undefined>;
217
217
  }, undefined>, v.ObjectSchema<{
218
218
  readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
@@ -410,8 +410,8 @@ type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" |
410
410
  //#endregion
411
411
  //#region src/hooks/input/types.d.ts
412
412
  /**
413
- * Internal type that combines base hook inputs with tool-specific inputs for PreToolUse events.
414
- * 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.
415
415
  *
416
416
  * @example
417
417
  * ```ts
@@ -426,13 +426,17 @@ type HookInput = { [EventKey in SupportedHookEvent]: EventKey extends "PreToolUs
426
426
  default: BaseHookInputs["PostToolUse"];
427
427
  } : EventKey extends "PostToolUseFailure" ? ToolSpecificPostToolUseFailureInput & {
428
428
  default: BaseHookInputs["PostToolUseFailure"];
429
+ } : EventKey extends "PermissionRequest" ? ToolSpecificPermissionRequestInput & {
430
+ default: BaseHookInputs["PermissionRequest"];
431
+ } : EventKey extends "PermissionDenied" ? ToolSpecificPermissionDeniedInput & {
432
+ default: BaseHookInputs["PermissionDenied"];
429
433
  } : {
430
434
  default: BaseHookInputs[EventKey];
431
435
  } };
432
436
  /**
433
437
  * Extracts all possible hook input types for a specific event type.
434
438
  * For non-tool-specific events, this returns only the default input type.
435
- * 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.
436
440
  *
437
441
  * @example
438
442
  * ```ts
@@ -486,6 +490,14 @@ type ToolSpecificPostToolUseFailureInput = { [K in keyof ToolSchema]: Omit<BaseH
486
490
  tool_input: ToolSchema[K]["input"];
487
491
  tool_name: K;
488
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
+ } };
489
501
  //#endregion
490
502
  //#region src/hooks/permission.d.ts
491
503
  /**
@@ -517,7 +529,7 @@ declare const permissionUpdateSchema: v.VariantSchema<"type", [v.ObjectSchema<{
517
529
  readonly type: v.LiteralSchema<"removeRules", undefined>;
518
530
  }, undefined>, v.ObjectSchema<{
519
531
  readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
520
- readonly mode: v.PicklistSchema<["acceptEdits", "bypassPermissions", "default", "dontAsk", "plan"], undefined>;
532
+ readonly mode: v.PicklistSchema<["acceptEdits", "bypassPermissions", "default", "dontAsk", "plan", "auto"], undefined>;
521
533
  readonly type: v.LiteralSchema<"setMode", undefined>;
522
534
  }, undefined>, v.ObjectSchema<{
523
535
  readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
@@ -640,8 +652,9 @@ interface PreToolUseHookOutput extends CommonHookOutputs {
640
652
  * - `allow` bypasses the permission system. `permissionDecisionReason` is shown to the user but not to Claude.
641
653
  * - `deny` prevents the tool call from executing. `permissionDecisionReason` is shown to Claude.
642
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.
643
656
  */
644
- permissionDecision?: "allow" | "ask" | "deny";
657
+ permissionDecision?: "allow" | "ask" | "deny" | "defer";
645
658
  permissionDecisionReason?: string;
646
659
  updatedInput?: Record<string, unknown>;
647
660
  additionalContext?: string;
package/dist/index.mjs CHANGED
@@ -134,7 +134,8 @@ const permissionUpdateSchema = v.variant("type", [
134
134
  "bypassPermissions",
135
135
  "default",
136
136
  "dontAsk",
137
- "plan"
137
+ "plan",
138
+ "auto"
138
139
  ]),
139
140
  type: v.literal("setMode")
140
141
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-hooks-ts",
3
- "version": "2.1.87",
3
+ "version": "2.1.91",
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.88",
65
+ "@anthropic-ai/claude-agent-sdk": "0.2.91",
66
66
  "get-stdin": "10.0.0",
67
67
  "valibot": "^1.1.0"
68
68
  },