cc-hooks-ts 2.0.76 → 2.1.1

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
@@ -221,9 +221,11 @@ For detailed information about available JSON fields and their behavior, see the
221
221
  >
222
222
  > You can enable it in Claude Code by going to `/config` and setting "verbose" to true.
223
223
 
224
- Claude Code also accepts async hook responses.
224
+ Async JSON output allows hooks to perform longer computations without blocking the Claude Code TUI.
225
225
 
226
- Use `context.defer()` when you need extra time to compute hook output.
226
+ You can use `context.defer()` to respond Claude Code immediately while performing longer computations in the background.
227
+
228
+ You should complete the async operation within a reasonable time (e.g. 15 seconds).
227
229
 
228
230
  ```ts
229
231
  import { defineHook } from "cc-hooks-ts";
package/dist/index.d.mts CHANGED
@@ -104,7 +104,7 @@ declare const HookInputSchemas: {
104
104
  readonly hook_event_name: v.LiteralSchema<"PreCompact", undefined>;
105
105
  } & {
106
106
  custom_instructions: v.NullableSchema<v.StringSchema<undefined>, undefined>;
107
- trigger: v.UnionSchema<[v.LiteralSchema<"manual", undefined>, v.LiteralSchema<"auto", undefined>], undefined>;
107
+ trigger: v.PicklistSchema<["manual", "auto"], undefined>;
108
108
  }, undefined>;
109
109
  readonly SessionStart: v.ObjectSchema<{
110
110
  readonly cwd: v.StringSchema<undefined>;
@@ -113,7 +113,7 @@ declare const HookInputSchemas: {
113
113
  readonly transcript_path: v.StringSchema<undefined>;
114
114
  readonly hook_event_name: v.LiteralSchema<"SessionStart", undefined>;
115
115
  } & {
116
- source: v.UnionSchema<[v.LiteralSchema<"startup", undefined>, v.LiteralSchema<"resume", undefined>, v.LiteralSchema<"clear", undefined>, v.LiteralSchema<"compact", undefined>], undefined>;
116
+ source: v.PicklistSchema<["startup", "resume", "clear", "compact"], undefined>;
117
117
  }, undefined>;
118
118
  readonly SessionEnd: v.ObjectSchema<{
119
119
  readonly cwd: v.StringSchema<undefined>;
@@ -122,7 +122,7 @@ declare const HookInputSchemas: {
122
122
  readonly transcript_path: v.StringSchema<undefined>;
123
123
  readonly hook_event_name: v.LiteralSchema<"SessionEnd", undefined>;
124
124
  } & {
125
- reason: v.StringSchema<undefined>;
125
+ reason: v.PicklistSchema<["clear", "logout", "prompt_input_exit", "other", "bypass_permissions_disabled"], undefined>;
126
126
  }, undefined>;
127
127
  readonly PermissionRequest: v.ObjectSchema<{
128
128
  readonly cwd: v.StringSchema<undefined>;
@@ -132,39 +132,39 @@ declare const HookInputSchemas: {
132
132
  readonly hook_event_name: v.LiteralSchema<"PermissionRequest", undefined>;
133
133
  } & {
134
134
  permission_suggestions: v.ExactOptionalSchema<v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
135
- readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
136
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
135
+ readonly behavior: v.PicklistSchema<["allow", "deny", "ask"], undefined>;
136
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
137
137
  readonly rules: v.ArraySchema<v.ObjectSchema<{
138
138
  readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
139
139
  readonly toolName: v.StringSchema<undefined>;
140
140
  }, undefined>, undefined>;
141
141
  readonly type: v.LiteralSchema<"addRules", undefined>;
142
142
  }, undefined>, v.ObjectSchema<{
143
- readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
144
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
143
+ readonly behavior: v.PicklistSchema<["allow", "deny", "ask"], undefined>;
144
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
145
145
  readonly rules: v.ArraySchema<v.ObjectSchema<{
146
146
  readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
147
147
  readonly toolName: v.StringSchema<undefined>;
148
148
  }, undefined>, undefined>;
149
149
  readonly type: v.LiteralSchema<"replaceRules", undefined>;
150
150
  }, undefined>, v.ObjectSchema<{
151
- readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
152
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
151
+ readonly behavior: v.PicklistSchema<["allow", "deny", "ask"], undefined>;
152
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
153
153
  readonly rules: v.ArraySchema<v.ObjectSchema<{
154
154
  readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
155
155
  readonly toolName: v.StringSchema<undefined>;
156
156
  }, undefined>, undefined>;
157
157
  readonly type: v.LiteralSchema<"removeRules", undefined>;
158
158
  }, undefined>, v.ObjectSchema<{
159
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
160
- readonly mode: v.UnionSchema<[v.LiteralSchema<"acceptEdits", undefined>, v.LiteralSchema<"bypassPermissions", undefined>, v.LiteralSchema<"default", undefined>, v.LiteralSchema<"dontAsk", undefined>, v.LiteralSchema<"delegate", undefined>, v.LiteralSchema<"plan", undefined>], undefined>;
159
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
160
+ readonly mode: v.PicklistSchema<["acceptEdits", "bypassPermissions", "default", "dontAsk", "delegate", "plan"], undefined>;
161
161
  readonly type: v.LiteralSchema<"setMode", undefined>;
162
162
  }, undefined>, v.ObjectSchema<{
163
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
163
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
164
164
  readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
165
165
  readonly type: v.LiteralSchema<"addDirectories", undefined>;
166
166
  }, undefined>, v.ObjectSchema<{
167
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
167
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
168
168
  readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
169
169
  readonly type: v.LiteralSchema<"removeDirectories", undefined>;
170
170
  }, undefined>], undefined>, undefined>, undefined>;
@@ -265,39 +265,39 @@ type ToolSpecificPostToolUseFailureInput = { [K in keyof ToolSchema]: Omit<BaseH
265
265
  * @package
266
266
  */
267
267
  declare const permissionUpdateSchema: v.VariantSchema<"type", [v.ObjectSchema<{
268
- readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
269
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
268
+ readonly behavior: v.PicklistSchema<["allow", "deny", "ask"], undefined>;
269
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
270
270
  readonly rules: v.ArraySchema<v.ObjectSchema<{
271
271
  readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
272
272
  readonly toolName: v.StringSchema<undefined>;
273
273
  }, undefined>, undefined>;
274
274
  readonly type: v.LiteralSchema<"addRules", undefined>;
275
275
  }, undefined>, v.ObjectSchema<{
276
- readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
277
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
276
+ readonly behavior: v.PicklistSchema<["allow", "deny", "ask"], undefined>;
277
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
278
278
  readonly rules: v.ArraySchema<v.ObjectSchema<{
279
279
  readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
280
280
  readonly toolName: v.StringSchema<undefined>;
281
281
  }, undefined>, undefined>;
282
282
  readonly type: v.LiteralSchema<"replaceRules", undefined>;
283
283
  }, undefined>, v.ObjectSchema<{
284
- readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
285
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
284
+ readonly behavior: v.PicklistSchema<["allow", "deny", "ask"], undefined>;
285
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
286
286
  readonly rules: v.ArraySchema<v.ObjectSchema<{
287
287
  readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
288
288
  readonly toolName: v.StringSchema<undefined>;
289
289
  }, undefined>, undefined>;
290
290
  readonly type: v.LiteralSchema<"removeRules", undefined>;
291
291
  }, undefined>, v.ObjectSchema<{
292
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
293
- readonly mode: v.UnionSchema<[v.LiteralSchema<"acceptEdits", undefined>, v.LiteralSchema<"bypassPermissions", undefined>, v.LiteralSchema<"default", undefined>, v.LiteralSchema<"dontAsk", undefined>, v.LiteralSchema<"delegate", undefined>, v.LiteralSchema<"plan", undefined>], undefined>;
292
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
293
+ readonly mode: v.PicklistSchema<["acceptEdits", "bypassPermissions", "default", "dontAsk", "delegate", "plan"], undefined>;
294
294
  readonly type: v.LiteralSchema<"setMode", undefined>;
295
295
  }, undefined>, v.ObjectSchema<{
296
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
296
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
297
297
  readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
298
298
  readonly type: v.LiteralSchema<"addDirectories", undefined>;
299
299
  }, undefined>, v.ObjectSchema<{
300
- readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
300
+ readonly destination: v.PicklistSchema<["userSettings", "projectSettings", "localSettings", "session", "cliArg"], undefined>;
301
301
  readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
302
302
  readonly type: v.LiteralSchema<"removeDirectories", undefined>;
303
303
  }, undefined>], undefined>;
package/dist/index.mjs CHANGED
@@ -33,17 +33,17 @@ function createContext(input) {
33
33
  })
34
34
  };
35
35
  }
36
- const permissionBehaviorSchema = v.union([
37
- v.literal("allow"),
38
- v.literal("deny"),
39
- v.literal("ask")
36
+ const permissionBehaviorSchema = v.picklist([
37
+ "allow",
38
+ "deny",
39
+ "ask"
40
40
  ]);
41
- const permissionUpdateDestinationSchema = v.union([
42
- v.literal("userSettings"),
43
- v.literal("projectSettings"),
44
- v.literal("localSettings"),
45
- v.literal("session"),
46
- v.literal("cliArg")
41
+ const permissionUpdateDestinationSchema = v.picklist([
42
+ "userSettings",
43
+ "projectSettings",
44
+ "localSettings",
45
+ "session",
46
+ "cliArg"
47
47
  ]);
48
48
  const permissionRuleValueSchema = v.object({
49
49
  ruleContent: v.exactOptional(v.string()),
@@ -70,13 +70,13 @@ const permissionUpdateSchema = v.variant("type", [
70
70
  }),
71
71
  v.object({
72
72
  destination: permissionUpdateDestinationSchema,
73
- mode: v.union([
74
- v.literal("acceptEdits"),
75
- v.literal("bypassPermissions"),
76
- v.literal("default"),
77
- v.literal("dontAsk"),
78
- v.literal("delegate"),
79
- v.literal("plan")
73
+ mode: v.picklist([
74
+ "acceptEdits",
75
+ "bypassPermissions",
76
+ "default",
77
+ "dontAsk",
78
+ "delegate",
79
+ "plan"
80
80
  ]),
81
81
  type: v.literal("setMode")
82
82
  }),
@@ -141,15 +141,21 @@ const HookInputSchemas = {
141
141
  }),
142
142
  PreCompact: buildHookInputSchema("PreCompact", {
143
143
  custom_instructions: v.nullable(v.string()),
144
- trigger: v.union([v.literal("manual"), v.literal("auto")])
144
+ trigger: v.picklist(["manual", "auto"])
145
145
  }),
146
- SessionStart: buildHookInputSchema("SessionStart", { source: v.union([
147
- v.literal("startup"),
148
- v.literal("resume"),
149
- v.literal("clear"),
150
- v.literal("compact")
146
+ SessionStart: buildHookInputSchema("SessionStart", { source: v.picklist([
147
+ "startup",
148
+ "resume",
149
+ "clear",
150
+ "compact"
151
+ ]) }),
152
+ SessionEnd: buildHookInputSchema("SessionEnd", { reason: v.picklist([
153
+ "clear",
154
+ "logout",
155
+ "prompt_input_exit",
156
+ "other",
157
+ "bypass_permissions_disabled"
151
158
  ]) }),
152
- SessionEnd: buildHookInputSchema("SessionEnd", { reason: v.string() }),
153
159
  PermissionRequest: buildHookInputSchema("PermissionRequest", {
154
160
  permission_suggestions: v.exactOptional(v.array(permissionUpdateSchema)),
155
161
  tool_input: v.unknown(),
@@ -187,11 +193,10 @@ async function handleHookResult(eventName, hookResult) {
187
193
  return process.exit(2);
188
194
  case "json-async": {
189
195
  const userTimeout = hookResult.timeoutMs;
190
- const startAsync = {
196
+ console.log(JSON.stringify({
191
197
  async: true,
192
198
  asyncTimeout: userTimeout ?? void 0
193
- };
194
- console.log(JSON.stringify(startAsync));
199
+ }));
195
200
  const safeInvokeDeferredHook = async () => {
196
201
  try {
197
202
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-hooks-ts",
3
- "version": "2.0.76",
3
+ "version": "2.1.1",
4
4
  "type": "module",
5
5
  "description": "Write claude code hooks with type safety",
6
6
  "sideEffects": false,
@@ -49,20 +49,20 @@
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
- "oxfmt": "0.19.0",
52
+ "oxfmt": "0.21.0",
53
53
  "pkg-pr-new": "0.0.62",
54
54
  "publint": "0.3.16",
55
- "release-it": "19.1.0",
55
+ "release-it": "19.2.2",
56
56
  "release-it-pnpm": "4.6.6",
57
- "tsdown": "0.18.1",
57
+ "tsdown": "0.18.4",
58
58
  "type-fest": "5.3.1",
59
59
  "typescript": "5.9.3",
60
- "typescript-eslint": "8.50.0",
60
+ "typescript-eslint": "8.51.0",
61
61
  "unplugin-unused": "0.5.6",
62
62
  "vitest": "4.0.16"
63
63
  },
64
64
  "dependencies": {
65
- "@anthropic-ai/claude-agent-sdk": "0.1.76",
65
+ "@anthropic-ai/claude-agent-sdk": "0.2.1",
66
66
  "valibot": "^1.1.0"
67
67
  },
68
68
  "scripts": {