{"id":6426,"date":"2026-05-16T14:13:30","date_gmt":"2026-05-16T06:13:30","guid":{"rendered":"https:\/\/blog.coolcoding.cn\/?p=6426"},"modified":"2026-05-16T14:17:29","modified_gmt":"2026-05-16T06:17:29","slug":"%e6%89%93%e9%80%a0%e5%8f%af%e9%9d%a0%e7%9a%84-ai-%e7%bc%96%e7%a8%8b%e7%8e%af%e5%a2%83%ef%bc%9aclaude-code-hooks-%e5%ae%8c%e6%95%b4%e5%bc%80%e5%8f%91%e8%80%85%e6%8c%87%e5%8d%97-%e8%bd%ac","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=6426","title":{"rendered":"\u6253\u9020\u53ef\u9760\u7684 AI \u7f16\u7a0b\u73af\u5883\uff1aClaude Code Hooks \u5b8c\u6574\u5f00\u53d1\u8005\u6307\u5357 [\u8f6c]"},"content":{"rendered":"\n<p>LINK:https:\/\/zhuanlan.zhihu.com\/p\/2028796296723447848<\/p>\n\n\n\n<p><a href=\"https:\/\/zhida.zhihu.com\/search?content_id=273333664&amp;content_type=Article&amp;match_order=1&amp;q=Claude+Code&amp;zd_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6aGlkYV9zZXJ2ZXIiLCJleHAiOjE3NzkwODQ0NzksInEiOiJDbGF1ZGUgQ29kZSIsInpoaWRhX3NvdXJjZSI6ImVudGl0eSIsImNvbnRlbnRfaWQiOjI3MzMzMzY2NCwiY29udGVudF90eXBlIjoiQXJ0aWNsZSIsIm1hdGNoX29yZGVyIjoxLCJ6ZF90b2tlbiI6bnVsbH0.l6g05PIzO4We6rKsvExWsekqOshY7LkdTRrWCCmaylc&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">Claude Code<\/a>&nbsp;\u64c5\u957f\u5199\u4ee3\u7801\uff0c\u4f46\u5b83\u672c\u8d28\u4e0a\u4ecd\u7136\u662f\u4e00\u4e2a\u6982\u7387\u7cfb\u7edf\u3002\u4f60\u53ef\u4ee5\u8981\u6c42\u5b83\u5728\u6bcf\u6b21\u7f16\u8f91\u6587\u4ef6\u540e\u8fd0\u884c&nbsp;<a href=\"https:\/\/zhida.zhihu.com\/search?content_id=273333664&amp;content_type=Article&amp;match_order=1&amp;q=Prettier&amp;zd_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6aGlkYV9zZXJ2ZXIiLCJleHAiOjE3NzkwODQ0NzksInEiOiJQcmV0dGllciIsInpoaWRhX3NvdXJjZSI6ImVudGl0eSIsImNvbnRlbnRfaWQiOjI3MzMzMzY2NCwiY29udGVudF90eXBlIjoiQXJ0aWNsZSIsIm1hdGNoX29yZGVyIjoxLCJ6ZF90b2tlbiI6bnVsbH0.ja1oZ0yWQaeUTQB5gWyYsV5UkfzplUYdduWdOZVR0UI&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">Prettier<\/a>\u3002\u4f60\u53ef\u4ee5\u628a\u8fd9\u4e2a\u6307\u4ee4\u5199\u8fdb&nbsp;<code>CLAUDE.md<\/code>\u3002\u4f46\u6709\u4e9b\u65f6\u5019\uff0c\u5b83\u5c31\u662f\u4f1a\u2026\u2026\u5fd8\u8bb0\u3002<\/p>\n\n\n\n<p><strong><a href=\"https:\/\/zhida.zhihu.com\/search?content_id=273333664&amp;content_type=Article&amp;match_order=1&amp;q=Claude+Code+hooks&amp;zd_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6aGlkYV9zZXJ2ZXIiLCJleHAiOjE3NzkwODQ0NzksInEiOiJDbGF1ZGUgQ29kZSBob29rcyIsInpoaWRhX3NvdXJjZSI6ImVudGl0eSIsImNvbnRlbnRfaWQiOjI3MzMzMzY2NCwiY29udGVudF90eXBlIjoiQXJ0aWNsZSIsIm1hdGNoX29yZGVyIjoxLCJ6ZF90b2tlbiI6bnVsbH0.hcQWwq7opOE8mHlmDbDbOyMssMm53Df_gqr0_2jpsEg&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">Claude Code hooks<\/a><\/strong>&nbsp;\u89e3\u51b3\u7684\u6b63\u662f\u8fd9\u4e2a\u95ee\u9898\uff1a\u5728\u6bcf\u6b21\u64cd\u4f5c\u524d\u3001\u8fc7\u7a0b\u4e2d\u548c\u4e4b\u540e\u63d0\u4f9b\u786e\u5b9a\u6027\u7684\u63a7\u5236\uff0c\u8ba9\u8fd9\u4e9b\u89c4\u5219\u53d8\u6210\u771f\u6b63\u4f1a\u88ab\u6267\u884c\u7684\u6d41\u7a0b\u3002<\/p>\n\n\n\n<p>\u8fc7\u53bb\u51e0\u4e2a\u6708\u91cc\uff0c\u6211\u5728\u591a\u4e2a\u9879\u76ee\u4e2d\u4f7f\u7528\u4e86 hooks\uff0c\u5b83\u5df2\u7ecf\u6210\u4e3a\u6574\u4e2a Claude Code \u5de5\u4f5c\u6d41\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u672c\u6587\u4f1a\u4ece\u57fa\u7840\u8bb2\u8d77\uff0c\u5e26\u4f60\u642d\u5efa\u4e00\u5957\u53ef\u4ee5\u76f4\u63a5\u843d\u5730\u4f7f\u7528\u7684\u914d\u7f6e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Claude Code Hooks \u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n\n\n\n<p>Claude Code hooks \u672c\u8d28\u4e0a\u5c31\u662f\u4e00\u4e9b\u4f60\u81ea\u5df1\u5b9a\u4e49\u7684\u64cd\u4f5c\uff0c\u6bd4\u5982 shell \u547d\u4ee4\u3001HTTP \u8c03\u7528\uff0c\u6216\u8005\u989d\u5916\u7684\u63d0\u793a\uff0c\u5b83\u4eec\u4f1a\u5728 Claude Code \u7684\u4e0d\u540c\u9636\u6bb5\u81ea\u52a8\u6267\u884c\u3002<\/p>\n\n\n\n<p>\u548c\u5199\u5728\u63d0\u793a\u8bcd\u91cc\u7684\u7ea6\u5b9a\u4e0d\u4e00\u6837\uff0chooks \u662f<strong>\u4e00\u5b9a\u4f1a\u89e6\u53d1\u7684<\/strong>\uff0c\u4e0d\u4f1a\u88ab\u300c\u5fd8\u6389\u300d\u3002\u8fd9\u4e5f\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u66f4\u7a33\u5b9a\u5730\u63a7\u5236\u4e00\u4e9b\u4e8b\u60c5\uff0c\u6bd4\u5982\u4ee3\u7801\u683c\u5f0f\u5316\u3001\u5b89\u5168\u68c0\u67e5\u3001\u901a\u77e5\uff0c\u6216\u8005\u6574\u4e2a\u5f00\u53d1\u6d41\u7a0b\u91cc\u7684\u81ea\u52a8\u5316\u6b65\u9aa4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6982\u7387\u6027\u95ee\u9898<\/strong><\/h3>\n\n\n\n<p>\u5173\u952e\u70b9\u5728\u8fd9\u91cc\uff1a<strong>CLAUDE.md \u91cc\u7684\u89c4\u5219\u66f4\u50cf\u662f\u5efa\u8bae\uff0c\u800c\u4e0d\u662f\u5f3a\u5236\u6267\u884c\u7684\u7ea6\u675f<\/strong>\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u5199\u4e0b<code>\u201c\u7f16\u8f91 TypeScript \u6587\u4ef6\u540e\u603b\u662f\u8fd0\u884c npx prettier --write\u201d<\/code>\uff0c\u5927\u591a\u6570\u65f6\u5019 Claude \u4f1a\u7167\u505a\u3002\u4f46\u95ee\u9898\u5c31\u5728\u4e8e\u2014\u2014\u300c\u5927\u591a\u6570\u65f6\u5019\u300d\u662f\u4e0d\u591f\u7684\u3002\u5f53\u4f60\u9700\u8981\u7edf\u4e00\u4ee3\u7801\u683c\u5f0f\u3001\u963b\u6b62\u4ee3\u7801\u8fdb\u5165\u751f\u4ea7\uff0c\u6216\u8005\u8bb0\u5f55\u5173\u952e\u64cd\u4f5c\u65f6\uff0c\u8fd9\u79cd\u4e0d\u786e\u5b9a\u6027\u5c31\u4f1a\u53d8\u6210\u9690\u60a3\u3002<\/p>\n\n\n\n<p>\u8fd9\u5176\u5b9e\u662f\u6240\u6709 AI \u7f16\u7801\u5de5\u5177\u90fd\u4f1a\u9047\u5230\u7684\u95ee\u9898\uff1aClaude \u672c\u8d28\u4e0a\u662f\u8bed\u8a00\u6a21\u578b\uff0c\u662f\u57fa\u4e8e\u6982\u7387\u5de5\u4f5c\u7684\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4e0a\u4e0b\u6587\u53bb\u5f15\u5bfc\u5b83\uff0c\u4f46\u6ca1\u529e\u6cd5\u4fdd\u8bc1\u5b83\u6bcf\u6b21\u90fd\u6309\u89c4\u5219\u6267\u884c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Hooks \u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898<\/strong><\/h3>\n\n\n\n<p>Hooks \u7684\u601d\u8def\u5f88\u76f4\u63a5\uff1a\u4e0d\u518d\u4f9d\u8d56 LLM \u7684\u300c\u8bb0\u4e0d\u8bb0\u5f97\u300d\uff0c\u800c\u662f\u76f4\u63a5\u5728\u5173\u952e\u8282\u70b9\u63d2\u5165\u786e\u5b9a\u6027\u7684\u6267\u884c\u903b\u8f91\u3002<\/p>\n\n\n\n<p>\u5b83\u4eec\u4f1a\u5728\u7279\u5b9a\u7684\u751f\u547d\u5468\u671f\u9636\u6bb5\u89e6\u53d1\uff0c\u6bd4\u5982\u5de5\u5177\u8fd0\u884c\u524d\uff08<code>PreToolUse<\/code>\uff09\u3001\u8fd0\u884c\u540e\uff08<code>PostToolUse<\/code>\uff09\u3001\u6536\u5230\u901a\u77e5\u65f6\u3001\u4f1a\u8bdd\u5f00\u59cb\uff0c\u6216\u8005 Claude \u505c\u6b62\u65f6\u3002\u53ef\u4ee5\u628a\u5b83\u7406\u89e3\u6210\u7ed9 AI \u7f16\u7801\u6d41\u7a0b\u52a0\u4e86\u4e00\u5c42\u300c\u81ea\u52a8\u6267\u884c\u7684\u94a9\u5b50\u300d\uff0c\u6709\u70b9\u7c7b\u4f3c&nbsp;<a href=\"https:\/\/zhida.zhihu.com\/search?content_id=273333664&amp;content_type=Article&amp;match_order=1&amp;q=Git+hooks&amp;zd_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6aGlkYV9zZXJ2ZXIiLCJleHAiOjE3NzkwODQ0NzksInEiOiJHaXQgaG9va3MiLCJ6aGlkYV9zb3VyY2UiOiJlbnRpdHkiLCJjb250ZW50X2lkIjoyNzMzMzM2NjQsImNvbnRlbnRfdHlwZSI6IkFydGljbGUiLCJtYXRjaF9vcmRlciI6MSwiemRfdG9rZW4iOm51bGx9.nI5jP4OTaIdWK9ctrS8VzZoXPpy-9XSfCEPEcHkuGP4&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">Git hooks<\/a>\uff0c\u53ea\u4e0d\u8fc7\u4f5c\u7528\u5bf9\u8c61\u6362\u6210\u4e86 Claude\u3002<\/p>\n\n\n\n<p>\u76ee\u524d\u4e3b\u8981\u6709\u56db\u79cd\u7c7b\u578b\uff1a<\/p>\n\n\n\n<ul>\n<li><strong>command<\/strong>\uff1a\u6267\u884c shell \u811a\u672c<\/li>\n\n\n\n<li><strong>HTTP<\/strong>\uff1a\u53d1\u9001 webhook \u8bf7\u6c42<\/li>\n\n\n\n<li><strong>prompt<\/strong>\uff1a\u505a\u4e00\u6b21\u7b80\u5355\u7684 LLM \u5224\u65ad\uff08\u6bd4\u5982\u662f\/\u5426\uff09<\/li>\n\n\n\n<li><strong>agent<\/strong>\uff1a\u542f\u52a8\u4e00\u4e2a\u5e26\u5de5\u5177\u80fd\u529b\u7684\u5b50 agent<\/li>\n<\/ul>\n\n\n\n<p>\u5b9e\u9645\u7528\u4e0b\u6765\uff0c\u5927\u90e8\u5206\u573a\u666f\u7528 command \u5c31\u591f\u4e86\uff0c\u80fd\u8986\u76d6 90% \u7684\u9700\u6c42\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Hooks \u5de5\u4f5c\u539f\u7406\uff1a\u4e8b\u4ef6\u9a71\u52a8\u7684\u56db\u6b65\u6d41\u7a0b<\/strong><\/h3>\n\n\n\n<p>Claude Code hooks \u7684\u6267\u884c\u6d41\u7a0b\u5176\u5b9e\u5f88\u7b80\u5355\uff1a\u5f53\u67d0\u4e2a\u4e8b\u4ef6\u89e6\u53d1\uff08\u6bd4\u5982&nbsp;<code>PreToolUse(Write)<\/code>\uff09\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5148\u68c0\u67e5\u5339\u914d\u89c4\u5219\uff0c\u770b\u6709\u6ca1\u6709\u5bf9\u5e94\u7684 hook \u9700\u8981\u6267\u884c\u3002\u5982\u679c\u5339\u914d\u4e0a\uff0c\u5c31\u8fd0\u884c\u4f60\u7684 hook \u811a\u672c\uff0c\u5e76\u901a\u8fc7 stdin \u4f20\u5165\u4e00\u6bb5 JSON \u6570\u636e\u3002<\/p>\n\n\n\n<p>\u811a\u672c\u6267\u884c\u5b8c\u4e4b\u540e\uff0c\u4f1a\u6839\u636e\u9000\u51fa\u7801\u51b3\u5b9a\u4e0b\u4e00\u6b65\uff1a<\/p>\n\n\n\n<ul>\n<li>\u8fd4\u56de&nbsp;<code>0<\/code>\uff1a\u7ee7\u7eed\u6267\u884c\u539f\u64cd\u4f5c<\/li>\n\n\n\n<li>\u8fd4\u56de&nbsp;<code>2<\/code>\uff1a\u76f4\u63a5\u963b\u6b62\u8fd9\u6b21\u64cd\u4f5c<\/li>\n<\/ul>\n\n\n\n<p>\u4e0d\u7ba1\u4f60\u7528\u7684\u662f\u54ea\u79cd\u7c7b\u578b\u7684 hook\uff0c\u8fd9\u5957\u6d41\u7a0b\u90fd\u662f\u4e00\u6837\u7684\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u4e8b\u4ef6 \u2192 \u5339\u914d\u5668 \u2192 Hook \u2192 \u9000\u51fa\u7801\uff084\u6b65\u6d41\u7a0b\uff09<\/strong><\/h3>\n\n\n\n<p>\u6bcf\u4e2a hook \u7684\u6267\u884c\u6d41\u7a0b\u5176\u5b9e\u5c31\u662f\u8fd9\u56db\u6b65\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1. \u4e8b\u4ef6\u89e6\u53d1          \u4f8b\u5982 PreToolUse(Write)\n       |\n2. \u5339\u914d\u5668\u68c0\u67e5        \u770b \"Write\" \u662f\u5426\u547d\u4e2d hook \u7684\u5339\u914d\u89c4\u5219\n       |\n3. Hook \u6267\u884c         \u8fd0\u884c\u811a\u672c\uff0c\u901a\u8fc7 stdin \u6536\u5230 JSON\n       |\n4. \u9000\u51fa\u7801\u51b3\u5b9a        0 = \u653e\u884c | 2 = \u62e6\u622a | \u5176\u4ed6 = \u62a5\u9519<\/code><\/pre>\n\n\n\n<p>\u4f20\u7ed9\u811a\u672c\u7684 JSON \u91cc\uff0c\u4f1a\u5305\u542b\u8fd9\u6b21\u64cd\u4f5c\u7684\u5b8c\u6574\u4fe1\u606f\uff0c\u6bd4\u5982&nbsp;<code>tool_name<\/code>\u3001<code>tool_input<\/code>\uff08\u6587\u4ef6\u8def\u5f84\u3001\u5185\u5bb9\u3001\u547d\u4ee4\uff09\u4ee5\u53ca\u4e00\u4e9b\u4f1a\u8bdd\u4e0a\u4e0b\u6587\u3002\u4f60\u53ea\u9700\u8981\u8bfb\u8fd9\u4e2a JSON\uff0c\u7136\u540e\u6309\u81ea\u5df1\u7684\u89c4\u5219\u5904\u7406\uff0c\u6700\u540e\u8fd4\u56de\u4e00\u4e2a\u9000\u51fa\u7801\u3002<\/p>\n\n\n\n<p>\u5728&nbsp;<code>PreToolUse<\/code>&nbsp;\u8fd9\u79cd\u573a\u666f\u91cc\uff0c\u9000\u51fa\u7801&nbsp;<code>2<\/code>&nbsp;\u7279\u522b\u6709\u7528\uff1a\u5b83\u53ef\u4ee5\u76f4\u63a5\u62e6\u4e0b\u8fd9\u6b21\u64cd\u4f5c\uff0c\u5e76\u628a\u4f60\u8f93\u51fa\u7684\u5185\u5bb9\u4f5c\u4e3a\u53cd\u9988\u8fd4\u56de\u7ed9 Claude\u3002Claude \u4f1a\u6839\u636e\u8fd9\u6bb5\u53cd\u9988\u8c03\u6574\u63a5\u4e0b\u6765\u7684\u884c\u4e3a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u914d\u7f6e\u4f5c\u7528\u57df\uff1a\u7528\u6237\u3001\u9879\u76ee\u548c\u672c\u5730<\/strong><\/h3>\n\n\n\n<p>Hooks \u53ef\u4ee5\u653e\u5728\u4e09\u4e2a\u5c42\u7ea7\u7684&nbsp;<code><a href=\"https:\/\/zhida.zhihu.com\/search?content_id=273333664&amp;content_type=Article&amp;match_order=1&amp;q=settings.json&amp;zd_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6aGlkYV9zZXJ2ZXIiLCJleHAiOjE3NzkwODQ0NzksInEiOiJzZXR0aW5ncy5qc29uIiwiemhpZGFfc291cmNlIjoiZW50aXR5IiwiY29udGVudF9pZCI6MjczMzMzNjY0LCJjb250ZW50X3R5cGUiOiJBcnRpY2xlIiwibWF0Y2hfb3JkZXIiOjEsInpkX3Rva2VuIjpudWxsfQ.Udb3BFTw1UQ4sDAtE5q05kEwF07yjPLpsbskLcQhwhw&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">settings.json<\/a><\/code>&nbsp;\u4e2d\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u4f5c\u7528\u57df<\/th><th>\u6587\u4ef6<\/th><th>\u63d0\u4ea4\u5230 Git\uff1f<\/th><th>\u7528\u4f8b<\/th><\/tr><tr><td>User<\/td><td>~\/.claude\/settings.json<\/td><td>\u5426<\/td><td>\u4e2a\u4eba\u9ed8\u8ba4\u914d\u7f6e\uff08\u901a\u77e5\u3001\u683c\u5f0f\u5316\u504f\u597d\uff09<\/td><\/tr><tr><td>Project<\/td><td>.claude\/settings.json<\/td><td>\u662f<\/td><td>\u56e2\u961f\u5171\u4eab\u89c4\u5219\uff08\u6587\u4ef6\u4fdd\u62a4\u3001\u6d4b\u8bd5\u3001lint\uff09<\/td><\/tr><tr><td>Local<\/td><td>.claude\/settings.local.json<\/td><td>\u5426\uff08gitignore\uff09<\/td><td>\u5f53\u524d\u9879\u76ee\u7684\u4e2a\u4eba\u8986\u76d6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5b9e\u9645\u7528\u4e0b\u6765\uff0c<strong>\u6700\u6709\u4ef7\u503c\u7684\u662f Project \u8fd9\u4e00\u5c42<\/strong>\u3002\u628a hooks \u5199\u8fdb&nbsp;<code>.claude\/settings.json<\/code>&nbsp;\u5e76\u63d0\u4ea4\u5230\u4ed3\u5e93\u540e\uff0c\u56e2\u961f\u91cc\u7684\u6bcf\u4e2a\u4eba\u90fd\u4f1a\u81ea\u52a8\u7528\u4e0a\u540c\u4e00\u5957\u89c4\u5219\uff0c\u4e0d\u9700\u8981\u518d\u624b\u52a8\u914d\u7f6e\u4e00\u904d\uff0c\u4e5f\u66f4\u4e0d\u5bb9\u6613\u51fa\u73b0\u73af\u5883\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u9664\u4e86\u5728&nbsp;<code>settings.json<\/code>&nbsp;\u6216\u63d2\u4ef6\u4e2d\u914d\u7f6e\uff0chooks \u4e5f\u53ef\u4ee5\u76f4\u63a5\u5b9a\u4e49\u5728&nbsp;<strong>skills<\/strong>&nbsp;\u548c&nbsp;<strong>subagents<\/strong>&nbsp;\u91cc\uff0c\u901a\u8fc7 frontmatter \u58f0\u660e\u3002\u8fd9\u7c7b hooks \u4f5c\u7528\u57df\u4ec5\u9650\u7ec4\u4ef6\u751f\u547d\u5468\u671f\uff0c\u5e76\u5728\u6267\u884c\u7ed3\u675f\u540e\u81ea\u52a8\u6e05\u7406\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u5728 subagent \u4e2d\u5b9a\u4e49\u7684&nbsp;<code>Stop<\/code>&nbsp;hook\uff0c\u4f1a\u81ea\u52a8\u8f6c\u6362\u4e3a&nbsp;<code>SubagentStop<\/code>\uff0c\u56e0\u4e3a\u5b50 agent \u7ed3\u675f\u65f6\u89e6\u53d1\u7684\u5c31\u662f\u8fd9\u4e2a\u4e8b\u4ef6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><code>if<\/code>&nbsp;\u5b57\u6bb5\uff1a\u66f4\u7ec6\u7c92\u5ea6\u7684\u8fc7\u6ee4<\/strong><\/h3>\n\n\n\n<p>\u4ece Claude Code v2.1.85 \u5f00\u59cb\uff0chooks \u652f\u6301&nbsp;<code>if<\/code>&nbsp;\u5b57\u6bb5\uff0c\u53ef\u4ee5\u6309\u53c2\u6570\u8fc7\u6ee4\uff0c\u800c\u4e0d\u53ea\u662f\u770b\u5de5\u5177\u540d\u79f0\u3002\u6bd4\u5982\u4ee5\u524d\u4f60\u53ea\u80fd\u5339\u914d&nbsp;<code>Bash<\/code>\uff0c\u90a3\u6240\u6709 Bash \u547d\u4ee4\u90fd\u4f1a\u89e6\u53d1\uff1b\u73b0\u5728\u53ef\u4ee5\u53ea\u9488\u5bf9\u50cf&nbsp;<code>git push<\/code>&nbsp;\u8fd9\u6837\u7684\u7279\u5b9a\u547d\u4ee4\u751f\u6548\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"matcher\": \"Bash\",\n  \"if\": \"tool_input.command matches 'git push'\",\n  \"hooks\": &#91;{ \"type\": \"command\", \"command\": \".\/scripts\/check-branch.sh\" }]\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u6539\u52a8\u5176\u5b9e\u5f88\u5173\u952e\u3002\u4ee5\u524d\u8981\u4e48\u5339\u914d\u592a\u5bbd\uff08\u6240\u6709 Bash \u90fd\u89e6\u53d1\uff09\uff0c\u8981\u4e48\u53ea\u80fd\u628a\u5224\u65ad\u903b\u8f91\u5199\u5728\u811a\u672c\u91cc\uff0c\u914d\u7f6e\u548c\u5b9e\u73b0\u6df7\u5728\u4e00\u8d77\uff0c\u5bb9\u6613\u53d8\u4e71\u3002\u73b0\u5728\u53ef\u4ee5\u76f4\u63a5\u5728\u914d\u7f6e\u5c42\u628a\u8303\u56f4\u6536\u7d27\uff0c\u903b\u8f91\u66f4\u6e05\u6670\uff0c\u4e5f\u66f4\u597d\u7ef4\u62a4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>JSON \u8f93\u51fa\uff1a\u66f4\u7cbe\u7ec6\u7684\u63a7\u5236<\/strong><\/h3>\n\n\n\n<p>\u9664\u4e86\u9000\u51fa\u7801\uff0chooks \u8fd8\u53ef\u4ee5\u8fd4\u56de\u7ed3\u6784\u5316 JSON\uff0c\u7528\u6765\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u884c\u4e3a\u3002<\/p>\n\n\n\n<p><strong>PreToolUse\uff1a\u6267\u884c\u524d\u63a7\u5236<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hookSpecificOutput\": {\n    \"hookEventName\": \"PreToolUse\",\n    \"permissionDecision\": \"allow\",\n    \"permissionDecisionReason\": \"\u5b89\u5168\u8bfb\u53d6\u64cd\u4f5c\",\n    \"updatedInput\": { \"command\": \"modified-command\" },\n    \"additionalContext\": \"Context for Claude\"\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5e38\u89c1\u5b57\u6bb5\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul>\n<li><code>allow<\/code>\uff1a\u76f4\u63a5\u653e\u884c\uff08\u8df3\u8fc7\u6743\u9650\u68c0\u67e5\uff09<\/li>\n\n\n\n<li><code>deny<\/code>\uff1a\u963b\u6b62\u6267\u884c\uff0c\u5e76\u8bf4\u660e\u539f\u56e0<\/li>\n\n\n\n<li><code>ask<\/code>\uff1a\u8ba9\u7528\u6237\u786e\u8ba4<\/li>\n\n\n\n<li><code>updatedInput<\/code>\uff1a\u5728\u6267\u884c\u524d\u4fee\u6539\u53c2\u6570\uff08\u6bd4\u5982\u6539\u547d\u4ee4\uff09<\/li>\n\n\n\n<li><code>additionalContext<\/code>\uff1a\u7ed9 Claude \u8865\u5145\u4fe1\u606f<\/li>\n<\/ul>\n\n\n\n<p><strong>PermissionRequest\uff1a\u6743\u9650\u9636\u6bb5\u63a7\u5236<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hookSpecificOutput\": {\n    \"hookEventName\": \"PermissionRequest\",\n    \"decision\": {\n      \"behavior\": \"allow\",\n      \"updatedInput\": { \"command\": \"npm run lint\" }\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p><strong>Stop \/ SubagentStop\uff1a\u7ed3\u679c\u9636\u6bb5\u7ea6\u675f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"decision\": \"block\",\n  \"reason\": \"\u6d4b\u8bd5\u5931\u8d25\u3002\u8bf7\u5728\u5b8c\u6210\u6d4b\u8bd5\u524d\u4fee\u590d\u5b83\u4eec\"\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Hooks \u4e8b\u4ef6\u7c7b\u578b\uff1a\u5feb\u901f\u53c2\u8003\u8868<\/strong><\/h3>\n\n\n\n<p>Claude Code \u5728\u6574\u4e2a\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u63d0\u4f9b\u4e86 20 \u591a\u79cd hook \u4e8b\u4ef6\uff08\u53ef\u4ee5\u5728\u5b98\u65b9\u6587\u6863\u548c changelog \u91cc\u67e5\u5230\u5b8c\u6574\u5217\u8868\uff09\u3002\u4f46\u5b9e\u9645\u7528\u4e0b\u6765\uff0c\u6700\u5e38\u7528\u7684\u8fd8\u662f\u8fd9\u51e0\u4e2a\uff1a<code>PreToolUse<\/code>\u3001<code>PostToolUse<\/code>\u3001<code>Notification<\/code>&nbsp;\u548c&nbsp;<code>Stop<\/code>\u3002<br>\u50cf&nbsp;<code>ConfigChange<\/code>\u3001<code>FileChanged<\/code>&nbsp;\u8fd9\u4e9b\u65b0\u4e00\u70b9\u7684\u4e8b\u4ef6\uff0c\u66f4\u9002\u5408\u505a\u4e00\u4e9b\u9ad8\u7ea7\u81ea\u52a8\u5316\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5e38\u7528\u4e8b\u4ef6\u7684\u901f\u67e5\u8868\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u4e8b\u4ef6<\/th><th>\u4f55\u65f6\u89e6\u53d1<\/th><th>\u53ef\u963b\u6b62\uff1f<\/th><th>\u5e38\u89c1\u7528\u4f8b<\/th><\/tr><tr><td>SessionStart<\/td><td>\u4f1a\u8bdd\u5f00\u59cb\u65f6<\/td><td>\u5426<\/td><td>\u6ce8\u5165\u4e0a\u4e0b\u6587\u3001\u521d\u59cb\u5316\u73af\u5883<\/td><\/tr><tr><td>UserPromptSubmit<\/td><td>\u7528\u6237\u63d0\u4ea4\u63d0\u793a\u65f6<\/td><td>\u662f<\/td><td>\u8f93\u5165\u6821\u9a8c\u3001\u5185\u5bb9\u8fc7\u6ee4<\/td><\/tr><tr><td>PreToolUse<\/td><td>\u5de5\u5177\u6267\u884c\u4e4b\u524d<\/td><td>\u662f<\/td><td>\u963b\u6b62\u5371\u9669\u547d\u4ee4\u3001\u4fdd\u62a4\u5173\u952e\u6587\u4ef6<\/td><\/tr><tr><td>PermissionRequest<\/td><td>\u6743\u9650\u8bf7\u6c42\u5f39\u51fa\u65f6<\/td><td>\u662f<\/td><td>\u81ea\u52a8\u6279\u51c6\u6216\u62d2\u7edd<\/td><\/tr><tr><td>PermissionDenied<\/td><td>\u6743\u9650\u5931\u8d25\u65f6<\/td><td>\u5426<\/td><td>\u8bb0\u5f55\u5ba1\u8ba1\u3001\u544a\u8b66<\/td><\/tr><tr><td>PostToolUse<\/td><td>\u5de5\u5177\u5b8c\u6210\u4e4b\u540e<\/td><td>\u5426<\/td><td>\u81ea\u52a8\u683c\u5f0f\u5316\u3001\u8fd0\u884c\u6d4b\u8bd5\u3001\u8bb0\u5f55\u64cd\u4f5c<\/td><\/tr><tr><td>PostToolUseFailure<\/td><td>\u5de5\u5177\u6267\u884c\u5931\u8d25\u540e<\/td><td>\u5426<\/td><td>\u9519\u8bef\u5904\u7406\u3001\u8865\u507f\u903b\u8f91<\/td><\/tr><tr><td>Notification<\/td><td>Claude \u53d1\u9001\u901a\u77e5\u65f6<\/td><td>\u5426<\/td><td>\u684c\u9762\u901a\u77e5\u3001Slack \u63a8\u9001<\/td><\/tr><tr><td>SubagentStart<\/td><td>\u5b50 agent \u542f\u52a8\u65f6<\/td><td>\u5426<\/td><td>\u76d1\u63a7\u6267\u884c\u8fc7\u7a0b<\/td><\/tr><tr><td>SubagentStop<\/td><td>\u5b50 agent \u7ed3\u675f\u65f6<\/td><td>\u662f<\/td><td>\u6821\u9a8c\u8f93\u51fa\u7ed3\u679c<\/td><\/tr><tr><td>TaskCreated<\/td><td>\u65b0\u4efb\u52a1\u521b\u5efa\u65f6<\/td><td>\u662f<\/td><td>\u505a\u4efb\u52a1\u8ddf\u8e2a<\/td><\/tr><tr><td>TaskCompleted<\/td><td>\u4efb\u52a1\u5b8c\u6210\u65f6<\/td><td>\u662f<\/td><td>\u505a\u4efb\u52a1\u8ddf\u8e2a<\/td><\/tr><tr><td>Stop<\/td><td>Claude \u5b8c\u6210\u54cd\u5e94\u65f6<\/td><td>\u662f<\/td><td>\u6536\u5c3e\u6e05\u7406\u3001\u751f\u6210\u603b\u7ed3<\/td><\/tr><tr><td>ConfigChange<\/td><td>\u914d\u7f6e\u53d8\u66f4\u65f6<\/td><td>\u662f<\/td><td>\u70ed\u66f4\u65b0\u914d\u7f6e<\/td><\/tr><tr><td>FileChanged<\/td><td>\u6587\u4ef6\u53d8\u5316\u65f6<\/td><td>\u5426<\/td><td>\u89e6\u53d1\u6784\u5efa\u3001\u5237\u65b0\u7f13\u5b58<\/td><\/tr><tr><td>WorktreeCreate<\/td><td>\u521b\u5efa Git worktree \u65f6<\/td><td>\u662f<\/td><td>\u521d\u59cb\u5316\u73af\u5883<\/td><\/tr><tr><td>PreCompact<\/td><td>\u4e0a\u4e0b\u6587\u538b\u7f29\u524d<\/td><td>\u662f<\/td><td>\u4fdd\u5b58\u5173\u952e\u72b6\u6001<\/td><\/tr><tr><td>PostCompact<\/td><td>\u4e0a\u4e0b\u6587\u538b\u7f29\u540e<\/td><td>\u5426<\/td><td>\u6062\u590d\u5173\u952e\u4e0a\u4e0b\u6587<\/td><\/tr><tr><td>SessionEnd<\/td><td>\u4f1a\u8bdd\u7ed3\u675f\u65f6<\/td><td>\u5426<\/td><td>\u6e05\u7406\u8d44\u6e90\u3001\u8bb0\u5f55\u65e5\u5fd7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5927\u90e8\u5206\u573a\u666f\uff0c\u5176\u5b9e\u7528\u597d&nbsp;<code>PreToolUse<\/code>&nbsp;\u548c&nbsp;<code>PostToolUse<\/code>&nbsp;\u5c31\u591f\u4e86\u3002\u5982\u679c\u518d\u52a0\u4e00\u4e2a&nbsp;<code>SessionStart<\/code>\uff0c\u57fa\u672c\u53ef\u4ee5\u8986\u76d6\u5927\u591a\u6570\u65e5\u5e38\u81ea\u52a8\u5316\u9700\u6c42\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u56db\u79cd Hook \u7c7b\u578b\u8be6\u89e3<\/strong><\/h3>\n\n\n\n<p>Claude Code \u652f\u6301\u56db\u79cd hook \u7c7b\u578b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u7c7b\u578b<\/th><th>\u901f\u5ea6<\/th><th>\u590d\u6742\u5ea6<\/th><th>\u6700\u9002\u5408<\/th><th>\u793a\u4f8b<\/th><\/tr><tr><td>Command<\/td><td>\u5feb<\/td><td>\u4f4e<\/td><td>\u683c\u5f0f\u5316\u3001\u62e6\u622a\u3001\u8bb0\u5f55<\/td><td>\u7f16\u8f91\u6587\u4ef6\u540e\u8fd0\u884c Prettier<\/td><\/tr><tr><td>HTTP<\/td><td>\u4e2d<\/td><td>\u4e2d<\/td><td>\u5916\u90e8\u96c6\u6210\u3001webhook<\/td><td>\u5b8c\u6210\u540e\u901a\u77e5 Slack<\/td><\/tr><tr><td>Prompt<\/td><td>\u6162<\/td><td>\u4e2d<\/td><td>\u7b80\u5355\u5224\u65ad<\/td><td>\u201c\u8fd9\u6bb5\u4ee3\u7801\u662f\u5426\u5b89\u5168\uff1f\u201d<\/td><\/tr><tr><td>Agent<\/td><td>\u6700\u6162<\/td><td>\u9ad8<\/td><td>\u590d\u6742\u6821\u9a8c<\/td><td>\u68c0\u67e5\u4ee3\u7801\u662f\u5426\u7b26\u5408\u9879\u76ee\u89c4\u8303<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Command Hooks\uff08\u4e3b\u529b\u519b\uff09<\/strong><\/h3>\n\n\n\n<p>Command hooks \u672c\u8d28\u4e0a\u5c31\u662f\u6267\u884c\u4e00\u6bb5 shell \u547d\u4ee4\uff0c\u5e76\u901a\u8fc7\u9000\u51fa\u7801\u51b3\u5b9a\u7ed3\u679c\u3002\u6267\u884c\u65f6\u4f1a\u901a\u8fc7 stdin \u62ff\u5230\u4e00\u4efd JSON\uff0c\u91cc\u9762\u5305\u542b\u5f53\u524d\u64cd\u4f5c\u7684\u6240\u6709\u4fe1\u606f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"PreToolUse\": &#91;{\n      \"matcher\": \"Bash\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"jq -r '.tool_input.command' | grep -q 'rm -rf \/' &amp;&amp; exit 2 || exit 0\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5927\u591a\u6570\u5b9e\u9645\u573a\u666f\u90fd\u4f1a\u7528\u5230\u5b83\u2014\u2014\u6bd4\u5982\u4ee3\u7801\u683c\u5f0f\u5316\u3001\u6587\u4ef6\u4fdd\u62a4\u3001\u901a\u77e5\u3001\u4ee5\u53ca\u5404\u79cd\u81ea\u52a8\u5316\u6d41\u7a0b\u3002\u4f18\u70b9\u4e5f\u5f88\u76f4\u63a5\uff1a\u5feb\u3001\u7b80\u5355\u3001\u53ef\u63a7\u3002<\/p>\n\n\n\n<p><strong>\u5b9e\u7528\u6280\u5de7<\/strong>\uff1a\u53ef\u4ee5\u52a0\u4e0a&nbsp;<code>async: true<\/code>\uff0c\u8ba9 hook \u5728\u540e\u53f0\u6267\u884c\uff0c\u4e0d\u963b\u585e Claude \u7684\u6d41\u7a0b\uff0c\u9002\u5408\u7528\u5728\u65e5\u5fd7\u8bb0\u5f55\u3001\u901a\u77e5\u8fd9\u7c7b\u4e0d\u9700\u8981\u540c\u6b65\u5b8c\u6210\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>HTTP Hooks\uff08\u5916\u90e8\u96c6\u6210\uff09<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/zhida.zhihu.com\/search?content_id=273333664&amp;content_type=Article&amp;match_order=1&amp;q=HTTP+hooks&amp;zd_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6aGlkYV9zZXJ2ZXIiLCJleHAiOjE3NzkwODQ0NzksInEiOiJIVFRQIGhvb2tzIiwiemhpZGFfc291cmNlIjoiZW50aXR5IiwiY29udGVudF9pZCI6MjczMzMzNjY0LCJjb250ZW50X3R5cGUiOiJBcnRpY2xlIiwibWF0Y2hfb3JkZXIiOjEsInpkX3Rva2VuIjpudWxsfQ.x3YS3VEoBiC-P9vb4Zam4pMTQwX1YgqPaeVUtN3z0Sc&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">HTTP hooks<\/a>&nbsp;\u4f1a\u628a\u5f53\u524d\u4e8b\u4ef6\u4ee5 JSON \u7684\u5f62\u5f0f POST \u5230\u4e00\u4e2a URL\uff0c\u7136\u540e\u6839\u636e\u8fd4\u56de\u7684\u72b6\u6001\u7801\u51b3\u5b9a\u7ed3\u679c\u3002\u5b83\u5f88\u9002\u5408\u7528\u6765\u5bf9\u63a5\u5916\u90e8\u7cfb\u7edf\uff0c\u6bd4\u5982\u53d1\u6d88\u606f\u5230 Slack\u3001Discord\u3001PagerDuty\uff0c\u6216\u8005\u63a5\u5165\u4f60\u81ea\u5df1\u7684\u76d1\u63a7\u548c\u4eea\u8868\u677f\u3002\u5982\u679c\u9700\u8981\u66f4\u4e25\u683c\u7684\u63a7\u5236\uff0c\u4e5f\u53ef\u4ee5\u5728\u6267\u884c\u64cd\u4f5c\u524d\u5148\u8bf7\u6c42\u5916\u90e8\u670d\u52a1\uff0c\u8ba9\u5b83\u6765\u51b3\u5b9a\u662f\u5426\u653e\u884c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"Stop\": &#91;{\n      \"matcher\": \"\",\n      \"hooks\": &#91;{\n        \"type\": \"http\",\n        \"url\": \"https:\/\/your-api.com\/claude-webhook\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u548c&nbsp;<a href=\"https:\/\/zhida.zhihu.com\/search?content_id=273333664&amp;content_type=Article&amp;match_order=1&amp;q=command+hooks&amp;zd_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6aGlkYV9zZXJ2ZXIiLCJleHAiOjE3NzkwODQ0NzksInEiOiJjb21tYW5kIGhvb2tzIiwiemhpZGFfc291cmNlIjoiZW50aXR5IiwiY29udGVudF9pZCI6MjczMzMzNjY0LCJjb250ZW50X3R5cGUiOiJBcnRpY2xlIiwibWF0Y2hfb3JkZXIiOjEsInpkX3Rva2VuIjpudWxsfQ.tBhvPdo07VcMPfCWL8AX6f3W2IvaCHTpe7BFzJjdKzI&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">command hooks<\/a>&nbsp;\u4e0d\u540c\uff0c\u8fd9\u91cc\u6ca1\u6709\u300c\u9000\u51fa\u7801\u300d\uff0c\u800c\u662f\u5b8c\u5168\u4f9d\u8d56&nbsp;<strong>HTTP \u72b6\u6001\u7801 + \u54cd\u5e94\u5185\u5bb9<\/strong>\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Response<\/th><th>\u884c\u4e3a<\/th><\/tr><tr><td>2xx + \u7a7a body<\/td><td>\u6210\u529f\uff0c\u76f8\u5f53\u4e8e exit 0<\/td><\/tr><tr><td>2xx + \u6587\u672c<\/td><td>\u6210\u529f\uff0c\u6587\u672c\u4f1a\u4f5c\u4e3a\u4e0a\u4e0b\u6587\u4f20\u7ed9 Claude<\/td><\/tr><tr><td>2xx + JSON<\/td><td>\u6210\u529f\uff0c\u6309 command hooks \u7684 JSON \u7ed3\u6784\u89e3\u6790<\/td><\/tr><tr><td>\u975e 2xx \u72b6\u6001\u7801<\/td><td>\u4e0d\u4f1a\u963b\u6b62\uff0c\u53ea\u8bb0\u5f55\u9519\u8bef\u5e76\u7ee7\u7eed<\/td><\/tr><tr><td>\u8fde\u63a5\u5931\u8d25 \/ \u8d85\u65f6<\/td><td>\u4e0d\u4f1a\u963b\u6b62\uff0c\u53ea\u8bb0\u5f55\u9519\u8bef\u5e76\u7ee7\u7eed<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>\u5173\u952e\u533a\u522b<\/strong>\uff1aHTTP \u72b6\u6001\u7801\u672c\u8eab\u65e0\u6cd5\u963b\u6b62\u64cd\u4f5c\uff0c\u5373\u4f7f\u8fd4\u56de 4xx \/ 5xx\uff0c\u4e5f\u53ea\u662f\u8bb0\u5f55\u9519\u8bef\uff0c\u6d41\u7a0b\u8fd8\u662f\u4f1a\u7ee7\u7eed\u3002\u5982\u679c\u4f60\u771f\u7684\u60f3\u300c\u62e6\u4f4f\u300d\u67d0\u4e2a\u64cd\u4f5c\uff0c\u5fc5\u987b\u8fd4\u56de 2xx + \u7279\u5b9a JSON \u7ed3\u6784\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hookSpecificOutput\": {\n    \"hookEventName\": \"PreToolUse\",\n    \"permissionDecision\": \"deny\",\n    \"permissionDecisionReason\": \"\u88ab\u5b89\u5168\u7b56\u7565\u963b\u6b62\"\n  }\n}<\/code><\/pre>\n\n\n\n<p>HTTP hooks \u652f\u6301\u5728 headers \u91cc\u4f7f\u7528\u73af\u5883\u53d8\u91cf\uff0c\u4f46\u524d\u63d0\u662f\uff1a<strong>\u8fd9\u4e9b\u53d8\u91cf\u5fc5\u987b\u663e\u5f0f\u5199\u5728&nbsp;<code>allowedEnvVars<\/code>&nbsp;\u91cc<\/strong>\u3002\u8fd9\u662f\u4e3a\u4e86\u907f\u514d\u65e0\u610f\u4e2d\u6cc4\u9732\u654f\u611f\u4fe1\u606f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"type\": \"http\",\n  \"url\": \"https:\/\/hooks.example.com\/validate\",\n  \"headers\": {\n    \"Authorization\": \"Bearer $API_KEY\",\n    \"X-Team-Id\": \"$TEAM_ID\"\n  },\n  \"allowedEnvVars\": &#91;\"API_KEY\", \"TEAM_ID\"]\n}<\/code><\/pre>\n\n\n\n<p>\u6709\u4e00\u4e2a\u5f88\u5bb9\u6613\u5ffd\u7565\u7684\u70b9\uff1a<strong>\u672a\u58f0\u660e\u7684\u53d8\u91cf\u4f1a\u88ab\u89e3\u6790\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u4e0d\u4f1a\u62a5\u9519<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><a href=\"https:\/\/zhida.zhihu.com\/search?content_id=273333664&amp;content_type=Article&amp;match_order=1&amp;q=Prompt+Hooks&amp;zd_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6aGlkYV9zZXJ2ZXIiLCJleHAiOjE3NzkwODQ0NzksInEiOiJQcm9tcHQgSG9va3MiLCJ6aGlkYV9zb3VyY2UiOiJlbnRpdHkiLCJjb250ZW50X2lkIjoyNzMzMzM2NjQsImNvbnRlbnRfdHlwZSI6IkFydGljbGUiLCJtYXRjaF9vcmRlciI6MSwiemRfdG9rZW4iOm51bGx9.qFl2jvH70XV2DQLtoN6VrIq7GYzZMLr9yjMpMLs87AY&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">Prompt Hooks<\/a>\uff08AI \u9a71\u52a8\u7684\u51b3\u7b56\uff09<\/strong><\/h3>\n\n\n\n<p>Prompt hooks \u4f1a\u628a\u5f53\u524d\u4e8b\u4ef6\u7684\u6570\u636e\u518d\u4ea4\u7ed9 Claude\uff0c\u8ba9\u5b83\u505a\u4e00\u6b21\u7b80\u5355\u5224\u65ad\uff08\u901a\u5e38\u662f\u653e\u884c\u8fd8\u662f\u963b\u6b62\uff09\u3002\u8fd4\u56de\u7ed3\u679c\u662f\u4e00\u4e2a JSON\uff0c\u6bd4\u5982&nbsp;<code>\"decision\": \"allow\"<\/code>&nbsp;\u6216&nbsp;<code>\"block\"<\/code>\uff0c\u540c\u65f6\u5e26\u4e0a\u7b80\u5355\u7684\u7406\u7531\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"PreToolUse\": &#91;{\n      \"matcher\": \"Bash\",\n      \"hooks\": &#91;{\n        \"type\": \"prompt\",\n        \"prompt\": \"\u8fd9\u4e2a bash \u547d\u4ee4\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u8fd0\u884c\u5b89\u5168\u5417\uff1f\u8003\u8651\uff1a\u5b83\u662f\u5426\u4fee\u6539\u7cfb\u7edf\u6587\u4ef6\u3001\u5220\u9664\u6570\u636e\u6216\u8bbf\u95ee\u654f\u611f\u51ed\u636e\uff1f\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u7c7b hook \u8981\u614e\u7528\u2014\u2014\u6bcf\u89e6\u53d1\u4e00\u6b21\uff0c\u5c31\u76f8\u5f53\u4e8e\u591a\u8dd1\u4e86\u4e00\u6b21\u6a21\u578b\u8c03\u7528\uff0c\u65e2\u6709\u5ef6\u8fdf\u4e5f\u6709\u6210\u672c\u3002<\/p>\n\n\n\n<p>\u4f46\u5728\u4e00\u4e9b\u786e\u5b9e\u9700\u8981\u300c\u5224\u65ad\u300d\u7684\u573a\u666f\u4e0b\uff0c\u5b83\u5f88\u6709\u7528\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<ul>\n<li>\u8fd9\u4e2a\u6570\u636e\u5e93\u8fc1\u79fb\u662f\u4e0d\u662f\u6709\u7834\u574f\u6027<\/li>\n\n\n\n<li>\u8fd9\u6bb5\u4ee3\u7801\u662f\u5426\u5b58\u5728\u660e\u663e\u98ce\u9669<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u79cd\u4e3b\u89c2\u5224\u65ad\uff0c\u7528\u89c4\u5219\u5f88\u96be\u5199\u6e05\u695a\uff0c\u7528 prompt hook \u53cd\u800c\u66f4\u5408\u9002\u3002\u53e6\u5916\uff0cprompt hook \u7528\u7684\u6a21\u578b\u5c31\u662f\u4f60\u5f53\u524d\u4f1a\u8bdd\u91cc\u7684\u6a21\u578b\uff0c\u4e0d\u9700\u8981\u5355\u72ec\u914d\u7f6e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Agent Hooks\uff08\u5de5\u5177\u8f85\u52a9\u9a8c\u8bc1\uff09<\/strong><\/h3>\n\n\n\n<p>Agent hooks \u4f1a\u542f\u52a8\u4e00\u4e2a\u5b50 agent\uff0c\u8fd9\u4e2a\u5b50 agent \u53ef\u4ee5\u7528 Read\u3001Grep\u3001Glob \u7b49\u5de5\u5177\uff0c\u5728\u505a\u51b3\u5b9a\u4e4b\u524d\u5148\u53bb\u8bfb\u6587\u4ef6\u3001\u67e5\u4ee3\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"PreToolUse\": &#91;{\n      \"matcher\": \"Write\",\n      \"hooks\": &#91;{\n        \"type\": \"agent\",\n        \"prompt\": \"\u68c0\u67e5\u6b63\u5728\u5199\u5165\u7684\u6587\u4ef6\u662f\u5426\u9075\u5faa\u9879\u76ee\u7684\u547d\u540d\u7ea6\u5b9a\u548c\u5bfc\u5165\u6a21\u5f0f\u3002\u9605\u8bfb .claude\/CONVENTIONS.md \u4e86\u89e3\u89c4\u5219\u3002\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u53ef\u4ee5\u628a\u5b83\u7406\u89e3\u6210\uff1a\u5728\u5173\u952e\u64cd\u4f5c\u524d\uff0c\u5148\u8ba9\u300c\u53e6\u4e00\u4e2a Claude\u300d\u5e2e\u4f60\u505a\u4e00\u8f6e\u66f4\u6df1\u5165\u7684\u68c0\u67e5\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e5f\u662f\u6700\u5f3a\u7684\u4e00\u79cd hook\uff0c\u4f46\u4ee3\u4ef7\u4e5f\u6700\u5927\u2014\u2014\u66f4\u6162\u3001\u66f4\u590d\u6742\u3002\u4e00\u822c\u53ea\u5728\u90a3\u79cd\u5fc5\u987b\u770b\u4e0a\u4e0b\u6587\u624d\u80fd\u5224\u65ad\u7684\u9ad8\u98ce\u9669\u573a\u666f\u4e0b\u4f7f\u7528\uff0c\u6bd4\u5982\u4ee3\u7801\u89c4\u8303\u6821\u9a8c\u3001\u590d\u6742\u903b\u8f91\u68c0\u67e5\u7b49\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7 \u4e2a\u751f\u4ea7\u7ea7 Hook \u793a\u4f8b\uff08\u5f00\u7bb1\u5373\u7528\uff09<\/strong><\/h3>\n\n\n\n<p>\u5728\u5b9e\u9645\u9879\u76ee\u91cc\uff0c\u6700\u5e38\u7528\u7684\u4e00\u4e9b hooks \u57fa\u672c\u90fd\u56f4\u7ed5\u8fd9\u51e0\u4ef6\u4e8b\uff1a\u81ea\u52a8\u683c\u5f0f\u5316\uff08Prettier \/ Black\uff09\u3001\u4fdd\u62a4\u5173\u952e\u6587\u4ef6\u3001\u4efb\u52a1\u5b8c\u6210\u65f6\u53d1\u901a\u77e5\u3001\u4f1a\u8bdd\u5f00\u59cb\u65f6\u6ce8\u5165\u4e0a\u4e0b\u6587\u3001\u4ee3\u7801\u53d8\u66f4\u540e\u8dd1\u6d4b\u8bd5\u3001\u9650\u5236\u5206\u652f\u64cd\u4f5c\uff0c\u4ee5\u53ca\u8bb0\u5f55\u6240\u6709\u5de5\u5177\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u7684\u6bcf\u4e2a\u793a\u4f8b\uff0c\u90fd\u662f\u53ef\u4ee5\u76f4\u63a5\u7528\u7684&nbsp;<code>settings.json<\/code>&nbsp;\u7247\u6bb5\uff0c\u653e\u5230&nbsp;<code>.claude\/settings.json<\/code>&nbsp;\u5c31\u80fd\u751f\u6548\u3002\u5982\u679c\u60f3\u770b\u66f4\u591a\u73a9\u6cd5\uff0c\u53ef\u4ee5\u53c2\u8003\u793e\u533a\u91cc\u7684\u4e00\u4e9b\u6574\u7406\uff08\u6bd4\u5982 awesome-claude-code[1]\uff09\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. \u81ea\u52a8\u683c\u5f0f\u5316<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"PostToolUse\": &#91;{\n      \"matcher\": \"Write|Edit\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"FILE=$(jq -r '.tool_input.file_path \/\/ .tool_input.file' \/dev\/stdin); case \\\\\"$FILE\\\\\" in *.ts|*.tsx|*.js|*.jsx) npx prettier --write \\\\\"$FILE\\\\\" 2&gt;\/dev\/null;; *.py) black \\\\\"$FILE\\\\\" 2&gt;\/dev\/null;; esac; exit 0\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a hook \u4f1a\u5728\u6bcf\u6b21&nbsp;<code>Write<\/code>&nbsp;\u6216&nbsp;<code>Edit<\/code>&nbsp;\u540e\u89e6\u53d1\uff0c\u4ece stdin \u7684 JSON \u91cc\u62ff\u5230\u6587\u4ef6\u8def\u5f84\uff0c\u7136\u540e\u6309\u6587\u4ef6\u7c7b\u578b\u8fd0\u884c\u5bf9\u5e94\u7684\u683c\u5f0f\u5316\u5de5\u5177\u3002<\/p>\n\n\n\n<p>\u6700\u540e\u7684&nbsp;<code>exit 0<\/code>&nbsp;\u5f88\u5173\u952e\u2014\u2014\u4e0d\u7ba1\u683c\u5f0f\u5316\u6709\u6ca1\u6709\u6210\u529f\uff0c\u90fd\u4e0d\u4f1a\u963b\u6b62 Claude \u7684\u64cd\u4f5c\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u683c\u5f0f\u5316\u5931\u8d25\u4e0d\u5e94\u8be5\u6253\u65ad\u6d41\u7a0b\u3002<\/p>\n\n\n\n<p>\u4e00\u4e2a\u5b9e\u7528\u5efa\u8bae\uff1a\u5982\u679c\u4f60\u662f\u591a\u8bed\u8a00\u9879\u76ee\uff0c\u53ef\u4ee5\u987a\u624b\u52a0\u4e0a\uff1a<\/p>\n\n\n\n<ul>\n<li><code>*.go<\/code>&nbsp;\u2192&nbsp;<code>gofmt<\/code><\/li>\n\n\n\n<li><code>*.rs<\/code>&nbsp;\u2192&nbsp;<code>rustfmt<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. \u4fdd\u62a4\u654f\u611f\u6587\u4ef6<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"PreToolUse\": &#91;{\n      \"matcher\": \"Write|Edit\",\n      \"if\": \"tool_input.file_path matches '(\\\\\\\\.env|\\\\\\\\.env\\\\\\\\.local|package-lock\\\\\\\\.json|yarn\\\\\\\\.lock|pnpm-lock\\\\\\\\.yaml)'\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"echo '{\\\\\"message\\\\\": \\\\\"BLOCKED: \u6b64\u6587\u4ef6\u53d7\u4fdd\u62a4\u3002\u8bf7\u624b\u52a8\u7f16\u8f91\u3002\\\\\"}' &amp;&amp; exit 2\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5173\u952e\u70b9\u662f&nbsp;<code>exit 2<\/code>\uff1a\u5b83\u4f1a\u963b\u6b62\u8fd9\u6b21\u64cd\u4f5c\uff0c\u5e76\u628a\u4f60\u8f93\u51fa\u7684 JSON \u5f53\u4f5c\u53cd\u9988\u8fd4\u56de\u7ed9 Claude\u3002Claude \u6536\u5230\u540e\u4e00\u822c\u4f1a\u6539\u6210\u63d0\u793a\u4f60\u624b\u52a8\u5904\u7406\u3002<code>if<\/code>&nbsp;\u8fd9\u4e00\u5c42\u4e5f\u5f88\u91cd\u8981\u2014\u2014\u53ea\u5728\u5339\u914d\u8fd9\u4e9b\u6587\u4ef6\u65f6\u624d\u89e6\u53d1\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u6b63\u5e38\u5199\u5165\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. \u5b8c\u6210\u901a\u77e5<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"Notification\": &#91;{\n      \"matcher\": \"\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"MSG=$(jq -r '.message \/\/ \\\\\"Claude Code \u4efb\u52a1\u5b8c\u6210\\\\\"' \/dev\/stdin); if &#91; \\\\\"$(uname)\\\\\" = 'Darwin' ]; then osascript -e \\\\\"display notification \\\\\\\\\\\\\"$MSG\\\\\\\\\\\\\" with title \\\\\\\\\\\\\"Claude Code\\\\\\\\\\\\\"\\\\\"; else notify-send 'Claude Code' \\\\\"$MSG\\\\\"; fi; exit 0\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u9002\u7528\u4e8e macOS\uff08osascript\uff09\u548c Linux\uff08notify-send\uff09\u3002<code>matcher<\/code>&nbsp;\u4e3a\u7a7a\u8868\u793a\u4f1a\u5339\u914d\u6240\u6709\u901a\u77e5\u4e8b\u4ef6\u3002\u4f60\u53ef\u4ee5\u653e\u5fc3\u628a\u957f\u4efb\u52a1\u4e22\u7ed9 Claude\uff0c\u7136\u540e\u5207\u53bb\u505a\u522b\u7684\u4e8b\uff0c\u7b49\u7cfb\u7edf\u5f39\u7a97\u63d0\u9192\u4f60\u7ed3\u679c\u5c31\u884c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. \u4f1a\u8bdd\u4e0a\u4e0b\u6587\u6ce8\u5165<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"SessionStart\": &#91;{\n      \"matcher\": \"\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"echo '{\\\\\"message\\\\\": \\\\\"\u9879\u76ee: '\\\\\"$(basename $(pwd))\\\\\"' | \u5206\u652f: '\\\\\"$(git branch --show-current 2&gt;\/dev\/null || echo none)\\\\\"' | \u6700\u540e\u63d0\u4ea4: '\\\\\"$(git log --oneline -1 2&gt;\/dev\/null || echo none)\\\\\"'\\\\\"}'; exit 0\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4f1a\u628a\u5f53\u524d\u9879\u76ee\u540d\u3001Git \u5206\u652f\u548c\u6700\u8fd1\u4e00\u6b21\u63d0\u4ea4\u5e26\u5165\u6bcf\u4e2a\u4f1a\u8bdd\u3002Claude \u4f1a\u81ea\u52a8\u8bfb\u53d6\u8fd9\u4e9b\u4fe1\u606f\uff0c\u4e0d\u7528\u4f60\u518d\u624b\u52a8\u8bf4\u660e\u5f53\u524d\u5728\u54ea\u4e2a\u5206\u652f\u4e0a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. \u81ea\u52a8\u8fd0\u884c\u6d4b\u8bd5<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"PostToolUse\": &#91;{\n      \"matcher\": \"Write|Edit\",\n      \"if\": \"tool_input.file_path matches '\\\\\\\\.(ts|tsx|js|jsx|py)$'\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"FILE=$(jq -r '.tool_input.file_path' \/dev\/stdin); TEST_FILE=$(echo \\\\\"$FILE\\\\\" | sed 's\/\\\\\\\\.&#91;^.]*$\/.test&amp;\/'); if &#91; -f \\\\\"$TEST_FILE\\\\\" ]; then npx jest \\\\\"$TEST_FILE\\\\\" --no-coverage 2&gt;&amp;1 | tail -5; fi; exit 0\",\n        \"timeout\": 30000\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u68c0\u6d4b\u5230\u5bf9\u5e94\u7684\u6d4b\u8bd5\u6587\u4ef6\u5b58\u5728\uff0c\u5b83\u4f1a\u5728 Claude \u4fee\u6539\u6e90\u4ee3\u7801\u540e\u81ea\u52a8\u8fd0\u884c\u6d4b\u8bd5\u3002<code>tail -5<\/code>&nbsp;\u7528\u6765\u63a7\u5236\u8f93\u51fa\u957f\u5ea6\uff0c\u907f\u514d\u65e5\u5fd7\u592a\u957f\uff0c<code>timeout<\/code>&nbsp;\u5219\u9632\u6b62\u6d4b\u8bd5\u5361\u4f4f\u6216\u5931\u63a7\u3002\u8fd9\u4e2a\u914d\u7f6e\u548c AI \u9a71\u52a8\u7684\u4ee3\u7801\u5ba1\u67e5\u6d41\u7a0b\u914d\u5408\u5f97\u5f88\u597d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. \u5206\u652f\u4fdd\u62a4\u5f3a\u5236\u6267\u884c\uff08\u9ad8\u7ea7\uff09<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"PreToolUse\": &#91;{\n      \"matcher\": \"Bash\",\n      \"if\": \"tool_input.command matches 'git push.*(main|master|production)'\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"echo '{\\\\\"message\\\\\": \\\\\"BLOCKED: \u76f4\u63a5\u63a8\u9001\u5230\u53d7\u4fdd\u62a4\u5206\u652f\u3002\u4f7f\u7528\u529f\u80fd\u5206\u652f\u5e76\u6253\u5f00 PR\u3002\\\\\"}' &amp;&amp; exit 2\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4f1a\u963b\u6b62\u4efb\u4f55\u5bf9 main\u3001master \u6216 production \u5206\u652f\u7684&nbsp;<code>git push<\/code>&nbsp;\u64cd\u4f5c\u3002Claude \u4f1a\u6536\u5230\u5931\u8d25\u53cd\u9988\uff0c\u5e76\u901a\u5e38\u4f1a\u6539\u4e3a\u5efa\u8bae\u4f60\u5207\u5230\u529f\u80fd\u5206\u652f\u518d\u63d0\u4ea4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. \u5b89\u5168\u5ba1\u8ba1\u65e5\u5fd7\uff08\u9ad8\u7ea7\uff09<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"PostToolUse\": &#91;{\n      \"matcher\": \"Bash\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"INPUT=$(cat \/dev\/stdin); CMD=$(echo \\\\\"$INPUT\\\\\" | jq -r '.tool_input.command'); echo \\\\\"&#91;$(date -u +%Y-%m-%dT%H:%M:%SZ)] BASH: $CMD\\\\\" &gt;&gt; .claude\/audit.log; exit 0\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5b83\u4f1a\u628a Claude \u6267\u884c\u7684\u6bcf\u4e00\u6761 Bash \u547d\u4ee4\u8bb0\u5f55\u5230\u5ba1\u8ba1\u65e5\u5fd7\u4e2d\uff0c\u5e76\u9644\u5e26 UTC \u65f6\u95f4\u6233\u3002\u8fd9\u4e2a\u65e5\u5fd7\u5728\u505a\u5b89\u5168\u5ba1\u67e5\u6216\u8005\u56de\u6eaf\u300c\u5f53\u65f6\u5230\u5e95\u6267\u884c\u4e86\u4ec0\u4e48\u300d\u65f6\u7279\u522b\u6709\u7528\u3002\u4e00\u822c\u5efa\u8bae\u628a&nbsp;<code>.claude\/audit.log<\/code>&nbsp;\u52a0\u5230&nbsp;<code>.gitignore<\/code>&nbsp;\u91cc\uff0c\u907f\u514d\u88ab\u63d0\u4ea4\u5230\u4ed3\u5e93\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5f00\u7bb1\u5373\u7528\u7684 Hooks \u5165\u95e8\u914d\u7f6e<\/strong><\/h3>\n\n\n\n<p>\u4e00\u4e2a\u6bd4\u8f83\u901a\u7528\u7684\u5165\u95e8\u914d\u7f6e\uff0c\u901a\u5e38\u4f1a\u5305\u542b\u8fd9\u51e0\u7c7b hooks\uff1a<\/p>\n\n\n\n<ul>\n<li>\u6587\u4ef6\u7f16\u8f91\u540e\u81ea\u52a8\u683c\u5f0f\u5316<\/li>\n\n\n\n<li>\u4efb\u52a1\u5b8c\u6210\u65f6\u53d1\u9001\u901a\u77e5<\/li>\n\n\n\n<li>\u4fdd\u62a4\u654f\u611f\u6587\u4ef6<\/li>\n\n\n\n<li>\u4f1a\u8bdd\u5f00\u59cb\u65f6\u6ce8\u5165\u4e0a\u4e0b\u6587<\/li>\n\n\n\n<li>\u5728\u7ed3\u675f\u65f6\u505a\u4e00\u4e9b\u6e05\u7406\uff08Stop hook\uff09<\/li>\n<\/ul>\n\n\n\n<p>\u57fa\u672c\u4e0a\u53ef\u4ee5\u7528\u5728\u6bcf\u4e00\u4e2a\u65b0\u9879\u76ee\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u6280\u672f\u6808\u505a\u4e00\u70b9\u8c03\u6574\uff0c\u4f46\u6574\u4f53\u7ed3\u6784\u57fa\u672c\u4e0d\u53d8\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5b8c\u6574\u914d\u7f6e<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"hooks\": {\n    \"SessionStart\": &#91;{\n      \"matcher\": \"\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"echo '{\\\\\"message\\\\\": \\\\\"\u9879\u76ee: '\\\\\"$(basename $(pwd))\\\\\"' | \u5206\u652f: '\\\\\"$(git branch --show-current 2&gt;\/dev\/null)\\\\\"' | Node: '\\\\\"$(node -v 2&gt;\/dev\/null)\\\\\"'\\\\\"}'; exit 0\"\n      }]\n    }],\n    \"PreToolUse\": &#91;{\n      \"matcher\": \"Write|Edit\",\n      \"if\": \"tool_input.file_path matches '(\\\\\\\\.env|\\\\\\\\.env\\\\\\\\..+|.*lock\\\\\\\\.json|.*lock\\\\\\\\.yaml)'\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"echo '{\\\\\"message\\\\\": \\\\\"\u53d7\u4fdd\u62a4\u7684\u6587\u4ef6\u3002\u8bf7\u624b\u52a8\u7f16\u8f91\u3002\\\\\"}' &amp;&amp; exit 2\"\n      }]\n    }],\n    \"PostToolUse\": &#91;{\n      \"matcher\": \"Write|Edit\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"FILE=$(jq -r '.tool_input.file_path \/\/ .tool_input.file' \/dev\/stdin); case \\\\\"$FILE\\\\\" in *.ts|*.tsx|*.js|*.jsx) npx prettier --write \\\\\"$FILE\\\\\" 2&gt;\/dev\/null;; *.py) black \\\\\"$FILE\\\\\" 2&gt;\/dev\/null;; *.go) gofmt -w \\\\\"$FILE\\\\\" 2&gt;\/dev\/null;; esac; exit 0\"\n      }]\n    }],\n    \"Notification\": &#91;{\n      \"matcher\": \"\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"MSG=$(jq -r '.message \/\/ \\\\\"\u5b8c\u6210\\\\\"' \/dev\/stdin); osascript -e \\\\\"display notification \\\\\\\\\\\\\"$MSG\\\\\\\\\\\\\" with title \\\\\\\\\\\\\"Claude Code\\\\\\\\\\\\\"\\\\\" 2&gt;\/dev\/null || notify-send 'Claude Code' \\\\\"$MSG\\\\\" 2&gt;\/dev\/null; exit 0\"\n      }]\n    }],\n    \"Stop\": &#91;{\n      \"matcher\": \"\",\n      \"hooks\": &#91;{\n        \"type\": \"command\",\n        \"command\": \"echo '&#91;STOP] '\\\\\"$(date +%H:%M:%S)\\\\\"'' &gt;&gt; .claude\/session.log; exit 0\"\n      }]\n    }]\n  }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5982\u4f55\u9488\u5bf9\u4f60\u7684\u6280\u672f\u6808\u5b9a\u5236<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u6280\u672f\u6808<\/th><th>\u683c\u5f0f\u5316\u547d\u4ee4<\/th><th>\u6d4b\u8bd5\u547d\u4ee4<\/th><th>\u76d1\u89c6\u6269\u5c55\u540d<\/th><\/tr><tr><td>Node\/TypeScript<\/td><td>npx prettier &#8211;write<\/td><td>npx jest &#8211;no-coverage<\/td><td>.ts, .tsx, .js, .jsx<\/td><\/tr><tr><td>Python<\/td><td>black<\/td><td>pytest -x<\/td><td>.py<\/td><\/tr><tr><td>Go<\/td><td>gofmt -w<\/td><td>go test .\/&#8230;<\/td><td>.go<\/td><\/tr><tr><td>Rust<\/td><td>rustfmt<\/td><td>cargo test<\/td><td>.rs<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u628a\u524d\u9762\u90a3\u4e9b hooks \u793a\u4f8b\u91cc\u7684\u683c\u5f0f\u5316\u547d\u4ee4\u3001\u6d4b\u8bd5\u547d\u4ee4\u548c\u6587\u4ef6\u5339\u914d\u89c4\u5219\uff0c\u66ff\u6362\u6210\u4f60\u5f53\u524d\u6280\u672f\u6808\u5bf9\u5e94\u7684\u7248\u672c\u5c31\u884c\u4e86\uff0c\u6574\u4f53\u7ed3\u6784\u57fa\u672c\u4e0d\u7528\u52a8\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u9a8c\u8bc1 Hooks \u662f\u5426\u751f\u6548<\/strong><\/h3>\n\n\n\n<p>\u53ef\u4ee5\u7528\u4e0b\u9762\u4e09\u79cd\u65b9\u5f0f\u5feb\u901f\u786e\u8ba4 hooks \u6709\u6ca1\u6709\u6b63\u5e38\u5de5\u4f5c\uff1a<\/p>\n\n\n\n<p><strong>1.&nbsp;<code>\/hooks<\/code>&nbsp;\u547d\u4ee4<\/strong><\/p>\n\n\n\n<p>\u5728 Claude Code \u91cc\u8f93\u5165&nbsp;<code>\/hooks<\/code>\uff0c\u53ef\u4ee5\u770b\u5230\u5f53\u524d\u6ce8\u518c\u7684\u6240\u6709 hooks\uff0c\u5305\u62ec\u5339\u914d\u5668\u548c\u542f\u7528\u72b6\u6001\u3002\u8fd9\u662f\u6700\u76f4\u63a5\u7684\u67e5\u770b\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p><strong>2. \u68c0\u67e5\u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n\n\n\n<p>\u76f4\u63a5\u67e5\u770b\u914d\u7f6e\uff1a<\/p>\n\n\n\n<ul>\n<li><code>~\/.claude\/settings.json<\/code>\uff08\u7528\u6237\u7ea7\uff09<\/li>\n\n\n\n<li><code>.claude\/settings.json<\/code>\uff08\u9879\u76ee\u7ea7\uff09<\/li>\n<\/ul>\n\n\n\n<p>\u786e\u8ba4\u4f60\u7684 hooks \u662f\u5426\u771f\u7684\u5199\u8fdb\u53bb\u4e86\u3001\u6709\u6ca1\u6709\u62fc\u5199\u6216\u7ed3\u6784\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>3. \u5feb\u901f\u5f00\u5173<\/strong><\/p>\n\n\n\n<p>\u5728&nbsp;<code>settings.json<\/code>&nbsp;\u91cc\u52a0\u4e0a&nbsp;<code>\"disableAllHooks\": true<\/code>&nbsp;\u53ef\u4ee5\u4e34\u65f6\u5173\u95ed\u6240\u6709 hooks\uff08\u4e0d\u7528\u5220\u914d\u7f6e\uff09\u3002\u9700\u8981\u6062\u590d\u65f6\uff0c\u5220\u6389\u8fd9\u4e00\u884c\u6216\u6539\u6210&nbsp;<code>false<\/code>&nbsp;\u5373\u53ef\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>CI\/CD \u96c6\u6210\u4e0e\u5b9e\u8df5<\/strong><\/h3>\n\n\n\n<p>Claude Code \u7684 hooks \u5728 Headless \u6a21\u5f0f\uff08<code>claude -p<\/code>\uff09\u4e0b\u540c\u6837\u53ef\u4ee5\u5de5\u4f5c\uff0c\u4e0d\u8fc7\u6709\u4e00\u4e9b\u9700\u8981\u6ce8\u610f\u7684\u5dee\u5f02\uff1a<\/p>\n\n\n\n<ul>\n<li><code>Notification<\/code>&nbsp;hooks \u4f9d\u7136\u4f1a\u89e6\u53d1\uff0c\u4f46\u5728 CI \u73af\u5883\u91cc\u66f4\u9002\u5408\u6539\u6210\u5199\u65e5\u5fd7\uff0c\u800c\u4e0d\u662f\u53d1\u684c\u9762\u901a\u77e5<\/li>\n\n\n\n<li><code>PreToolUse<\/code>&nbsp;\u8fd4\u56de\u9000\u51fa\u7801 2 \u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u4e2d\u65ad\u6d41\u7a0b\uff0c\u7528\u4e8e\u63d2\u5165\u4eba\u5de5\u5ba1\u6838\u6b65\u9aa4<\/li>\n<\/ul>\n\n\n\n<p>\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u901a\u5e38\u4f1a\u628a hooks \u548c CI \u4e00\u8d77\u7528\uff0c\u6bd4\u5982\u5728 GitHub Actions \u91cc\u901a\u8fc7&nbsp;<code>anthropics\/claude-code-action@v1<\/code>&nbsp;\u8dd1\u81ea\u52a8\u5316\u6d41\u7a0b\uff0c\u628a\u683c\u5f0f\u5316\u3001\u6821\u9a8c\u3001\u62e6\u622a\u8fd9\u4e9b\u903b\u8f91\u7edf\u4e00\u653e\u8fdb\u53bb\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Headless \u6a21\u5f0f\u884c\u4e3a<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Hook \u4e8b\u4ef6<\/th><th>\u4ea4\u4e92\u6a21\u5f0f<\/th><th>Headless \u6a21\u5f0f<\/th><th>CI \u5efa\u8bae<\/th><\/tr><tr><td>PreToolUse (\u9000\u51fa 2)<\/td><td>\u963b\u6b62\u5e76\u63d0\u793a<\/td><td>\u6682\u505c\uff08\u53ef &#8211;resume\uff09<\/td><td>\u7528\u4e8e\u5f3a\u5236\u4eba\u5de5\u5ba1\u6279<\/td><\/tr><tr><td>PostToolUse<\/td><td>\u6b63\u5e38\u6267\u884c<\/td><td>\u6b63\u5e38\u6267\u884c<\/td><td>\u4fdd\u7559\u683c\u5f0f\u5316\u3001\u65e5\u5fd7\u7b49\u64cd\u4f5c<\/td><\/tr><tr><td>Notification<\/td><td>\u684c\u9762\u901a\u77e5<\/td><td>\u4ecd\u89e6\u53d1\uff08\u65e0 UI\uff09<\/td><td>\u6539\u4e3a\u5199\u65e5\u5fd7\u6216\u53d1 Slack<\/td><\/tr><tr><td>Stop<\/td><td>\u6267\u884c\u6e05\u7406<\/td><td>\u6267\u884c\u6e05\u7406<\/td><td>\u7528\u4e8e\u6536\u96c6 CI \u4ea7\u7269<\/td><\/tr><tr><td>SessionStart<\/td><td>\u6ce8\u5165\u4e0a\u4e0b\u6587<\/td><td>\u6ce8\u5165\u4e0a\u4e0b\u6587<\/td><td>\u6ce8\u5165 CI \u73af\u5883\u53d8\u91cf<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5728 Headless \u6a21\u5f0f\u4e0b\uff0c\u6709\u4e00\u4e2a\u5f88\u5bb9\u6613\u88ab\u5ffd\u7565\u4f46\u975e\u5e38\u5b9e\u7528\u7684\u70b9\uff1a\u5f53 PreToolUse \u8fd4\u56de\u9000\u51fa\u7801 2 \u65f6\uff0c\u5e76\u4e0d\u4f1a\u53ea\u662f\u7b80\u5355\u5931\u8d25\uff0c\u800c\u662f\u6682\u505c\u6574\u4e2a\u6d41\u7a0b\uff0c\u7b49\u5f85\u4f60\u7528&nbsp;<code>--resume<\/code>&nbsp;\u6062\u590d\u3002\u8fd9\u76f8\u5f53\u4e8e\u5728 CI \u6d41\u6c34\u7ebf\u91cc\u52a0\u4e86\u4e00\u4e2a\u300c\u4eba\u5de5\u5ba1\u6279\u8282\u70b9\u300d\uff0c\u53ef\u4ee5\u5728\u5173\u952e\u64cd\u4f5c\u524d\u5f3a\u5236\u4eba\u5de5\u4ecb\u5165\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>GitHub Actions \u96c6\u6210<\/strong><\/h3>\n\n\n\n<p>\u8fd9\u662f\u4e00\u4e2a\u6700\u5c0f\u53ef\u7528\u7684 GitHub Actions \u793a\u4f8b\uff0c\u7528\u6765\u5728 CI \u4e2d\u8fd0\u884c Claude Code\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- name: \u8fd0\u884c Claude Code\n  uses: anthropics\/claude-code-action@v1\n  with:\n    prompt: \"\u5ba1\u67e5\u6b64 PR \u5e76\u5efa\u8bae\u6539\u8fdb\"\n    allowed_tools: \"Read,Grep,Glob\"\n  env:\n    ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}<\/code><\/pre>\n\n\n\n<p>\u4f60\u7684&nbsp;<code>.claude\/settings.json<\/code>&nbsp;\u4f1a\u8ddf\u7740\u4ed3\u5e93\u4e00\u8d77\u8fdb\u5165 CI \u73af\u5883\uff0c\u6240\u4ee5\u8fd9\u4e9b hooks \u5728 CI \u91cc\u7684\u89e6\u53d1\u65b9\u5f0f\u548c\u672c\u5730\u662f\u4e00\u6837\u7684\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u67d0\u4e9b hooks \u4f9d\u8d56\u672c\u5730\u73af\u5883\uff08\u6bd4\u5982&nbsp;<code>osascript<\/code>&nbsp;\u8fd9\u79cd\u684c\u9762\u901a\u77e5\uff09\uff0c\u6700\u597d\u52a0\u4e0a\u515c\u5e95\u903b\u8f91\u6216\u8005\u6761\u4ef6\u5224\u65ad\uff0c\u907f\u514d\u5728 CI \u91cc\u51fa\u95ee\u9898\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u56e2\u961f Hook \u7ba1\u7406<\/strong><\/h3>\n\n\n\n<p>\u5728\u56e2\u961f\u91cc\uff0c\u4e00\u4e2a\u6bd4\u8f83\u7a33\u5b9a\u7684\u505a\u6cd5\u662f\u6309\u4f5c\u7528\u57df\u5206\u5c42\u7ba1\u7406 hooks\uff1a<\/p>\n\n\n\n<ul>\n<li><strong><code>.claude\/settings.json<\/code>\uff08\u63d0\u4ea4\u5230\u4ed3\u5e93\uff09<\/strong>&nbsp;\u2014\u2014 \u653e\u56e2\u961f\u5171\u4eab\u89c4\u5219\uff0c\u6bd4\u5982\u6587\u4ef6\u4fdd\u62a4\u3001\u81ea\u52a8\u683c\u5f0f\u5316\u3001\u5206\u652f\u4fdd\u62a4\u3002\u8fd9\u4e00\u5c42\u76f8\u5f53\u4e8e\u300c\u56e2\u961f\u89c4\u8303\u300d\uff0c\u6240\u6709\u4eba\u90fd\u4f1a\u751f\u6548\u3002<\/li>\n\n\n\n<li><strong><code>.claude\/settings.local.json<\/code>\uff08gitignore\uff09<\/strong>\u2014\u2014 \u653e\u4e2a\u4eba\u914d\u7f6e\uff0c\u6bd4\u5982\u901a\u77e5\u65b9\u5f0f\u3001\u81ea\u5b9a\u4e49\u65e5\u5fd7\u3001\u5b9e\u9a8c\u6027 hooks\uff0c\u53ea\u5bf9\u81ea\u5df1\u751f\u6548\u3002<\/li>\n\n\n\n<li><strong><code>~\/.claude\/settings.json<\/code>\uff08\u5168\u5c40\uff09<\/strong>\u2014\u2014 \u653e\u8de8\u9879\u76ee\u7684\u9ed8\u8ba4\u8bbe\u7f6e\uff0c\u6bd4\u5982\u901a\u77e5\u98ce\u683c\u3001\u683c\u5f0f\u5316\u504f\u597d\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u56e2\u961f\u7edf\u4e00\u89c4\u5219\uff08\u7c7b\u4f3c&nbsp;<code>.editorconfig<\/code>\uff09 + \u672c\u5730\u4e2a\u4eba\u914d\u7f6e\uff08\u7c7b\u4f3c IDE \u8bbe\u7f6e\uff09\u3002\u5f53\u5171\u4eab hooks \u56fa\u5316\u5728\u4ed3\u5e93\u91cc\u4e4b\u540e\uff0c\u300c\u5728\u6211\u673a\u5668\u4e0a\u6ca1\u95ee\u9898\u300d\u7684\u60c5\u51b5\u4f1a\u660e\u663e\u51cf\u5c11\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5e38\u89c1\u95ee\u9898\u4e0e\u6545\u969c\u6392\u67e5<\/strong><\/h3>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Hook \u6ca1\u6709\u89e6\u53d1<\/strong><\/h3>\n\n\n\n<p><strong>Matcher \u62fc\u5199\u95ee\u9898<\/strong>\uff1amatcher \u533a\u5206\u5927\u5c0f\u5199\uff0c\u6bd4\u5982&nbsp;<code>\"write\"<\/code>&nbsp;\u4e0d\u4f1a\u5339\u914d&nbsp;<code>Write<\/code>\u3002\u53ef\u4ee5\u7528&nbsp;<code>\/hooks<\/code>&nbsp;\u67e5\u770b\u5b9e\u9645\u7684\u5de5\u5177\u540d\u79f0\u3002<\/p>\n\n\n\n<p><strong>JSON \u683c\u5f0f\u9519\u8bef<\/strong>\uff1a\u5c11\u4e00\u4e2a\u9017\u53f7\u6216\u62ec\u53f7\uff0c\u6574\u4e2a hooks \u53ef\u80fd\u76f4\u63a5\u5931\u6548\uff0c\u800c\u4e14\u6ca1\u6709\u660e\u663e\u63d0\u793a\u3002\u53ef\u4ee5\u7528&nbsp;<code>jq . settings.json<\/code>&nbsp;\u68c0\u67e5\u683c\u5f0f\u3002<\/p>\n\n\n\n<p><strong>\u88ab\u5168\u5c40\u7981\u7528\u4e86<\/strong>\uff1a\u68c0\u67e5\u662f\u5426\u5b58\u5728\uff1a<code>\"disableAllHooks\": true<\/code>\uff0c\u5982\u679c\u6709\uff0c\u6240\u6709 hooks \u90fd\u4e0d\u4f1a\u6267\u884c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Hook \u8fd0\u884c\u4f46\u4e0d\u963b\u6b62<\/strong><\/h3>\n\n\n\n<p><strong>\u9000\u51fa\u7801\u7528\u9519\u4e86<\/strong>\uff1a<code>exit 1<\/code>&nbsp;\u8868\u793a\u300c\u6267\u884c\u51fa\u9519\u300d\uff0c\u4e0d\u662f\u300c\u963b\u6b62\u64cd\u4f5c\u300d\u3002\u5982\u679c\u8981\u62e6\u622a\uff0c\u5fc5\u987b\u7528&nbsp;<code>exit 2<\/code>\u3002\u8fd9\u662f\u6700\u5e38\u89c1\u7684\u5751\u3002<\/p>\n\n\n\n<p><strong>\u6ca1\u6709\u8fd4\u56de\u63d0\u793a\u4fe1\u606f<\/strong>\uff1a\u963b\u6b62\u64cd\u4f5c\u65f6\uff0c\u6700\u597d\u8fd4\u56de\u4e00\u6bb5 JSON\uff0c\u8ba9 Claude \u77e5\u9053\u539f\u56e0\uff1a<code>echo '{\"message\": \"\u963b\u6b62: \u539f\u56e0\"}'<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u65e0\u9650\u5faa\u73af<\/strong><\/h3>\n\n\n\n<p><strong>Stop hook \u89e6\u53d1\u4e86\u65b0\u7684\u64cd\u4f5c<\/strong>\uff1a\u5982\u679c\u4f60\u7684&nbsp;<code>Stop<\/code>&nbsp;hook \u91cc\u53c8\u53bb\u5199\u6587\u4ef6\u3001\u6267\u884c\u547d\u4ee4\uff0c\u53ef\u80fd\u4f1a\u518d\u6b21\u89e6\u53d1 Claude \u7684\u6d41\u7a0b\uff0c\u4ece\u800c\u8fdb\u5165\u5faa\u73af\u3002\u5efa\u8bae&nbsp;<code>Stop<\/code>&nbsp;hook \u53ea\u505a\u300c\u88ab\u52a8\u64cd\u4f5c\u300d\uff0c\u6bd4\u5982\u8bb0\u5f55\u65e5\u5fd7\u3001\u53d1\u9001\u901a\u77e5\u3001\u6e05\u7406\u8d44\u6e90\u3002<\/p>\n\n\n\n<p><strong>PostToolUse hook \u5f15\u53d1\u4e8c\u6b21\u7f16\u8f91<\/strong>\uff1a\u5982\u679c&nbsp;<code>PostToolUse<\/code>&nbsp;hook \u4fee\u6539\u4e86\u6587\u4ef6\uff0c\u5c31\u4f1a\u518d\u6b21\u89e6\u53d1&nbsp;<code>PostToolUse<\/code>\uff0c\u5f62\u6210\u8fde\u9501\u53cd\u5e94\u3002\u5efa\u8bae\u9650\u5236 matcher\uff08\u53ea\u5339\u914d\u7279\u5b9a\u6587\u4ef6\u6216\u64cd\u4f5c\uff09\u6216\u4f7f\u7528&nbsp;<code>if<\/code>&nbsp;\u6761\u4ef6\u907f\u514d\u91cd\u590d\u89e6\u53d1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6027\u80fd\u95ee\u9898<\/strong><\/h3>\n\n\n\n<p><strong>SessionStart \u592a\u91cd<\/strong>\uff1a\u6240\u6709&nbsp;<code>SessionStart<\/code>&nbsp;hooks \u4f1a\u5728\u542f\u52a8\u65f6\u540c\u6b65\u6267\u884c\uff0c\u5982\u679c\u6570\u91cf\u591a\u6216\u903b\u8f91\u590d\u6742\uff0c\u5c31\u4f1a\u62d6\u6162\u542f\u52a8\u3002\u5efa\u8bae\u4f7f\u7528\u8f7b\u91cf\u64cd\u4f5c\uff0c\u6bcf\u4e2a\u6700\u597d\u5728 1 \u79d2\u5185\u5b8c\u6210\u3002<\/p>\n\n\n\n<p><strong>\u70ed\u8def\u5f84\u91cc\u8dd1\u91cd\u811a\u672c<\/strong>\uff1a<code>PreToolUse<\/code>&nbsp;\u548c&nbsp;<code>PostToolUse<\/code>&nbsp;\u4f1a\u9891\u7e41\u89e6\u53d1\uff0c\u5982\u679c\u91cc\u9762\u6709\u7f51\u7edc\u8bf7\u6c42\u6216\u91cd\u8ba1\u7b97\uff0c\u5f88\u5bb9\u6613\u62d6\u6162\u6574\u4f53\u901f\u5ea6\u3002\u5efa\u8bae\u7ed9 hook \u52a0&nbsp;<code>timeout<\/code>\uff08\u6beb\u79d2\uff09\u6216\u8005\u628a\u903b\u8f91\u62c6\u5230 HTTP hook \/ \u540e\u7aef\u670d\u52a1\u91cc\u5904\u7406.<\/p>\n\n\n\n<p><strong>\u6ca1\u6709\u505a\u7f13\u5b58<\/strong>\uff1a\u5982\u679c\u6bcf\u6b21\u90fd\u91cd\u590d\u505a\u540c\u6837\u7684\u68c0\u67e5\uff08\u6bd4\u5982\u67e5\u5f53\u524d\u5206\u652f\u3001\u5224\u65ad\u662f\u5426\u53d7\u4fdd\u62a4\uff09\uff0c\u6027\u80fd\u4f1a\u5f88\u5dee\u3002\u5efa\u8bae\u628a\u7ed3\u679c\u7f13\u5b58\u5230\u4e34\u65f6\u6587\u4ef6\uff0c\u907f\u514d\u6bcf\u6b21\u90fd\u8dd1\u4e00\u904d Git \u6216\u5176\u4ed6\u547d\u4ee4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5f15\u7528\u94fe\u63a5<\/strong><\/h3>\n\n\n\n<p><code>[1]<\/code>&nbsp;awesome-claude-code:&nbsp;<em><a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/github.com\/hesreallyhim\/awesome-claude-code\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/hesreallyhim<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>LINK:https:\/\/zhuanlan.zhihu.com\/p\/2028796296723447848 C [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[67],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/6426"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6426"}],"version-history":[{"count":1,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/6426\/revisions"}],"predecessor-version":[{"id":6427,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/6426\/revisions\/6427"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}