This commit is contained in:
kz777 2026-01-29 11:34:45 +08:00
commit 161937e558
3 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,9 @@
{
"name": "msg-notify-plugin",
"description": "msg notify plugin",
"version": "1.0.0",
"author": {
"name": "kevinzhw"
},
"hooks": "./config/hook.json"
}

28
config/hook.json Normal file
View File

@ -0,0 +1,28 @@
{
"hooks": {
"PreToolUse": [
{
"matcher": "Read|Write|Edit|Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/plugins/msg-notify-plugin/hooks/notify.sh",
"timeout": 300
}
]
}
],
"PostToolUse": [
{
"matcher": "Read|Write|Edit|Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/plugins/msg-notify-plugin/hooks/notify.sh",
"timeout": 300
}
]
}
]
}
}

36
hooks/notify.sh Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
json=$(cat)
hook_event_name=$(jq -r '.hook_event_name' <<< "$json")
tool_name=$(jq -r '.tool_name' <<< "$json")
session_id=$(jq -r '.session_id' <<< "$json")
file_path=$(jq -r '.tool_input.file_path' <<< "$json")
if [ "$hook_event_name" == "PreToolUse" ];then
if [ "$tool_name" == "Read" ]; then
notify-hook log "$(echo -e "session:$session_id, \n开始读取文件:$file_path")"
elif [ "$tool_name" == "Write" ]; then
notify-hook log "session:$session_id, 开始创建文件:$file_path"
elif [ "$tool_name" == "Edit" ]; then
notify-hook log "session:$session_id, 开始编辑文件:$file_path"
fi
elif [ "$hook_event_name" == "PostToolUse" ];then
if [ "$tool_name" == "Read" ]; then
notify-hook log "session:$session_id, 读取了文件:$file_path"
elif [ "$tool_name" == "Write" ]; then
notify-hook log "session:$session_id, 创建了文件:$file_path"
elif [ "$tool_name" == "Edit" ]; then
notify-hook log "session:$session_id, 编辑了文件:$file_path"
elif [ "$tool_name" == "Bash" ]; then
command_content=$(jq -r '.tool_input.command' <<< "$json")
std_err=$(jq -r '.tool_response.stderr' <<< "$json")
interrupted=$(jq -r '.tool_response.interruptedr' <<< "$json")
if [ "$interrupted" == "true" ]; then
notify-hook log "$(echo -e "session:$session_id, \n命令:$command_content. 执行终止!!!")"
elif [ "$std_err" == "" ]; then
notify-hook log "session:$session_id, 命令:$command_content. 执行成功."
else
notify-hook log "session:$session_id, 命令:$command_content. 执行失败:$std_err"
fi
fi
fi