Skip to content

Commit 06a7210

Browse files
fix: get hook_type from process.argv[2] instead of payload (#10)
The hook_type is now properly retrieved from command line arguments (process.argv[2]) and added to the payload, allowing Claude to pass the hook type via CLI rather than requiring it in the JSON payload. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 73ec81d commit 06a7210

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

templates/hooks/lib.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,17 @@ export function log(...args: any[]): void {
101101

102102
// Main hook runner
103103
export function runHook(handlers: HookHandlers): void {
104+
const hook_type = process.argv[2]
105+
104106
process.stdin.on('data', async (data) => {
105107
try {
106-
const payload: HookPayload = JSON.parse(data.toString())
108+
const inputData = JSON.parse(data.toString())
109+
const payload: HookPayload = {
110+
...inputData,
111+
hook_type: hook_type as any
112+
}
107113

108-
switch (payload.hook_type) {
114+
switch (hook_type) {
109115
case 'PreToolUse':
110116
if (handlers.preToolUse) {
111117
const response = await handlers.preToolUse(payload)

0 commit comments

Comments
 (0)