{ "hooks":{ "Stop":[ { "hooks":[ { "type":"prompt", "prompt":"You are evaluating whether Claude should stop working. Context: $ARGUMENTS\n\nCheck: 1) Are all user-requested tasks complete? 2) Are there any unresolved errors? 3) Is follow-up work needed?\n\nRespond with JSON: {\"ok\": true} to allow stopping, or {\"ok\": false, \"reason\": \"explanation\"} to continue.", "timeout":30 } ] } ] } }
6.5 异步运行测试套件
文件修改后,在后台异步运行测试,不阻塞 Claude 继续工作,测试完成后将结果反馈到下一次对话轮次。
在 .claude/hooks/run-tests-async.sh 中创建脚本:
#!/bin/bash INPUT=$(cat) FILE_PATH=$(echo"$INPUT"| jq -r'.tool_input.file_path // empty') # 仅对源文件运行测试 if[["$FILE_PATH"!= *.go ]];then exit0 fi RESULT=$(go test ./... 2>&1) EXIT_CODE=$? if[$EXIT_CODE-eq0];then echo"{\"systemMessage\": \"All tests passed after editing $FILE_PATH\"}" else echo"{\"systemMessage\": \"Tests FAILED after editing $FILE_PATH:\\n$RESULT\"}" fi
[DEBUG] Executing hooks for PostToolUse:Write [DEBUG] Found 1 hook matchers in settings [DEBUG] Matched 1 hooks for query "Write" [DEBUG] Executing hook command:.claude/hooks/lint-check.sh with timeout 600000ms [DEBUG] Hook command completed with status 0:<stdout output>