@goodfoot/claude-code-hooks 1.0.10 → 1.0.11
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/cli.js +597 -604
- package/dist/constants.js +12 -12
- package/dist/env.js +36 -38
- package/dist/hooks.js +22 -22
- package/dist/index.js +37 -67
- package/dist/logger.js +371 -362
- package/dist/outputs.js +33 -34
- package/dist/runtime.js +99 -96
- package/dist/scaffold.js +178 -182
- package/dist/tool-helpers.js +255 -103
- package/dist/types.js +35 -0
- package/package.json +8 -11
- package/types/cli.d.ts +67 -98
- package/types/constants.d.ts +1 -1
- package/types/env.d.ts +16 -16
- package/types/hooks.d.ts +168 -254
- package/types/index.d.ts +15 -130
- package/types/logger.d.ts +285 -285
- package/types/outputs.d.ts +154 -229
- package/types/runtime.d.ts +4 -6
- package/types/scaffold.d.ts +6 -6
- package/types/tool-helpers.d.ts +206 -77
- package/types/types.d.ts +497 -0
- package/dist/inputs.js +0 -35
- package/dist/tool-inputs.js +0 -21
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Claude Code hooks.
|
|
3
|
+
*
|
|
4
|
+
* This module provides:
|
|
5
|
+
* - Hook input types (wire format with snake_case)
|
|
6
|
+
* - Tool input types for type guards
|
|
7
|
+
* - SDK type re-exports for extension and reference
|
|
8
|
+
* @see https://code.claude.com/docs/en/hooks
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Re-exports types from @anthropic-ai/claude-agent-sdk with "SDK" prefix.
|
|
13
|
+
* These are used as base types for extension, ensuring synchronization with the SDK.
|
|
14
|
+
*/
|
|
15
|
+
export type { BaseHookInput as SDKBaseHookInput, HookEvent as SDKHookEvent, HookInput as SDKHookInput, NotificationHookInput as SDKNotificationHookInput, PermissionMode as SDKPermissionMode, PermissionRequestHookInput as SDKPermissionRequestHookInput, PermissionUpdate as SDKPermissionUpdate, PostToolUseFailureHookInput as SDKPostToolUseFailureHookInput, PostToolUseHookInput as SDKPostToolUseHookInput, PreCompactHookInput as SDKPreCompactHookInput, PreToolUseHookInput as SDKPreToolUseHookInput, SessionEndHookInput as SDKSessionEndHookInput, SessionStartHookInput as SDKSessionStartHookInput, StopHookInput as SDKStopHookInput, SubagentStartHookInput as SDKSubagentStartHookInput, SubagentStopHookInput as SDKSubagentStopHookInput, UserPromptSubmitHookInput as SDKUserPromptSubmitHookInput, } from "@anthropic-ai/claude-agent-sdk/entrypoints/agentSdkTypes.js";
|
|
16
|
+
import type { BaseHookInput as SDKBaseHookInput, NotificationHookInput as SDKNotificationHookInput, PermissionMode as SDKPermissionMode, PermissionRequestHookInput as SDKPermissionRequestHookInput, PermissionUpdate as SDKPermissionUpdate, PostToolUseFailureHookInput as SDKPostToolUseFailureHookInput, PostToolUseHookInput as SDKPostToolUseHookInput, PreCompactHookInput as SDKPreCompactHookInput, PreToolUseHookInput as SDKPreToolUseHookInput, SessionEndHookInput as SDKSessionEndHookInput, SessionStartHookInput as SDKSessionStartHookInput, StopHookInput as SDKStopHookInput, SubagentStartHookInput as SDKSubagentStartHookInput, SubagentStopHookInput as SDKSubagentStopHookInput, UserPromptSubmitHookInput as SDKUserPromptSubmitHookInput } from "@anthropic-ai/claude-agent-sdk/entrypoints/agentSdkTypes.js";
|
|
17
|
+
import type { AgentInput, AskUserQuestionInput, BashInput, ExitPlanModeInput, FileEditInput, FileReadInput, FileWriteInput, GlobInput, GrepInput, KillShellInput, NotebookEditInput, TaskOutputInput, TodoWriteInput, WebFetchInput, WebSearchInput } from "@anthropic-ai/claude-agent-sdk/sdk-tools.js";
|
|
18
|
+
/**
|
|
19
|
+
* Permission mode for controlling how tool executions are handled.
|
|
20
|
+
* @see https://code.claude.com/docs/en/hooks#permission-modes
|
|
21
|
+
*/
|
|
22
|
+
export type PermissionMode = SDKPermissionMode;
|
|
23
|
+
/**
|
|
24
|
+
* Source that triggered a session start event.
|
|
25
|
+
*
|
|
26
|
+
* - `'startup'` - New session started from scratch
|
|
27
|
+
* - `'resume'` - Resuming a previous session
|
|
28
|
+
* - `'clear'` - Session cleared and restarted
|
|
29
|
+
* - `'compact'` - Session restarted after context compaction
|
|
30
|
+
* @deprecated Matches SDK inline literal. Kept for backward compatibility.
|
|
31
|
+
*/
|
|
32
|
+
export type SessionStartSource = "startup" | "resume" | "clear" | "compact";
|
|
33
|
+
/**
|
|
34
|
+
* Trigger type for pre-compact events.
|
|
35
|
+
*
|
|
36
|
+
* - `'manual'` - User explicitly requested compaction
|
|
37
|
+
* - `'auto'` - Automatic compaction due to context length
|
|
38
|
+
* @deprecated Matches SDK inline literal. Kept for backward compatibility.
|
|
39
|
+
*/
|
|
40
|
+
export type PreCompactTrigger = "manual" | "auto";
|
|
41
|
+
/**
|
|
42
|
+
* Reason for session end events.
|
|
43
|
+
*
|
|
44
|
+
* - `'clear'` - Session cleared by user
|
|
45
|
+
* - `'logout'` - User logged out
|
|
46
|
+
* - `'prompt_input_exit'` - User exited at prompt input
|
|
47
|
+
* - `'other'` - Other reasons
|
|
48
|
+
*
|
|
49
|
+
* Note: SDK's ExitReason resolves to string. This type provides concrete literals for better DX.
|
|
50
|
+
*/
|
|
51
|
+
export type SessionEndReason = "clear" | "logout" | "prompt_input_exit" | "other";
|
|
52
|
+
/**
|
|
53
|
+
* Common fields present in all hook inputs.
|
|
54
|
+
*
|
|
55
|
+
* Every hook receives these base fields providing session context.
|
|
56
|
+
* Hook-specific inputs extend this base with additional fields.
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* // All hook inputs include these fields
|
|
60
|
+
* const handleAnyHook = (input: BaseHookInput) => {
|
|
61
|
+
* console.log(`Session: ${input.session_id}`);
|
|
62
|
+
* console.log(`Working directory: ${input.cwd}`);
|
|
63
|
+
* console.log(`Transcript: ${input.transcript_path}`);
|
|
64
|
+
* };
|
|
65
|
+
* ```
|
|
66
|
+
* @see https://code.claude.com/docs/en/hooks#hook-input-structure
|
|
67
|
+
*/
|
|
68
|
+
export interface BaseHookInput extends SDKBaseHookInput {
|
|
69
|
+
/**
|
|
70
|
+
* Current permission mode for tool execution.
|
|
71
|
+
* Overrides SDK's string type with stricter literal union.
|
|
72
|
+
* May be undefined if using default mode.
|
|
73
|
+
*/
|
|
74
|
+
permission_mode?: PermissionMode;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Input for PreToolUse hooks.
|
|
78
|
+
*
|
|
79
|
+
* Fires before any tool is executed, allowing you to:
|
|
80
|
+
* - Inspect and validate tool inputs
|
|
81
|
+
* - Allow, deny, or modify the tool execution
|
|
82
|
+
* - Add custom permission logic
|
|
83
|
+
*
|
|
84
|
+
* This hook uses `tool_name` for matcher matching.
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // Block dangerous Bash commands
|
|
88
|
+
* preToolUseHook({ matcher: 'Bash' }, async (input: PreToolUseInput) => {
|
|
89
|
+
* const command = input.tool_input.command as string;
|
|
90
|
+
* if (command.includes('rm -rf')) {
|
|
91
|
+
* return preToolUseOutput({
|
|
92
|
+
* deny: 'Destructive commands are not allowed'
|
|
93
|
+
* });
|
|
94
|
+
* }
|
|
95
|
+
* return preToolUseOutput({ allow: true });
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
* @see https://code.claude.com/docs/en/hooks#pretooluse
|
|
99
|
+
*/
|
|
100
|
+
export type PreToolUseInput = SDKPreToolUseHookInput;
|
|
101
|
+
/**
|
|
102
|
+
* Input for PostToolUse hooks.
|
|
103
|
+
*
|
|
104
|
+
* Fires after a tool executes successfully, allowing you to:
|
|
105
|
+
* - Inspect tool results
|
|
106
|
+
* - Add additional context to the conversation
|
|
107
|
+
* - Modify MCP tool output
|
|
108
|
+
*
|
|
109
|
+
* This hook uses `tool_name` for matcher matching.
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* // Add context after file reads
|
|
113
|
+
* postToolUseHook({ matcher: 'Read' }, async (input: PostToolUseInput) => {
|
|
114
|
+
* const filePath = input.tool_input.file_path as string;
|
|
115
|
+
* return postToolUseOutput({
|
|
116
|
+
* additionalContext: `File ${filePath} was read successfully`
|
|
117
|
+
* });
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
* @see https://code.claude.com/docs/en/hooks#posttooluse
|
|
121
|
+
*/
|
|
122
|
+
export type PostToolUseInput = SDKPostToolUseHookInput;
|
|
123
|
+
/**
|
|
124
|
+
* Input for PostToolUseFailure hooks.
|
|
125
|
+
*
|
|
126
|
+
* Fires after a tool execution fails, allowing you to:
|
|
127
|
+
* - Log or report tool failures
|
|
128
|
+
* - Add context about the failure
|
|
129
|
+
* - Take corrective action
|
|
130
|
+
*
|
|
131
|
+
* This hook uses `tool_name` for matcher matching.
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* // Log tool failures
|
|
135
|
+
* postToolUseFailureHook({ matcher: '.*' }, async (input: PostToolUseFailureInput) => {
|
|
136
|
+
* console.error(`Tool ${input.tool_name} failed: ${input.error}`);
|
|
137
|
+
* return postToolUseFailureOutput({
|
|
138
|
+
* additionalContext: 'Please try an alternative approach'
|
|
139
|
+
* });
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
* @see https://code.claude.com/docs/en/hooks#posttoolusefailure
|
|
143
|
+
*/
|
|
144
|
+
export type PostToolUseFailureInput = SDKPostToolUseFailureHookInput;
|
|
145
|
+
/**
|
|
146
|
+
* Input for Notification hooks.
|
|
147
|
+
*
|
|
148
|
+
* Fires when Claude Code sends a notification, allowing you to:
|
|
149
|
+
* - Forward notifications to external systems
|
|
150
|
+
* - Log important events
|
|
151
|
+
* - Trigger custom alerting
|
|
152
|
+
*
|
|
153
|
+
* This hook uses `notification_type` for matcher matching.
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // Forward notifications to Slack
|
|
157
|
+
* notificationHook({}, async (input: NotificationInput) => {
|
|
158
|
+
* await sendSlackMessage(input.title, input.message);
|
|
159
|
+
* return notificationOutput({});
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
* @see https://code.claude.com/docs/en/hooks#notification
|
|
163
|
+
*/
|
|
164
|
+
export type NotificationInput = SDKNotificationHookInput;
|
|
165
|
+
/**
|
|
166
|
+
* Input for UserPromptSubmit hooks.
|
|
167
|
+
*
|
|
168
|
+
* Fires when a user submits a prompt, allowing you to:
|
|
169
|
+
* - Add additional context or instructions
|
|
170
|
+
* - Log user interactions
|
|
171
|
+
* - Validate or transform prompts
|
|
172
|
+
*
|
|
173
|
+
* This hook does not support matchers; it fires on all prompt submissions.
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* // Add project context to every prompt
|
|
177
|
+
* userPromptSubmitHook({}, async (input: UserPromptSubmitInput) => {
|
|
178
|
+
* return userPromptSubmitOutput({
|
|
179
|
+
* additionalContext: await getProjectContext()
|
|
180
|
+
* });
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
* @see https://code.claude.com/docs/en/hooks#userpromptsubmit
|
|
184
|
+
*/
|
|
185
|
+
export type UserPromptSubmitInput = SDKUserPromptSubmitHookInput;
|
|
186
|
+
/**
|
|
187
|
+
* Input for SessionStart hooks.
|
|
188
|
+
*
|
|
189
|
+
* Fires when a Claude Code session starts or restarts, allowing you to:
|
|
190
|
+
* - Initialize session state
|
|
191
|
+
* - Inject context or instructions
|
|
192
|
+
* - Set up logging or monitoring
|
|
193
|
+
*
|
|
194
|
+
* This hook uses `source` for matcher matching.
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* // Initialize context for new sessions
|
|
198
|
+
* sessionStartHook({ matcher: 'startup' }, async (input: SessionStartInput) => {
|
|
199
|
+
* return sessionStartOutput({
|
|
200
|
+
* additionalContext: JSON.stringify({
|
|
201
|
+
* project: 'my-project',
|
|
202
|
+
* initialized: true
|
|
203
|
+
* })
|
|
204
|
+
* });
|
|
205
|
+
* });
|
|
206
|
+
* ```
|
|
207
|
+
* @see https://code.claude.com/docs/en/hooks#sessionstart
|
|
208
|
+
*/
|
|
209
|
+
export type SessionStartInput = SDKSessionStartHookInput;
|
|
210
|
+
/**
|
|
211
|
+
* Input for SessionEnd hooks.
|
|
212
|
+
*
|
|
213
|
+
* Fires when a Claude Code session ends, allowing you to:
|
|
214
|
+
* - Clean up session resources
|
|
215
|
+
* - Log session metrics
|
|
216
|
+
* - Persist session state
|
|
217
|
+
*
|
|
218
|
+
* This hook uses `reason` for matcher matching.
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* // Log session end
|
|
222
|
+
* sessionEndHook({}, async (input: SessionEndInput) => {
|
|
223
|
+
* console.log(`Session ended: ${input.reason}`);
|
|
224
|
+
* return sessionEndOutput({});
|
|
225
|
+
* });
|
|
226
|
+
* ```
|
|
227
|
+
* @see https://code.claude.com/docs/en/hooks#sessionend
|
|
228
|
+
*/
|
|
229
|
+
export interface SessionEndInput extends Omit<SDKSessionEndHookInput, "reason"> {
|
|
230
|
+
/**
|
|
231
|
+
* The reason the session ended.
|
|
232
|
+
*
|
|
233
|
+
* - `'clear'` - Session cleared by user
|
|
234
|
+
* - `'logout'` - User logged out
|
|
235
|
+
* - `'prompt_input_exit'` - User exited at prompt input
|
|
236
|
+
* - `'other'` - Other reasons
|
|
237
|
+
*/
|
|
238
|
+
reason: SessionEndReason;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Input for Stop hooks.
|
|
242
|
+
*
|
|
243
|
+
* Fires when Claude Code is about to stop, allowing you to:
|
|
244
|
+
* - Block the stop and require additional action
|
|
245
|
+
* - Confirm the user wants to stop
|
|
246
|
+
* - Clean up resources before stopping
|
|
247
|
+
*
|
|
248
|
+
* This hook does not support matchers; it fires on all stop events.
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* // Require confirmation before stopping with pending changes
|
|
252
|
+
* stopHook({}, async (input: StopInput) => {
|
|
253
|
+
* const pendingChanges = await checkPendingChanges();
|
|
254
|
+
* if (pendingChanges.length > 0) {
|
|
255
|
+
* return stopOutput({
|
|
256
|
+
* decision: 'block',
|
|
257
|
+
* reason: 'There are uncommitted changes'
|
|
258
|
+
* });
|
|
259
|
+
* }
|
|
260
|
+
* return stopOutput({ decision: 'approve' });
|
|
261
|
+
* });
|
|
262
|
+
* ```
|
|
263
|
+
* @see https://code.claude.com/docs/en/hooks#stop
|
|
264
|
+
*/
|
|
265
|
+
export type StopInput = SDKStopHookInput;
|
|
266
|
+
/**
|
|
267
|
+
* Input for SubagentStart hooks.
|
|
268
|
+
*
|
|
269
|
+
* Fires when a subagent (Task tool) starts, allowing you to:
|
|
270
|
+
* - Inject context for the subagent
|
|
271
|
+
* - Log subagent invocations
|
|
272
|
+
* - Configure subagent behavior
|
|
273
|
+
*
|
|
274
|
+
* This hook uses `agent_type` for matcher matching.
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* // Add context for explore subagents
|
|
278
|
+
* subagentStartHook({ matcher: 'explore' }, async (input: SubagentStartInput) => {
|
|
279
|
+
* return subagentStartOutput({
|
|
280
|
+
* additionalContext: 'Focus on finding patterns and conventions'
|
|
281
|
+
* });
|
|
282
|
+
* });
|
|
283
|
+
* ```
|
|
284
|
+
* @see https://code.claude.com/docs/en/hooks#subagentstart
|
|
285
|
+
*/
|
|
286
|
+
export type SubagentStartInput = SDKSubagentStartHookInput;
|
|
287
|
+
/**
|
|
288
|
+
* Input for SubagentStop hooks.
|
|
289
|
+
*
|
|
290
|
+
* Fires when a subagent completes or stops, allowing you to:
|
|
291
|
+
* - Process subagent results
|
|
292
|
+
* - Clean up subagent resources
|
|
293
|
+
* - Log subagent completion
|
|
294
|
+
* - Block subagent from stopping
|
|
295
|
+
*
|
|
296
|
+
* This hook uses `agent_type` for matcher matching.
|
|
297
|
+
* @example
|
|
298
|
+
* ```typescript
|
|
299
|
+
* // Block explore subagent if task incomplete
|
|
300
|
+
* subagentStopHook({ matcher: 'explore' }, async (input: SubagentStopInput) => {
|
|
301
|
+
* console.log(`Subagent ${input.agent_id} (${input.agent_type}) stopping`);
|
|
302
|
+
* return subagentStopOutput({
|
|
303
|
+
* decision: 'block',
|
|
304
|
+
* reason: 'Please verify all files were explored'
|
|
305
|
+
* });
|
|
306
|
+
* });
|
|
307
|
+
* ```
|
|
308
|
+
* @see https://code.claude.com/docs/en/hooks#subagentstop
|
|
309
|
+
*/
|
|
310
|
+
export interface SubagentStopInput extends SDKSubagentStopHookInput {
|
|
311
|
+
/**
|
|
312
|
+
* Type of subagent that is stopping.
|
|
313
|
+
* Examples: 'explore', 'codebase-analysis', custom agent types
|
|
314
|
+
*/
|
|
315
|
+
agent_type: string;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Input for PreCompact hooks.
|
|
319
|
+
*
|
|
320
|
+
* Fires before context compaction occurs, allowing you to:
|
|
321
|
+
* - Preserve important information before compaction
|
|
322
|
+
* - Log compaction events
|
|
323
|
+
* - Modify custom instructions for the compacted context
|
|
324
|
+
*
|
|
325
|
+
* This hook uses `trigger` for matcher matching.
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* // Log compaction events
|
|
329
|
+
* preCompactHook({}, async (input: PreCompactInput) => {
|
|
330
|
+
* console.log(`Compacting (${input.trigger})`);
|
|
331
|
+
* return preCompactOutput({});
|
|
332
|
+
* });
|
|
333
|
+
* ```
|
|
334
|
+
* @see https://code.claude.com/docs/en/hooks#precompact
|
|
335
|
+
*/
|
|
336
|
+
export type PreCompactInput = SDKPreCompactHookInput;
|
|
337
|
+
/**
|
|
338
|
+
* Input for PermissionRequest hooks.
|
|
339
|
+
*
|
|
340
|
+
* Fires when a permission prompt would be shown, allowing you to:
|
|
341
|
+
* - Auto-approve or deny tool executions
|
|
342
|
+
* - Implement custom permission logic
|
|
343
|
+
* - Modify tool inputs before approval
|
|
344
|
+
*
|
|
345
|
+
* This hook uses `tool_name` for matcher matching.
|
|
346
|
+
* @example
|
|
347
|
+
* ```typescript
|
|
348
|
+
* // Auto-approve read operations in allowed directories
|
|
349
|
+
* permissionRequestHook({ matcher: 'Read' }, async (input: PermissionRequestInput) => {
|
|
350
|
+
* const filePath = input.tool_input.file_path as string;
|
|
351
|
+
* if (filePath.startsWith('/allowed/')) {
|
|
352
|
+
* return permissionRequestOutput({
|
|
353
|
+
* allow: true
|
|
354
|
+
* });
|
|
355
|
+
* }
|
|
356
|
+
* return permissionRequestOutput({}); // Fall through to normal permission prompt
|
|
357
|
+
* });
|
|
358
|
+
* ```
|
|
359
|
+
* @see https://code.claude.com/docs/en/hooks#permissionrequest
|
|
360
|
+
*/
|
|
361
|
+
export interface PermissionRequestInput extends SDKPermissionRequestHookInput {
|
|
362
|
+
/**
|
|
363
|
+
* Unique identifier for this specific tool invocation.
|
|
364
|
+
*/
|
|
365
|
+
tool_use_id: string;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Discriminated union of all hook input types.
|
|
369
|
+
*
|
|
370
|
+
* Use this type when handling multiple hook types in a single handler
|
|
371
|
+
* or when the hook type is not known statically.
|
|
372
|
+
* @example
|
|
373
|
+
* ```typescript
|
|
374
|
+
* // Handle any hook type with type narrowing
|
|
375
|
+
* function handleHook(input: HookInput) {
|
|
376
|
+
* switch (input.hook_event_name) {
|
|
377
|
+
* case 'PreToolUse':
|
|
378
|
+
* // TypeScript knows input is PreToolUseInput here
|
|
379
|
+
* console.log(`Tool: ${input.tool_name}`);
|
|
380
|
+
* break;
|
|
381
|
+
* case 'SessionStart':
|
|
382
|
+
* // TypeScript knows input is SessionStartInput here
|
|
383
|
+
* console.log(`Source: ${input.source}`);
|
|
384
|
+
* break;
|
|
385
|
+
* // ... handle other hook types
|
|
386
|
+
* }
|
|
387
|
+
* }
|
|
388
|
+
* ```
|
|
389
|
+
* @see https://code.claude.com/docs/en/hooks
|
|
390
|
+
*/
|
|
391
|
+
export type HookInput = PreToolUseInput | PostToolUseInput | PostToolUseFailureInput | NotificationInput | UserPromptSubmitInput | SessionStartInput | SessionEndInput | StopInput | SubagentStartInput | SubagentStopInput | PreCompactInput | PermissionRequestInput;
|
|
392
|
+
/**
|
|
393
|
+
* Hook event name literal union.
|
|
394
|
+
*
|
|
395
|
+
* All valid hook event names that can appear in the `hook_event_name` field.
|
|
396
|
+
*/
|
|
397
|
+
export type HookEventName = HookInput["hook_event_name"];
|
|
398
|
+
/**
|
|
399
|
+
* All hook event names as a readonly array.
|
|
400
|
+
*
|
|
401
|
+
* Useful for iteration and validation.
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* for (const eventName of HOOK_EVENT_NAMES) {
|
|
405
|
+
* console.log(`Supported hook: ${eventName}`);
|
|
406
|
+
* }
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
export declare const HOOK_EVENT_NAMES: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest"];
|
|
410
|
+
export type { SDKPermissionUpdate as PermissionUpdate };
|
|
411
|
+
/**
|
|
412
|
+
* Re-export all tool input types from the official Claude Agent SDK.
|
|
413
|
+
* Uses `export type *` because sdk-tools.d.ts has no JavaScript runtime counterpart.
|
|
414
|
+
* @see {@link https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk | @anthropic-ai/claude-agent-sdk}
|
|
415
|
+
*/
|
|
416
|
+
export type * from "@anthropic-ai/claude-agent-sdk/sdk-tools.js";
|
|
417
|
+
/**
|
|
418
|
+
* A single edit entry within a MultiEdit operation.
|
|
419
|
+
*/
|
|
420
|
+
export interface MultiEditEntry {
|
|
421
|
+
/** The text to search for. */
|
|
422
|
+
old_string: string;
|
|
423
|
+
/** The text to replace old_string with. */
|
|
424
|
+
new_string: string;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Input structure for the MultiEdit tool.
|
|
428
|
+
*
|
|
429
|
+
* The MultiEdit tool performs multiple search-and-replace operations on a single file.
|
|
430
|
+
* All edits are applied atomically.
|
|
431
|
+
* @example
|
|
432
|
+
* ```typescript
|
|
433
|
+
* // Example tool input
|
|
434
|
+
* {
|
|
435
|
+
* file_path: '/workspace/src/index.ts',
|
|
436
|
+
* edits: [
|
|
437
|
+
* { old_string: 'const x = 1;', new_string: 'const x = 2;' },
|
|
438
|
+
* { old_string: 'const y = 1;', new_string: 'const y = 2;' }
|
|
439
|
+
* ]
|
|
440
|
+
* }
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
443
|
+
export interface MultiEditToolInput {
|
|
444
|
+
/** Absolute path to the file to edit. */
|
|
445
|
+
file_path: string;
|
|
446
|
+
/** Array of edit operations to apply. */
|
|
447
|
+
edits: MultiEditEntry[];
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Union of all file-modifying tool inputs.
|
|
451
|
+
*
|
|
452
|
+
* Use this type when you need to handle Write, Edit, or MultiEdit generically.
|
|
453
|
+
*/
|
|
454
|
+
export type FileModifyingToolInput = FileWriteInput | FileEditInput | MultiEditToolInput;
|
|
455
|
+
/**
|
|
456
|
+
* Tool names for file-modifying tools.
|
|
457
|
+
*
|
|
458
|
+
* Use this type when you need to reference the tool name in type guards.
|
|
459
|
+
*/
|
|
460
|
+
export type FileModifyingToolName = "Write" | "Edit" | "MultiEdit";
|
|
461
|
+
/**
|
|
462
|
+
* Union of all known tool inputs.
|
|
463
|
+
*
|
|
464
|
+
* This includes all tool inputs that have well-defined type structures.
|
|
465
|
+
*/
|
|
466
|
+
export type KnownToolInput = FileWriteInput | FileEditInput | MultiEditToolInput | FileReadInput | BashInput | GlobInput | GrepInput | AgentInput | TaskOutputInput | ExitPlanModeInput | KillShellInput | NotebookEditInput | TodoWriteInput | WebFetchInput | WebSearchInput | AskUserQuestionInput;
|
|
467
|
+
/**
|
|
468
|
+
* Tool names for all known tools with typed inputs.
|
|
469
|
+
*/
|
|
470
|
+
export type KnownToolName = "Write" | "Edit" | "MultiEdit" | "Read" | "Bash" | "Glob" | "Grep" | "Task" | "TaskOutput" | "ExitPlanMode" | "KillShell" | "NotebookEdit" | "TodoWrite" | "WebFetch" | "WebSearch" | "AskUserQuestion";
|
|
471
|
+
/**
|
|
472
|
+
* Type mapping from tool name to tool input type.
|
|
473
|
+
*
|
|
474
|
+
* Used by typed factory overloads to provide automatic typing.
|
|
475
|
+
* @example
|
|
476
|
+
* ```typescript
|
|
477
|
+
* type WriteInput = ToolInputMap['Write']; // FileWriteInput
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
export interface ToolInputMap {
|
|
481
|
+
Write: FileWriteInput;
|
|
482
|
+
Edit: FileEditInput;
|
|
483
|
+
MultiEdit: MultiEditToolInput;
|
|
484
|
+
Read: FileReadInput;
|
|
485
|
+
Bash: BashInput;
|
|
486
|
+
Glob: GlobInput;
|
|
487
|
+
Grep: GrepInput;
|
|
488
|
+
Task: AgentInput;
|
|
489
|
+
TaskOutput: TaskOutputInput;
|
|
490
|
+
ExitPlanMode: ExitPlanModeInput;
|
|
491
|
+
KillShell: KillShellInput;
|
|
492
|
+
NotebookEdit: NotebookEditInput;
|
|
493
|
+
TodoWrite: TodoWriteInput;
|
|
494
|
+
WebFetch: WebFetchInput;
|
|
495
|
+
WebSearch: WebSearchInput;
|
|
496
|
+
AskUserQuestion: AskUserQuestionInput;
|
|
497
|
+
}
|
package/dist/inputs.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Input types for Claude Code hooks using wire format (snake_case).
|
|
3
|
-
*
|
|
4
|
-
* These types match the JSON format that Claude Code sends via stdin. Property names
|
|
5
|
-
* use snake_case to match the wire protocol directly without transformation overhead.
|
|
6
|
-
* Each hook input type includes comprehensive JSDoc documentation explaining when
|
|
7
|
-
* the hook fires and how to use it.
|
|
8
|
-
* @see https://code.claude.com/docs/en/hooks
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* All hook event names as a readonly array.
|
|
13
|
-
*
|
|
14
|
-
* Useful for iteration and validation.
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* for (const eventName of HOOK_EVENT_NAMES) {
|
|
18
|
-
* console.log(`Supported hook: ${eventName}`);
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export const HOOK_EVENT_NAMES = [
|
|
23
|
-
'PreToolUse',
|
|
24
|
-
'PostToolUse',
|
|
25
|
-
'PostToolUseFailure',
|
|
26
|
-
'Notification',
|
|
27
|
-
'UserPromptSubmit',
|
|
28
|
-
'SessionStart',
|
|
29
|
-
'SessionEnd',
|
|
30
|
-
'Stop',
|
|
31
|
-
'SubagentStart',
|
|
32
|
-
'SubagentStop',
|
|
33
|
-
'PreCompact',
|
|
34
|
-
'PermissionRequest'
|
|
35
|
-
];
|
package/dist/tool-inputs.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for well-known Claude Code tool inputs.
|
|
3
|
-
*
|
|
4
|
-
* These types define the structure of `toolInput` for common Claude Code tools.
|
|
5
|
-
* Use them with type guards from `tool-helpers.ts` for safe type narrowing,
|
|
6
|
-
* or with typed hook factory overloads for automatic typing.
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { isWriteTool, getFilePath } from '@goodfoot/claude-code-hooks';
|
|
10
|
-
*
|
|
11
|
-
* preToolUseHook({ matcher: 'Write|Edit|MultiEdit' }, (input) => {
|
|
12
|
-
* if (isWriteTool(input)) {
|
|
13
|
-
* // input.tool_input is now typed as WriteToolInput
|
|
14
|
-
* console.log(input.tool_input.file_path);
|
|
15
|
-
* }
|
|
16
|
-
* });
|
|
17
|
-
* ```
|
|
18
|
-
* @see https://code.claude.com/docs/en/hooks
|
|
19
|
-
* @module
|
|
20
|
-
*/
|
|
21
|
-
export {};
|