@hasna/hooks 0.2.6 → 0.2.8

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.
Files changed (49) hide show
  1. package/bin/index.js +645 -43
  2. package/dist/index.js +89 -5
  3. package/hooks/hook-affected-tests/LICENSE +191 -0
  4. package/hooks/hook-affected-tests/README.md +37 -0
  5. package/hooks/hook-affected-tests/package.json +50 -0
  6. package/hooks/hook-affected-tests/src/hook.ts +148 -0
  7. package/hooks/hook-affected-tests/tsconfig.json +25 -0
  8. package/hooks/hook-agentmessages/bin/cli.ts +125 -0
  9. package/hooks/hook-announce-start/LICENSE +191 -0
  10. package/hooks/hook-announce-start/README.md +35 -0
  11. package/hooks/hook-announce-start/package.json +51 -0
  12. package/hooks/hook-announce-start/src/hook.ts +137 -0
  13. package/hooks/hook-announce-start/tsconfig.json +25 -0
  14. package/hooks/hook-announce-stop/LICENSE +191 -0
  15. package/hooks/hook-announce-stop/README.md +35 -0
  16. package/hooks/hook-announce-stop/package.json +51 -0
  17. package/hooks/hook-announce-stop/src/hook.ts +160 -0
  18. package/hooks/hook-announce-stop/tsconfig.json +25 -0
  19. package/hooks/hook-checkdocs/bun.lock +25 -0
  20. package/hooks/hook-commandlog/src/hook.ts +15 -38
  21. package/hooks/hook-conflict-detect/LICENSE +191 -0
  22. package/hooks/hook-conflict-detect/README.md +38 -0
  23. package/hooks/hook-conflict-detect/package.json +50 -0
  24. package/hooks/hook-conflict-detect/src/hook.ts +116 -0
  25. package/hooks/hook-conflict-detect/tsconfig.json +25 -0
  26. package/hooks/hook-costwatch/src/hook.ts +39 -42
  27. package/hooks/hook-dm-inject/LICENSE +191 -0
  28. package/hooks/hook-dm-inject/README.md +42 -0
  29. package/hooks/hook-dm-inject/package.json +51 -0
  30. package/hooks/hook-dm-inject/src/hook.ts +115 -0
  31. package/hooks/hook-dm-inject/tsconfig.json +25 -0
  32. package/hooks/hook-errornotify/src/hook.ts +20 -65
  33. package/hooks/hook-failure-to-task/LICENSE +191 -0
  34. package/hooks/hook-failure-to-task/README.md +40 -0
  35. package/hooks/hook-failure-to-task/package.json +51 -0
  36. package/hooks/hook-failure-to-task/src/hook.ts +171 -0
  37. package/hooks/hook-failure-to-task/tsconfig.json +25 -0
  38. package/hooks/hook-filelock/LICENSE +191 -0
  39. package/hooks/hook-filelock/README.md +44 -0
  40. package/hooks/hook-filelock/package.json +50 -0
  41. package/hooks/hook-filelock/src/hook.ts +147 -0
  42. package/hooks/hook-filelock/tsconfig.json +25 -0
  43. package/hooks/hook-sessionlog/src/hook.ts +11 -52
  44. package/hooks/hook-typecheck-gate/LICENSE +191 -0
  45. package/hooks/hook-typecheck-gate/README.md +46 -0
  46. package/hooks/hook-typecheck-gate/package.json +50 -0
  47. package/hooks/hook-typecheck-gate/src/hook.ts +152 -0
  48. package/hooks/hook-typecheck-gate/tsconfig.json +25 -0
  49. package/package.json +1 -1
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2025 Hasna
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -0,0 +1,42 @@
1
+ # hook-dm-inject
2
+
3
+ A Notification hook that injects unread direct messages into agent context. Keeps multi-agent teams in sync by surfacing DMs automatically.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ hooks install dm-inject
9
+ ```
10
+
11
+ ## How it works
12
+
13
+ On each `Notification` event:
14
+ 1. Runs `conversations read --unread --json` to fetch unread DMs
15
+ 2. If any exist, writes them to stderr (injected into Claude's context)
16
+ 3. Marks messages as read via `conversations mark-read`
17
+
18
+ ## Requirements
19
+
20
+ The `conversations` CLI must be installed and configured:
21
+
22
+ ```bash
23
+ bun install -g @hasna/open-conversations
24
+ conversations doctor
25
+ ```
26
+
27
+ ## Output format
28
+
29
+ Messages appear in Claude's context as:
30
+
31
+ ```
32
+ [hook-dm-inject] You have 2 unread DM(s):
33
+
34
+ 1. From agent-backend at 14:32:10: The API endpoint is ready, you can proceed.
35
+ 2. From hasna at 14:35:02: Please prioritize the auth module.
36
+
37
+ Please acknowledge these messages when appropriate.
38
+ ```
39
+
40
+ ## Event
41
+
42
+ - **Notification** (all notification types)
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@hasna/hook-dm-inject",
3
+ "version": "0.1.0",
4
+ "description": "Claude Code hook that injects unread DMs into agent context on Notification events",
5
+ "type": "module",
6
+ "main": "./dist/hook.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/hook.js",
10
+ "types": "./dist/hook.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "README.md"
16
+ ],
17
+ "scripts": {
18
+ "build": "bun build ./src/hook.ts --outdir ./dist --target node",
19
+ "prepublishOnly": "bun run build",
20
+ "typecheck": "tsc --noEmit"
21
+ },
22
+ "keywords": [
23
+ "claude-code",
24
+ "claude",
25
+ "hook",
26
+ "messages",
27
+ "dm",
28
+ "context",
29
+ "inject",
30
+ "agent-teams"
31
+ ],
32
+ "author": "Hasna",
33
+ "license": "Apache-2.0",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/hasna/hooks.git"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "registry": "https://registry.npmjs.org/"
41
+ },
42
+ "engines": {
43
+ "node": ">=18",
44
+ "bun": ">=1.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/bun": "^1.3.8",
48
+ "@types/node": "^20",
49
+ "typescript": "^5.0.0"
50
+ }
51
+ }
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env bun
2
+
3
+ /**
4
+ * Claude Code Hook: dm-inject
5
+ *
6
+ * Notification hook that injects unread DMs into agent context.
7
+ * On each Notification event, checks for unread messages via the `conversations`
8
+ * CLI and injects them as context so the agent can respond.
9
+ */
10
+
11
+ import { readFileSync } from "fs";
12
+ import { execSync } from "child_process";
13
+
14
+ interface HookInput {
15
+ session_id: string;
16
+ cwd: string;
17
+ hook_event_name: string;
18
+ notification_type?: string;
19
+ message?: string;
20
+ }
21
+
22
+ interface HookOutput {
23
+ continue: boolean;
24
+ suppressOutput?: boolean;
25
+ }
26
+
27
+ function readStdinJson(): HookInput | null {
28
+ try {
29
+ const input = readFileSync(0, "utf-8").trim();
30
+ if (!input) return null;
31
+ return JSON.parse(input);
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+
37
+ function respond(output: HookOutput): void {
38
+ console.log(JSON.stringify(output));
39
+ }
40
+
41
+ interface DmMessage {
42
+ id: string;
43
+ from: string;
44
+ content: string;
45
+ created_at: string;
46
+ }
47
+
48
+ function fetchUnreadDms(): DmMessage[] {
49
+ try {
50
+ const output = execSync("conversations read --unread --json", {
51
+ encoding: "utf-8",
52
+ timeout: 10_000,
53
+ stdio: ["pipe", "pipe", "pipe"],
54
+ });
55
+ const data = JSON.parse(output.trim());
56
+ if (Array.isArray(data)) return data as DmMessage[];
57
+ if (data.messages && Array.isArray(data.messages)) return data.messages as DmMessage[];
58
+ return [];
59
+ } catch {
60
+ return [];
61
+ }
62
+ }
63
+
64
+ function markRead(ids: string[]): void {
65
+ if (ids.length === 0) return;
66
+ try {
67
+ execSync(`conversations mark-read ${ids.join(" ")}`, {
68
+ encoding: "utf-8",
69
+ timeout: 5_000,
70
+ stdio: ["pipe", "pipe", "pipe"],
71
+ });
72
+ } catch {}
73
+ }
74
+
75
+ export function run(): void {
76
+ const input = readStdinJson();
77
+
78
+ if (!input) {
79
+ respond({ continue: true });
80
+ return;
81
+ }
82
+
83
+ const dms = fetchUnreadDms();
84
+
85
+ if (dms.length === 0) {
86
+ respond({ continue: true });
87
+ return;
88
+ }
89
+
90
+ // Format DMs for injection into context
91
+ const lines = [
92
+ `[hook-dm-inject] You have ${dms.length} unread DM(s):`,
93
+ "",
94
+ ...dms.map((dm, i) => {
95
+ const from = dm.from || "unknown";
96
+ const time = dm.created_at ? new Date(dm.created_at).toLocaleTimeString() : "";
97
+ return `${i + 1}. From ${from}${time ? ` at ${time}` : ""}: ${dm.content}`;
98
+ }),
99
+ "",
100
+ "Please acknowledge these messages when appropriate.",
101
+ ];
102
+
103
+ // Inject into stderr so it appears in Claude's context
104
+ process.stderr.write(lines.join("\n") + "\n");
105
+
106
+ // Mark messages as read
107
+ const ids = dms.map((m) => m.id).filter(Boolean);
108
+ markRead(ids);
109
+
110
+ respond({ continue: true });
111
+ }
112
+
113
+ if (import.meta.main) {
114
+ run();
115
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "lib": ["ESNext"],
6
+ "moduleResolution": "bundler",
7
+ "allowImportingTsExtensions": true,
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "declaration": true,
18
+ "declarationMap": true,
19
+ "outDir": "./dist",
20
+ "rootDir": "./src",
21
+ "types": ["bun-types"]
22
+ },
23
+ "include": ["src/**/*"],
24
+ "exclude": ["node_modules", "dist"]
25
+ }
@@ -3,16 +3,13 @@
3
3
  /**
4
4
  * Claude Code Hook: errornotify
5
5
  *
6
- * PostToolUse hook that detects tool failures and logs errors.
7
- * Checks tool output for error indicators (non-zero exit codes,
8
- * error messages) and logs warnings to stderr. Optionally writes
9
- * to a .claude/errors.log file for persistent error tracking.
10
- *
6
+ * PostToolUse hook that detects tool failures and logs errors to SQLite (~/.hooks/hooks.db).
7
+ * Also writes warnings to stderr for immediate terminal visibility.
11
8
  * Never blocks — always outputs { continue: true }.
12
9
  */
13
10
 
14
- import { readFileSync, appendFileSync, mkdirSync, existsSync } from "fs";
15
- import { join } from "path";
11
+ import { readFileSync } from "fs";
12
+ import { writeHookEvent } from "../../../src/lib/db-writer";
16
13
 
17
14
  interface HookInput {
18
15
  session_id: string;
@@ -26,9 +23,6 @@ interface HookOutput {
26
23
  continue: true;
27
24
  }
28
25
 
29
- /**
30
- * Read and parse JSON from stdin
31
- */
32
26
  function readStdinJson(): HookInput | null {
33
27
  try {
34
28
  const input = readFileSync(0, "utf-8").trim();
@@ -39,31 +33,19 @@ function readStdinJson(): HookInput | null {
39
33
  }
40
34
  }
41
35
 
42
- /**
43
- * Check if the tool output indicates a failure
44
- */
45
36
  function detectError(input: HookInput): { isError: boolean; message: string } {
46
37
  const output = input.tool_output || {};
47
38
 
48
- // Check for explicit exit code
49
39
  const exitCode = output.exit_code ?? output.exitCode ?? output.code;
50
40
  if (exitCode !== undefined && exitCode !== null && exitCode !== 0) {
51
41
  const stderr = (output.stderr as string) || (output.output as string) || "unknown error";
52
- return {
53
- isError: true,
54
- message: `Exit code ${exitCode}: ${truncate(stderr, 200)}`,
55
- };
42
+ return { isError: true, message: `Exit code ${exitCode}: ${truncate(stderr, 200)}` };
56
43
  }
57
44
 
58
- // Check for error field
59
45
  if (output.error && typeof output.error === "string") {
60
- return {
61
- isError: true,
62
- message: `Error: ${truncate(output.error, 200)}`,
63
- };
46
+ return { isError: true, message: `Error: ${truncate(output.error, 200)}` };
64
47
  }
65
48
 
66
- // Check output text for common error indicators
67
49
  const outputText =
68
50
  (output.stderr as string) ||
69
51
  (output.output as string) ||
@@ -72,7 +54,6 @@ function detectError(input: HookInput): { isError: boolean; message: string } {
72
54
  "";
73
55
 
74
56
  if (typeof outputText === "string" && outputText.length > 0) {
75
- // Check for common error patterns in output
76
57
  const errorPatterns = [
77
58
  /^error:/im,
78
59
  /^fatal:/im,
@@ -98,13 +79,9 @@ function detectError(input: HookInput): { isError: boolean; message: string } {
98
79
 
99
80
  for (const pattern of errorPatterns) {
100
81
  if (pattern.test(outputText)) {
101
- // Extract the first relevant line
102
82
  const lines = outputText.split("\n").filter((l: string) => l.trim());
103
83
  const errorLine = lines.find((l: string) => pattern.test(l)) || lines[0] || "";
104
- return {
105
- isError: true,
106
- message: truncate(errorLine.trim(), 200),
107
- };
84
+ return { isError: true, message: truncate(errorLine.trim(), 200) };
108
85
  }
109
86
  }
110
87
  }
@@ -112,17 +89,11 @@ function detectError(input: HookInput): { isError: boolean; message: string } {
112
89
  return { isError: false, message: "" };
113
90
  }
114
91
 
115
- /**
116
- * Truncate a string to a maximum length
117
- */
118
92
  function truncate(str: string, maxLen: number): string {
119
93
  if (str.length <= maxLen) return str;
120
94
  return str.slice(0, maxLen) + "...";
121
95
  }
122
96
 
123
- /**
124
- * Get a human-readable description of what was being executed
125
- */
126
97
  function getToolContext(input: HookInput): string {
127
98
  const toolName = input.tool_name;
128
99
  const toolInput = input.tool_input || {};
@@ -140,36 +111,11 @@ function getToolContext(input: HookInput): string {
140
111
  }
141
112
  }
142
113
 
143
- /**
144
- * Write error to .claude/errors.log
145
- */
146
- function writeErrorLog(cwd: string, toolContext: string, errorMessage: string, sessionId: string): void {
147
- try {
148
- const claudeDir = join(cwd, ".claude");
149
- if (!existsSync(claudeDir)) {
150
- mkdirSync(claudeDir, { recursive: true });
151
- }
152
-
153
- const logFile = join(claudeDir, "errors.log");
154
- const timestamp = new Date().toISOString();
155
- const entry = `[${timestamp}] [session:${sessionId.slice(0, 8)}] ${toolContext} — ${errorMessage}\n`;
156
- appendFileSync(logFile, entry);
157
- } catch {
158
- // Silently fail — logging should never cause issues
159
- }
160
- }
161
-
162
- /**
163
- * Output hook response
164
- */
165
114
  function respond(): void {
166
115
  const output: HookOutput = { continue: true };
167
116
  console.log(JSON.stringify(output));
168
117
  }
169
118
 
170
- /**
171
- * Main hook execution
172
- */
173
119
  export function run(): void {
174
120
  const input = readStdinJson();
175
121
 
@@ -182,11 +128,20 @@ export function run(): void {
182
128
 
183
129
  if (isError) {
184
130
  const toolContext = getToolContext(input);
185
- console.error(`[hook-errornotify] FAILURE in ${toolContext}`);
186
- console.error(`[hook-errornotify] ${message}`);
187
131
 
188
- // Write to persistent error log
189
- writeErrorLog(input.cwd, toolContext, message, input.session_id);
132
+ // Keep stderr warnings for immediate terminal visibility
133
+ process.stderr.write(`[hook-errornotify] FAILURE in ${toolContext}\n`);
134
+ process.stderr.write(`[hook-errornotify] ${message}\n`);
135
+
136
+ writeHookEvent({
137
+ session_id: input.session_id,
138
+ hook_name: "errornotify",
139
+ event_type: "PostToolUse",
140
+ tool_name: input.tool_name,
141
+ tool_input: JSON.stringify(input.tool_input),
142
+ error: message,
143
+ project_dir: input.cwd,
144
+ });
190
145
  }
191
146
 
192
147
  respond();