{"id":119,"date":"2026-03-21T22:47:18","date_gmt":"2026-03-21T14:47:18","guid":{"rendered":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/gateway-cli-backends\/"},"modified":"2026-03-21T23:29:02","modified_gmt":"2026-03-21T15:29:02","slug":"gateway-cli-backends","status":"publish","type":"post","link":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/gateway-cli-backends\/","title":{"rendered":"CLI \u540e\u7aef"},"content":{"rendered":"<h1>CLI \u540e\u7aef<\/h1>\n<h1>CLI \u540e\u7aef\uff08\u56de\u9000\u8fd0\u884c\u65f6\uff09<\/h1>\n<p>\u5f53 API \u63d0\u4f9b\u5546\u5b95\u673a\u3001\u88ab\u9650\u6d41\u6216\u6682\u65f6\u5f02\u5e38\u65f6\uff0cOpenClaw \u53ef\u4ee5\u8fd0\u884c<strong>\u672c\u5730 AI CLI<\/strong> \u4f5c\u4e3a<strong>\u7eaf\u6587\u672c\u56de\u9000<\/strong>\u3002\u8fd9\u662f\u6709\u610f\u4fdd\u5b88\u7684\u8bbe\u8ba1\uff1a<\/p>\n<ul>\n<li><strong>\u5de5\u5177\u88ab\u7981\u7528<\/strong>\uff08\u65e0\u5de5\u5177\u8c03\u7528\uff09\u3002<\/li>\n<li><strong>\u6587\u672c\u8f93\u5165 \u2192 \u6587\u672c\u8f93\u51fa<\/strong>\uff08\u53ef\u9760\uff09\u3002<\/li>\n<li><strong>\u652f\u6301\u4f1a\u8bdd<\/strong>\uff08\u56e0\u6b64\u540e\u7eed\u8f6e\u6b21\u4fdd\u6301\u8fde\u8d2f\uff09\u3002<\/li>\n<li>\u5982\u679c CLI \u63a5\u53d7\u56fe\u50cf\u8def\u5f84\uff0c<strong>\u56fe\u50cf\u53ef\u4ee5\u4f20\u9012<\/strong>\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u88ab\u8bbe\u8ba1\u4e3a<strong>\u5b89\u5168\u7f51<\/strong>\u800c\u975e\u4e3b\u8981\u8def\u5f84\u3002\u5f53\u4f60\u60f3\u8981&#8221;\u59cb\u7ec8\u6709\u6548&#8221;\u7684\u6587\u672c\u54cd\u5e94\u800c\u4e0d\u4f9d\u8d56\u5916\u90e8 API \u65f6\u4f7f\u7528\u5b83\u3002<\/p>\n<h2>\u65b0\u624b\u53cb\u597d\u5feb\u901f\u5f00\u59cb<\/h2>\n<p>\u4f60\u53ef\u4ee5<strong>\u65e0\u9700\u4efb\u4f55\u914d\u7f6e<\/strong>\u4f7f\u7528 Claude Code CLI\uff08OpenClaw \u81ea\u5e26\u5185\u7f6e\u9ed8\u8ba4\u503c\uff09\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nopenclaw agent &#8211;message &#8220;hi&#8221; &#8211;model claude-cli\/opus-4.5<\/p>\n<pre><code>\nCodex CLI \u4e5f\u53ef\u4ee5\u5f00\u7bb1\u5373\u7528\uff1a\n\n```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nopenclaw agent --message &quot;hi&quot; --model codex-cli\/gpt-5.2-codex\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u7684 Gateway \u7f51\u5173 \u7f51\u5173\u5728 launchd\/systemd \u4e0b\u8fd0\u884c\u4e14 PATH \u5f88\u7cbe\u7b80\uff0c\u53ea\u9700\u6dfb\u52a0\u547d\u4ee4\u8def\u5f84\uff1a<\/p>\n<p>&#8220;`json5  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{<br \/>\n  agents: {<br \/>\n    defaults: {<br \/>\n      cliBackends: {<br \/>\n        &#8220;claude-cli&#8221;: {<br \/>\n          command: &#8220;\/opt\/homebrew\/bin\/claude&#8221;,<br \/>\n        },<br \/>\n      },<br \/>\n    },<br \/>\n  },<br \/>\n}<\/p>\n<pre><code>\n\u5c31\u8fd9\u6837\u3002\u9664\u4e86 CLI \u672c\u8eab\u5916\uff0c\u4e0d\u9700\u8981\u5bc6\u94a5\uff0c\u4e0d\u9700\u8981\u989d\u5916\u7684\u8ba4\u8bc1\u914d\u7f6e\u3002\n\n## \u4f5c\u4e3a\u56de\u9000\u4f7f\u7528\n\n\u5c06 CLI \u540e\u7aef\u6dfb\u52a0\u5230\u4f60\u7684\u56de\u9000\u5217\u8868\u4e2d\uff0c\u8fd9\u6837\u5b83\u53ea\u5728\u4e3b\u8981\u6a21\u578b\u5931\u8d25\u65f6\u8fd0\u884c\uff1a\n\n```json5  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  agents: {\n    defaults: {\n      model: {\n        primary: &quot;anthropic\/claude-opus-4-5&quot;,\n        fallbacks: [&quot;claude-cli\/opus-4.5&quot;],\n      },\n      models: {\n        &quot;anthropic\/claude-opus-4-5&quot;: { alias: &quot;Opus&quot; },\n        &quot;claude-cli\/opus-4.5&quot;: {},\n      },\n    },\n  },\n}\n<\/code><\/pre>\n<p>\u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u4f60\u4f7f\u7528 <code>agents.defaults.models<\/code>\uff08\u5141\u8bb8\u5217\u8868\uff09\uff0c\u5fc5\u987b\u5305\u542b <code>claude-cli\/...<\/code>\u3002<\/li>\n<li>\u5982\u679c\u4e3b\u8981\u63d0\u4f9b\u5546\u5931\u8d25\uff08\u8ba4\u8bc1\u3001\u9650\u6d41\u3001\u8d85\u65f6\uff09\uff0cOpenClaw \u5c06\u63a5\u7740\u5c1d\u8bd5 CLI \u540e\u7aef\u3002<\/li>\n<\/ul>\n<h2>\u914d\u7f6e\u6982\u89c8<\/h2>\n<p>\u6240\u6709 CLI \u540e\u7aef\u4f4d\u4e8e\uff1a<\/p>\n<pre><code>agents.defaults.cliBackends\n<\/code><\/pre>\n<p>\u6bcf\u4e2a\u6761\u76ee\u4ee5<strong>\u63d0\u4f9b\u5546 ID<\/strong>\uff08\u4f8b\u5982 <code>claude-cli<\/code>\u3001<code>my-cli<\/code>\uff09\u4e3a\u952e\u3002\u63d0\u4f9b\u5546 ID \u6210\u4e3a\u4f60\u7684\u6a21\u578b\u5f15\u7528\u7684\u5de6\u4fa7\u90e8\u5206\uff1a<\/p>\n<pre><code>&lt;provider&gt;\/&lt;model&gt;\n<\/code><\/pre>\n<h3>\u914d\u7f6e\u793a\u4f8b<\/h3>\n<p>&#8220;`json5  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{<br \/>\n  agents: {<br \/>\n    defaults: {<br \/>\n      cliBackends: {<br \/>\n        &#8220;claude-cli&#8221;: {<br \/>\n          command: &#8220;\/opt\/homebrew\/bin\/claude&#8221;,<br \/>\n        },<br \/>\n        &#8220;my-cli&#8221;: {<br \/>\n          command: &#8220;my-cli&#8221;,<br \/>\n          args: [&#8220;&#8211;json&#8221;],<br \/>\n          output: &#8220;json&#8221;,<br \/>\n          input: &#8220;arg&#8221;,<br \/>\n          modelArg: &#8220;&#8211;model&#8221;,<br \/>\n          modelAliases: {<br \/>\n            &#8220;claude-opus-4-5&#8221;: &#8220;opus&#8221;,<br \/>\n            &#8220;claude-sonnet-4-5&#8221;: &#8220;sonnet&#8221;,<br \/>\n          },<br \/>\n          sessionArg: &#8220;&#8211;session&#8221;,<br \/>\n          sessionMode: &#8220;existing&#8221;,<br \/>\n          sessionIdFields: [&#8220;session_id&#8221;, &#8220;conversation_id&#8221;],<br \/>\n          systemPromptArg: &#8220;&#8211;system&#8221;,<br \/>\n          systemPromptWhen: &#8220;first&#8221;,<br \/>\n          imageArg: &#8220;&#8211;image&#8221;,<br \/>\n          imageMode: &#8220;repeat&#8221;,<br \/>\n          serialize: true,<br \/>\n        },<br \/>\n      },<br \/>\n    },<br \/>\n  },<br \/>\n}<\/p>\n<pre><code>\n## \u5de5\u4f5c\u539f\u7406\n\n1. **\u9009\u62e9\u540e\u7aef**\u57fa\u4e8e\u63d0\u4f9b\u5546\u524d\u7f00\uff08`claude-cli\/...`\uff09\u3002\n2. **\u6784\u5efa\u7cfb\u7edf\u63d0\u793a**\u4f7f\u7528\u76f8\u540c\u7684 OpenClaw \u63d0\u793a + \u5de5\u4f5c\u533a\u4e0a\u4e0b\u6587\u3002\n3. **\u6267\u884c CLI**\u5e76\u5e26\u6709\u4f1a\u8bdd ID\uff08\u5982\u679c\u652f\u6301\uff09\uff0c\u4f7f\u5386\u53f2\u8bb0\u5f55\u4fdd\u6301\u4e00\u81f4\u3002\n4. **\u89e3\u6790\u8f93\u51fa**\uff08JSON \u6216\u7eaf\u6587\u672c\uff09\u5e76\u8fd4\u56de\u6700\u7ec8\u6587\u672c\u3002\n5. **\u6301\u4e45\u5316\u4f1a\u8bdd ID**\u6309\u540e\u7aef\uff0c\u4f7f\u540e\u7eed\u8bf7\u6c42\u590d\u7528\u76f8\u540c\u7684 CLI \u4f1a\u8bdd\u3002\n\n## \u4f1a\u8bdd\n\n* \u5982\u679c CLI \u652f\u6301\u4f1a\u8bdd\uff0c\u8bbe\u7f6e `sessionArg`\uff08\u4f8b\u5982 `--session-id`\uff09\u6216 `sessionArgs`\uff08\u5360\u4f4d\u7b26 `{sessionId}`\uff09\u5f53 ID \u9700\u8981\u63d2\u5165\u5230\u591a\u4e2a\u6807\u5fd7\u4e2d\u65f6\u3002\n* \u5982\u679c CLI \u4f7f\u7528\u5e26\u6709\u4e0d\u540c\u6807\u5fd7\u7684**\u6062\u590d\u5b50\u547d\u4ee4**\uff0c\u8bbe\u7f6e `resumeArgs`\uff08\u6062\u590d\u65f6\u66ff\u6362 `args`\uff09\u4ee5\u53ca\u53ef\u9009\u7684 `resumeOutput`\uff08\u7528\u4e8e\u975e JSON \u6062\u590d\uff09\u3002\n* `sessionMode`\uff1a\n  * `always`\uff1a\u59cb\u7ec8\u53d1\u9001\u4f1a\u8bdd ID\uff08\u5982\u679c\u6ca1\u6709\u5b58\u50a8\u5219\u4f7f\u7528\u65b0 UUID\uff09\u3002\n  * `existing`\uff1a\u4ec5\u5728\u4e4b\u524d\u5b58\u50a8\u4e86\u4f1a\u8bdd ID \u65f6\u624d\u53d1\u9001\u3002\n  * `none`\uff1a\u4ece\u4e0d\u53d1\u9001\u4f1a\u8bdd ID\u3002\n\n## \u56fe\u50cf\uff08\u4f20\u9012\uff09\n\n\u5982\u679c\u4f60\u7684 CLI \u63a5\u53d7\u56fe\u50cf\u8def\u5f84\uff0c\u8bbe\u7f6e `imageArg`\uff1a\n\n```json5  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nimageArg: &quot;--image&quot;,\nimageMode: &quot;repeat&quot;\n<\/code><\/pre>\n<p>OpenClaw \u4f1a\u5c06 base64 \u56fe\u50cf\u5199\u5165\u4e34\u65f6\u6587\u4ef6\u3002\u5982\u679c\u8bbe\u7f6e\u4e86 <code>imageArg<\/code>\uff0c\u8fd9\u4e9b\u8def\u5f84\u4f5c\u4e3a CLI \u53c2\u6570\u4f20\u9012\u3002\u5982\u679c\u7f3a\u5c11 <code>imageArg<\/code>\uff0cOpenClaw \u4f1a\u5c06\u6587\u4ef6\u8def\u5f84\u9644\u52a0\u5230\u63d0\u793a\u4e2d\uff08\u8def\u5f84\u6ce8\u5165\uff09\uff0c\u8fd9\u5bf9\u4e8e\u4ece\u7eaf\u8def\u5f84\u81ea\u52a8\u52a0\u8f7d\u672c\u5730\u6587\u4ef6\u7684 CLI \u6765\u8bf4\u5df2\u7ecf\u8db3\u591f\uff08Claude Code CLI \u884c\u4e3a\uff09\u3002<\/p>\n<h2>\u8f93\u5165 \/ \u8f93\u51fa<\/h2>\n<ul>\n<li><code>output: \"json\"<\/code>\uff08\u9ed8\u8ba4\uff09\u5c1d\u8bd5\u89e3\u6790 JSON \u5e76\u63d0\u53d6\u6587\u672c + \u4f1a\u8bdd ID\u3002<\/li>\n<li><code>output: \"jsonl\"<\/code> \u89e3\u6790 JSONL \u6d41\uff08Codex CLI <code>--json<\/code>\uff09\u5e76\u63d0\u53d6\u6700\u540e\u4e00\u6761\u667a\u80fd\u4f53\u6d88\u606f\u4ee5\u53ca\u5b58\u5728\u65f6\u7684 <code>thread_id<\/code>\u3002<\/li>\n<li><code>output: \"text\"<\/code> \u5c06 stdout \u89c6\u4e3a\u6700\u7ec8\u54cd\u5e94\u3002<\/li>\n<\/ul>\n<p>\u8f93\u5165\u6a21\u5f0f\uff1a<\/p>\n<ul>\n<li><code>input: \"arg\"<\/code>\uff08\u9ed8\u8ba4\uff09\u5c06\u63d0\u793a\u4f5c\u4e3a\u6700\u540e\u4e00\u4e2a CLI \u53c2\u6570\u4f20\u9012\u3002<\/li>\n<li><code>input: \"stdin\"<\/code> \u901a\u8fc7 stdin \u53d1\u9001\u63d0\u793a\u3002<\/li>\n<li>\u5982\u679c\u63d0\u793a\u5f88\u957f\u4e14\u8bbe\u7f6e\u4e86 <code>maxPromptArgChars<\/code>\uff0c\u5219\u4f7f\u7528 stdin\u3002<\/li>\n<\/ul>\n<h2>\u9ed8\u8ba4\u503c\uff08\u5185\u7f6e\uff09<\/h2>\n<p>OpenClaw \u81ea\u5e26 <code>claude-cli<\/code> \u7684\u9ed8\u8ba4\u503c\uff1a<\/p>\n<ul>\n<li><code>command: \"claude\"<\/code><\/li>\n<li><code>args: [\"-p\", \"--output-format\", \"json\", \"--dangerously-skip-permissions\"]<\/code><\/li>\n<li><code>resumeArgs: [\"-p\", \"--output-format\", \"json\", \"--dangerously-skip-permissions\", \"--resume\", \"{sessionId}\"]<\/code><\/li>\n<li><code>modelArg: \"--model\"<\/code><\/li>\n<li><code>systemPromptArg: \"--append-system-prompt\"<\/code><\/li>\n<li><code>sessionArg: \"--session-id\"<\/code><\/li>\n<li><code>systemPromptWhen: \"first\"<\/code><\/li>\n<li><code>sessionMode: \"always\"<\/code><\/li>\n<\/ul>\n<p>OpenClaw \u4e5f\u81ea\u5e26 <code>codex-cli<\/code> \u7684\u9ed8\u8ba4\u503c\uff1a<\/p>\n<ul>\n<li><code>command: \"codex\"<\/code><\/li>\n<li><code>args: [\"exec\",\"--json\",\"--color\",\"never\",\"--sandbox\",\"read-only\",\"--skip-git-repo-check\"]<\/code><\/li>\n<li><code>resumeArgs: [\"exec\",\"resume\",\"{sessionId}\",\"--color\",\"never\",\"--sandbox\",\"read-only\",\"--skip-git-repo-check\"]<\/code><\/li>\n<li><code>output: \"jsonl\"<\/code><\/li>\n<li><code>resumeOutput: \"text\"<\/code><\/li>\n<li><code>modelArg: \"--model\"<\/code><\/li>\n<li><code>imageArg: \"--image\"<\/code><\/li>\n<li><code>sessionMode: \"existing\"<\/code><\/li>\n<\/ul>\n<p>\u4ec5\u5728\u9700\u8981\u65f6\u8986\u76d6\uff08\u5e38\u89c1\uff1a\u7edd\u5bf9 <code>command<\/code> \u8def\u5f84\uff09\u3002<\/p>\n<h2>\u9650\u5236<\/h2>\n<ul>\n<li><strong>\u65e0 OpenClaw \u5de5\u5177<\/strong>\uff08CLI \u540e\u7aef\u6c38\u8fdc\u4e0d\u4f1a\u6536\u5230\u5de5\u5177\u8c03\u7528\uff09\u3002\u67d0\u4e9b CLI \u53ef\u80fd\u4ecd\u4f1a\u8fd0\u884c\u5b83\u4eec\u81ea\u5df1\u7684\u667a\u80fd\u4f53\u5de5\u5177\u3002<\/li>\n<li><strong>\u65e0\u6d41\u5f0f\u4f20\u8f93<\/strong>\uff08CLI \u8f93\u51fa\u88ab\u6536\u96c6\u540e\u8fd4\u56de\uff09\u3002<\/li>\n<li><strong>\u7ed3\u6784\u5316\u8f93\u51fa<\/strong>\u53d6\u51b3\u4e8e CLI \u7684 JSON \u683c\u5f0f\u3002<\/li>\n<li><strong>Codex CLI \u4f1a\u8bdd<\/strong>\u901a\u8fc7\u6587\u672c\u8f93\u51fa\u6062\u590d\uff08\u65e0 JSONL\uff09\uff0c\u8fd9\u6bd4\u521d\u59cb\u7684 <code>--json<\/code> \u8fd0\u884c\u7ed3\u6784\u5316\u7a0b\u5ea6\u4f4e\u3002OpenClaw \u4f1a\u8bdd\u4ecd\u7136\u6b63\u5e38\u5de5\u4f5c\u3002<\/li>\n<\/ul>\n<h2>\u6545\u969c\u6392\u9664<\/h2>\n<ul>\n<li><strong>\u627e\u4e0d\u5230 CLI<\/strong>\uff1a\u5c06 <code>command<\/code> \u8bbe\u7f6e\u4e3a\u5b8c\u6574\u8def\u5f84\u3002<\/li>\n<li><strong>\u6a21\u578b\u540d\u79f0\u9519\u8bef<\/strong>\uff1a\u4f7f\u7528 <code>modelAliases<\/code> \u5c06 <code>provider\/model<\/code> \u6620\u5c04\u5230 CLI \u6a21\u578b\u3002<\/li>\n<li><strong>\u65e0\u4f1a\u8bdd\u8fde\u7eed\u6027<\/strong>\uff1a\u8bf7\u786e\u4fdd\u8bbe\u7f6e\u4e86 <code>sessionArg<\/code> \u4e14 <code>sessionMode<\/code> \u4e0d\u662f <code>none<\/code>\uff08Codex CLI \u76ee\u524d\u65e0\u6cd5\u4f7f\u7528 JSON \u8f93\u51fa\u6062\u590d\uff09\u3002<\/li>\n<li><strong>\u56fe\u50cf\u88ab\u5ffd\u7565<\/strong>\uff1a\u8bbe\u7f6e <code>imageArg<\/code>\uff08\u5e76\u9a8c\u8bc1 CLI \u652f\u6301\u6587\u4ef6\u8def\u5f84\uff09\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>CLI \u540e\u7aef CLI \u540e\u7aef\uff08\u56de\u9000\u8fd0\u884c\u65f6\uff09 \u5f53 API \u63d0\u4f9b\u5546\u5b95\u673a\u3001\u88ab\u9650\u6d41\u6216\u6682\u65f6\u5f02\u5e38\u65f6\uff0cOpenClaw \u53ef\u4ee5\u8fd0 [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-119","post","type-post","status-publish","format-standard","hentry","category-docs"],"_links":{"self":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":2,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"predecessor-version":[{"id":832,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/119\/revisions\/832"}],"wp:attachment":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}