{"id":679,"date":"2026-08-04T17:05:21","date_gmt":"2026-08-04T09:05:21","guid":{"rendered":"https:\/\/subk.me\/?p=679"},"modified":"2026-08-04T17:05:21","modified_gmt":"2026-08-04T09:05:21","slug":"claude-code-%e6%8f%90%e7%a4%ba%e8%af%8d%e6%97%a0%e6%84%9f%e8%87%aa%e5%8a%a8%e5%a4%87%e4%bb%bd%ef%bc%9awindows-%e4%b8%8e-ubuntu-%e5%8f%8c%e5%b9%b3%e5%8f%b0%e9%85%8d%e7%bd%ae%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/subk.me\/?p=679","title":{"rendered":"Claude Code \u63d0\u793a\u8bcd\u65e0\u611f\u81ea\u52a8\u5907\u4efd\uff1aWindows \u4e0e Ubuntu \u53cc\u5e73\u53f0\u914d\u7f6e\u6307\u5357"},"content":{"rendered":"<p>\u5728\u4f7f\u7528 AI \u7f16\u7a0b\u5de5\u5177\uff08\u5982 <strong>Claude Code<\/strong>\uff09\u8fdb\u884c\u591a\u8f6e\u4ea4\u4e92\u65f6\uff0c\u6211\u4eec\u5e38\u5e38\u4f1a\u8f93\u5165\u5927\u91cf\u7cbe\u5fc3\u8c03\u4f18\u7684\u63d0\u793a\u8bcd\uff08Prompts\uff09\u3002\u4f46\u968f\u7740\u5bf9\u8bdd\u4e0d\u65ad\u6df1\u5165\uff0c\u7cfb\u7edf\u751f\u6210\u7684\u4ee3\u7801\u548c\u4e2d\u95f4\u8fc7\u7a0b\u5f80\u5f80\u4f1a\u6324\u6ee1\u7ec8\u7aef\u5c4f\u5e55\uff0c\u60f3\u8981\u56de\u5934\u7ffb\u627e\u81ea\u5df1\u66fe\u7ecf\u6572\u4e0b\u7684\u67d0\u6761\u5173\u952e Prompt \u5c31\u4f1a\u53d8\u5f97\u975e\u5e38\u7e41\u7410\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u75db\u70b9\uff0c\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5229\u7528 Claude Code \u539f\u751f\u7684 <strong>Hook \u673a\u5236<\/strong>\uff0c\u901a\u8fc7\u51e0\u5341\u884c\u6781\u5176\u8f7b\u91cf\u7684 Node.js \u811a\u672c\uff0c\u5b9e\u73b0<strong>\u6bcf\u6b21\u6309\u4e0b Enter \u63d0\u4ea4\u63d0\u793a\u8bcd\u65f6\uff0c\u9759\u9ed8\u3001\u65e0\u611f\u5730\u81ea\u52a8\u8bb0\u5f55\u201c\u65f6\u95f4\u6233 + \u9879\u76ee\u7edd\u5bf9\u8def\u5f84 + \u63d0\u793a\u8bcd\u5185\u5bb9\u201d<\/strong>\uff0c\u5e76\u7edf\u4e00\u4fdd\u5b58\u5230\u672c\u5730\u65e5\u5fd7\u6587\u4ef6\u4e2d\u7684\u65b9\u6848\u3002<\/p>\n<hr \/>\n<h2>\u4e00\u3001 Windows \u73af\u5883\u914d\u7f6e<\/h2>\n<p>Windows \u73af\u5883\u7531\u4e8e\u8def\u5f84\u5206\u9694\u7b26\uff08<code>\\<\/code>\uff09\u548c\u9ed8\u8ba4\u7ec8\u7aef\u7279\u6027\u7684\u5f71\u54cd\uff0c\u4f7f\u7528\u72ec\u7acb JS \u811a\u672c\u8c03\u7528\u7684\u65b9\u5f0f\u6700\u4e3a\u7a33\u5b9a\uff0c\u80fd\u591f\u5f7b\u5e95\u907f\u5f00 JSON \u8f6c\u4e49\u62a5\u9519\u95ee\u9898\u3002<\/p>\n<h3>1. \u521b\u5efa\u72ec\u7acb Hook \u811a\u672c<\/h3>\n<p>\u5728\u8def\u5f84 <code>C:\\Users\\\u4f60\u7684\u7528\u6237\u540d\\.claude\\hooks\\<\/code> \u4e0b\u65b0\u5efa\u6587\u4ef6 <strong><code>log_prompt.js<\/code><\/strong>\uff0c\u5e76\u586b\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre><code class=\"lang-javascript language-javascript javascript\">const fs = require(&#039;fs&#039;);\nconst path = require(&#039;path&#039;);\n\nlet body = &#039;&#039;;\n\/\/ \u76d1\u542c\u6807\u51c6\u8f93\u5165\u6d41\uff0c\u83b7\u53d6 Claude Code \u4f20\u5165\u7684 JSON \u6570\u636e\nprocess.stdin.on(&#039;data&#039;, chunk =&gt; { body += chunk; });\n\nprocess.stdin.on(&#039;end&#039;, () =&gt; {\n  try {\n    if (!body.trim()) return;\n    const data = JSON.parse(body);\n\n    \/\/ \u517c\u5bb9\u4e0d\u540c\u7248\u672c\u7684 Prompt \u5b57\u6bb5\u4f4d\u7f6e\n    const prompt = data.prompt || data.content || (data.message &amp;&amp; data.message.content);\n    if (!prompt) return;\n\n    \/\/ \u83b7\u53d6\u5f53\u524d\u9879\u76ee\u7edd\u5bf9\u8def\u5f84\u5e76\u89c4\u8303\u5316 Windows \u659c\u6760\u683c\u5f0f\n    const cwd = data.cwd || process.cwd();\n    const fullProjectPath = path.normalize(cwd);\n\n    \/\/ \u683c\u5f0f\u5316\u672c\u5730\u65f6\u95f4 (\u5982 2026\/8\/4 16:15:00)\n    const now = new Date();\n    const timeStr = now.toLocaleString(&#039;zh-CN&#039;, { hour12: false });\n\n    \/\/ \u62fc\u63a5\u65e5\u5fd7\u6761\u76ee\n    const logEntry = `[${timeStr}] [${fullProjectPath}]\\n${prompt}\\n----------------------------------------\\n`;\n\n    \/\/ \u5199\u5165\u65e5\u5fd7\u5230 C:\\Users\\\u4f60\u7684\u7528\u6237\u540d\\.claude\\my_prompts.log\n    const logPath = path.join(process.env.USERPROFILE || &#039;C:\/Users\/&#039; + process.env.USERNAME, &#039;.claude&#039;, &#039;my_prompts.log&#039;);\n    fs.appendFileSync(logPath, logEntry, &#039;utf8&#039;);\n  } catch (err) {\n    \/\/ \u53d1\u751f\u5f02\u5e38\u65f6\u9759\u9ed8\u5ffd\u7565\uff0c\u4e0d\u5e72\u6270\u4e3b\u7a0b\u5e8f\n  }\n});\n<\/code><\/pre>\n<h3>2. \u4fee\u6539\u914d\u7f6e\u6587\u4ef6 <code>settings.json<\/code><\/h3>\n<p>\u6253\u5f00 <code>C:\\Users\\\u4f60\u7684\u7528\u6237\u540d\\.claude\\settings.json<\/code>\uff0c\u5728\u914d\u7f6e\u4e2d\u8865\u9f50 <code>hooks<\/code> \u8282\u70b9\u7684\u6ce8\u518c\uff1a<\/p>\n<pre><code class=\"lang-json language-json json\">{\n  &quot;env&quot;: {\n    &quot;CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC&quot;: &quot;1&quot;\n  },\n  &quot;includeCoAuthoredBy&quot;: false,\n  &quot;model&quot;: &quot;opus&quot;,\n  &quot;statusLine&quot;: {\n    &quot;type&quot;: &quot;command&quot;,\n    &quot;command&quot;: &quot;node C:\/Users\/\u4f60\u7684\u7528\u6237\u540d\/.claude\/hooks\/statusline.js&quot;\n  },\n  &quot;hooks&quot;: {\n    &quot;UserPromptSubmit&quot;: [\n      {\n        &quot;matcher&quot;: &quot;&quot;,\n        &quot;hooks&quot;: [\n          {\n            &quot;type&quot;: &quot;command&quot;,\n            &quot;command&quot;: &quot;node C:\/Users\/\u4f60\u7684\u7528\u6237\u540d\/.claude\/hooks\/log_prompt.js&quot;\n          }\n        ]\n      }\n    ]\n  }\n}\n<\/code><\/pre>\n<blockquote>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u8bf7\u5c06\u4e0a\u8ff0\u914d\u7f6e\u4e2d\u7684 <code>\u4f60\u7684\u7528\u6237\u540d<\/code> \u66ff\u6362\u4e3a\u4f60 Windows \u7cfb\u7edf\u5b9e\u9645\u7684\u7528\u6237\u540d\uff08\u5982 <code>subk<\/code>\uff09\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h2>\u4e8c\u3001 Ubuntu \/ Linux \u73af\u5883\u914d\u7f6e<\/h2>\n<p>Ubuntu \u73af\u5883\u4e0b\u652f\u6301\u6807\u51c6\u7684\u7c7b Unix \u8def\u5f84\u8868\u793a\uff08\u5982 <code>~<\/code> \u548c <code>\/home\/username\/<\/code>\uff09\uff0c\u811a\u672c\u903b\u8f91\u9ad8\u5ea6\u901a\u7528\u3002<\/p>\n<h3>1. \u521b\u5efa\u72ec\u7acb Hook \u811a\u672c<\/h3>\n<p>\u5728 Linux \u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u81ea\u52a8\u521b\u5efa\u76ee\u5f55\u5e76\u751f\u6210 <strong><code>~\/.claude\/hooks\/log_prompt.js<\/code><\/strong>\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">mkdir -p ~\/.claude\/hooks\n\ncat &lt;&lt; &#039;EOF&#039; &gt; ~\/.claude\/hooks\/log_prompt.js\nconst fs = require(&#039;fs&#039;);\nconst path = require(&#039;path&#039;);\nconst os = require(&#039;os&#039;);\n\nlet body = &#039;&#039;;\n\/\/ \u76d1\u542c\u6807\u51c6\u8f93\u5165\u83b7\u53d6 JSON \u683c\u5f0f\u6570\u636e\nprocess.stdin.on(&#039;data&#039;, chunk =&gt; { body += chunk; });\n\nprocess.stdin.on(&#039;end&#039;, () =&gt; {\n  try {\n    if (!body.trim()) return;\n    const data = JSON.parse(body);\n\n    \/\/ \u517c\u5bb9\u4e0d\u540c\u7248\u672c\u7684\u5b57\u6bb5\u540d\u79f0\n    const prompt = data.prompt || data.content || (data.message &amp;&amp; data.message.content);\n    if (!prompt) return;\n\n    \/\/ \u83b7\u53d6\u9879\u76ee\u7edd\u5bf9\u8def\u5f84 (Linux \u6807\u51c6\u6b63\u659c\u6760)\n    const cwd = data.cwd || process.cwd();\n    const fullProjectPath = path.resolve(cwd);\n\n    \/\/ \u683c\u5f0f\u5316\u65f6\u95f4 (\u5982 2026\/8\/4 16:40:00)\n    const now = new Date();\n    const timeStr = now.toLocaleString(&#039;zh-CN&#039;, { hour12: false });\n\n    \/\/ \u62fc\u63a5\u683c\u5f0f\u5316\u7684\u65e5\u5fd7\u5185\u5bb9\n    const logEntry = `[${timeStr}] [${fullProjectPath}]\\n${prompt}\\n----------------------------------------\\n`;\n\n    \/\/ \u81ea\u52a8\u8ffd\u52a0\u5199\u5165\u5230 ~\/.claude\/my_prompts.log\n    const logPath = path.join(os.homedir(), &#039;.claude&#039;, &#039;my_prompts.log&#039;);\n    fs.appendFileSync(logPath, logEntry, &#039;utf8&#039;);\n  } catch (err) {\n    \/\/ \u9759\u9ed8\u5904\u7406\u89e3\u6790\u6216\u5199\u5165\u5f02\u5e38\n  }\n});\nEOF\n<\/code><\/pre>\n<h3>2. \u4fee\u6539\u914d\u7f6e\u6587\u4ef6 <code>settings.json<\/code><\/h3>\n<p>\u4fee\u6539 Ubuntu \u4e0b\u7684 <code>~\/.claude\/settings.json<\/code> \u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"lang-json language-json json\">{\n  &quot;env&quot;: {\n    &quot;CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC&quot;: &quot;1&quot;\n  },\n  &quot;includeCoAuthoredBy&quot;: false,\n  &quot;model&quot;: &quot;opus&quot;,\n  &quot;statusLine&quot;: {\n    &quot;command&quot;: &quot;~\/.claude\/statusline.sh&quot;,\n    &quot;timeout&quot;: 10,\n    &quot;type&quot;: &quot;command&quot;\n  },\n  &quot;hooks&quot;: {\n    &quot;UserPromptSubmit&quot;: [\n      {\n        &quot;matcher&quot;: &quot;&quot;,\n        &quot;hooks&quot;: [\n          {\n            &quot;type&quot;: &quot;command&quot;,\n            &quot;command&quot;: &quot;node ~\/.claude\/hooks\/log_prompt.js&quot;\n          }\n        ]\n      }\n    ]\n  }\n}\n<\/code><\/pre>\n<hr \/>\n<h2>\u4e09\u3001 \u914d\u7f6e\u751f\u6548\u4e0e\u65e5\u5fd7\u67e5\u770b<\/h2>\n<p>\u5b8c\u6210\u4e0a\u8ff0\u914d\u7f6e\u540e\uff0c<strong>\u91cd\u542f Claude Code \u547d\u4ee4\u884c<\/strong>\u3002<\/p>\n<p>\u6bcf\u5f53\u4f60\u5728\u7ec8\u7aef\u4e2d\u63d0\u4ea4\u4e00\u6761 Prompt\uff0c\u811a\u672c\u5c31\u4f1a\u5728\u540e\u53f0\u5f02\u6b65\u5730\u5c06\u8f93\u5165\u5199\u5165\u5230\u5404\u81ea\u73af\u5883\u4e0b\u7684\u65e5\u5fd7\u4e2d\uff1a<\/p>\n<ul>\n<li><strong>Windows \u65e5\u5fd7\u6587\u4ef6\u8def\u5f84<\/strong>\uff1a<code>C:\\Users\\\u4f60\u7684\u7528\u6237\u540d\\.claude\\my_prompts.log<\/code><\/li>\n<li><strong>Ubuntu \u65e5\u5fd7\u6587\u4ef6\u8def\u5f84<\/strong>\uff1a<code>~\/.claude\/my_prompts.log<\/code><\/li>\n<\/ul>\n<h3>\u6700\u7ec8\u7684\u6548\u679c\u5c55\u793a\uff1a<\/h3>\n<pre><code class=\"lang-text language-text text\">[2026\/8\/4 16:15:09] [C:\\Users\\subk\\ai_coding\\temp]\n\u9879\u76ee\u540d\u79f0\u6211\u60f3\u628a\u7edd\u5bf9\u8def\u5f84\u4e5f\u5e26\u4e0a\uff0c\u4fee\u6539\u54ea\u4e2a\uff1f\n----------------------------------------\n[2026\/8\/4 16:40:22] [\/home\/subk\/projects\/my-web-app]\n\u5e2e\u6211\u4f7f\u7528 TypeScript \u91cd\u6784\u8fd9\u4e2a API \u8bf7\u6c42\u7684\u6838\u5fc3\u65b9\u6cd5\n----------------------------------------\n<\/code><\/pre>\n<h3>\u4e3a\u4ec0\u4e48\u9009\u62e9\u8fd9\u4e2a\u65b9\u6848\uff1f<\/h3>\n<ol>\n<li><strong>\u7eaf\u539f\u751f\u7406\u5ff5<\/strong>\uff1a\u65e0\u9700\u5b89\u88c5\u793e\u533a\u9891\u7e41\u66f4\u65b0\u3001\u7248\u672c\u4e0d\u517c\u5bb9\u7684\u5404\u79cd Marketplace \u63d2\u4ef6\u3002<\/li>\n<li><strong>\u7edd\u5bf9\u7a33\u5b9a<\/strong>\uff1a\u5229\u7528 Node.js \u539f\u751f API \u6587\u4ef6\u8ffd\u52a0\uff0c\u96f6\u4f9d\u8d56\uff0c\u8de8\u5e73\u53f0\u3002<\/li>\n<li><strong>\u6781\u901f\u65e0\u611f<\/strong>\uff1a\u57fa\u4e8e <code>UserPromptSubmit<\/code> \u4e8b\u4ef6\uff0c\u5728\u540e\u53f0\u9759\u9ed8\u8fd0\u884c\uff0c\u5b8c\u5168\u4e0d\u963b\u585e\u4ea4\u4e92\u4f53\u9a8c\u3002<\/li>\n<\/ol>","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528 AI \u7f16\u7a0b\u5de5\u5177\uff08\u5982 Claude Code\uff09\u8fdb\u884c\u591a\u8f6e\u4ea4\u4e92\u65f6\uff0c\u6211\u4eec\u5e38\u5e38\u4f1a\u8f93\u5165\u5927\u91cf\u7cbe\u5fc3\u8c03\u4f18\u7684\u63d0\u793a\u8bcd\uff08Pro [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-679","post","type-post","status-publish","format-standard","hentry","category-it"],"_links":{"self":[{"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/posts\/679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/subk.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=679"}],"version-history":[{"count":1,"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/posts\/679\/revisions"}],"predecessor-version":[{"id":680,"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/posts\/679\/revisions\/680"}],"wp:attachment":[{"href":"https:\/\/subk.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/subk.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/subk.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}