cc-hooks-ts 0.0.1 → 0.0.2
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 +11 -10
- package/dist/index.d.mts +5 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,24 +13,22 @@ npx npym add cc-hooks-ts
|
|
|
13
13
|
> [!NOTE]
|
|
14
14
|
> We highly recommend using Bun or Deno for automatic dependency downloading at runtime.
|
|
15
15
|
>
|
|
16
|
-
> - Deno: <https://docs.deno.com/runtime/fundamentals/modules/#managing-third-party-modules-and-libraries>
|
|
17
16
|
> - Bun: <https://bun.com/docs/runtime/autoimport>
|
|
17
|
+
> - Deno: <https://docs.deno.com/runtime/fundamentals/modules/#managing-third-party-modules-and-libraries>
|
|
18
18
|
|
|
19
19
|
### Define a Hook
|
|
20
20
|
|
|
21
|
-
With
|
|
21
|
+
With Bun:
|
|
22
22
|
|
|
23
23
|
```typescript
|
|
24
|
-
#!/usr/bin/env -S
|
|
24
|
+
#!/usr/bin/env -S bun run --silent
|
|
25
25
|
import { defineHook, runHook } from "cc-hooks-ts";
|
|
26
26
|
|
|
27
|
-
// Session start hook
|
|
28
27
|
const sessionHook = defineHook({
|
|
29
28
|
trigger: { SessionStart: true },
|
|
30
29
|
run: (context) => {
|
|
31
|
-
console.log(`Session started: ${context.input.session_id}`);
|
|
32
30
|
return context.success({
|
|
33
|
-
messageForUser: "
|
|
31
|
+
messageForUser: "Session started!"
|
|
34
32
|
});
|
|
35
33
|
}
|
|
36
34
|
});
|
|
@@ -38,17 +36,19 @@ const sessionHook = defineHook({
|
|
|
38
36
|
await runHook(sessionHook);
|
|
39
37
|
```
|
|
40
38
|
|
|
41
|
-
Or with
|
|
39
|
+
Or with Deno:
|
|
42
40
|
|
|
43
41
|
```typescript
|
|
44
|
-
#!/usr/bin/env -S
|
|
45
|
-
import { defineHook, runHook } from "cc-hooks-ts";
|
|
42
|
+
#!/usr/bin/env -S deno run --quiet --allow-env --allow-read
|
|
43
|
+
import { defineHook, runHook } from "npm:cc-hooks-ts";
|
|
46
44
|
|
|
45
|
+
// Session start hook
|
|
47
46
|
const sessionHook = defineHook({
|
|
48
47
|
trigger: { SessionStart: true },
|
|
49
48
|
run: (context) => {
|
|
49
|
+
console.log(`Session started: ${context.input.session_id}`);
|
|
50
50
|
return context.success({
|
|
51
|
-
messageForUser: "
|
|
51
|
+
messageForUser: "Welcome to your coding session!"
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
});
|
|
@@ -86,6 +86,7 @@ For better type inference in PreToolUse and PostToolUse hooks, you can extend th
|
|
|
86
86
|
Extend the `ToolSchema` interface to add custom tool definitions:
|
|
87
87
|
|
|
88
88
|
```typescript
|
|
89
|
+
// Use "npm:cc-hooks-ts" for Deno
|
|
89
90
|
declare module "cc-hooks-ts" {
|
|
90
91
|
interface ToolSchema {
|
|
91
92
|
MyCustomTool: {
|
package/dist/index.d.mts
CHANGED
|
@@ -54,19 +54,16 @@ type CommonHookOutputs = {
|
|
|
54
54
|
* @see {@link https://docs.anthropic.com/en/docs/claude-code/hooks#pretooluse-decision-control}
|
|
55
55
|
*/
|
|
56
56
|
interface PreToolUseHookOutput extends CommonHookOutputs {
|
|
57
|
-
/**
|
|
58
|
-
* - `block` automatically prompts Claude with `reason`.
|
|
59
|
-
* - `undefined` does nothing. `reason` is ignored.
|
|
60
|
-
*/
|
|
61
|
-
decision: "block" | undefined;
|
|
62
57
|
hookSpecificOutput?: {
|
|
63
58
|
hookEventName: "PreToolUse";
|
|
64
59
|
/**
|
|
65
|
-
*
|
|
60
|
+
* - `allow` bypasses the permission system. `permissionDecisionReason` is shown to the user but not to Claude.
|
|
61
|
+
* - `deny` prevents the tool call from executing. `permissionDecisionReason` is shown to Claude.
|
|
62
|
+
* - `ask` asks the user to confirm the tool call in the UI. `permissionDecisionReason` is shown to the user but not to Claude.
|
|
66
63
|
*/
|
|
67
|
-
|
|
64
|
+
permissionDecision: "allow" | "ask" | "deny";
|
|
65
|
+
permissionDecisionReason: string;
|
|
68
66
|
};
|
|
69
|
-
reason?: string;
|
|
70
67
|
}
|
|
71
68
|
/**
|
|
72
69
|
* @see {@link https://docs.anthropic.com/en/docs/claude-code/hooks#posttooluse-decision-control}
|