@goodfoot/claude-code-hooks 1.0.10 → 1.0.15
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 +599 -604
- package/dist/constants.js +13 -12
- package/dist/env.js +36 -38
- package/dist/hooks.js +62 -22
- package/dist/index.js +37 -67
- package/dist/logger.js +371 -362
- package/dist/outputs.js +51 -34
- package/dist/runtime.js +99 -96
- package/dist/scaffold.js +180 -183
- package/dist/tool-helpers.js +255 -103
- package/dist/types.js +36 -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 +203 -254
- package/types/index.d.ts +15 -130
- package/types/logger.d.ts +285 -285
- package/types/outputs.d.ts +193 -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/{inputs.d.ts → types.d.ts} +186 -252
- package/dist/inputs.js +0 -35
- package/dist/tool-inputs.js +0 -21
- package/types/tool-inputs.d.ts +0 -228
package/types/cli.d.ts
CHANGED
|
@@ -14,79 +14,79 @@
|
|
|
14
14
|
* ```
|
|
15
15
|
* @module
|
|
16
16
|
*/
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
17
|
+
import { HOOK_FACTORY_TO_EVENT } from "./constants.js";
|
|
18
|
+
import type { HookEventName } from "./types.js";
|
|
19
19
|
/**
|
|
20
20
|
* Hook context determines how paths are resolved in hooks.json.
|
|
21
21
|
*
|
|
22
22
|
* - `plugin`: Uses `$CLAUDE_PLUGIN_ROOT` for plugin hooks
|
|
23
23
|
* - `agent`: Uses `"$CLAUDE_PROJECT_DIR"` for agent hooks (.claude/hooks/)
|
|
24
24
|
*/
|
|
25
|
-
type HookContext =
|
|
25
|
+
type HookContext = "plugin" | "agent";
|
|
26
26
|
/**
|
|
27
27
|
* Command-line arguments parsed from process.argv.
|
|
28
28
|
*/
|
|
29
29
|
interface CliArgs {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
/** Glob pattern for hook source files. */
|
|
31
|
+
input: string;
|
|
32
|
+
/** Path for hooks.json output file. */
|
|
33
|
+
output: string;
|
|
34
|
+
/** Optional log file path. */
|
|
35
|
+
log?: string;
|
|
36
|
+
/** Show help. */
|
|
37
|
+
help: boolean;
|
|
38
|
+
/** Show version. */
|
|
39
|
+
version: boolean;
|
|
40
|
+
/** Directory path for scaffolding a new hook project. */
|
|
41
|
+
scaffold?: string;
|
|
42
|
+
/** Comma-separated list of hook types to generate when scaffolding. */
|
|
43
|
+
hooks?: string;
|
|
44
|
+
/** Node executable path to use in command output (default: "node"). */
|
|
45
|
+
executable?: string;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Metadata extracted from a hook file via TypeScript AST analysis.
|
|
49
49
|
*/
|
|
50
50
|
interface HookMetadata {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
/** The hook event type (PreToolUse, SessionStart, etc.). */
|
|
52
|
+
hookEventName: HookEventName;
|
|
53
|
+
/** Optional matcher pattern from hook config. */
|
|
54
|
+
matcher?: string;
|
|
55
|
+
/** Optional timeout in milliseconds from hook config. */
|
|
56
|
+
timeout?: number;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* A compiled hook with its metadata and output path.
|
|
60
60
|
*/
|
|
61
61
|
interface CompiledHook {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
/** Original source file path. */
|
|
63
|
+
sourcePath: string;
|
|
64
|
+
/** Compiled output file path. */
|
|
65
|
+
outputPath: string;
|
|
66
|
+
/** Output filename (e.g., "my-hook.abc123de.mjs"). */
|
|
67
|
+
outputFilename: string;
|
|
68
|
+
/** Extracted hook metadata. */
|
|
69
|
+
metadata: HookMetadata;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Individual hook configuration within a matcher group.
|
|
73
73
|
*/
|
|
74
74
|
interface HookConfig {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
/** Hook type - always "command" for compiled hooks. */
|
|
76
|
+
type: "command";
|
|
77
|
+
/** Absolute path to compiled hook executable. */
|
|
78
|
+
command: string;
|
|
79
|
+
/** Optional timeout in seconds. */
|
|
80
|
+
timeout?: number;
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Matcher group entry within an event type.
|
|
84
84
|
*/
|
|
85
85
|
interface MatcherEntry {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
/** Matcher pattern (tool name, regex, etc.). Optional for some event types. */
|
|
87
|
+
matcher?: string;
|
|
88
|
+
/** Array of hook configurations in this matcher group. */
|
|
89
|
+
hooks: HookConfig[];
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* The complete hooks.json structure expected by Claude Code.
|
|
@@ -94,15 +94,15 @@ interface MatcherEntry {
|
|
|
94
94
|
* Format: { hooks: { EventType: [ { matcher?, hooks: [...] } ] } }
|
|
95
95
|
*/
|
|
96
96
|
interface HooksJson {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
/** Object keyed by event type (PreToolUse, SessionStart, etc.). */
|
|
98
|
+
hooks: Partial<Record<HookEventName, MatcherEntry[]>>;
|
|
99
|
+
/** Generated file tracking metadata. */
|
|
100
|
+
__generated: {
|
|
101
|
+
/** Array of generated filenames. */
|
|
102
|
+
files: string[];
|
|
103
|
+
/** ISO timestamp of generation. */
|
|
104
|
+
timestamp: string;
|
|
105
|
+
};
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* Parses command-line arguments.
|
|
@@ -144,12 +144,12 @@ declare function discoverHookFiles(pattern: string, cwd: string): Promise<string
|
|
|
144
144
|
* Options for compiling a hook.
|
|
145
145
|
*/
|
|
146
146
|
interface CompileHookOptions {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
147
|
+
/** Absolute path to source file. */
|
|
148
|
+
sourcePath: string;
|
|
149
|
+
/** Directory for compiled output. */
|
|
150
|
+
outputDir: string;
|
|
151
|
+
/** Optional log file path to inject into compiled hook. */
|
|
152
|
+
logFilePath?: string;
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* Compiles a TypeScript hook file to a self-contained ESM executable.
|
|
@@ -171,17 +171,15 @@ declare function generateContentHash(content: string): string;
|
|
|
171
171
|
* @param compiledHooks - Array of compiled hooks
|
|
172
172
|
* @returns Nested map: EventType -> Matcher -> Hooks
|
|
173
173
|
*/
|
|
174
|
-
declare function groupHooksByEventAndMatcher(
|
|
175
|
-
compiledHooks: CompiledHook[]
|
|
176
|
-
): Map<HookEventName, Map<string | undefined, CompiledHook[]>>;
|
|
174
|
+
declare function groupHooksByEventAndMatcher(compiledHooks: CompiledHook[]): Map<HookEventName, Map<string | undefined, CompiledHook[]>>;
|
|
177
175
|
/**
|
|
178
176
|
* Result of detecting the hook context, including the root directory.
|
|
179
177
|
*/
|
|
180
178
|
interface HookContextInfo {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
179
|
+
/** Hook context type. */
|
|
180
|
+
context: HookContext;
|
|
181
|
+
/** Absolute path to the root directory (plugin root or project root). */
|
|
182
|
+
rootDir: string;
|
|
185
183
|
}
|
|
186
184
|
/**
|
|
187
185
|
* Auto-detects the hook context and root directory based on directory structure.
|
|
@@ -208,12 +206,7 @@ declare function detectHookContext(outputPath: string): HookContextInfo;
|
|
|
208
206
|
* @param executable - Node executable path (default: "node")
|
|
209
207
|
* @returns The command path string
|
|
210
208
|
*/
|
|
211
|
-
declare function generateCommandPath(
|
|
212
|
-
filename: string,
|
|
213
|
-
buildDir: string,
|
|
214
|
-
contextInfo: HookContextInfo,
|
|
215
|
-
executable?: string
|
|
216
|
-
): string;
|
|
209
|
+
declare function generateCommandPath(filename: string, buildDir: string, contextInfo: HookContextInfo, executable?: string): string;
|
|
217
210
|
/**
|
|
218
211
|
* Generates the hooks.json content in Claude Code's expected format.
|
|
219
212
|
*
|
|
@@ -224,12 +217,7 @@ declare function generateCommandPath(
|
|
|
224
217
|
* @param executable - Node executable path (default: "node")
|
|
225
218
|
* @returns The hooks.json structure
|
|
226
219
|
*/
|
|
227
|
-
declare function generateHooksJson(
|
|
228
|
-
compiledHooks: CompiledHook[],
|
|
229
|
-
buildDir: string,
|
|
230
|
-
contextInfo: HookContextInfo,
|
|
231
|
-
executable?: string
|
|
232
|
-
): HooksJson;
|
|
220
|
+
declare function generateHooksJson(compiledHooks: CompiledHook[], buildDir: string, contextInfo: HookContextInfo, executable?: string): HooksJson;
|
|
233
221
|
/**
|
|
234
222
|
* Reads an existing hooks.json file if it exists.
|
|
235
223
|
* @param outputPath - Path to the hooks.json file
|
|
@@ -257,25 +245,6 @@ declare function extractPreservedHooks(existingHooksJson: HooksJson): Partial<Re
|
|
|
257
245
|
* @param preservedHooks - Hooks to preserve from the existing hooks.json
|
|
258
246
|
* @returns Merged HooksJson
|
|
259
247
|
*/
|
|
260
|
-
declare function mergeHooksJson(
|
|
261
|
-
|
|
262
|
-
preservedHooks: Partial<Record<HookEventName, MatcherEntry[]>>
|
|
263
|
-
): HooksJson;
|
|
264
|
-
export {
|
|
265
|
-
parseArgs,
|
|
266
|
-
validateArgs,
|
|
267
|
-
analyzeHookFile,
|
|
268
|
-
discoverHookFiles,
|
|
269
|
-
compileHook,
|
|
270
|
-
generateContentHash,
|
|
271
|
-
detectHookContext,
|
|
272
|
-
generateCommandPath,
|
|
273
|
-
generateHooksJson,
|
|
274
|
-
groupHooksByEventAndMatcher,
|
|
275
|
-
readExistingHooksJson,
|
|
276
|
-
removeOldGeneratedFiles,
|
|
277
|
-
extractPreservedHooks,
|
|
278
|
-
mergeHooksJson,
|
|
279
|
-
HOOK_FACTORY_TO_EVENT
|
|
280
|
-
};
|
|
248
|
+
declare function mergeHooksJson(newHooksJson: HooksJson, preservedHooks: Partial<Record<HookEventName, MatcherEntry[]>>): HooksJson;
|
|
249
|
+
export { parseArgs, validateArgs, analyzeHookFile, discoverHookFiles, compileHook, generateContentHash, detectHookContext, generateCommandPath, generateHooksJson, groupHooksByEventAndMatcher, readExistingHooksJson, removeOldGeneratedFiles, extractPreservedHooks, mergeHooksJson, HOOK_FACTORY_TO_EVENT, };
|
|
281
250
|
export type { CliArgs, HookMetadata, CompiledHook, HookConfig, MatcherEntry, HooksJson };
|
package/types/constants.d.ts
CHANGED
package/types/env.d.ts
CHANGED
|
@@ -38,22 +38,22 @@
|
|
|
38
38
|
* These are the environment variables that Claude Code sets when running hooks.
|
|
39
39
|
*/
|
|
40
40
|
export declare const CLAUDE_ENV_VARS: {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Absolute path to the project root directory where Claude Code was started.
|
|
43
|
+
* Available in all hooks.
|
|
44
|
+
*/
|
|
45
|
+
readonly PROJECT_DIR: "CLAUDE_PROJECT_DIR";
|
|
46
|
+
/**
|
|
47
|
+
* Path to a file where SessionStart hooks can persist environment variables.
|
|
48
|
+
* Variables written to this file will be available in all subsequent bash commands.
|
|
49
|
+
* Only available in SessionStart hooks.
|
|
50
|
+
*/
|
|
51
|
+
readonly ENV_FILE: "CLAUDE_ENV_FILE";
|
|
52
|
+
/**
|
|
53
|
+
* Set to "true" when running in a remote (web) environment.
|
|
54
|
+
* Not set or empty when running in local CLI environment.
|
|
55
|
+
*/
|
|
56
|
+
readonly REMOTE: "CLAUDE_CODE_REMOTE";
|
|
57
57
|
};
|
|
58
58
|
/**
|
|
59
59
|
* Gets the Claude Code project directory.
|