{"id":532,"date":"2025-10-31T07:00:00","date_gmt":"2025-10-30T23:00:00","guid":{"rendered":"https:\/\/smartaiunion.com\/?p=532"},"modified":"2025-10-29T11:43:42","modified_gmt":"2025-10-29T03:43:42","slug":"%e5%a6%82%e4%bd%95%e5%bc%80%e5%8f%91%e4%b8%80%e4%b8%aa%e8%87%aa%e5%b7%b1%e7%9a%84-claude-code","status":"publish","type":"post","link":"https:\/\/smartaiunion.com\/index.php\/2025\/10\/31\/532\/","title":{"rendered":"\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u5df1\u7684 claude code"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u5b66\u4e60\u672c\u6587\u53ef\u80fd\u7684\u6536\u83b7<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7406\u89e3 Claude Code \u7684\u57fa\u672c\u539f\u7406\uff0c\u4ece\u800c\u66f4\u719f\u7ec3\u5730\u8fd0\u7528\u5b83\uff1b<\/li>\n\n\n\n<li>\u5b66\u4e60 ReAct \u6a21\u578b\u4e0e\u57fa\u7840\u5de5\u5177 tool \u5f00\u53d1\uff0c\u672a\u6765\u4f60\u4e5f\u53ef\u4ee5\u5c1d\u8bd5\u6784\u5efa\u4e00\u4e9b\u5b9e\u7528\u5c0f\u5de5\u5177\uff0c\u4f8b\u5982\u4ee3\u7801\u5206\u6790\u5668\u3001\u7ed3\u5408\u4e1a\u52a1\u77e5\u8bc6\u5e93\u7684\u667a\u80fd\u95ee\u7b54\u7cfb\u7edf\uff08Agentic RAG\uff09\u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u67e5\u770b\uff1a<a href=\"https:\/\/link.juejin.cn\/?target=https%3A%2F%2Fgithub.com%2Fhellosean1025%2Fcodeai\" target=\"_blank\" rel=\"noreferrer noopener\">\u6e90\u7801<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">mini\u7248\u672c\u80fd\u529b<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u652f\u6301\u591a\u8f6e\u5bf9\u8bdd\uff0c\u53ef\u5b8c\u6210\u5e38\u89c1\u7684\u4ee3\u7801\u5206\u6790\u3001\u529f\u80fd\u5f00\u53d1\u3001\u6587\u6863\u751f\u6210\u7b49\u4efb\u52a1\uff1b<\/li>\n\n\n\n<li>\u96c6\u6210\u5e38\u7528\u5de5\u5177\uff0c\u5982\u6587\u672c\u5904\u7406\u3001\u5f85\u529e\u7ba1\u7406\u3001\u4efb\u52a1\u6267\u884c\u4e0e\u641c\u7d22\u7b49\uff1b<\/li>\n\n\n\n<li>\u652f\u6301\u5b50\u4ee3\u7406\u4efb\u52a1\u8c03\u5ea6\u673a\u5236\uff1b<\/li>\n\n\n\n<li>\u5177\u5907\u4e00\u5b9a\u7684\u5f02\u5e38\u81ea\u9002\u5e94\u80fd\u529b\uff0c\u80fd\u591f\u5e94\u5bf9\u5e38\u89c1\u7684\u89c4\u5212\u5931\u8d25\u3001\u5de5\u5177\u6267\u884c\u9519\u8bef\u7b49\u95ee\u9898\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528<\/h3>\n\n\n\n<p>1.\u5728 zshrc \u914d\u7f6etoken\uff0c\u7136\u540e source ~\/.zshrc<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash\u4f53\u9a8cAI\u4ee3\u7801\u52a9\u624b\u4ee3\u7801\u89e3\u8bfb\u590d\u5236\u4ee3\u7801<code>export CODEAI_BASE_URL=\"\"\nexport CODEAI_AUTH_TOKEN=\"{{apikey}}\"\nexport CODEAI_MODEL_ID=\"\"\n<\/code><\/pre>\n\n\n\n<p>2.\u5b89\u88c5\u548c\u542f\u52a8<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash\u4f53\u9a8cAI\u4ee3\u7801\u52a9\u624b\u4ee3\u7801\u89e3\u8bfb\u590d\u5236\u4ee3\u7801<code>npm i -g mycodeai #Node \u7248\u672c\u9700\u8981 &gt;= 22\nmycodeai # \u542f\u52a8\n<\/code><\/pre>\n\n\n\n<p>3.\u4e8c\u6b21\u5f00\u53d1 \u6e90\u7801\uff1a<a href=\"https:\/\/link.juejin.cn\/?target=https%3A%2F%2Fgithub.com%2Fhellosean1025%2Fcodeai\" target=\"_blank\" rel=\"noreferrer noopener\">github.com\/hellosean10\u2026<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Claude Code \u539f\u7406\u7b80\u5355\u4ecb\u7ecd<\/h2>\n\n\n\n<p>Claude Code \u91c7\u7528\u4e86<strong>\u591a\u5c42<\/strong>&nbsp;<strong>\u667a\u80fd\u4f53<\/strong>&nbsp;<strong>\uff08Multi-Agent\uff09\u7684<\/strong>&nbsp;<strong>ReAct<\/strong>&nbsp;<strong>\u67b6\u6784\uff0c<\/strong>&nbsp;\u57fa\u4e8e ReAct \u67b6\u6784\u548c\u5408\u7406\u7684 tools \u8bbe\u8ba1\uff0c\u6d8c\u73b0\u4e86\u975e\u51e1\u7684\u667a\u80fd coding \u80fd\u529b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ReAct \u4ecb\u7ecd\uff1a<\/h3>\n\n\n\n<p>ReAct \u5c06\u95ee\u9898\u89e3\u51b3\u8fc7\u7a0b\u5206\u89e3\u4e3a\u5faa\u73af\u8fed\u4ee3\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u601d\u8003\uff08Thought\uff09<\/strong>\u00a0&#8211; \u6a21\u578b\u5206\u6790\u5f53\u524d\u72b6\u6001\uff0c\u63a8\u7406\u4e0b\u4e00\u6b65\u5e94\u8be5\u505a\u4ec0\u4e48<\/li>\n\n\n\n<li><strong>\u884c\u52a8\uff08Action\uff09<\/strong>\u00a0&#8211; \u6267\u884c\u5177\u4f53\u64cd\u4f5c\uff08\u5982\u8fd0\u884c\u4ee3\u7801\u3001\u8bfb\u53d6\u6587\u4ef6\u3001\u641c\u7d22\u6587\u6863\uff09<\/li>\n\n\n\n<li><strong>\u89c2\u5bdf\uff08Observation\uff09<\/strong>\u00a0&#8211; \u83b7\u53d6\u884c\u52a8\u7684\u7ed3\u679c\u53cd\u9988<\/li>\n\n\n\n<li><strong>\u518d\u601d\u8003<\/strong>\u00a0&#8211; \u57fa\u4e8e\u89c2\u5bdf\u7ed3\u679c\u7ee7\u7eed\u63a8\u7406&#8230;<\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u4e2a\u5faa\u73af\u6301\u7eed\u8fdb\u884c\uff0c\u76f4\u5230\u95ee\u9898\u89e3\u51b3\u3002&nbsp;<img decoding=\"async\" src=\"https:\/\/p6-xtjj-sign.byteimg.com\/tos-cn-i-73owjymdk6\/849e5f7dcf5648b39b9ab25cc72cb2b9~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgc2Vhbg==:q75.awebp?rk3s=f64ab15b&amp;x-expires=1762217513&amp;x-signature=AF01oyxdCx9St9JeKmooyeHaMC4%3D\" alt=\"image.png\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Multi-Agent\u67b6\u6784\u4ecb\u7ecd\uff1a<\/strong><\/h3>\n\n\n\n<p>\u5c3d\u7ba1\u591a\u667a\u80fd\u4f53\u7cfb\u7edf\u6b63\u5927\u884c\u5176\u9053\uff0cClaude Code \u5728 multi-agent \u8bbe\u8ba1\u4e0a\u975e\u5e38\u514b\u5236\uff0c\u53ea\u6709\u4e00\u4e2a\u4e3bagent\u3002\u5b83\u7ef4\u62a4\u7684\u662f\u4e00\u4e2a\u6241\u5e73\u7684\u4efb\u52a1\u5217\u8868\u3002\u5f53\u9047\u5230\u6bd4\u8f83\u590d\u6742\u4efb\u52a1\u65f6\uff0c\u4f1a\u884d\u751f\u65b0\u7684\u5b50 agent\u6765\uff0c\u4f46\u5b50 Agent \u7684\u5b50\u4efb\u52a1\u65e0\u6cd5\u521b\u5efa\u65b0\u7684\u5206\u652f\u3002&nbsp;<img decoding=\"async\" src=\"https:\/\/p6-xtjj-sign.byteimg.com\/tos-cn-i-73owjymdk6\/33cab6ef3010403bab015c53de610dd1~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgc2Vhbg==:q75.awebp?rk3s=f64ab15b&amp;x-expires=1762217513&amp;x-signature=gCmUnG4V4zswW%2B6meKpvMXuzbzs%3D\" alt=\"image.png\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4efb\u52a1\u62c6\u5206\u601d\u60f3<\/h3>\n\n\n\n<p>Claude code \u672c\u8eab\u662f\u5bf9\u51fd\u6570\u5f0f\u7ec4\u5408\u601d\u60f3\u7684\u4e00\u79cd\u5b9e\u8df5\uff0c\u5c06\u4e00\u4e2a\u6a21\u7cca\u7684\u5927\u578b\u4efb\u52a1\u9700\u6c42\u62c6\u5206\u4e3a\u5c0f\u4efb\u52a1\u51fd\u6570\uff0c\u63d0\u5347\u4e86\u4efb\u52a1\u7684\u786e\u5b9a\u6027\u548c\u51c6\u786e\u6027\u3002\u8f93\u5165\u662f\u9700\u6c42\u63cf\u8ff0\uff0c\u8f93\u51fa\u662f\u4ee3\u7801\u4ea7\u51fa\uff0cCode Agent \u901a\u8fc7\u89c4\u5212\u3001\u601d\u8003\u548c\u6267\u884c\u4e00\u6b65\u4e00\u6b65\u5b9e\u73b0\u76ee\u6807.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/p6-xtjj-sign.byteimg.com\/tos-cn-i-73owjymdk6\/e085032e249745338ff1c936cbb82094~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgc2Vhbg==:q75.awebp?rk3s=f64ab15b&amp;x-expires=1762217513&amp;x-signature=8FAoY2S8iDvy3BuG6lhYHKlHeIY%3D\" alt=\"image.png\"\/><\/figure>\n\n\n\n<p><strong>\u8fc7\u7a0b\u6a21\u62df\uff1a<\/strong>&nbsp;<strong>\u4eba\uff08\u8f93\u5165\uff09\uff1a<\/strong>&nbsp;\u8bf7\u5e2e\u5fd9\u5f00\u53d1\u4e00\u4e2a\u5546\u54c1\u5217\u8868\u9875\u9762<\/p>\n\n\n\n<p><strong>AI<\/strong>&nbsp;<strong>\uff08\u8f93\u51fa\u8fc7\u7a0b\uff09\uff1a<\/strong>&nbsp;\u592a\u96be\u4e86\uff0c\u4f46\u6211\u53ef\u4ee5\u62c6\u89e3\u4efb\u52a1\uff0c\u6309\u4eba\u7c7b\u4e00\u822c\u5f00\u53d1\u6765\u8bf4\uff0c\u6211\u751f\u6210\u5982\u4e0b\u4efb\u52a1\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u786e\u5b9a\u6280\u672f\u6808 React TS\u548c\u5b89\u88c5\u4f9d\u8d56<\/li>\n\n\n\n<li>\u786e\u5b9a\u4ee3\u7801\u76ee\u5f55<\/li>\n\n\n\n<li>\u5f00\u53d1\u7ec4\u4ef6\uff08\u7b5b\u9009\u3001\u5217\u8868\uff09<\/li>\n\n\n\n<li>\u6d4b\u8bd5\u4ee3\u7801<\/li>\n\n\n\n<li>\u5b8c\u6210<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u6280\u672f\u8bbe\u8ba1<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">ReAct \u8bbe\u8ba1<\/h3>\n\n\n\n<p>\u7531\u539f\u7406\u4ecb\u7ecd\u53ef\u77e5\uff0cclaude code ReAct \u6a21\u5f0f\u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u51fd\u6570\u5f0f\u7ec4\u5408\u601d\u60f3\uff0c\u6240\u4ee5\u6211\u4eec\u4e3b\u4f53\u67b6\u6784\u91c7\u7528\u51fd\u6570\u5f0f\u7f16\u7a0b\u65b9\u5f0f\uff1b<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/p6-xtjj-sign.byteimg.com\/tos-cn-i-73owjymdk6\/bd03f9e71bcd4990aab44d7d8ee5409a~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgc2Vhbg==:q75.awebp?rk3s=f64ab15b&amp;x-expires=1762217513&amp;x-signature=LWPrRVWX4fCgqSpB4r%2BldKqxZO4%3D\" alt=\"image.png\">&nbsp;\u6211\u4eec\u5c06\u4f1a\u8bbe\u8ba1\u4e00\u4e2a query\u51fd\u6570\uff0c\u8d1f\u8d23\u89c4\u5212\u4efb\u52a1\u548c\u6267\u884c tools<\/p>\n\n\n\n<p>\u6838\u5fc3\u601d\u8def\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u89c2\u5bdf\u548c\u6267\u884c\u9636\u6bb5\uff1a\u6839\u636e\u7528\u6237\u548cAI\u52a9\u624b\u6d88\u606f\uff0c\u8ba9 ai \u81ea\u884c\u5224\u65ad\u63a5\u4e0b\u6765\u8981\u505a\u7684\u4e8b\u60c5<\/li>\n\n\n\n<li>Tools: \u6839\u636e\u89c4\u5212\u7684 tools \u62c6\u5206\u4e3a\u53ef\u5e76\u884c\u6267\u884c\u7684 tools\u548c\u4e32\u884c\u6267\u884c\u7684 tools\uff0c\u5206\u522b\u6267\u884c<\/li>\n\n\n\n<li>\u9012\u5f52\uff1a\u5728\u6267\u884c\u5b8c\u6210tools\u540e\uff0c\u9012\u5f52\u5230\u4e0b\u4e00\u4e2aQuery\u51fd\u6570\uff0c\u4e0b\u4e00\u4e2a Query \u51fd\u6570\u6839\u636e\u4e0a\u4e00\u4e2a\u6267\u884c\u7ed3\u679c\u7ee7\u7eed<\/li>\n\n\n\n<li>\u6a21\u578b\u63d0\u793a\u8bcd\uff1a\u76f4\u63a5\u4f7f\u7528 claude code \u53cd\u7f16\u8bd1\u7248\u672c<\/li>\n<\/ul>\n\n\n\n<p>\u6838\u5fc3\u6e90\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php\u4f53\u9a8cAI\u4ee3\u7801\u52a9\u624b\u4ee3\u7801\u89e3\u8bfb\u590d\u5236\u4ee3\u7801<code>async function* queryInternal(\n  messages: Message[],\n  systemPrompt: string,\n  tools: Tool[],\n  context: QueryContext\n): AsyncGenerator&lt;Message, void, unknown&gt; {\n  const { iteration, maxIterations, verbose } = context;\n\n\n  const vercelMessages = convertToVercelMessages(messages);\n\n  const vercelTools = await convertToVercelAITools(tools, {\n    safeMode: false,\n  });\n\n  let result;\n  try {\n    \/\/ \u7b2c\u4e00\u6b65\uff0c\u89c2\u5bdf\u548c\u89c4\u5212\u4efb\u52a1\n    result = await generateText({\n      model: agentModel,\n      messages: vercelMessages,\n      tools: vercelTools,\n      system: systemPrompt\n    });\n  } catch (error) {\n    const errorMsg = error instanceof Error ? error.message : String(error);\n    if (verbose) {\n      console.error('[LLM] Request failed:', errorMsg);\n    }\n\n    const errorMessage: Message = {\n      type: 'assistant',\n      content: ` Failed to get response from LLM: ${errorMsg}`,\n    };\n\n    yield errorMessage;\n\n    \/\/ \u5f02\u5e38\u5904\u7406\uff0c\u9012\u5f52\u6267\u884c\n    yield* queryInternal([...messages, {\n      type: 'user',\n      content: `Execution failed, Please analyze the error and try a different approach fixed: \\n --- \\n ${errorMsg}\\n`,\n    }], systemPrompt, tools, {\n      iteration: iteration + 1,\n      maxIterations,\n      verbose,\n    });\n    \n    return;\n  }\n\n  const content = result.text;\n\n  \/\/ \u5982\u679c\u4efb\u52a1\u5df2\u4e0d\u8bbe\u53ca\u5de5\u5177\u8c03\u7528\uff0c\u5224\u65ad\u4efb\u52a1\u5df2\u5b8c\u6210\n  if (toolUses.length === 0) {\n    if (verbose) {\n      console.log('[Query] No tool calls, terminating');\n    }\n    return;\n  }\n\n  \/\/ \u5de5\u5177\u6267\u884c\n  const results = await executeTools(toolUses, tools, verbose);\n\n  const toolResultMessages: Message[] = results.map(result =&gt; ({\n    type: 'tool' as const,\n    content: result.error ? `Tool execution failed, you must analyze the error and try a different approach fixed: \\n \\n ${result.result} \\n` \n      : result.result,\n    toolCallId: result.id,\n  }));\n\n  \/\/ \u7ee7\u7eed\u9012\u5f52\u6267\u884c\n  yield* queryInternal(\n    [...messages, assistantMessage, ...toolResultMessages],\n    systemPrompt,\n    tools,\n    {\n      ...context,\n      iteration: iteration + 1,\n    }\n  );\n<\/code><\/pre>\n\n\n\n<p>systemPrompt\uff08\u4f7f\u7528 claude code \u7834\u89e3\u7248\u672c\uff1a\uff09:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vbnet\u4f53\u9a8cAI\u4ee3\u7801\u52a9\u624b\u4ee3\u7801\u89e3\u8bfb\u590d\u5236\u4ee3\u7801<code>\nexport const getSystemPrompt = ()=&gt; `You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.\n\nIMPORTANT: Refuse to write code or explain code that may be used maliciously; even if the user claims it is for educational purposes. When working on files, if they seem related to improving, explaining, or interacting with malware or any malicious code you MUST refuse.\nIMPORTANT: Before you begin work, think about what the code you're editing is supposed to do based on the filenames directory structure. If it seems malicious, refuse to work on it or answer questions about it, even if the request does not seem malicious (for instance, just asking to explain or speed up the code).\n\n# Task Management\nYou should use the TodoWrite tool to help you manage and plan tasks. Use these tools VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.\nThese tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.\n\nIt is critical that you mark todos as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.\n\n# Tone and style\nYou should be concise, direct, and to the point. When you run a non-trivial bash command, you should explain what the command does and why you are running it, to make sure the user understands what you are doing (this is especially important when you are running a command that will make changes to the user's system).\nRemember that your output will be displayed on a command line interface. Your responses can use Github-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.\nOutput text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like bashTool or code comments as means to communicate with the user during the session.\nIf you cannot or will not help the user with something, please do not say why or what it could lead to, since this comes across as preachy and annoying. Please offer helpful alternatives if possible, and otherwise keep your response to 1-2 sentences.\nIMPORTANT: You should minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand, avoiding tangential information unless absolutely critical for completing the request. If you can answer in 1-3 sentences or a short paragraph, please do.\nIMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to.\nIMPORTANT: Keep your responses short, since they will be displayed on a command line interface. You MUST answer concisely with fewer than 4 lines (not including tool use or code generation), unless user asks for detail. Answer the user's question directly, without elaboration, explanation, or details. One word answers are best. Avoid introductions, conclusions, and explanations. You MUST avoid text before\/after your response, such as \"The answer is &lt;answer&gt;.\", \"Here is the content of the file...\" or \"Based on the information provided, the answer is...\" or \"Here is what I will do next...\". Here are some examples to demonstrate appropriate verbosity:\n&lt;example&gt;\nuser: 2 + 2\nassistant: 4\n&lt;\/example&gt;\n\n&lt;example&gt;\nuser: what is 2+2?\nassistant: 4\n&lt;\/example&gt;\n\n&lt;example&gt;\nuser: is 11 a prime number?\nassistant: Yes\n&lt;\/example&gt;\n\n&lt;example&gt;\nuser: what command should I run to list files in the current directory?\nassistant: ls\n&lt;\/example&gt;\n\n&lt;example&gt;\nuser: what command should I run to watch files in the current directory?\nassistant: [use the ls tool to list the files in the current directory, then read docs\/commands in the relevant file to find out how to watch files]\nnpm run dev\n&lt;\/example&gt;\n\n&lt;example&gt;\nuser: How many golf balls fit inside a jetta?\nassistant: 150000\n&lt;\/example&gt;\n\n&lt;example&gt;\nuser: what files are in the directory src\/?\nassistant: [runs ls and sees foo.c, bar.c, baz.c]\nuser: which file contains the implementation of foo?\nassistant: src\/foo.c\n&lt;\/example&gt;\n\n&lt;example&gt;\nuser: write tests for new feature\nassistant: [uses grep and glob search tools to find where similar tests are defined, uses concurrent read file tool use blocks in one tool call to read relevant files at the same time, uses edit file tool to write new tests]\n&lt;\/example&gt;\n\n# Proactiveness\nYou are allowed to be proactive, but only when the user asks you to do something. You should strive to strike a balance between:\n1. Doing the right thing when asked, including taking actions and follow-up actions\n2. Not surprising the user with actions you take without asking\nFor example, if the user asks you how to approach something, you should do your best to answer their question first, and not immediately jump into taking actions.\n3. Do not add additional code explanation summary unless requested by the user. After working on a file, just stop, rather than providing an explanation of what you did.\n\n# Code style\n- Do not add comments to the code you write, unless the user asks you to, or the code is complex and requires additional context.\n\n# Doing tasks\nThe user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:\n- [IMPORTANT]Use the TodoWrite tool to plan the task if required\n\nNEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive.\n\n- Tool results and user messages may include &lt;system-reminder&gt; tags. &lt;system-reminder&gt; tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.\n\n# Tool usage policy\n- When doing file search, prefer to use the Task tool in order to reduce context usage.\n- You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance.\n- When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run \"git status\" and \"git diff\", send a single message with two tool calls to run the calls in parallel.\n- It is always better to speculatively read multiple files as a batch that are potentially useful.\n- It is always better to speculatively perform multiple searches as a batch that are potentially useful.\n- For making multiple edits to the same file, prefer using the MultiEdit tool over multiple Edit tool calls.\n\nYou MUST answer concisely with fewer than 4 lines of text (not including tool use or code generation), unless user asks for detail.\n\n${getEnvInfo()}\n`;\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Tools \u8bbe\u8ba1<\/h3>\n\n\n\n<p>\u57fa\u4e8e\u51fd\u6570\u5f0f\u7f16\u7a0b\u601d\u60f3\uff0c\u5b9a\u4e49tool\u53c2\u6570\u548c\u6267\u884c\u903b\u8f91 \u901a\u8fc7\u589e\u52a0 readonly \u5c5e\u6027\uff0c\u5224\u65adtool\u662f\u5426\u80fd\u5e76\u884c\u6267\u884c\uff0c\u52a0\u5feb\u6027\u80fd<\/p>\n\n\n\n<p>Read tool \u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">typescript\u4f53\u9a8cAI\u4ee3\u7801\u52a9\u624b\u4ee3\u7801\u89e3\u8bfb\u590d\u5236\u4ee3\u7801<code>import { z } from \"zod\";\nimport { readFile } from \"fs\/promises\";\nimport { Tool } from \"..\/query.js\";\n\nexport const readTool: Tool = {\n  name: \"read\",\n  description: \"Read the contents of a file from the filesystem\",\n  inputSchema: z.object({\n    file_path: z.string().describe(\"The absolute path to the file to read\"),\n    offset: z.number().optional().describe(\"The line number to start reading from (0-based)\"),\n    limit: z.number().optional().describe(\"The maximum number of lines to read\"),\n  }),\n  isReadOnly: () =&gt; true,\n  execute: async (input: { file_path: string; offset?: number; limit?: number }) =&gt; {\n    try {\n      const content = await readFile(input.file_path, \"utf-8\");\n      const lines = content.split(\"\\n\");\n\n      const startLine = input.offset ?? 0;\n      const endLine = input.limit ? startLine + input.limit : lines.length;\n      const selectedLines = lines.slice(startLine, endLine);\n\n      const formatted = selectedLines\n        .map((line, idx) =&gt; `${startLine + idx + 1}\u2192${line}`)\n        .join(\"\\n\");\n\n      return formatted || \"(empty file)\";\n    } catch (error) {\n      throw new Error(\n        `Failed to read file ${input.file_path}: ${\n          error instanceof Error ? error.message : String(error)\n        }`\n      );\n    }\n  },\n};\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5de5\u5177<\/h2>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u5f00\u53d1\u5404\u7c7b\u5de5\u5177\uff0c\u4ece\u6ee1\u8db3\u57fa\u7840\u9700\u8981\u770b\uff0cwrite\u5199\u5165\u6587\u4ef6 \u3001task\u62c6\u5206\u72ec\u7acbagent\u4efb\u52a1\u3001bash\u6267\u884c\u811a\u672c\u3001grep\u6587\u672c\u641c\u7d22\u3001glob \u6587\u4ef6\u641c\u7d22\u3001ls \u67e5\u770b\u6587\u4ef6\u5217\u8868\u3001edit \u6587\u4ef6\u7f16\u8f91\u7b49\u5de5\u5177\u662f\u5fc5\u987b\u7684<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Write<\/h3>\n\n\n\n<p>Write \u5de5\u5177\u7528\u6765\u5199\u5165\u6587\u4ef6\uff0c\u903b\u8f91\u6bd4\u8f83\u7b80\u5355\uff0c\u8fd9\u91cc\u505a\u4e86\u4e00\u4e2a\u7b80\u5355\u6c99\u76d2\uff0c\u907f\u514d\u6267\u884c\u4e00\u4e9b\u5371\u9669\u64cd\u4f5c<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">typescript\u4f53\u9a8cAI\u4ee3\u7801\u52a9\u624b\u4ee3\u7801\u89e3\u8bfb\u590d\u5236\u4ee3\u7801<code>import { z } from \"zod\";\nimport { writeFile, mkdir } from \"fs\/promises\";\nimport { dirname, resolve } from \"path\";\nimport { Tool } from \"..\/query.js\";\n\nexport const writeTool: Tool = {\n  name: \"write\",\n  description: \"Write a file to the local filesystem, creating it if it doesn't exist or overwriting if it does\",\n  inputSchema: z.object({\n    file_path: z.string().describe(\"The path to the file to write\"),\n    content: z.string().describe(\"The content to write to the file\"),\n  }),\n  isReadOnly: () =&gt; false,\n  execute: async (input: { file_path: string; content: string }) =&gt; {\n    \/\/ \u5982\u679c\u662f\u76f8\u5bf9\u8def\u5f84\uff0c\u8bf7\u4f7f\u7528 process.cwd join\n    const absolutePath = resolve(input.file_path);\n    try {\n      const allowedBasePaths = new Set([\n        process.cwd(),\n        '\/tmp',\n        '\/var\/tmp'\n      ]);\n      \/\/ \u68c0\u67e5\u662f\u5426\u5728\u5b89\u5168\u76ee\u5f55\n      const isInAllowedPath = Array.from(allowedBasePaths).some(basePath =&gt; \n        absolutePath.startsWith(basePath)\n      );\n      \n      if (!isInAllowedPath) {\n        throw new Error(\n          `File writing paths only allowed in: ${Array.from(allowedBasePaths).join(', ')}`\n        );\n      }\n      const dir = dirname(absolutePath);\n      await mkdir(dir, { recursive: true });\n\n      await writeFile(absolutePath, input.content, \"utf-8\");\n\n      const lines = input.content.split(\"\\n\").length;\n      return `Successfully wrote ${lines} lines to ${absolutePath}`;\n    } catch (error) {\n      throw new Error(\n        `Failed to write file ${absolutePath}: ${\n          error instanceof Error ? error.message : String(error)\n        }`\n      );\n    }\n  },\n};\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Todo List \u5b9e\u73b0<\/h3>\n\n\n\n<p>Todo list\u662f\u4e2a\u8bb0\u4e8b\u672c\uff0c\u5728\u591a\u8f6e\u5bf9\u8bdd\u4e2d\u4fdd\u6301\u4efb\u52a1\u72b6\u6001\u7684\u4e00\u81f4\u6027\uff0c\u4e5f\u80fd\u8ba9LLM \u53ef\u4ee5\u57fa\u4e8e todo \u5217\u8868\u51b3\u5b9a\u4e0b\u4e00\u6b65\u505a\u4ec0\u4e48\u3002 \u8fd9\u7c7b\u4f3c\u4e8e\u4eba\u5728\u5904\u7406\u590d\u6742\u4efb\u52a1\u65f6\u4f1a\u5217\u6e05\u5355\u3001\u6807\u8bb0\u5b8c\u6210\u72b6\u6001\u4e00\u6837\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u91cc\u662f AI \u548c\u4eba\u5171\u4eab\u8fd9\u4e2a\u6e05\u5355\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">typescript\u4f53\u9a8cAI\u4ee3\u7801\u52a9\u624b\u4ee3\u7801\u89e3\u8bfb\u590d\u5236\u4ee3\u7801<code>import { z } from \"zod\";\nimport { Tool } from \"..\/query.js\";\n\nexport type TodoItem = {\n  content: string;\n  status: \"pending\" | \"in_progress\" | \"completed\";\n  activeForm: string;\n};\n\nlet globalTodoList: TodoItem[] = [];\n\ntype TodoListener = () =&gt; void;\nconst todoListeners: TodoListener[] = [];\n\nexport const addTodoListener = (listener: TodoListener): () =&gt; void =&gt; {\n  todoListeners.push(listener);\n  return () =&gt; {\n    const index = todoListeners.indexOf(listener);\n    if (index &gt; -1) {\n      todoListeners.splice(index, 1);\n    }\n  };\n};\n\nconst notifyTodoListeners = (): void =&gt; {\n  todoListeners.forEach(listener =&gt; {\n    try {\n      listener();\n    } catch (error) {\n      console.error('Todo listener error:', error);\n    }\n  });\n};\n\nexport const todoTool: Tool = {\n  name: \"TodoWrite\",\n  description: \"Creates and manages todo items for task tracking and progress management in the current session.\",\n  inputSchema: z.object({\n    action: z.enum([\"list\", \"add\", \"update\", \"clear\"]).describe(\"Action to perform on the todo list\"),\n    todos: z\n      .array(\n        z.object({\n          content: z.string().describe(\"Task description (imperative form)\"),\n          status: z.enum([\"pending\", \"in_progress\", \"completed\"]).describe(\"Task status\"),\n          activeForm: z.string().describe(\"Task description in present continuous form\"),\n        })\n      )\n      .optional()\n      .describe(\"Complete todo list (for 'update' action)\"),\n    content: z.string().optional().describe(\"Task content for 'add' action\"),\n  }),\n  isReadOnly: () =&gt; true,\n  execute: async (input: {\n    action: \"list\" | \"add\" | \"update\" | \"clear\";\n    todos?: TodoItem[];\n    content?: string;\n  }) =&gt; {\n    try {\n      switch (input.action) {\n        case \"list\":\n          if (globalTodoList.length === 0) {\n            return \"Todo list is empty\";\n          }\n          return globalTodoList\n            .map((todo, idx) =&gt; {\n              const status = {\n                pending: \"\u23f8\ufe0f\",\n                in_progress: \"\u25b6\ufe0f\",\n                completed: \"\u2705\",\n              }[todo.status];\n              return `${idx + 1}. ${status} ${todo.content}`;\n            })\n            .join(\"\\n\");\n\n        case \"add\":\n          if (!input.content) {\n            throw new Error(\"Content required for 'add' action\");\n          }\n          globalTodoList.push({\n            content: input.content,\n            status: \"pending\",\n            activeForm: `${input.content.replace(\/^[A-Z]\/, (c) =&gt; c.toLowerCase())}ing`,\n          });\n          notifyTodoListeners();\n          return `Added todo: ${input.content}`;\n\n        case \"update\":\n          if (!input.todos) {\n            throw new Error(\"Todos array required for 'update' action\");\n          }\n          globalTodoList = input.todos;\n          const pending = globalTodoList.filter((t) =&gt; t.status === \"pending\").length;\n          const inProgress = globalTodoList.filter((t) =&gt; t.status === \"in_progress\").length;\n          const completed = globalTodoList.filter((t) =&gt; t.status === \"completed\").length;\n          notifyTodoListeners();\n          return `Updated todo list: ${completed} completed, ${inProgress} in progress, ${pending} pending`;\n\n        case \"clear\":\n          const count = globalTodoList.length;\n          globalTodoList = [];\n          notifyTodoListeners();\n          return `Cleared ${count} todos`;\n\n        default:\n          throw new Error(`Unknown action: ${input.action}`);\n      }\n    } catch (error) {\n      throw new Error(\n        `Todo operation failed: ${error instanceof Error ? error.message : String(error)}`\n      );\n    }\n  },\n};\n\nexport const getTodoList = () =&gt; globalTodoList;\n\nexport const resetTodoList = () =&gt; {\n  globalTodoList = [];\n  notifyTodoListeners();\n};\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b50 agent Task<\/h3>\n\n\n\n<p>Task \u5de5\u5177\u662f claude code \u5206\u8eab\uff0c\u53ef\u4ee5\u5728\u4e3b agent \u5206\u8eab\u4e00\u4e2a\u5b50 agent\uff0c\u4f46\u5b50 agent \u4e0d\u652f\u6301\u7ee7\u7eed\u5206\u8eab \u5b9e\u73b0\u539f\u7406\u4e3b\u8981\u662f\u5728\u6267\u884c\u9636\u6bb5\uff0c\u9012\u5f52\u8c03\u7528 query \u51fd\u6570\uff0c\u53e6\u5916 tools \u5de5\u5177\u8fc7\u6ee4\u6389 task\uff08\u907f\u514d\u65e0\u9650\u9012\u5f52\u548c\u964d\u4f4e\u590d\u6742\u5ea6\uff09<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vbnet\u4f53\u9a8cAI\u4ee3\u7801\u52a9\u624b\u4ee3\u7801\u89e3\u8bfb\u590d\u5236\u4ee3\u7801<code>\nexport const taskTool: Tool = {\n  name: \"task\",\n  description: async () =&gt; {\n    return `Launch a new task to handle complex, multi-step tasks autonomously.\n \nWhen to use the task tool:\n* When you determine that a task is too complex and the context may exceed LLM limits, please break down complex tasks so that individual task contexts remain within the model's limitations\n* If the task description mentions that it should be used proactively\n\nUsage notes:\n1. Launch multiple tasks concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses\n2. When the task is done, it will return a single message back to you. The result returned by the task is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.\n3. Each task invocation is stateless. You will not be able to send additional messages to the task, nor will the task be able to communicate with you outside of its final report. Therefore, your prompt should contain a highly detailed task description for the task to perform autonomously and you should specify exactly what information the task should return back to you in its final and only message to you.\n4. The task's outputs should generally be trusted\n5. Clearly tell the task whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent\n    `;\n  },\n  inputSchema: z.object({\n    description: z.string().describe(\"A short (3-5 word) description of the task\"),\n    prompt: z.string().describe(\"The task for the agent to perform\"),\n  }),\n  isReadOnly: () =&gt; false,\n  execute: async (input: {\n    description: string;\n    prompt: string;\n  }) =&gt; {\n    try {\n      const messages: Message[] = [\n        {\n          type: \"user\",\n          content: input.prompt,\n        },\n      ];\n      const {allTools} = await import('.\/index.js');\n      const subAgentTools: Tool[] = allTools.filter(item=&gt; item.name !== 'task');\n\n      const systemPrompt = getAgentPrompt(input.description);\n\n      const options: QueryOptions = {\n        systemPrompt,\n        tools: subAgentTools,\n        verbose: false,\n      };\n\n      const results: Message[] = [];\n      for await (const message of query(messages, options)) {\n        console.info('Assistant:', message)\n        results.push(message);\n      }\n\n      const finalAssistantMessage = results\n        .filter((m) =&gt; m.type === \"assistant\")\n        .pop();\n\n      if (!finalAssistantMessage) {\n        return \"Task completed but no response was generated\";\n      }\n\n      return `Task \"${input.description}\" completed:\\n\\n${finalAssistantMessage.content}`;\n    } catch (error) {\n      throw new Error(\n        `Task execution failed: ${error instanceof Error ? error.message : String(error)}`\n      );\n    }\n  },\n};\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5176\u4ed6\u5de5\u5177<\/h3>\n\n\n\n<p>\u5176\u4ed6\u5de5\u5177\u5f00\u53d1\u5c31\u4e0d\u4e00\u4e00\u8d58\u8ff0\u4e86\uff0c\u53ef\u67e5\u770b\u6e90\u7801\u4e86\u89e3&nbsp;<a href=\"https:\/\/link.juejin.cn\/?target=https%3A%2F%2Fgithub.com%2Fhellosean1025%2Fcodeai\" target=\"_blank\" rel=\"noreferrer noopener\">\u6e90\u7801<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5c3e\u8bed<\/h2>\n\n\n\n<p>\u770b\u5b8c\u672c\u6587\u7684\u4f60\uff0c\u76f8\u4fe1\u5df2\u7ecf\u57fa\u672c\u4e86\u89e3\u4e86 claude code \u539f\u7406\uff0c\u57fa\u4e8e\u73b0\u6709\u7684 ReAct\u67b6\u6784\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd9\u4e2a\u57fa\u7840\u4e0a\u5b9e\u73b0\u66f4\u591atool\u548c\u80fd\u529b\uff0c\u6bd4\u5982 mcp\uff08\u672c\u8d28\u4e0a\u4e5f\u662f tool)\u3001websearch\u3001urlfetch \u3001context\u3001\u66f4\u597d\u7684\u7528\u6237\u754c\u9762\u7ba1\u7406\u7b49\u80fd\u529b\u3002<\/p>\n\n\n\n<p>AI Coding \u5de5\u5177\u76ee\u524d\u4e2a\u4eba\u89c9\u5f97\u8fd8\u662f\u5904\u4e8e\u521d\u7ea7\u9636\u6bb5\uff0c\u5927\u6a21\u578b\u6f5c\u529b\u548c\u5de5\u7a0b\u6f5c\u529b\u5e76\u6ca1\u6709\u88ab\u6316\u5e72\u51c0\uff0c\u4ece\u5de5\u7a0b\u65b9\u9762\uff0c\u8fd9\u51e0\u4e2a\u65b9\u9762\u672a\u6765\u6f5c\u529b\u5de8\u5927\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4efb\u52a1\u89c4\u5212\u548c\u8c03\u5ea6\u6267\u884c\u5de5\u5177\uff0c\u80fd\u591f\u505a\u66f4\u590d\u6742\u9879\u76ee\u7684\u4efb\u52a1\u62c6\u89e3\u548c\u6267\u884c\u8c03\u5ea6\uff0c\u89e3\u51b3\u5927\u578b\u9879\u76ee ai coding \u751f\u6210\u7ed3\u679c\u4e0d\u7a33\u5b9a\u3001\u5e7b\u89c9\u7b49\u95ee\u9898<\/li>\n\n\n\n<li>\u4e1a\u52a1\u6280\u672f\u77e5\u8bc6\u5927\u8111 agentic\uff0c\u5982\u679c\u4f60\u7ecf\u5e38\u7528 ai \u5de5\u5177\u5e94\u8be5\u5c31\u80fd\u611f\u89c9\u5230\u5f53 ai \u5728\u4e0d\u4e86\u89e3\u4e1a\u52a1\u9879\u76ee\u57fa\u672c\u77e5\u8bc6\u3001\u4e0d\u4e86\u89e3\u73b0\u6709\u6a21\u5757\u60c5\u51b5\u4e0b\u662f\u591a\u4e48\u4e0d\u53ef\u9760\uff0c\u4f46\u8fd9\u65b9\u9762\u4e00\u76f4\u662f\u7a7a\u767d\uff0cclaude code \u7b56\u7565\u662f\u5c3d\u53ef\u80fd\u8bfb\u53d6\u9700\u8981\u7684\u6587\u4ef6\u548c\u4f7f\u7528 grep\u641c\u7d22<\/li>\n\n\n\n<li>TDD \u9a71\u52a8\u5f00\u53d1\u5de5\u5177,\u5728\u6709\u4e86 ai \u80fd\u529b\u52a0\u6301\u540e\uff0c\u76f8\u4fe1\u672a\u6765 TDD \u9a71\u52a8\u5f00\u53d1\u4e00\u5b9a\u4f1a\u6d41\u884c\uff0c\u8fd9\u4e5f\u662f\u63d0\u5347\u8d28\u91cf\u3001\u7ed9AI\u9ad8\u8d28\u91cf\u4e0a\u4e0b\u6587\u6709\u6548\u624b\u6bb5<\/li>\n\n\n\n<li><\/li>\n\n\n\n<li>\u6587\u7ae0\u94fe\u63a5\uff1ahttps:\/\/juejin.cn\/post\/7565734395886387252<\/li>\n\n\n\n<li><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5b66\u4e60\u672c\u6587\u53ef\u80fd\u7684\u6536\u83b7 \u67e5\u770b\uff1a\u6e90\u7801 mini\u7248\u672c\u80fd\u529b \u4f7f\u7528 1.\u5728 zs&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":442,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-532","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tools"],"_links":{"self":[{"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/posts\/532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/comments?post=532"}],"version-history":[{"count":2,"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/posts\/532\/revisions"}],"predecessor-version":[{"id":567,"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/posts\/532\/revisions\/567"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/media\/442"}],"wp:attachment":[{"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/media?parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/categories?post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartaiunion.com\/index.php\/wp-json\/wp\/v2\/tags?post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}