From 161937e55826de9be526e02038fc5110a7d9e44b Mon Sep 17 00:00:00 2001 From: kz777 Date: Thu, 29 Jan 2026 11:34:45 +0800 Subject: [PATCH] create --- .claude-plugin/plugin.json | 9 +++++++++ config/hook.json | 28 ++++++++++++++++++++++++++++ hooks/notify.sh | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 config/hook.json create mode 100755 hooks/notify.sh diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..ef54b37 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,9 @@ +{ + "name": "msg-notify-plugin", + "description": "msg notify plugin", + "version": "1.0.0", + "author": { + "name": "kevinzhw" + }, + "hooks": "./config/hook.json" +} diff --git a/config/hook.json b/config/hook.json new file mode 100644 index 0000000..542f0d5 --- /dev/null +++ b/config/hook.json @@ -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 + } + ] + } + ] + } +} diff --git a/hooks/notify.sh b/hooks/notify.sh new file mode 100755 index 0000000..8c3b0ef --- /dev/null +++ b/hooks/notify.sh @@ -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