cc-hooks-ts 0.0.1 → 0.0.3

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
@@ -13,22 +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 Deno:
21
+ With Bun:
22
22
 
23
23
  ```typescript
24
- #!/usr/bin/env -S deno run --quiet --allow-env --allow-read
24
+ #!/usr/bin/env -S bun run --silent
25
25
  import { defineHook, runHook } from "cc-hooks-ts";
26
26
 
27
27
  // Session start hook
28
28
  const sessionHook = defineHook({
29
29
  trigger: { SessionStart: true },
30
30
  run: (context) => {
31
- console.log(`Session started: ${context.input.session_id}`);
31
+ // do something great
32
32
  return context.success({
33
33
  messageForUser: "Welcome to your coding session!"
34
34
  });
@@ -38,17 +38,19 @@ const sessionHook = defineHook({
38
38
  await runHook(sessionHook);
39
39
  ```
40
40
 
41
- Or with Bun:
41
+ Or with Deno:
42
42
 
43
43
  ```typescript
44
- #!/usr/bin/env -S bun run --silent
45
- import { defineHook, runHook } from "cc-hooks-ts";
44
+ #!/usr/bin/env -S deno run --quiet --allow-env --allow-read
45
+ import { defineHook, runHook } from "npm:cc-hooks-ts";
46
46
 
47
+ // Session start hook
47
48
  const sessionHook = defineHook({
48
49
  trigger: { SessionStart: true },
49
50
  run: (context) => {
51
+ // do something great
50
52
  return context.success({
51
- messageForUser: "Session started!"
53
+ messageForUser: "Welcome to your coding session!"
52
54
  });
53
55
  }
54
56
  });
@@ -86,6 +88,7 @@ For better type inference in PreToolUse and PostToolUse hooks, you can extend th
86
88
  Extend the `ToolSchema` interface to add custom tool definitions:
87
89
 
88
90
  ```typescript
91
+ // Use "npm:cc-hooks-ts" for Deno
89
92
  declare module "cc-hooks-ts" {
90
93
  interface ToolSchema {
91
94
  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
- * Adds context for Claude to consider.
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
- additionalContext?: string;
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}
package/dist/index.mjs CHANGED
@@ -103,10 +103,8 @@ function handleHookResult(eventName, hookResult) {
103
103
  switch (hookResult.kind) {
104
104
  case "success":
105
105
  if (eventName === "UserPromptSubmit" || eventName === "SessionStart") {
106
- if (isNonEmptyString(hookResult.payload.additionalClaudeContext)) {
107
- console.log(hookResult.payload.additionalClaudeContext);
108
- return process.exit(0);
109
- }
106
+ if (isNonEmptyString(hookResult.payload.additionalClaudeContext)) console.log(hookResult.payload.additionalClaudeContext);
107
+ return process.exit(0);
110
108
  }
111
109
  if (isNonEmptyString(hookResult.payload.messageForUser)) console.log(hookResult.payload.messageForUser);
112
110
  return process.exit(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-hooks-ts",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "description": "Write claude code hooks with type safety",
6
6
  "sideEffects": false,