8 8
9本页列出 Claude Code 显示的运行时错误以及如何从每个错误中恢复,以及当响应似乎有问题但没有错误时要检查的内容。对于安装错误(如 `command not found` 或设置期间的 TLS 失败),请参阅[排查安装和登录问题](/docs/zh-CN/troubleshoot-install)。9本页列出 Claude Code 显示的运行时错误以及如何从每个错误中恢复,以及当响应似乎有问题但没有错误时要检查的内容。对于安装错误(如 `command not found` 或设置期间的 TLS 失败),请参阅[排查安装和登录问题](/docs/zh-CN/troubleshoot-install)。
10 10
11除了[包装器和 IDE 错误](#wrapper-and-ide-errors)(由启动程序打印而不是 Claude Code 本身打印)外,这些错误和恢复命令适用于 CLI、[桌面应用](/docs/zh-CN/desktop)和[云会话](/docs/zh-CN/claude-code-on-the-web),因为这三个都包装相同的 Claude Code CLI。对于其他表面特定的问题,请参阅该表面页面上的故障排除部分。11除了[包装器和 IDE 错误](#wrapper-and-ide-errors)(由启动程序打印而不是 Claude Code 本身打印)外,这些错误和恢复命令适用于 CLI、[桌面应用](/docs/zh-CN/desktop)和[云端会话](/docs/zh-CN/claude-code-on-the-web),因为这三个都包装相同的 Claude Code CLI。对于其他特定于使用入口的问题,请参阅该使用入口页面上的故障排除部分。
12 12
13<Note>13<Note>
14 Claude Code 调用 Claude API 来获取模型响应,因此大多数运行时错误映射到底层 API 错误代码。本页介绍每个错误在 Claude Code 中的含义以及如何恢复。有关原始 HTTP 状态代码定义,请参阅 [Claude Platform 错误参考](https://platform.claude.com/docs/en/api/errors)。14 Claude Code 调用 Claude API 来获取模型响应,因此大多数运行时错误映射到底层 API 错误代码。本页介绍每个错误在 Claude Code 中的含义以及如何恢复。有关原始 HTTP 状态代码定义,请参阅 [Claude Platform 错误参考](https://platform.claude.com/docs/en/api/errors)。
75| `Remote Control stopped — the app running this session is now signed in to a different Claude account` | [身份验证](#remote-control-stopped-because-the-app-running-the-session-signed-out-or-switched-accounts) |75| `Remote Control stopped — the app running this session is now signed in to a different Claude account` | [身份验证](#remote-control-stopped-because-the-app-running-the-session-signed-out-or-switched-accounts) |
76| `Remote Control stopped — the app running this session is signed out of Claude` | [身份验证](#remote-control-stopped-because-the-app-running-the-session-signed-out-or-switched-accounts) |76| `Remote Control stopped — the app running this session is signed out of Claude` | [身份验证](#remote-control-stopped-because-the-app-running-the-session-signed-out-or-switched-accounts) |
77| `Couldn't verify your organization's policy for remote control` | [Troubleshoot Remote Control](/docs/zh-CN/remote-control#couldnt-verify-your-organizations-policy-for-remote-control) |77| `Couldn't verify your organization's policy for remote control` | [Troubleshoot Remote Control](/docs/zh-CN/remote-control#couldnt-verify-your-organizations-policy-for-remote-control) |
78| `Remote Control is disabled by your organization's policy` | [Troubleshoot Remote Control](/docs/zh-CN/remote-control#remote-control-is-disabled-by-your-organizations-policy) |
79| `Remote Control was turned off by your organization's policy` | [Troubleshoot Remote Control](/docs/zh-CN/remote-control#remote-control-was-turned-off-by-your-organizations-policy) |
78| `OAuth token revoked` / `OAuth token has expired` | [身份验证](#oauth-token-revoked-or-expired) |80| `OAuth token revoked` / `OAuth token has expired` | [身份验证](#oauth-token-revoked-or-expired) |
81| `Failed to authenticate: OAuth token revoked` | [身份验证](#oauth-token-revoked-or-expired) |
82| `Your account does not have access to Claude. Please login again or contact your administrator.` | [身份验证](#oauth-token-revoked-or-expired) |
79| `API Error: 401 Invalid authentication credentials` | [身份验证](#api-error-401-invalid-authentication-credentials) |83| `API Error: 401 Invalid authentication credentials` | [身份验证](#api-error-401-invalid-authentication-credentials) |
80| `Login expired · Please run /login` | [身份验证](#login-expired) |84| `Login expired · Please run /login` | [身份验证](#login-expired) |
81| `Failed to start OAuth callback server` | [身份验证](#failed-to-start-oauth-callback-server) |85| `Failed to start OAuth callback server` | [身份验证](#failed-to-start-oauth-callback-server) |
186| `The connection dropped while downloading the update` | [安装错误](#the-connection-dropped-while-downloading-the-update) |190| `The connection dropped while downloading the update` | [安装错误](#the-connection-dropped-while-downloading-the-update) |
187| `Download timed out: exceeded the total deadline` | [安装错误](#the-connection-dropped-while-downloading-the-update) |191| `Download timed out: exceeded the total deadline` | [安装错误](#the-connection-dropped-while-downloading-the-update) |
188| `--bg and --print conflict` | [命令行错误](#conflict-between-bg-and-print) |192| `--bg and --print conflict` | [命令行错误](#conflict-between-bg-and-print) |
193| `Error: Cannot use both --append-subagent-system-prompt and --append-subagent-system-prompt-file. Please use only one.` | [命令行错误](#conflict-between-a-system-prompt-flag-and-its-file-form) |
189| `Cloud sessions cannot be created from a --restricted session` | [命令行错误](#cloud-sessions-cannot-be-created-from-a-restricted-session) |194| `Cloud sessions cannot be created from a --restricted session` | [命令行错误](#cloud-sessions-cannot-be-created-from-a-restricted-session) |
190| `Cloud sessions are disabled by your organization's policy` | [命令行错误](#cloud-sessions-are-disabled-by-your-organizations-policy) |195| `Cloud sessions are disabled by your organization's policy` | [命令行错误](#cloud-sessions-are-disabled-by-your-organizations-policy) |
191| `Couldn't verify your organization's policy for cloud sessions` | [命令行错误](#cloud-sessions-are-disabled-by-your-organizations-policy) |196| `Couldn't verify your organization's policy for cloud sessions` | [命令行错误](#cloud-sessions-are-disabled-by-your-organizations-policy) |
203| `Could not read Claude Code config` | [命令行错误](#could-not-read-claude-code-config) |208| `Could not read Claude Code config` | [命令行错误](#could-not-read-claude-code-config) |
204| `Could not import <server>: <reason>` | [命令行错误](#could-not-import-a-server-from-claude-desktop) |209| `Could not import <server>: <reason>` | [命令行错误](#could-not-import-a-server-from-claude-desktop) |
205| `Cannot add MCP server to scope: managed` | [命令行错误](#cannot-add-mcp-server-to-the-managed-scope) |210| `Cannot add MCP server to scope: managed` | [命令行错误](#cannot-add-mcp-server-to-the-managed-scope) |
211| `Cannot add MCP server: your organization's managed settings allow only MCP servers that plugins provide` | [命令行错误](#cannot-add-mcp-server-when-managed-settings-allow-only-plugin-servers) |
206| `is Anthropic-hosted and doesn't support local OAuth` | [命令行错误](#anthropic-hosted-and-doesnt-support-local-oauth) |212| `is Anthropic-hosted and doesn't support local OAuth` | [命令行错误](#anthropic-hosted-and-doesnt-support-local-oauth) |
207| `Can't read .mcp.json: it isn't a regular file or is larger than 2097152 bytes` | [命令行错误](#cant-read-mcp-json) |213| `Can't read .mcp.json: it isn't a regular file or is larger than 2097152 bytes` | [命令行错误](#cant-read-mcp-json) |
208| `MCP server "<name>" was not saved to` / `was not removed from` | [命令行错误](#mcp-server-was-not-saved-or-removed) |214| `MCP server "<name>" was not saved to` / `was not removed from` | [命令行错误](#mcp-server-was-not-saved-or-removed) |
240| `Skill usage reports are not available on this connection.` | [命令行错误](#skill-usage-reports-are-not-available-on-this-connection) |246| `Skill usage reports are not available on this connection.` | [命令行错误](#skill-usage-reports-are-not-available-on-this-connection) |
241| `Custom output styles can't be selected over Remote Control or from a relayed message` | [命令行错误](#custom-output-styles-cant-be-selected-over-remote-control) |247| `Custom output styles can't be selected over Remote Control or from a relayed message` | [命令行错误](#custom-output-styles-cant-be-selected-over-remote-control) |
242| `Output styles are saved to local settings (.claude/settings.local.json), which this session doesn't load` | [命令行错误](#output-styles-are-saved-to-local-settings-which-this-session-doesnt-load) |248| `Output styles are saved to local settings (.claude/settings.local.json), which this session doesn't load` | [命令行错误](#output-styles-are-saved-to-local-settings-which-this-session-doesnt-load) |
249| `/recap only runs when you ask for it yourself in this session` | [命令行错误](#recap-only-runs-when-you-ask-for-it-yourself) |
243| `` `plugin eval` is currently in early access `` / `` `plugin eval` is currently unavailable `` | [Plugin 错误](#plugin-eval-is-currently-in-early-access) |250| `` `plugin eval` is currently in early access `` / `` `plugin eval` is currently unavailable `` | [Plugin 错误](#plugin-eval-is-currently-in-early-access) |
244| `Marketplace "<name>" is registered from an untrusted source` | [Plugin 错误](#marketplace-is-registered-from-an-untrusted-source) |251| `Marketplace "<name>" is registered from an untrusted source` | [Plugin 错误](#marketplace-is-registered-from-an-untrusted-source) |
245| `Claude Code refuses the marketplace name "<name>"` | [Plugin 错误](#claude-code-refuses-the-marketplace-name) |252| `Claude Code refuses the marketplace name "<name>"` | [Plugin 错误](#claude-code-refuses-the-marketplace-name) |
246| `Marketplace name impersonates an official Anthropic/Claude marketplace` | [Plugin 错误](#claude-code-refuses-the-marketplace-name) |253| `Marketplace name impersonates an official Anthropic/Claude marketplace` | [Plugin 错误](#claude-code-refuses-the-marketplace-name) |
247| `Marketplace "<name>" is already added from a different source` | [Plugin 错误](#marketplace-is-already-added-from-a-different-source) |254| `Marketplace "<name>" is already added from a different source` | [Plugin 错误](#marketplace-is-already-added-from-a-different-source) |
248| `"<name>" is another spelling of "<reserved>", a reserved marketplace name` | [Plugin 错误](#marketplace-name-is-another-spelling-of-a-reserved-name) |255| `"<name>" is another spelling of "<reserved>", a reserved marketplace name` | [Plugin 错误](#marketplace-name-is-another-spelling-of-a-reserved-name) |
256| `Marketplace "<name>" is added but ignored` | [Plugin 故障排除](/docs/zh-CN/plugins/troubleshooting#marketplace-is-added-but-ignored) |
257| `Marketplace "<name>" is registered but was refused (see the debug log)` | [Plugin 故障排除](/docs/zh-CN/plugins/troubleshooting#marketplace-is-added-but-ignored) |
249| `references ${user_config.*} in a shell-form command` | [Plugin 错误](#plugin-command-references-user-config) |258| `references ${user_config.*} in a shell-form command` | [Plugin 错误](#plugin-command-references-user-config) |
250| `Monitor "<name>" from plugin <plugin> references ${user_config.*} in its command` | [Plugin 错误](#plugin-command-references-user-config) |259| `Monitor "<name>" from plugin <plugin> references ${user_config.*} in its command` | [Plugin 错误](#plugin-command-references-user-config) |
251| `headersHelper for MCP server '<name>' references ${user_config.*}` | [Plugin 错误](#plugin-command-references-user-config) |260| `headersHelper for MCP server '<name>' references ${user_config.*}` | [Plugin 错误](#plugin-command-references-user-config) |
252| `Plugin archive integrity check failed` | [Plugin 错误](#plugin-archive-integrity-check-failed) |261| `Plugin archive integrity check failed` | [Plugin 错误](#plugin-archive-integrity-check-failed) |
262| `An npm plugin source must name a registry package` | [Plugin 故障排除](/docs/zh-CN/plugins/troubleshooting#an-npm-plugin-source-must-name-a-registry-package) |
253| `path escapes plugin directory` | [Plugin 错误](#path-escapes-plugin-directory) |263| `path escapes plugin directory` | [Plugin 错误](#path-escapes-plugin-directory) |
254| `path could not be checked` | [Plugin 错误](#path-could-not-be-checked) |264| `path could not be checked` | [Plugin 错误](#path-could-not-be-checked) |
255| `its marketplace entry path does not stay inside the marketplace directory` | [Plugin 错误](#marketplace-entry-path-does-not-stay-inside-the-marketplace-directory) |265| `its marketplace entry path does not stay inside the marketplace directory` | [Plugin 错误](#marketplace-entry-path-does-not-stay-inside-the-marketplace-directory) |
342| `Unable to read managed policy settings` | [配置警告](#unable-to-read-managed-policy-settings) |352| `Unable to read managed policy settings` | [配置警告](#unable-to-read-managed-policy-settings) |
343| `otelHeadersHelper failed; telemetry is not being exported. See /status: ...` | [配置警告](#otelheadershelper-failed) |353| `otelHeadersHelper failed; telemetry is not being exported. See /status: ...` | [配置警告](#otelheadershelper-failed) |
344| `"crossSessionInbound" must be one of "accept", "hold", "refuse"` | [配置警告](#crosssessioninbound-must-be-one-of-accept-hold-refuse) |354| `"crossSessionInbound" must be one of "accept", "hold", "refuse"` | [配置警告](#crosssessioninbound-must-be-one-of-accept-hold-refuse) |
355| `API Error: ANTHROPIC_FOUNDRY_RESOURCE must be a Foundry resource name` | [配置警告](#anthropic-foundry-resource-must-be-a-foundry-resource-name) |
345| `headersHelper not run — this workspace has no persisted trust` | [配置警告](#headershelper-not-run) |356| `headersHelper not run — this workspace has no persisted trust` | [配置警告](#headershelper-not-run) |
346| `Invalid permission rule "..." was skipped: Malformed Tool(content) rule` | [配置警告](#malformed-tool-content-rule) |357| `Invalid permission rule "..." was skipped: Malformed Tool(content) rule` | [配置警告](#malformed-tool-content-rule) |
347| `... is not matched by file permission checks` | [配置警告](#is-not-matched-by-file-permission-checks) |358| `... is not matched by file permission checks` | [配置警告](#is-not-matched-by-file-permission-checks) |
360Claude Code 重试这些故障:371Claude Code 重试这些故障:
361 372
362* 在 Claude 响应开始流式传输之前到达的服务器错误、过载响应和请求超时。373* 在 Claude 响应开始流式传输之前到达的服务器错误、过载响应和请求超时。
363* 连接断开。当连接在请求过程中途断开,且 Claude 尚未完成其响应的任何部分(包括其思考过程)时,Claude Code 会使用相同的退避重新发送请求,转换继续进行,即使某些文本已经开始流式传输。当连接在 Claude 完成思考之后但在开始任何文本或工具调用之前断开时,Claude Code 改为快速连续重新发送请求最多两次,如果连接在该点继续断开,则以 `Connection lost before a response was produced` 结束转换。374* 在 Claude 完成思考之后、但在开始任何文本或工具调用之前到达的服务器错误或过载响应。Claude Code 会在该点重试服务器错误最多两次。在 v2.1.284 之前,Claude Code 会在该点以该错误结束轮次。
364* Claude Code 检测到的连接在您的计算机进入睡眠状态时在请求过程中途被破坏。Claude Code 将其计为上述规则下的断开连接;一旦重试标签命名了具体原因,它会读作 `Connection lost while your computer was asleep`,如果转换在 Claude 完成思考之后但在任何文本或工具调用之前结束,消息会读作 `Your computer went to sleep before a response was produced`。375* 连接断开。当连接在请求过程中途断开,且 Claude 尚未完成其响应的任何部分(包括其思考过程)时,Claude Code 会使用相同的退避重新发送请求,轮次继续进行,即使某些文本已经开始流式传输。当连接在 Claude 完成思考之后但在开始任何文本或工具调用之前断开时,Claude Code 改为快速连续重新发送请求最多两次,如果连接在该点继续断开,则以 `Connection lost before a response was produced` 结束轮次。
365* 停滞的响应流,当响应头已到达但 Claude 响应的任何部分都未到达,或当 Claude 完成思考但尚未开始任何文本或工具调用时:Claude Code 中止停滞连接并最多重新发送一次请求,不在上述 10 次尝试预算之外。如果响应在 Claude 完成思考之后但在任何文本或工具调用之前第二次停滞,Claude Code 以 `The response stalled before a response was produced` 结束转换。376* Claude Code 检测到的连接在您的计算机进入睡眠状态时在请求过程中途被破坏。Claude Code 将其计为上述规则下的断开连接;一旦重试标签命名了具体原因,它会读作 `Connection lost while your computer was asleep`,如果轮次在 Claude 完成思考之后但在任何文本或工具调用之前结束,消息会读作 `Your computer went to sleep before a response was produced`。
366* 流式请求 API 从未用响应头回答,在 [first-byte deadline runs](/docs/zh-CN/network-config#streaming-idle-watchdogs) 的连接上:Claude Code 在截止时间中止它,并在重试预算内每个模型请求最多重新发送一次,然后如果该尝试也未得到回答,则以 [No response from API](#no-response-from-api) 结束转换。在其他连接上,请求等待 `API_TIMEOUT_MS`。当您设置 `CLAUDE_CODE_RETRY_WATCHDOG` 时,一次重试上限不适用。377* 停滞的响应流,当响应头已到达但 Claude 响应的任何部分都未到达,或当 Claude 完成思考但尚未开始任何文本或工具调用时:Claude Code 中止停滞连接并最多重新发送一次请求,不计入上述 10 次尝试预算。如果响应在 Claude 完成思考之后但在任何文本或工具调用之前第二次停滞,Claude Code 以 `The response stalled before a response was produced` 结束轮次。
378* 流式请求 API 从未用响应头回答,在 [first-byte deadline runs](/docs/zh-CN/network-config#streaming-idle-watchdogs) 的连接上:Claude Code 在截止时间中止它,并在重试预算内每个模型请求最多重新发送一次,然后如果该尝试也未得到回答,则以 [No response from API](#no-response-from-api) 结束轮次。在其他连接上,请求等待 `API_TIMEOUT_MS`。当您设置 `CLAUDE_CODE_RETRY_WATCHDOG` 时,一次重试上限不适用。
367* 临时 429 节流,但不是网关的支出限制 `429`,这不是节流;请参阅 [Spend limit reached](#spend-limit-reached)。379* 临时 429 节流,但不是网关的支出限制 `429`,这不是节流;请参阅 [Spend limit reached](#spend-limit-reached)。
368 * 当您使用 claude.ai 订阅登录时,这包括不携带您计划配额头的 429 节流。在 v2.1.199 之前,Claude Code 仅对 API 密钥和企业登录重试这些节流。380 * 当您使用 claude.ai 订阅登录时,这包括不携带您套餐配额头的 429 节流。在 v2.1.199 之前,Claude Code 仅对 API 密钥和企业登录重试这些节流。
369* 因为输入加上 `max_tokens` 超过上下文限制而被拒绝的请求。以相同方式重新发送它会以相同方式失败,所以 Claude Code 使用减少的 `max_tokens` 重试,并在两种情况下停止重试并改为压缩:381* 因为输入加上 `max_tokens` 超过上下文限制而被拒绝的请求。以相同方式重新发送它会以相同方式失败,所以 Claude Code 使用减少的 `max_tokens` 重试,并在两种情况下停止重试并改为压缩:
370 * 当没有减少可以适应时,例如当对话本身几乎填满上下文窗口时。382 * 当没有减少可以适应时,例如当对话本身几乎填满上下文窗口时。
371 * 当重试无法进一步缩小 `max_tokens` 时。在 v2.1.218 之前,Claude Code 可以重新发送仍然不适应的减少请求,例如当扩展思考预算超过剩余上下文时,直到重试预算用尽。383 * 当重试无法进一步缩小 `max_tokens` 时。在 v2.1.218 之前,Claude Code 可以重新发送仍然不适应的减少请求,例如当扩展思考预算超过剩余上下文时,直到重试预算用尽。
372* [Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) 上过期或缺失的 Google Cloud 凭证,或在您的机器上加载失败的 AWS 凭证。Claude Code 丢弃其缓存的凭证并重试最多两次,然后报告错误以便您可以立即重新身份验证,如 [Could not load AWS or Google Cloud credentials](#could-not-load-aws-or-google-cloud-credentials) 下所述。在 v2.1.228 之前,Claude Code 通过完整重试预算重试失败的 Google Cloud 凭证,然后显示错误。384* [Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) 上过期或缺失的 Google Cloud 凭据,或在您的机器上加载失败的 AWS 凭据。Claude Code 丢弃其缓存的凭据并重试最多两次,然后报告错误以便您可以立即重新身份验证,如 [Could not load AWS or Google Cloud credentials](#could-not-load-aws-or-google-cloud-credentials) 下所述。在 v2.1.228 之前,Claude Code 通过完整重试预算重试失败的 Google Cloud 凭据,然后显示错误。
373* 来自 Anthropic API 的 `401` 或 `403`,直接或通过 [LLM gateway](/docs/zh-CN/llm-gateway),而 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 脚本提供凭证。Claude Code 重新运行脚本并使用其新输出重试,在完整重试预算内。当脚本本身在重新运行时失败时,Claude Code 改为显示 [Your apiKeyHelper script is failing](#your-apikeyhelper-script-is-failing)。385* 来自 Anthropic API 的 `401` 或 `403`,直接或通过 [LLM gateway](/docs/zh-CN/llm-gateway),而 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 脚本提供凭据。Claude Code 重新运行脚本并使用其新输出重试,在完整重试预算内。当脚本本身在重新运行时失败时,Claude Code 改为显示 [Your apiKeyHelper script is failing](#your-apikeyhelper-script-is-failing)。
374 386
375在 v2.1.227 之前,`Connection lost before a response was produced` 读作 `Connection closed while thinking, before producing a response`,`The response stalled before a response was produced` 读作 `Response stalled while thinking, before producing a response`。387在 v2.1.227 之前,`Connection lost before a response was produced` 读作 `Connection closed while thinking, before producing a response`,`The response stalled before a response was produced` 读作 `Response stalled while thinking, before producing a response`。
376 388
377Claude Code 不重试这些故障:389Claude Code 不重试这些故障:
378 390
379* TLS 证书验证失败,例如 TLS 检查代理、缺失的 `NODE_EXTRA_CA_CERTS` 包或过期的证书。Claude Code 在第一次尝试时报告错误,以便您可以立即修复证书设置;请参阅 [SSL certificate errors](#ssl-certificate-errors)。Claude Code 仍然重试瞬时 TLS 条件,例如握手超时。在 v2.1.199 之前,Claude Code 通过完整重试预算重试证书失败,然后显示错误。391* TLS 证书验证失败,例如 TLS 检查代理、缺失的 `NODE_EXTRA_CA_CERTS` 包或过期的证书。Claude Code 在第一次尝试时报告错误,以便您可以立即修复证书设置;请参阅 [SSL certificate errors](#ssl-certificate-errors)。Claude Code 仍然重试瞬时 TLS 条件,例如握手超时。在 v2.1.199 之前,Claude Code 通过完整重试预算重试证书失败,然后显示错误。
380* 服务器错误、断开连接或停滞流在 Claude 完成文本块或工具调用之后到达,或在完成思考之后开始一个但在完成响应之前。Claude Code 不重新运行请求,因为这可能会执行相同的工具调用两次。它保留 Claude 完成的内容,运行 Claude 完成的任何工具调用,并从其结果继续转换。对于您在交互式会话和非交互式会话中看到的内容,请阅读 [The response above may be incomplete](#the-response-above-may-be-incomplete)。在 v2.1.199 之前,当服务器错误在流中途到达时,Claude Code 丢弃部分输出并将整个转换报告为错误。392* 服务器错误、断开连接或停滞流在 Claude 完成文本块或工具调用之后到达,或在完成思考之后开始一个但在完成响应之前。Claude Code 不重新运行请求,因为这可能会执行相同的工具调用两次。它保留 Claude 完成的内容,运行 Claude 完成的任何工具调用,并从其结果继续轮次。对于您在交互式会话和非交互式会话中看到的内容,请阅读 [The response above may be incomplete](#the-response-above-may-be-incomplete)。在 v2.1.199 之前,当服务器错误在流中途到达时,Claude Code 丢弃部分输出并将整个轮次报告为错误。
381* 在 Claude 完成响应之后到达的故障:无需重试任何内容,所以 Claude Code 保留完整响应并正常结束转换。393* 在 Claude 完成响应之后到达的故障:无需重试任何内容,所以 Claude Code 保留完整响应并正常结束轮次。
382* [Amazon Bedrock 流式响应具有意外的 content-type](#bedrock-streaming-response-has-an-unexpected-content-type),因为重写响应的网关或代理会以相同方式重写重试。需要 Claude Code v2.1.208 或更高版本。394* [Amazon Bedrock 流式响应具有意外的 content-type](#bedrock-streaming-response-has-an-unexpected-content-type),因为重写响应的网关或代理会以相同方式重写重试。需要 Claude Code v2.1.208 或更高版本。
383* 失败的流式请求的非流式重试获得成功状态但 [body 中没有 Claude API 消息](#api-returned-an-empty-or-malformed-response)。Claude Code 以该错误结束转换。395* 失败的流式请求的非流式重试获得成功状态但 [body 中没有 Claude API 消息](#api-returned-an-empty-or-malformed-response)。Claude Code 以该错误结束轮次。
384* 您的组织的策略检查拒绝的请求,其表现为携带拒绝消息的 `API Error:` 行。您的组织管理员使用 [Inference hooks](https://platform.claude.com/docs/en/manage-claude/inference-hooks)(Claude Enterprise 功能)设置检查,消息以他们配置的说明结尾,或默认告诉您联系他们。Claude Code 不会将拒绝的请求重新发送到相同模型或 [fallback model](/docs/zh-CN/model-config#fallback-model-chains),因为拒绝涉及请求的内容而不是模型。在 v2.1.239 之前,Claude Code 可以重新发送拒绝的请求,不流式传输或在配置的备用模型上,然后向您显示拒绝。396* 您的组织的策略检查拒绝的请求,其表现为携带拒绝消息的 `API Error:` 行。您的组织管理员使用 [Inference hooks](https://platform.claude.com/docs/en/manage-claude/inference-hooks)(Claude Enterprise 功能)设置检查,消息以他们配置的说明结尾,或默认告诉您联系他们。Claude Code 不会将拒绝的请求重新发送到相同模型或 [fallback model](/docs/zh-CN/model-config#fallback-model-chains),因为拒绝涉及请求的内容而不是模型。在 v2.1.239 之前,Claude Code 可以重新发送拒绝的请求,不流式传输或在配置的备用模型上,然后向您显示拒绝。
385 397
386<h3 id="what-you-see-while-claude-code-retries-or-waits">398<h3 id="what-you-see-while-claude-code-retries-or-waits">
393 405
394如果在请求仍然待处理时响应流上 20 秒内没有数据到达,微调器显示 `Waiting for API response · will retry in … · check your network`,然后任何重试都尚未开始。请求尚未失败:倒计时运行到 Claude Code 中止停滞连接的点。中止后,您看到的内容取决于响应已进行的距离:406如果在请求仍然待处理时响应流上 20 秒内没有数据到达,微调器显示 `Waiting for API response · will retry in … · check your network`,然后任何重试都尚未开始。请求尚未失败:倒计时运行到 Claude Code 中止停滞连接的点。中止后,您看到的内容取决于响应已进行的距离:
395 407
396* 在 Claude 完成文本块或工具调用之前,或在完成思考之后开始一个,Claude Code 重试请求或以错误结束转换。[Automatic retries](#automatic-retries) 说明它重试哪些停滞以及多少次。408* 在 Claude 完成文本块或工具调用之前,或在完成思考之后开始一个,Claude Code 重试请求或以错误结束轮次。[Automatic retries](#automatic-retries) 说明它重试哪些停滞以及多少次。
397* 在 Claude 完成文本块或工具调用之后,或在完成思考之后开始一个,但在 Claude 完成响应之前,Claude Code 保留 Claude 完成的内容,从 Claude 完成的任何工具调用继续转换,并显示 [The response above may be incomplete](#the-response-above-may-be-incomplete)。在非交互式会话中,以及对于任何会话中的子代理响应,Claude Code 可能首先提示 Claude 继续响应;该条目说明何时执行以及何时您仍然在那里看到通知。409* 在 Claude 完成文本块或工具调用之后,或在完成思考之后开始一个,但在 Claude 完成响应之前,Claude Code 保留 Claude 完成的内容,从 Claude 完成的任何工具调用继续轮次,并显示 [The response above may be incomplete](#the-response-above-may-be-incomplete)。在非交互式会话中,以及对于任何会话中的子代理响应,Claude Code 可能首先提示 Claude 继续响应;该条目说明何时执行以及何时您仍然在那里看到通知。
398* 在 Claude 完成响应之后,Claude Code 正常结束转换。410* 在 Claude 完成响应之后,Claude Code 正常结束轮次。
399 411
400一旦数据恢复或重试成功,横幅会自动清除。如果它在每次尝试时重新出现,将其视为 [network issue](#unable-to-connect-to-api)。在 v2.1.185 之前,横幅在 10 秒后出现,措辞不同。412一旦数据恢复或重试成功,横幅会自动清除。如果它在每次尝试时重新出现,将其视为 [network issue](#unable-to-connect-to-api)。在 v2.1.185 之前,横幅在 10 秒后出现,措辞不同。
401 413
402当 Claude 咨询 [advisor](/docs/zh-CN/advisor) 时,横幅在 90 秒无数据后出现,而不是 20 秒,因为长时间的顾问审查可以发送超过 20 秒的任何内容。在 v2.1.214 之前,20 秒阈值也适用于顾问调用,所以横幅在顾问审查期间出现,即使没有任何问题。414当 Claude 咨询 [advisor](/docs/zh-CN/advisor) 时,横幅在 90 秒无数据后出现,而不是 20 秒,因为长时间的顾问审查可能在远超 20 秒的时间内不发送任何数据。在 v2.1.214 之前,20 秒阈值也适用于顾问调用,所以横幅在顾问审查期间出现,即使没有任何问题。
403 415
404<h3 id="tune-retry-behavior">416<h3 id="tune-retry-behavior">
405 调整重试行为417 调整重试行为
418 服务器错误430 服务器错误
419</h2>431</h2>
420 432
421这些错误中的大多数来自推理提供商:Anthropic API 上的 Anthropic 服务,以及 Amazon Bedrock、Google Cloud 的 Agent Platform、Microsoft Foundry 或自定义网关上该提供商端点后面的服务。[Auto mode 无法确定操作的安全性](#auto-mode-cannot-determine-the-safety-of-an-action)和[Agent 因 API 错误而提前终止](#agent-terminated-early-due-to-an-api-error)也涵盖了您这一方的原因,例如无法调用分类器模型的 Amazon Bedrock 账户或达到使用限制的子代理。433这些错误中的大多数来自推理提供商:Anthropic API 上的 Anthropic 服务,以及 Amazon Bedrock、Google Cloud 的 Agent Platform、Microsoft Foundry 或自定义网关上该提供商端点后面的服务。[自动模式无法确定操作的安全性](#auto-mode-cannot-determine-the-safety-of-an-action)和[Agent 因 API 错误而提前终止](#agent-terminated-early-due-to-an-api-error)也涵盖了您这一方的原因,例如无法调用分类器模型的 Amazon Bedrock 账户或达到用量限制的子代理。
422 434
423<h3 id="api-error-500-internal-server-error">435<h3 id="api-error-500-internal-server-error">
424 API Error: 500 Internal server error436 API Error: 500 Internal server error
432 444
433尾部句子指出了检查服务健康状况的位置,因提供商而异。Amazon Bedrock、Google Cloud 的 Agent Platform 和 Microsoft Foundry 配置会指出该提供商的服务状态。自定义 `ANTHROPIC_BASE_URL` 会指出网关主机。445尾部句子指出了检查服务健康状况的位置,因提供商而异。Amazon Bedrock、Google Cloud 的 Agent Platform 和 Microsoft Foundry 配置会指出该提供商的服务状态。自定义 `ANTHROPIC_BASE_URL` 会指出网关主机。
434 446
435API 本身的 5xx 表示 API 内部出现了意外故障。它不是由您的提示、设置或账户引起的。447API 本身的 5xx 表示 API 内部出现了意外故障。它不是由您的提示词、设置或账户引起的。
436 448
437当代理、负载均衡器或网关用 HTML 错误页面回复时,消息显示状态代码和页面的标题,例如 `API Error: 502 Bad Gateway`。对于没有标题的页面,消息显示状态代码及其标准名称。在 v2.1.281 之前,当页面有标题时状态代码被丢弃,当页面没有标题时打印页面的原始标记。449当代理、负载均衡器或网关用 HTML 错误页面回复时,消息显示状态代码和页面的标题,例如 `API Error: 502 Bad Gateway`。对于没有标题的页面,消息显示状态代码及其标准名称。在 v2.1.281 之前,当页面有标题时状态代码被丢弃,当页面没有标题时打印页面的原始标记。
438 450
439**应该做什么:**451**应该做什么:**
440 452
441* 检查 [status.claude.com](https://status.claude.com) 或消息中指出的提供商状态页面,查看是否有活跃事件453* 检查 [status.claude.com](https://status.claude.com) 或消息中指出的提供商状态页面,查看是否有活跃事件
442* 等待一分钟,然后再次发送您的消息。您的原始消息仍在对话中,因此对于较长的提示,您可以输入 `try again` 而不是粘贴整个内容。454* 等待一分钟,然后再次发送您的消息。您的原始消息仍在对话中,因此对于较长的提示词,您可以输入 `try again` 而不是粘贴整个内容。
443* 如果错误持续存在且没有发布事件,请运行 `/feedback` 以便 Anthropic 可以使用您的请求详情进行调查。如果您的环境中 `/feedback` 不可用,请参阅[报告错误](#report-an-error)。455* 如果错误持续存在且没有发布事件,请运行 `/feedback` 以便 Anthropic 可以使用您的请求详情进行调查。如果您的环境中 `/feedback` 不可用,请参阅[报告错误](#report-an-error)。
444 456
445<h3 id="api-error-repeated-529-overloaded-errors">457<h3 id="api-error-repeated-529-overloaded-errors">
454 466
455尾部句子因提供商而异,方式与上面的 500 错误相同。467尾部句子因提供商而异,方式与上面的 500 错误相同。
456 468
457529 不是您的使用限制,也不会计入您的配额。469529 不是您的用量限制,也不会计入您的配额。
458 470
459**应该做什么:**471**应该做什么:**
460 472
474Request timed out486Request timed out
475```487```
476 488
477这可能在高负载期间或模型生成非常大的响应时发生。默认请求超时为 10 分钟。489这可能在高负载期间或模型生成非常大的响应时发生。默认请求超时时间为 10 分钟。
478 490
479**应该做什么:**491**应该做什么:**
480 492
486 No response from API498 No response from API
487</h3>499</h3>
488 500
489Claude Code 发送了流式请求,API 在第一个字节的截止时间内没有返回响应头,因此 Claude Code 中止了请求,而不是等待完整的 `API_TIMEOUT_MS` 请求超时(默认为 10 分钟)。Claude Code 最多再发送一次请求,如果[重试预算](#tune-retry-behavior)允许的话。当重试也没有得到回复时,该轮次以此消息结束,该消息显示每次尝试等待了多长时间。当您设置 [`CLAUDE_CODE_RETRY_WATCHDOG`](/docs/zh-CN/env-vars) 时,一次重试的上限不适用,Claude Code 在[调整重试行为](#tune-retry-behavior)中描述的预算下重试。501Claude Code 发送了流式请求,API 在第一个字节的截止时间内没有返回响应头,因此 Claude Code 中止了请求,而不是等待完整的 `API_TIMEOUT_MS` 请求超时时间(默认为 10 分钟)。Claude Code 最多再发送一次请求,如果[重试预算](#tune-retry-behavior)允许的话。当重试也没有得到回复时,该轮次以此消息结束,该消息显示每次尝试等待了多长时间。当您设置 [`CLAUDE_CODE_RETRY_WATCHDOG`](/docs/zh-CN/env-vars) 时,一次重试的上限不适用,Claude Code 在[调整重试行为](#tune-retry-behavior)中描述的预算下重试。
490 502
491```text theme={null}503```text theme={null}
492API Error: No response from API (waited 3m, then 10m on the retry). If a proxy or gateway on your network holds responses until they complete, raise API_TIMEOUT_MS or CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS to wait longer.504API Error: No response from API (waited 3m, then 10m on the retry). If a proxy or gateway on your network holds responses until they complete, raise API_TIMEOUT_MS or CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS to wait longer.
494 506
495Claude Code 分别为第一次尝试的等待响应头和重试的等待设置:507Claude Code 分别为第一次尝试的等待响应头和重试的等待设置:
496 508
497* **第一次尝试**:当您将其设置为 1 或更多时使用 [`CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS`](/docs/zh-CN/env-vars),限制在 10 秒到 30 分钟之间。否则 Claude Code 使用[流式空闲监视程序](/docs/zh-CN/network-config#streaming-idle-watchdogs)中列出的字节级监视程序超时,因此改变该超时的变量也会改变此等待。无论哪种方式,Claude Code 为请求体的每 32KB 添加一秒。509* **第一次尝试**:当您将其设置为 1 或更多时使用 [`CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS`](/docs/zh-CN/env-vars),限制在 10 秒到 30 分钟之间。否则 Claude Code 使用[流式空闲监视程序](/docs/zh-CN/network-config#streaming-idle-watchdogs)中列出的字节级监视程序超时时间,因此改变该超时时间的变量也会改变此等待。无论哪种方式,Claude Code 为请求体的每 32KB 添加一秒。
498* **重试**:比 `API_TIMEOUT_MS` 少一秒,默认略低于 10 分钟,以便重试可以超过保持响应直到生成完成的代理或网关。在 Amazon Bedrock 上,重试使用与第一次尝试相同的截止时间,消息显示一个持续时间而不是两个。510* **重试**:比 `API_TIMEOUT_MS` 少一秒,默认略低于 10 分钟,以便重试可以超过保持响应直到生成完成的代理或网关。在 Amazon Bedrock 上,重试使用与第一次尝试相同的截止时间,消息显示一个持续时间而不是两个。
499 511
500两个等待都不超过正 `API_TIMEOUT_MS` 少一秒,正 `API_TIMEOUT_MS` 低于 11 秒会关闭截止时间。字节级监视程序仅在响应头到达后才开始,因此在此之后停止发送字节的响应遵循[停滞流规则](#automatic-retries)而不是此截止时间。512两个等待都不超过正 `API_TIMEOUT_MS` 少一秒,正 `API_TIMEOUT_MS` 低于 11 秒会关闭截止时间。字节级监视程序仅在响应头到达后才开始,因此在此之后停止发送字节的响应遵循[停滞流规则](#automatic-retries)而不是此截止时间。
501 513
502**应该做什么:**514**应该做什么:**
503 515
504* 再次发送您的消息。您的原始消息仍在对话中,因此对于较长的提示,您可以输入 `try again` 而不是粘贴整个内容。516* 再次发送您的消息。您的原始消息仍在对话中,因此对于较长的提示词,您可以输入 `try again` 而不是粘贴整个内容。
505* 如果重复出现,将其视为[网络或代理问题](#unable-to-connect-to-api)。517* 如果重复出现,将其视为[网络或代理问题](#unable-to-connect-to-api)。
506* 如果您网络上的代理或网关保持响应直到完成,请提高 `API_TIMEOUT_MS` 以便重试等待更长时间。在 Amazon Bedrock 上,也提高 `CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS`。518* 如果您网络上的代理或网关保持响应直到完成,请提高 `API_TIMEOUT_MS` 以便重试等待更长时间。在 Amazon Bedrock 上,也提高 `CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS`。
507* 如果第一次尝试持续超时,然后重试成功,请提高 `CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS` 以便第一次尝试也等待足够长的时间。519* 如果第一次尝试持续超时,然后重试成功,请提高 `CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS` 以便第一次尝试也等待足够长的时间。
508 520
509在 v2.1.242 之前,Claude Code 在未回复的流式请求失败之前等待完整的 `API_TIMEOUT_MS` 请求超时(默认为 10 分钟)。在 v2.1.261 之前,重试等待与第一次尝试相同的截止时间,消息没有显示持续时间。521在 v2.1.242 之前,Claude Code 在未回复的流式请求失败之前等待完整的 `API_TIMEOUT_MS` 请求超时时间(默认为 10 分钟)。在 v2.1.261 之前,重试等待与第一次尝试相同的截止时间,消息没有显示持续时间。
510 522
511<h3 id="the-response-above-may-be-incomplete">523<h3 id="the-response-above-may-be-incomplete">
512 The response above may be incomplete524 The response above may be incomplete
528* `Your computer went to sleep mid-response`:Claude Code 检测到您的计算机在响应流式传输时进入睡眠状态。一旦您的计算机唤醒,Claude Code 会将连接视为断开并停止从中读取。540* `Your computer went to sleep mid-response`:Claude Code 检测到您的计算机在响应流式传输时进入睡眠状态。一旦您的计算机唤醒,Claude Code 会将连接视为断开并停止从中读取。
529* `Part of the response never arrived`:流事件在 API 和 Claude Code 之间被丢弃,因此后来的事件引用了从未到达的内容。在 v2.1.281 之前,此情况以 `API Error: Content block not found` 结束轮次。541* `Part of the response never arrived`:流事件在 API 和 Claude Code 之间被丢弃,因此后来的事件引用了从未到达的内容。在 v2.1.281 之前,此情况以 `API Error: Content block not found` 结束轮次。
530* `The response stream was malformed`:为已完成的内容块到达了事件,或事件到达时已损坏。损坏的事件是指其数据不是有效 JSON、其内容缺失或其内容与事件类型不匹配的事件。在 v2.1.284 之前,当具有无效 JSON 的事件在 Claude 完成其思考、文本块或工具调用后到达时,解析器的原始错误(例如以 `API Error: JSON Parse error` 开头的错误)出现。542* `The response stream was malformed`:为已完成的内容块到达了事件,或事件到达时已损坏。损坏的事件是指其数据不是有效 JSON、其内容缺失或其内容与事件类型不匹配的事件。在 v2.1.284 之前,当具有无效 JSON 的事件在 Claude 完成其思考、文本块或工具调用后到达时,解析器的原始错误(例如以 `API Error: JSON Parse error` 开头的错误)出现。
531* `The response stopped arriving`:连接保持打开但停止传递数据,因此流式空闲监视程序中止了它。在 v2.1.222 之前,Claude Code 也可能在通过 `ANTHROPIC_BASE_URL` 或 `ANTHROPIC_AWS_BASE_URL` 到达的[网关](/docs/zh-CN/gateways)连接上报告此故障,同时服务器的保活 ping 仍在到达,因为它只在那里计算已解析的响应事件;升级会停止这些虚假超时。通过提供商基础 URL(如 `ANTHROPIC_BEDROCK_BASE_URL`)到达的网关不被字节监视程序包装;请参阅[流式空闲监视程序](/docs/zh-CN/network-config#streaming-idle-watchdogs)。543* `The response stopped arriving`:连接保持打开但停止传递数据,因此流式空闲监视程序中止了它。在 v2.1.222 之前,Claude Code 也可能在通过 `ANTHROPIC_BASE_URL` 或 `ANTHROPIC_AWS_BASE_URL` 到达的[网关](/docs/zh-CN/gateways)连接上报告此故障,同时服务器的保活 ping 仍在到达,因为它只在那里计算已解析的响应事件;升级会在这些路由上停止这些虚假超时。通过提供商基础 URL(如 `ANTHROPIC_BEDROCK_BASE_URL`)到达的网关不被字节监视程序包装;请参阅[流式空闲监视程序](/docs/zh-CN/network-config#streaming-idle-watchdogs)。
532 544
533在 v2.1.227 之前,`Connection lost mid-response` 读作 `Connection closed mid-response`,`The response stopped arriving` 读作 `Response stalled mid-stream`。545在 v2.1.227 之前,`Connection lost mid-response` 读作 `Connection closed mid-response`,`The response stopped arriving` 读作 `Response stalled mid-stream`。
534 546
541 553
542* 在响应的早期,Claude Code 要么重试故障,要么以不同的错误结束轮次。请参阅[自动重试](#automatic-retries)。554* 在响应的早期,Claude Code 要么重试故障,要么以不同的错误结束轮次。请参阅[自动重试](#automatic-retries)。
543* 当这些故障之一在 Claude 完成响应后到达时,Claude Code 保留完整响应并正常结束轮次,没有此通知。在 v2.1.222 之前,当连接在响应完成后断开或停滞时,Claude Code 显示此通知,并将轮次报告为错误,即使响应是完整的。555* 当这些故障之一在 Claude 完成响应后到达时,Claude Code 保留完整响应并正常结束轮次,没有此通知。在 v2.1.222 之前,当连接在响应完成后断开或停滞时,Claude Code 显示此通知,并将轮次报告为错误,即使响应是完整的。
544* 在[非交互式会话](/docs/zh-CN/headless)中,例如 `-p` 运行、[Agent SDK](/docs/zh-CN/agent-sdk/overview) 运行或[云会话](/docs/zh-CN/claude-code-on-the-web),当截断响应在主对话中且包含文本但没有工具调用时,您不必自己发送 `continue`:Claude Code 保留部分输出并提示 Claude 从停止的地方继续,最多连续三次。您只有在 Claude Code 用完这些继续后才会看到此通知。在 v2.1.246 之前,Claude Code 在第一次截断时以此通知结束非交互式轮次。556* 在[非交互式会话](/docs/zh-CN/headless)中,例如 `-p` 运行、[Agent SDK](/docs/zh-CN/agent-sdk/overview) 运行或[云端会话](/docs/zh-CN/claude-code-on-the-web),当截断响应在主对话中且包含文本但没有工具调用时,您不必自己发送 `continue`:Claude Code 保留部分输出并提示 Claude 从停止的地方继续,最多连续三次。您只有在 Claude Code 用完这些继续后才会看到此通知。在 v2.1.246 之前,Claude Code 在第一次截断时以此通知结束非交互式轮次。
545* 在[子代理](/docs/zh-CN/sub-agents#api-errors-in-subagents)中,无论会话是否交互式:当其截断响应包含文本但没有工具调用时,Claude Code 提示子代理继续。通知仅在这些继续用完后才成为子代理的最后一条消息。在 v2.1.257 之前,子代理在第一次截断时显示此通知。557* 在[子代理](/docs/zh-CN/sub-agents#api-errors-in-subagents)中,无论会话是否交互式:当其截断响应包含文本但没有工具调用时,Claude Code 提示子代理继续。通知仅在这些继续用完后才成为子代理的最后一条消息。在 v2.1.257 之前,子代理在第一次截断时显示此通知。
546 558
547**应该做什么:**559**应该做什么:**
548 560
549* 在交互式会话中,阅读屏幕上剩余的响应:Claude Code 保留 Claude 在错误前完成的每个块,但当轮次结束时丢弃中断的最后块,因此最后的句子或工具调用可能会丢失。回复 `continue` 以让 Claude 从其最后完成的块继续。561* 在交互式会话中,阅读屏幕上剩余的响应:Claude Code 保留 Claude 在错误前完成的每个块,但当轮次结束时丢弃中断的最后块,因此最后的句子或工具调用可能会丢失。回复 `continue` 以让 Claude 从其最后完成的块继续。
550* 在[非交互式模式](/docs/zh-CN/headless)(`-p`)中:562* 在[非交互模式](/docs/zh-CN/headless)(`-p`)中:
551 * 使用默认文本输出,Claude Code 打印它仍然从轮次早期保留的最后完成的文本块,然后是此消息。当它不保留任何内容时,Claude Code 仅打印此消息,例如因为 Claude Code 在轮次中间压缩了对话并清除了该文本。在 v2.1.219 之前,Claude Code 仅在 `-p` 文本输出中打印此消息并丢弃它已经生成的响应。563 * 使用默认文本输出,Claude Code 打印它仍然从轮次早期保留的最后完成的文本块,然后是此消息。当它不保留任何内容时,Claude Code 仅打印此消息,例如因为 Claude Code 在轮次中间压缩了对话并清除了该文本。在 v2.1.219 之前,Claude Code 仅在 `-p` 文本输出中打印此消息并丢弃它已经生成的响应。
552 * 使用 `--output-format json` 或 `stream-json`,Claude Code 在 `result` 字段中报告此消息。564 * 使用 `--output-format json` 或 `stream-json`,Claude Code 在 `result` 字段中报告此消息。
553 * 一旦连接稳定,要继续该轮次,请恢复会话并按照[继续对话](/docs/zh-CN/headless#continue-conversations)中的说明发送 `continue`。565 * 一旦连接稳定,要继续该轮次,请恢复会话并按照[继续对话](/docs/zh-CN/headless#continue-conversations)中的说明发送 `continue`。
556 Auto mode cannot determine the safety of an action568 Auto mode cannot determine the safety of an action
557</h3>569</h3>
558 570
559[auto mode](/docs/zh-CN/permission-modes#eliminate-prompts-with-auto-mode) 使用的模型无法对操作进行分类,因此 auto mode 没有自动批准该操作。您看到的消息取决于分类器如何失败。571[自动模式](/docs/zh-CN/permission-modes#eliminate-prompts-with-auto-mode)使用的模型无法对操作进行分类,因此自动模式没有自动批准该操作。您看到的消息取决于分类器如何失败。
560 572
561对工作目录内的读取、搜索和编辑会跳过分类器,因此它们在所有这些情况下都继续工作。573对工作目录内的读取、搜索和编辑会跳过分类器,因此它们在所有这些情况下都继续工作。
562 574
572 584
573**应该做什么:**585**应该做什么:**
574 586
575* 几秒后重试;Claude 看到相同的消息,通常会自动重试。暂时故障与 [auto mode 资格](/docs/zh-CN/permission-modes#eliminate-prompts-with-auto-mode)无关;您不需要更改设置587* 几秒后重试;Claude 看到相同的消息,通常会自动重试。暂时故障与[自动模式资格](/docs/zh-CN/permission-modes#eliminate-prompts-with-auto-mode)无关;您不需要更改设置
576* 如果重试持续失败,继续进行只读任务,稍后回到被阻止的操作588* 如果重试持续失败,继续进行只读任务,稍后回到被阻止的操作
577* 在 Amazon Bedrock 上,如果消息在每次重试时返回,请检查您的账户是否可以调用它指出的模型:对于标准 Amazon Bedrock 模型,确认您的 [IAM 策略](/docs/zh-CN/amazon-bedrock#iam-configuration)允许调用它;对于 Mantle 模型 ID,[联系您的 AWS 账户团队](/docs/zh-CN/amazon-bedrock#mantle-endpoint-errors)589* 在 Amazon Bedrock 上,如果消息在每次重试时返回,请检查您的账户是否可以调用它指出的模型:对于标准 Amazon Bedrock 模型,确认您的 [IAM 策略](/docs/zh-CN/amazon-bedrock#iam-configuration)允许调用它;对于 Mantle 模型 ID,[联系您的 AWS 账户团队](/docs/zh-CN/amazon-bedrock#mantle-endpoint-errors)
578 590
579当分类器请求失败是因为您的 OAuth 令牌过期或被另一个会话轮换时,Claude Code 刷新令牌并重试请求一次,因此例行令牌过期不会显示为此消息。在 v2.1.216 之前,过期或轮换的令牌会导致每个分类器请求失败,auto mode 会拒绝每个检查的操作,直到令牌被刷新。591当分类器请求失败是因为您的 OAuth 令牌过期或被另一个会话轮换时,Claude Code 刷新令牌并重试请求一次,因此常规的令牌过期不会显示为此消息。在 v2.1.216 之前,过期或轮换的令牌会导致每个分类器请求失败,自动模式会以此消息拒绝每个检查的操作,直到令牌被刷新。
580 592
581当分类器返回无法解析的响应时:593当分类器返回无法解析的响应时:
582 594
595Auto mode could not evaluate this action and is blocking it for safety — a safety check separate from auto mode blocked this request because of earlier conversation content — it isn't about the action itself — run with --debug for details607Auto mode could not evaluate this action and is blocking it for safety — a safety check separate from auto mode blocked this request because of earlier conversation content — it isn't about the action itself — run with --debug for details
596```608```
597 609
598Claude Code 拒绝该操作,但告诉 Claude 这不是对该操作不安全的判断,并继续进行其他任务而不是重试。这些拒绝不计入 [auto mode 的暂停阈值](/docs/zh-CN/permission-modes#when-auto-mode-falls-back)。在[非交互式](/docs/zh-CN/headless) `-p` 运行中,Claude Code 不会停止运行。Claude 接收的内容取决于它请求操作的位置:610Claude Code 拒绝该操作,但告诉 Claude 这不是对该操作不安全的判断,并继续进行其他任务而不是重试。这些拒绝不计入[自动模式的暂停阈值](/docs/zh-CN/permission-modes#when-auto-mode-falls-back)。在[非交互式](/docs/zh-CN/headless) `-p` 运行中,Claude Code 不会停止运行。Claude 接收的内容取决于它请求操作的位置:
599 611
600* 对于 `-p` 运行中没有 `--input-format stream-json` 的[后台子代理](/docs/zh-CN/sub-agents#run-subagents-in-foreground-or-background),Claude Code 返回包含 `Agent aborted: auto mode classifier request refused by the safety safeguard in headless mode` 的错误结果612* 对于 `-p` 运行中没有 `--input-format stream-json` 的[后台子代理](/docs/zh-CN/sub-agents#run-subagents-in-foreground-or-background),Claude Code 返回包含 `Agent aborted: auto mode classifier request refused by the safety safeguard in headless mode` 的错误结果
601* 在其他地方,包括交互式会话和 `-p` 运行的主对话,Claude Code 将该拒绝返回给 Claude613* 在其他地方,包括交互式会话和 `-p` 运行的主对话,Claude Code 将该拒绝返回给 Claude
602 614
603在 v2.1.225 之前,Claude Code 将这些拒绝计入暂停阈值,并返回与真正分类器块相同的拒绝消息。615在 v2.1.225 之前,Claude Code 将这些拒绝计入暂停阈值,并返回与真正分类器阻止相同的拒绝消息。
604 616
605**应该做什么:**617**应该做什么:**
606 618
607* 这不是对您的操作的决定。您对话中已有的内容在 auto mode 将对话发送给分类器时触发了 API 上的安全过滤器619* 这不是对您的操作的决定。您对话中已有的内容在自动模式将对话发送给分类器时触发了 API 上的安全过滤器
608* 重试无法帮助;相同的对话内容将再次触发过滤器620* 重试无法帮助;相同的对话内容将再次触发过滤器
609* 在交互式会话中,切换到不同的[权限模式](/docs/zh-CN/permission-modes),以便您可以在提示时批准该操作621* 在交互式会话中,切换到不同的[权限模式](/docs/zh-CN/permission-modes),以便您可以在提示时批准该操作
610* 开始一个新对话,不包含触发内容622* 开始一个新对话,不包含触发内容
617 629
618操作发生的情况取决于 Claude 请求它的位置:630操作发生的情况取决于 Claude 请求它的位置:
619 631
620* 在交互式会话中,auto mode 回退到该操作的正常权限提示,以便您可以手动批准或拒绝它632* 在交互式会话中,自动模式回退到该操作的正常权限提示,以便您可以手动批准或拒绝它
621* 对于[非交互式](/docs/zh-CN/headless) `-p` 运行中没有 `--input-format stream-json` 的[后台子代理](/docs/zh-CN/sub-agents#run-subagents-in-foreground-or-background),Claude Code 返回包含 `Agent aborted: auto mode classifier transcript exceeded context window in headless mode` 的错误结果,运行继续633* 对于[非交互式](/docs/zh-CN/headless) `-p` 运行中没有 `--input-format stream-json` 的[后台子代理](/docs/zh-CN/sub-agents#run-subagents-in-foreground-or-background),Claude Code 返回包含 `Agent aborted: auto mode classifier transcript exceeded context window in headless mode` 的错误结果,运行继续
622* 在 `-p` 运行中的其他地方,没有 [`--permission-prompt-tool`](/docs/zh-CN/cli-reference#cli-flags),没有提示可以回退到,因此操作不运行,运行继续634* 在 `-p` 运行中的其他地方,没有 [`--permission-prompt-tool`](/docs/zh-CN/cli-reference#cli-flags),没有提示可以回退到,因此操作不运行,运行继续
623 635
630 The server returned no safety verdict642 The server returned no safety verdict
631</h3>643</h3>
632 644
633在[服务器端分类器审查](/docs/zh-CN/permission-modes#server-side-classifier-review)下,当服务器对操作没有给出判决时,auto mode 拒绝该操作。当 Claude Code 可以确定一个类别时,拒绝会在括号中指出一个类别,例如 `(timed out)`:645在[服务器端分类器审查](/docs/zh-CN/permission-modes#server-side-classifier-review)下,当服务器对操作没有给出判决时,自动模式拒绝该操作。当 Claude Code 可以确定一个类别时,拒绝会在括号中指出一个类别,例如 `(timed out)`:
634 646
635```text theme={null}647```text theme={null}
636The server-side auto mode classifier gave no verdict (timed out), so auto mode cannot determine the safety of <tool>.648The server-side auto mode classifier gave no verdict (timed out), so auto mode cannot determine the safety of <tool>.
638 650
639消息的其余部分告诉 Claude 一次重试是否可以帮助。在某些这些拒绝之前,Claude Code 会等待,以便 Claude 的下一次尝试不会立即跟随。在交互式会话中等待期间,微调器显示 `Auto mode check unavailable` 和倒计时,按 `Esc` 会中断轮次。651消息的其余部分告诉 Claude 一次重试是否可以帮助。在某些这些拒绝之前,Claude Code 会等待,以便 Claude 的下一次尝试不会立即跟随。在交互式会话中等待期间,微调器显示 `Auto mode check unavailable` 和倒计时,按 `Esc` 会中断轮次。
640 652
641在连续十个响应都没有判决后,auto mode 停止轮次:653在连续十个响应都没有判决后,自动模式停止轮次:
642 654
643```text theme={null}655```text theme={null}
644Auto mode is unavailable — the server returned no safety verdict for the last 10 responses, so Claude stopped. Send a message to try again, or switch out of auto mode.656Auto mode is unavailable — the server returned no safety verdict for the last 10 responses, so Claude stopped. Send a message to try again, or switch out of auto mode.
646 658
647停止消息在每种会话中出现在不同的位置:659停止消息在每种会话中出现在不同的位置:
648 660
649* 在交互式会话中,消息作为警告出现在记录中,轮次结束661* 在交互式会话中,消息作为警告出现在会话记录中,轮次结束
650* 在[非交互式](/docs/zh-CN/headless) `-p` 运行中,运行结束并报告执行错误。使用默认文本输出,消息在 stderr 上打印。662* 在[非交互式](/docs/zh-CN/headless) `-p` 运行中,运行结束并报告执行错误。使用默认文本输出,消息在 stderr 上打印。
651* 当[子代理](/docs/zh-CN/sub-agents)达到限制时,子代理在完成之前停止,Claude 接收它生成的任何内容,并附带 auto mode 停止它的说明663* 当[子代理](/docs/zh-CN/sub-agents)达到限制时,子代理在完成之前停止,Claude 接收它生成的任何内容,并附带自动模式停止它的说明
652 664
653**应该做什么:**665**应该做什么:**
654 666
655* 发送另一条消息以让 Claude 重试。响应计数重新开始。667* 发送另一条消息以让 Claude 重试。响应计数重新开始。
656* 如果停止重复且您的请求通过[LLM 网关或代理](/docs/zh-CN/llm-gateway),检查它是否截断流式响应或重写它们。[服务器端分类器审查](/docs/zh-CN/permission-modes#server-side-classifier-review)说明哪种网关行为会导致拒绝,[网关兼容性指南](/docs/zh-CN/llm-gateway-protocol#feature-pass-through)列出了要保持不变的内容。668* 如果停止重复且您的请求通过[LLM 网关或代理](/docs/zh-CN/llm-gateway),检查它是否截断流式响应或重写它们。[服务器端分类器审查](/docs/zh-CN/permission-modes#server-side-classifier-review)说明哪种网关行为会导致拒绝,[网关兼容性指南](/docs/zh-CN/llm-gateway-protocol#feature-pass-through)列出了要保持不变的内容。
657* 在启动 Claude Code 之前设置 `CLAUDE_CODE_AUTO_MODE_SERVER=0` 以改用其自己的分类器请求。在 v2.1.281 之前,Claude Code 在直接连接到 Anthropic API 时不读取该变量。669* 在启动 Claude Code 之前设置 `CLAUDE_CODE_AUTO_MODE_SERVER=0` 以改用其自己的分类器请求。在 v2.1.281 之前,Claude Code 在直接连接到 Anthropic API 时不读取该变量。
658* 要自己批准操作,请改为[切换出 auto mode](/docs/zh-CN/permission-modes#switch-permission-modes)670* 要自己批准操作,请改为[切换出自动模式](/docs/zh-CN/permission-modes#switch-permission-modes)
659 671
660在 v2.1.280 之前,Claude Code 立即拒绝来自没有判决的响应的每个操作,从不停止轮次。672在 v2.1.280 之前,Claude Code 立即拒绝来自没有判决的响应的每个操作,从不停止轮次。
661 673
663 Agent terminated early due to an API error675 Agent terminated early due to an API error
664</h3>676</h3>
665 677
666[子代理](/docs/zh-CN/sub-agents)的 API 请求终止失败,例如因为达到了使用限制或服务器错误的重试用尽,因此子代理在完成其任务之前停止。此消息需要 Claude Code v2.1.199 或更高版本;在此之前,API 错误文本被返回给 Claude,就像它是子代理的结果一样。678[子代理](/docs/zh-CN/sub-agents)的 API 请求终止失败,例如因为达到了用量限制或服务器错误的重试用尽,因此子代理在完成其任务之前停止。此消息需要 Claude Code v2.1.199 或更高版本;在此之前,API 错误文本被返回给 Claude,就像它是子代理的结果一样。
667 679
668```text theme={null}680```text theme={null}
669Agent terminated early due to an API error: <error detail>681Agent terminated early due to an API error: <error detail>
671 683
672**应该做什么:**684**应该做什么:**
673 685
674* 将冒号后的错误详情与此页面上的其自己的部分匹配,例如[使用限制](#usage-limits)或[服务器错误](#server-errors),并按照该部分的步骤操作686* 将冒号后的错误详情与此页面上的其自己的部分匹配,例如[用量限制](#usage-limits)或[服务器错误](#server-errors),并按照该部分的步骤操作
675* 一旦底层错误清除,请要求 Claude 重试任务或[恢复子代理](/docs/zh-CN/sub-agents#resume-subagents)687* 一旦底层错误清除,请要求 Claude 重试任务或[恢复子代理](/docs/zh-CN/sub-agents#resume-subagents)
676 688
677当速率限制、过载或服务器错误中断已经生成文本输出的前台子代理时,Claude 接收该部分输出标记为不完整,而不是此错误。仅输出为工具调用的子代理也会收到此错误;在 v2.1.199 中,该形状返回了空的部分结果。请参阅[子代理中的 API 错误](/docs/zh-CN/sub-agents#api-errors-in-subagents)。689当速率限制、过载或服务器错误中断已经生成文本输出的前台子代理时,Claude 接收该部分输出标记为不完整,而不是此错误。仅输出为工具调用的子代理也会收到此错误;在 v2.1.199 中,该形状返回了空的部分结果。请参阅[子代理中的 API 错误](/docs/zh-CN/sub-agents#api-errors-in-subagents)。
697 709
698Claude Code 会阻止进一步的请求,直到消息中显示的重置时间。会话和周限制在所有模型中共享,因此切换模型不会恢复访问权限。Opus 和 Sonnet 限制各自仅适用于对该模型系列的请求,因此使用 `/model` 切换到该系列之外的模型可以继续工作。710Claude Code 会阻止进一步的请求,直到消息中显示的重置时间。会话和周限制在所有模型中共享,因此切换模型不会恢复访问权限。Opus 和 Sonnet 限制各自仅适用于对该模型系列的请求,因此使用 `/model` 切换到该系列之外的模型可以继续工作。
699 711
700在使用 claude.ai 订阅登录的交互式会话中,Claude Code 也可以在打开的会话中等待,并在重置后不久继续中断的任务。等待时,会话底部的一行显示 `Usage limit reached · continuing automatically at 3:45pm · esc to cancel`。在空提示处按 `Esc` 可取消等待。有关您看到的内容、如何开始或取消等待以及如何关闭自动继续的信息,请参阅 [Wait for a usage limit to reset](/docs/zh-CN/interactive-mode#wait-for-a-usage-limit-to-reset)。在 v2.1.234 之前,Claude Code 不提供此等待功能。712在使用 claude.ai 订阅登录的交互式会话中,Claude Code 也可以在打开的会话中等待,并在重置后不久继续中断的任务。有关您看到的内容、如何开始或取消等待以及如何关闭自动继续的信息,请参阅 [Wait for a usage limit to reset](/docs/zh-CN/interactive-mode#wait-for-a-usage-limit-to-reset)。在 v2.1.234 之前,Claude Code 不提供此等待功能。
701 713
702使用量同时计入会话和周额度。单次大量活动突发(例如大型工作流扇出)可能会在会话窗口重置之前耗尽周额度。714使用量同时计入会话和周额度。单次大量活动突发(例如大型工作流扇出)可能会在会话窗口重置之前耗尽周额度。
703 715
885 身份验证错误897 身份验证错误
886</h2>898</h2>
887 899
888这些错误意味着 Claude Code 无法向 API 证明您的身份。随时运行 `/status` 查看当前活跃的凭证。900这些错误表示 Claude Code 无法向 API 证明您的身份。您可以随时运行 `/status` 查看当前生效的凭据。
889 901
890<h3 id="not-logged-in">902<h3 id="not-logged-in">
891 未登录903 未登录
892</h3>904</h3>
893 905
894此会话没有可用的有效凭证。906此会话没有可用的有效凭据。
895 907
896```text theme={null}908```text theme={null}
897Not logged in · Please run /login909Not logged in · Please run /login
898```910```
899 911
900在 Claude Desktop 应用运行的会话中,例如 Code 标签页或 Cowork,消息读作 `Authentication required · Sign in again to continue`,您从应用中再次登录。912在由 Claude Desktop 应用运行的会话中(例如 Code 标签页或 Cowork),消息显示为 `Authentication required · Sign in again to continue`,您需要在应用中重新登录。
901 913
902**应该做什么:**914如果您在另一个使用相同[配置目录](/docs/zh-CN/claude-directory)的 Claude Code 窗口中使用 claude.ai 账户登录,显示此消息的交互式会话会自动开始使用该登录。您无需重启会话。
915
916在 macOS 上的 v2.1.286 之前版本中,您在另一个窗口登录后,该会话可能仍会继续显示此消息。在这些版本中,请重启显示此消息的会话。
917
918**解决方法:**
903 919
904* 运行 `/login` 以使用您的 Claude 订阅或 Console 账户进行身份验证920* 运行 `/login`,使用您的 Claude 订阅或 Console 账户进行身份验证
905* 如果您期望使用环境变量进行身份验证,请确认 `ANTHROPIC_API_KEY` 已在启动 `claude` 的 shell 中设置并导出921* 如果您原本希望通过环境变量进行身份验证,请确认在启动 `claude` 的 shell 中已设置并导出 `ANTHROPIC_API_KEY`
906* 对于无法进行交互式登录的 CI 或自动化,配置一个 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 脚本,在启动时获取密钥922* 对于无法进行交互式登录的 CI 或自动化场景,请配置一个在启动时获取密钥的 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 脚本
907* 查看 [身份验证优先级](/docs/zh-CN/authentication#authentication-precedence) 以了解当存在多个凭证时 Claude Code 使用哪个凭证923* 请参阅[身份验证优先级](/docs/zh-CN/authentication#authentication-precedence),了解存在多个凭据时 Claude Code 使用哪一个
908 924
909如果您被重复提示登录,请参阅 [未登录或令牌过期](/docs/zh-CN/troubleshoot-install#not-logged-in-or-token-expired) 了解系统时钟检查和 macOS 凭证存储恢复步骤。925如果系统反复提示您登录,请参阅[未登录或令牌已过期](/docs/zh-CN/troubleshoot-install#not-logged-in-or-token-expired),了解系统时钟检查以及 macOS 凭据存储的恢复步骤。
910 926
911<h3 id="could-not-resolve-authentication-method">927<h3 id="could-not-resolve-authentication-method">
912 无法解析身份验证方法928 无法确定身份验证方法
913</h3>929</h3>
914 930
915会话到达 API 客户端时没有任何凭证。[后台会话](/docs/zh-CN/agent-view) 和云会话在 worker 启动时没有凭证时显示此消息。交互式、`-p` 和 Agent SDK 运行报告与 [未登录](#not-logged-in) 相同的条件,并仅将此字符串写入其调试日志,因此如果您在那里找到它,请改为遵循该条目。931会话在没有任何凭据的情况下到达了 API 客户端。当工作进程在没有凭据的情况下启动时,[后台会话](/docs/zh-CN/agent-view)和云端会话会显示此消息。交互式运行、`-p` 运行和 Agent SDK 运行会将同样的情况报告为[未登录](#not-logged-in),并且只将此字符串写入调试日志,因此如果您是在调试日志中发现的,请改为按照该条目操作。
916 932
917```text theme={null}933```text theme={null}
918Could not resolve authentication method. Expected one of apiKey, authToken, credentials, config, or profile to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted934Could not resolve authentication method. Expected one of apiKey, authToken, credentials, config, or profile to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted
919```935```
920 936
921在当前版本上,该错误意味着 worker 进程没有可用的凭证。在 v2.1.174 之前,分配给空闲预初始化 worker 的后台会话即使配置了有效凭证也可能以这种方式失败。在 v2.1.176 之前,在被声明之前处于空闲状态的云会话也可能失败。升级以恢复。937在当前版本中,此错误表示工作进程没有可用的凭据。在 v2.1.174 之前,分配给空闲的预初始化工作进程的后台会话即使已配置有效凭据,也可能以这种方式失败。在 v2.1.176 之前,在被认领前处于空闲状态的云端会话也可能出现这种情况。升级即可恢复。
922 938
923**应该做什么:**939**解决方法:**
924 940
925* 如果这出现在后台或云会话中且您的凭证已配置,请升级到 v2.1.176 或更高版本941* 如果此错误出现在后台会话或云端会话中,且您的凭据已经配置好,请升级到 v2.1.176 或更高版本
926* 确认 `ANTHROPIC_API_KEY`、`CLAUDE_CODE_OAUTH_TOKEN` 或您的云提供商凭证已在启动 worker 的环境中设置,而不仅仅在您的交互式 shell 中942* 确认 `ANTHROPIC_API_KEY`、`CLAUDE_CODE_OAUTH_TOKEN` 或您的云服务提供商凭据已在启动工作进程的环境中设置,而不仅仅是在您的交互式 shell 中设置
927* 对于 Agent SDK,请参阅 [快速入门中的身份验证设置](/docs/zh-CN/agent-sdk/quickstart#setup)943* 对于 Agent SDK,请参阅[快速入门中的身份验证设置](/docs/zh-CN/agent-sdk/quickstart#setup)
928* 在同一环境中的交互式会话中运行 `/status` 以确认哪个凭证源可解析944* 在同一环境中的交互式会话里运行 `/status`,确认解析到的是哪个凭据来源
929 945
930<h3 id="invalid-api-key">946<h3 id="invalid-api-key">
931 无效的 API 密钥947 API 密钥无效
932</h3>948</h3>
933 949
934`ANTHROPIC_API_KEY` 环境变量或 `apiKeyHelper` 脚本返回了 API 拒绝的密钥,或 Claude Code 在发送前阻止了来自 `ANTHROPIC_API_KEY` 的密钥。950`ANTHROPIC_API_KEY` 环境变量或 `apiKeyHelper` 脚本返回了一个被 API 拒绝的密钥,或者 Claude Code 在发送前拦截了来自 `ANTHROPIC_API_KEY` 的密钥。
935 951
936```text theme={null}952```text theme={null}
937Invalid API key · Fix external API key953Invalid API key · Fix external API key
938```954```
939 955
940当消息在 `Fix external API key` 之后继续,并带有描述如 `Invalid X-Api-Key header value from ANTHROPIC_API_KEY: it contains a line break at character 41 (120 characters on 2 lines).` 时,API 从未看到该密钥。Claude Code 发现了 HTTP 标头无法传输的字符,并在发送前停止了请求。请参阅 [无效的请求标头值](#invalid-request-header-value) 了解如何读取描述并修复该值。956如果消息在 `Fix external API key` 之后还附有一段描述,例如 `Invalid X-Api-Key header value from ANTHROPIC_API_KEY: it contains a line break at character 41 (120 characters on 2 lines).`,则说明 API 从未收到该密钥。Claude Code 发现了一个 HTTP 标头无法承载的字符,并在发送前停止了请求。请参阅[请求标头值无效](#invalid-request-header-value),了解如何解读该描述并修正该值。
941 957
942**应该做什么:**958**解决方法:**
943 959
944* 检查拼写错误并确认密钥未在 [Console](https://platform.claude.com/settings/keys) 中被撤销960* 检查是否有拼写错误,并在 [Console](https://platform.claude.com/settings/keys) 中确认该密钥未被撤销
945* 在同一 shell 中,运行 `env | grep ANTHROPIC`,或在 PowerShell 中运行 `Get-ChildItem Env:ANTHROPIC*`。direnv、dotenv shell 插件和 IDE 终端等工具可以从项目中的 `.env` 文件加载过时的密钥,而无需您显式设置它961* 在同一个 shell 中运行 `env | grep ANTHROPIC`,或在 PowerShell 中运行 `Get-ChildItem Env:ANTHROPIC*`。direnv、dotenv shell 插件以及 IDE 终端等工具可能会从项目中的 `.env` 文件加载过时的密钥,而您并未显式设置它。
946* 取消设置 `ANTHROPIC_API_KEY` 并运行 `/login` 以改用订阅身份验证962* 取消设置 `ANTHROPIC_API_KEY` 并运行 `/login`,改用订阅身份验证
947* 如果密钥来自 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 脚本,请直接运行该脚本以确认它在 stdout 上打印有效密钥963* 如果密钥来自 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 脚本,请直接运行该脚本,确认它在 stdout 上输出了有效的密钥
948* 运行 `/status` 以确认 Claude Code 实际使用的凭证源964* 运行 `/status`,确认 Claude Code 实际使用的是哪个凭据来源
949 965
950<h3 id="your-apikeyhelper-script-is-failing">966<h3 id="your-apikeyhelper-script-is-failing">
951 您的 apiKeyHelper 脚本失败967 您的 apiKeyHelper 脚本运行失败
952</h3>968</h3>
953 969
954Claude Code 运行了您的 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 设置中的命令,但没有获得密钥。没有密钥,请求会到达 API,并带有占位符凭证,API 会以 `401` 拒绝它。终端中的 `Authentication` 面板显示发生了以下哪种情况:970Claude Code 运行了您的 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 设置中的命令,但没有得到密钥。没有密钥时,请求会携带一个占位凭据到达 API,API 会以 `401` 拒绝它。终端中的 `Authentication` 面板会显示发生了以下哪种情况:
955 971
956* 命令以错误退出或超时972* 命令以错误退出或超时
957* 命令未向 stdout 打印任何内容973* 命令没有向 stdout 输出任何内容
958* 命令打印了除密钥之外的内容,例如登录横幅或日志行。该面板显示 `returned output that cannot be used as an API key` 并说明了问题所在,而不重复输出。在 v2.1.227 之前,Claude Code 发送命令打印的任何内容,在修剪周围空格后。974* 命令输出了密钥以外的内容,例如登录横幅或日志行。面板会显示 `returned output that cannot be used as an API key` 并说明问题所在,但不会重复输出内容。在 v2.1.227 之前,Claude Code 会在去除首尾空白后发送命令输出的任何内容。
959 975
960```text theme={null}976```text theme={null}
961Your apiKeyHelper script is failing · This usually means you need to re-authenticate with your provider · Run /status to see the script's error output977Your apiKeyHelper script is failing · This usually means you need to re-authenticate with your provider · Run /status to see the script's error output
962```978```
963 979
964在 [非交互式模式](/docs/zh-CN/headless) 中,stderr 也带有具体原因,前缀为 `apiKeyHelper failed:`。980在[非交互模式](/docs/zh-CN/headless)下,stderr 也会带有具体原因,前缀为 `apiKeyHelper failed:`。
965 981
966Claude Code 重新运行脚本并在显示此消息之前最多重试请求两次,因此故障在三次尝试内出现。在 v2.1.208 之前,Claude Code 花费完整的 [重试预算](#automatic-retries) 使用占位符凭证重新发送请求,然后报告通用 `401` 身份验证错误而不是脚本故障。982在显示此消息之前,Claude Code 会重新运行脚本并最多再重试请求两次,因此失败会在三次尝试内显现。在 v2.1.208 之前,Claude Code 会用完全部[重试预算](#automatic-retries),用占位凭据反复重新发送请求,然后报告一个通用的 `401` 身份验证错误,而不是脚本失败。
967 983
968运行 `/login` 在这里没有帮助:只要设置存在,helper 的输出 [优先于](/docs/zh-CN/authentication#authentication-precedence) 保存的登录。984此时运行 `/login` 没有帮助:只要该设置存在,helper 的输出就[优先于](/docs/zh-CN/authentication#authentication-precedence)已保存的登录。
969 985
970**应该做什么:**986**解决方法:**
971 987
972* 直接在您的 shell 中运行在 `apiKeyHelper` 中配置的命令以重现故障988* 在您的 shell 中直接运行 `apiKeyHelper` 中配置的命令,以复现该失败
973* 如果命令报告会话过期,请使用您的凭证提供商重新身份验证,例如再次登录您的 SSO 或密钥保管库989* 如果命令报告会话已过期,请向您的凭据提供方重新进行身份验证,例如重新登录您的 SSO 或密钥保管库
974* 修复命令,使其仅将密钥打印到 stdout,作为单个可打印 ASCII 令牌,最多 16,384 个字符,并以代码 0 退出。请参阅 [使用 apiKeyHelper 轮换凭证](/docs/zh-CN/llm-gateway-connect#rotate-credentials-with-apikeyhelper) 了解工作设置。990* 修正命令,使其只向 stdout 输出密钥(一个由可打印 ASCII 字符组成、最多 16,384 个字符的单一令牌),并以退出码 0 退出。请参阅[使用 apiKeyHelper 轮换凭据](/docs/zh-CN/llm-gateway-connect#rotate-credentials-with-apikeyhelper)了解可用的设置方式。
975* 运行 `/status` 查看故障并确认 `apiKeyHelper` 是活跃凭证源。`apiKeyHelper` 行显示 `Failing` 以及最后一次故障的详细信息,例如退出代码和命令的错误输出,并在下一次成功运行后消失。在 v2.1.274 之前,`/status` 仅显示凭证源,而不是故障。991* 运行 `/status` 查看失败情况,并确认 `apiKeyHelper` 是当前生效的凭据来源。`apiKeyHelper` 行会显示 `Failing` 以及上一次失败的详细信息,例如退出码和命令的错误输出,并会在下一次成功运行后消失。在 v2.1.274 之前,`/status` 只显示凭据来源,不显示失败情况。
976* 每次命令失败时,其退出代码和错误输出也会出现在终端中的 `Authentication` 面板中。在 v2.1.212 之前,该面板的标题为 `Cloud authentication`。992* 每次命令失败时,其退出码和错误输出也会显示在终端的 `Authentication` 面板中。在 v2.1.212 之前,该面板的标题为 `Cloud authentication`。
977 993
978<h3 id="invalid-request-header-value">994<h3 id="invalid-request-header-value">
979 无效的请求标头值995 请求标头值无效
980</h3>996</h3>
981 997
982Claude Code 即将作为请求标头发送的值包含 HTTP 标头无法传输的字符:换行符、NUL 字节或 `U+00FF` 以上的字符,例如弯引号或零宽空格。Claude Code 在发送任何内容之前停止请求,并命名要修复的变量或设置。通常的原因是从文档或聊天粘贴的凭证,其中包含不可见字符或杂散换行符。998Claude Code 即将作为请求标头发送的某个值包含 HTTP 标头无法承载的字符:换行符、NUL 字节,或 `U+00FF` 以上的字符(例如弯引号或零宽空格)。Claude Code 会在发送任何内容之前停止请求,并指出需要修正的变量或设置。常见原因是从文档或聊天中粘贴的凭据带有不可见字符或多余的换行符。
983 999
984Claude Code 在直接向 Claude API 或通过 [LLM 网关](/docs/zh-CN/llm-gateway) 发送请求时运行此检查。在第三方云提供商(如 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock))上,Claude Code 在发送前不运行它。1000当 Claude Code 直接或通过 [LLM 网关](/docs/zh-CN/llm-gateway)向 Claude API 发送请求时,会执行此检查。在 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 等第三方云服务提供商上,Claude Code 不会在发送前执行此检查。
985 1001
986```text theme={null}1002```text theme={null}
987Invalid auth token · Fix external auth token1003Invalid auth token · Fix external auth token
989Invalid request header from the environment · Fix the environment variable1005Invalid request header from the environment · Fix the environment variable
990```1006```
991 1007
992消息的第一部分取决于坏值来自何处:1008消息的第一部分取决于错误值的来源:
993 1009
994* `Invalid auth token`:来自 [`ANTHROPIC_AUTH_TOKEN`](/docs/zh-CN/env-vars) 或 [`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 的持有者令牌1010* `Invalid auth token`:来自 [`ANTHROPIC_AUTH_TOKEN`](/docs/zh-CN/env-vars) 或 [`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 的 bearer 令牌
995* `Invalid ANTHROPIC_CUSTOM_HEADERS`:您在 [`ANTHROPIC_CUSTOM_HEADERS`](/docs/zh-CN/env-vars) 中设置的标头名称或值。描述计算哪个 `Name: Value` 对有问题,例如 `distinct header 2 of 3 parsed from ANTHROPIC_CUSTOM_HEADERS`,而不重复名称或值,因为您选择了两者。1011* `Invalid ANTHROPIC_CUSTOM_HEADERS`:您在 [`ANTHROPIC_CUSTOM_HEADERS`](/docs/zh-CN/env-vars) 中设置的标头名称或值。描述会指出出错的是第几个 `Name: Value` 对,例如 `distinct header 2 of 3 parsed from ANTHROPIC_CUSTOM_HEADERS`,但不会重复名称或值,因为两者都是您自己设定的。
996* `Invalid request header from the environment`:Claude Code 从另一个环境变量(如 `CLAUDE_AGENT_SDK_CLIENT_APP`)复制到请求标头中的值。描述命名要修复的变量。1012* `Invalid request header from the environment`:Claude Code 从另一个环境变量(例如 `CLAUDE_AGENT_SDK_CLIENT_APP`)复制到请求标头中的值。描述会指出需要修正的变量。
997 1013
998Claude Code 将此检查捕获的坏 `ANTHROPIC_API_KEY` 报告为 [无效的 API 密钥](#invalid-api-key),具有相同的尾部描述。它将坏的保存 `/login` 凭证报告为 [未登录](#not-logged-in);运行 `/login` 以保存新凭证。[`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 脚本的输出永远不会到达此检查:Claude Code 在脚本运行时验证它,并且输出 HTTP 标头无法传输的失败会导致 [您的 apiKeyHelper 脚本失败](#your-apikeyhelper-script-is-failing)。1014此检查捕获到的错误 `ANTHROPIC_API_KEY` 会被 Claude Code 报告为 [API 密钥无效](#invalid-api-key),并附带同样的尾部描述。错误的已保存 `/login` 凭据则会被报告为[未登录](#not-logged-in);运行 `/login` 保存一个新的凭据即可。[`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 脚本的输出永远不会进入此检查:Claude Code 在脚本运行时就会对其进行验证,HTTP 标头无法承载的输出会以[您的 apiKeyHelper 脚本运行失败](#your-apikeyhelper-script-is-failing)的形式失败。
999 1015
1000在第二个 `·` 之后,消息描述问题,如以下完整示例:1016在第二个 `·` 之后,消息会描述问题,完整示例如下:
1001 1017
1002```text theme={null}1018```text theme={null}
1003Invalid auth token · Fix external auth token · Invalid Authorization header value from ANTHROPIC_AUTH_TOKEN: it contains a line break at character 41 (120 characters on 2 lines).1019Invalid auth token · Fix external auth token · Invalid Authorization header value from ANTHROPIC_AUTH_TOKEN: it contains a line break at character 41 (120 characters on 2 lines).
1004```1020```
1005 1021
1006位置从 1 开始计算字符。描述由固定短语和字符计数构建,因此它永远不包括值本身。它仅在字符是众所周知的不可见或排版字符(如字节顺序标记、零宽空格或弯引号)时命名该字符,并将其他任何内容报告为 `a non-ASCII character`。1022位置按字符计数,从 1 开始。描述由固定短语和字符计数组成,因此永远不会包含值本身。只有当问题字符是众所周知的不可见字符或排版字符(例如字节顺序标记、零宽空格或弯引号)时,描述才会指出该字符,其他字符一律报告为 `a non-ASCII character`。
1007 1023
1008**应该做什么:**1024**解决方法:**
1009 1025
1010* 重新设置消息命名的变量或设置,重新输入报告位置周围的字符,而不是从同一来源再次粘贴1026* 重新设置消息中指出的变量或设置,手动重新输入所报告位置附近的字符,而不是再次从同一来源粘贴
1011* 对于 `ANTHROPIC_CUSTOM_HEADERS`,每行保留一个 `Name: Value` 对,并重写消息计数的对1027* 对于 `ANTHROPIC_CUSTOM_HEADERS`,每行保留一个 `Name: Value` 对,并重写消息所指出的那一对
1012* 运行 `/status` 以确认哪个凭证源处于活跃状态1028* 运行 `/status`,确认当前生效的凭据来源
1013 1029
1014<h3 id="this-organization-has-been-disabled">1030<h3 id="this-organization-has-been-disabled">
1015 此组织已被禁用1031 此组织已被停用
1016</h3>1032</h3>
1017 1033
1018Claude Code 正在使用来自已禁用 Console 组织的过时 `ANTHROPIC_API_KEY`。当您有保存的订阅登录时,密钥会覆盖它。1034Claude Code 正在使用来自已停用 Console 组织的过时 `ANTHROPIC_API_KEY`。当您有已保存的订阅登录时,该密钥会覆盖它。
1019 1035
1020```text theme={null}1036```text theme={null}
1021Your ANTHROPIC_API_KEY belongs to a disabled organization · Unset the environment variable to use your subscription instead1037Your ANTHROPIC_API_KEY belongs to a disabled organization · Unset the environment variable to use your subscription instead
1023API Error: 400 ... This organization has been disabled.1039API Error: 400 ... This organization has been disabled.
1024```1040```
1025 1041
1026`·` 之后的提示取决于您保存的凭证:当存储的 `/login` 可以在您取消设置密钥后接管时出现第一种形式,当密钥是您唯一的凭证时出现第二种形式。1042`·` 之后的提示取决于您已保存的凭据:当您取消设置该密钥后有已存储的 `/login` 可以接替时,显示第一种形式;当该密钥是您唯一的凭据时,显示第二种形式。
1027 1043
1028环境变量优先于 `/login`,因此在您的 shell 配置文件中导出或从 `.env` 文件加载的密钥即使您有有效的 Pro 或 Max 订阅也会被使用。在非交互式模式 (`-p`) 中,当存在密钥时始终使用该密钥。1044环境变量优先于 `/login`,因此即使您拥有可用的 Pro 或 Max 订阅,在 shell 配置文件中导出或从 `.env` 文件加载的密钥仍会被使用。在非交互模式(`-p`)下,只要存在该密钥,就总会使用它。
1029 1045
1030**应该做什么:**1046**解决方法:**
1031 1047
1032* 在当前 shell 中取消设置 `ANTHROPIC_API_KEY` 并从您的 shell 配置文件中删除它,然后重新启动 `claude`1048* 在当前 shell 中取消设置 `ANTHROPIC_API_KEY`,并将其从 shell 配置文件中删除,然后重新启动 `claude`
1033* 如果消息说 `Update or unset`,您没有保存的登录可以回退。取消设置密钥并运行 `/login`,或将密钥替换为来自活跃 Console 组织的密钥。1049* 如果消息显示 `Update or unset`,说明您没有可回退的已保存登录。请取消设置该密钥并运行 `/login`,或将其替换为来自活跃 Console 组织的密钥。
1034* 之后运行 `/status` 以确认活跃凭证是您的订阅1050* 之后运行 `/status`,确认当前生效的凭据是您的订阅
1035* 如果未设置环境变量且错误仍然存在,请联系支持或使用不同账户登录。1051* 如果没有设置任何环境变量但错误仍然存在,请联系支持团队或使用其他账户登录。
1036 1052
1037<h3 id="your-organization-has-disabled-api-key-authentication">1053<h3 id="your-organization-has-disabled-api-key-authentication">
1038 您的组织已禁用 API 密钥身份验证1054 您的组织已禁用 API 密钥身份验证
1039</h3>1055</h3>
1040 1056
1041此消息需要 Claude Code v2.1.169 或更高版本。您的 Console 组织的管理员已关闭 API 密钥身份验证,因此 API 拒绝 Claude Code 正在发送的密钥。`·` 之后的恢复提示因密钥来自何处而异:1057此消息需要 Claude Code v2.1.169 或更高版本。您的 Console 组织管理员已关闭 API 密钥身份验证,因此 API 会拒绝 Claude Code 发送的密钥。`·` 之后的恢复提示因密钥来源而异:
1042 1058
1043```text theme={null}1059```text theme={null}
1044Your organization has disabled API key authentication · Run /login to sign in with your claude.ai account1060Your organization has disabled API key authentication · Run /login to sign in with your claude.ai account
1048Your organization has disabled API key authentication · Sign in again with your claude.ai account1064Your organization has disabled API key authentication · Sign in again with your claude.ai account
1049```1065```
1050 1066
1051最后一种形式出现在 Claude Desktop 应用运行的会话中,例如 Code 标签页或 Cowork,您从应用中再次登录。1067最后一种形式出现在由 Claude Desktop 应用运行的会话中(例如 Code 标签页或 Cowork),此时您需要在应用中重新登录。
1052 1068
1053环境变量和 `apiKeyHelper` 优先于 `/login`,因此仅运行 `/login` 在任一仍在提供密钥时没有帮助。请参阅 [身份验证优先级](/docs/zh-CN/authentication#authentication-precedence)。1069环境变量和 `apiKeyHelper` 优先于 `/login`,因此只要其中任何一个仍在提供密钥,单独运行 `/login` 是没有帮助的。请参阅[身份验证优先级](/docs/zh-CN/authentication#authentication-precedence)。
1054 1070
1055**应该做什么:**1071**解决方法:**
1056 1072
1057* 如果消息命名 `ANTHROPIC_API_KEY`,在当前 shell 中取消设置它并从您的 shell 配置文件或 `.env` 文件中删除它,然后重新启动 `claude`1073* 如果消息中提到 `ANTHROPIC_API_KEY`,请在当前 shell 中取消设置它,并将其从 shell 配置文件或 `.env` 文件中删除,然后重新启动 `claude`
1058* 如果消息命名 `apiKeyHelper`,从您的 `settings.json` 中删除 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 设置1074* 如果消息中提到 `apiKeyHelper`,请从您的 `settings.json` 中删除 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 设置
1059* 运行 `/login` 以使用您的 claude.ai 账户登录1075* 运行 `/login`,使用您的 claude.ai 账户登录
1060* 之后运行 `/status` 以确认活跃凭证是您的订阅而不是 API 密钥1076* 之后运行 `/status`,确认当前生效的凭据是您的订阅而不是 API 密钥
1061* 如果您需要 API 密钥身份验证用于自动化,请要求您的组织管理员在 Console 中重新启用它1077* 如果您的自动化流程需要 API 密钥身份验证,请让组织管理员在 Console 中重新启用它
1062 1078
1063<h3 id="your-organization-has-disabled-claude-subscription-access">1079<h3 id="your-organization-has-disabled-claude-subscription-access">
1064 您的组织已禁用 Claude 订阅访问1080 您的组织已禁用 Claude 订阅访问
1065</h3>1081</h3>
1066 1082
1067您的 Claude 组织不允许使用订阅登录登录 Claude Code。使用同一账户再次运行 `/login` 会返回相同的错误。1083您的 Claude 组织不允许使用订阅登录来登录 Claude Code。使用同一账户再次运行 `/login` 会返回相同的错误。
1068 1084
1069```text theme={null}1085```text theme={null}
1070Your organization has disabled Claude subscription access for Claude Code · Use an Anthropic API key instead, or ask your admin to enable access1086Your organization has disabled Claude subscription access for Claude Code · Use an Anthropic API key instead, or ask your admin to enable access
1071```1087```
1072 1088
1073这是服务器端组织设置,因此无法从本地设置、环境变量或 CLI 标志覆盖。1089这是服务器端的组织设置,因此无法通过本地设置、环境变量或 CLI 标志覆盖。
1074 1090
1075Agent SDK 和 `-p` 非交互式模式将此显示为 `oauth_org_not_allowed` 错误代码。1091Agent SDK 和 `-p` 非交互模式会将其呈现为 `oauth_org_not_allowed` 错误代码。
1076 1092
1077**应该做什么:**1093**解决方法:**
1078 1094
1079* 要求您的管理员为您的组织启用 Claude Code 访问1095* 请管理员为您的组织启用 Claude Code 访问权限
1080* 使用 Console API 密钥而不是您的订阅进行身份验证。请参阅 [Claude Console 身份验证](/docs/zh-CN/authentication#claude-console-authentication) 了解设置。1096* 改用 Console API 密钥而不是订阅进行身份验证。设置方法请参阅 [Claude Console 身份验证](/docs/zh-CN/authentication#claude-console-authentication)。
1081* 如果您是管理员且看不到启用访问的选项,请联系 [Anthropic 支持](https://support.claude.com)1097* 如果您是管理员但找不到启用访问的选项,请联系 [Anthropic 支持](https://support.claude.com)
1082 1098
1083<h3 id="routines-are-disabled-by-your-organizations-policy">1099<h3 id="routines-are-disabled-by-your-organizations-policy">
1084 例程被您的组织的策略禁用1100 Routine 已被您组织的策略禁用
1085</h3>1101</h3>
1086 1102
1087您的 Team 或 Enterprise 组织中的所有者已在组织级别关闭例程。当您尝试创建或运行例程时会出现错误,例如从 [Routines](/docs/zh-CN/routines) UI on claude.ai/code。在 Claude Code v2.1.227 或更高版本上,相同的设置也 [隐藏 `/schedule`](/docs/zh-CN/routines#troubleshooting) 在 CLI 中。1103您所在的 Team 或 Enterprise 组织中的 Owner 已在组织级别关闭了 Routine。当您尝试创建或运行 Routine 时(例如通过 claude.ai/code 上的 [Routines](/docs/zh-CN/routines) 界面),会出现此错误。在 Claude Code v2.1.227 或更高版本中,同一设置还会在 CLI 中[隐藏 `/schedule`](/docs/zh-CN/routines#troubleshooting)。
1088 1104
1089```text theme={null}1105```text theme={null}
1090Routines are disabled by your organization's policy.1106Routines are disabled by your organization's policy.
1091```1107```
1092 1108
1093这是服务器端设置,因此无法从本地设置、环境变量或 CLI 标志覆盖。1109这是服务器端设置,因此无法通过本地设置、环境变量或 CLI 标志覆盖。
1094 1110
1095**应该做什么:**1111**解决方法:**
1096 1112
1097* 要求您的组织中的所有者在 [claude.ai/admin-settings/claude-code](https://claude.ai/admin-settings/claude-code) 启用 **Routines** 切换1113* 请您组织中的 Owner 在 [claude.ai/admin-settings/claude-code](https://claude.ai/admin-settings/claude-code) 启用 **Routines** 开关
1098* 对于不需要组织级例程的一次性计划工作,请参阅 [计划任务](/docs/zh-CN/scheduled-tasks)1114* 对于不需要组织级 Routine 的一次性定时工作,请参阅[定时任务](/docs/zh-CN/scheduled-tasks)
1099 1115
1100<h3 id="remote-control-requires-the-anthropic-api">1116<h3 id="remote-control-requires-the-anthropic-api">
1101 Remote Control 需要 Anthropic API1117 Remote Control 需要 Anthropic API
1102</h3>1118</h3>
1103 1119
1104会话不是直接与 Anthropic API 通信,因此 [Remote Control](/docs/zh-CN/remote-control) 需要。1120该会话没有直接与 Anthropic API 通信,而这是 [Remote Control](/docs/zh-CN/remote-control) 所必需的。
1105 1121
1106```text theme={null}1122```text theme={null}
1107Remote Control is only available when using Claude via api.anthropic.com. CLAUDE_CODE_USE_BEDROCK is set, so this session is using Amazon Bedrock — unset it (or run in a shell without it) to use Remote Control.1123Remote Control is only available when using Claude via api.anthropic.com. CLAUDE_CODE_USE_BEDROCK is set, so this session is using Amazon Bedrock — unset it (or run in a shell without it) to use Remote Control.
1108```1124```
1109 1125
1110第二句解释了什么将会话路由离开 Anthropic API;在 v2.1.219 之前,消息仅为第一句。根据原因,消息命名:1126第二句话解释了是什么让会话绕开了 Anthropic API;在 v2.1.219 之前,消息只有第一句话。根据原因不同,消息会指出:
1111 1127
1112* `CLAUDE_CODE_USE_*` 提供商变量,例如 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 的 `CLAUDE_CODE_USE_BEDROCK` 或 [Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) 的 `CLAUDE_CODE_USE_VERTEX`1128* 某个 `CLAUDE_CODE_USE_*` 提供商变量,例如用于 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 的 `CLAUDE_CODE_USE_BEDROCK` 或用于 [Google Cloud's Agent Platform](/docs/zh-CN/google-vertex-ai) 的 `CLAUDE_CODE_USE_VERTEX`
1113* [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 指向 `api.anthropic.com` 以外的主机,例如 [LLM 网关](/docs/zh-CN/llm-gateway) 或代理,即使您使用 claude.ai 登录;在 v2.1.196 之前,自定义基础 URL 不会阻止 Remote Control1129* [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 指向 `api.anthropic.com` 以外的主机,例如 [LLM 网关](/docs/zh-CN/llm-gateway)或代理,即使您使用 claude.ai 登录也是如此;在 v2.1.196 之前,自定义 base URL 不会阻止 Remote Control
1114* `ANTHROPIC_UNIX_SOCKET` 已设置,因此会话通过本地套接字而不是 `api.anthropic.com` 发送其请求1130* 设置了 `ANTHROPIC_UNIX_SOCKET`,因此会话通过本地套接字而不是发往 `api.anthropic.com` 来发送请求
1115* 企业 [云网关](/docs/zh-CN/claude-apps-gateway) 通过 `/login` 登录,不支持 Remote Control,没有变量可取消设置1131* 通过 `/login` 完成的企业[云网关](/docs/zh-CN/claude-apps-gateway)登录,它不支持 Remote Control,也没有可以取消设置的变量
1116 1132
1117**应该做什么:**1133**解决方法:**
1118 1134
1119* 取消设置消息命名的变量,例如 `CLAUDE_CODE_USE_BEDROCK` 或 `ANTHROPIC_BASE_URL`,并重新启动会话,或从直接与 Anthropic API 通信的会话启动 Remote Control1135* 取消设置消息中指出的变量(例如 `CLAUDE_CODE_USE_BEDROCK` 或 `ANTHROPIC_BASE_URL`)并重启会话,或从直接与 Anthropic API 通信的会话中启动 Remote Control
1120* 如果变量未在您的 shell 中设置,请检查您的 [设置文件](/docs/zh-CN/settings#where-settings-live) 中的 `env` 键,该键将环境变量应用于每个会话1136* 如果该变量并未在您的 shell 中设置,请检查您[设置文件](/docs/zh-CN/settings#where-settings-live)中的 `env` 键,它会将环境变量应用到每个会话
1121* 对于此和其他 Remote Control 启动消息,请参阅 [Remote Control 故障排除](/docs/zh-CN/remote-control#troubleshooting)1137* 关于此消息及其他 Remote Control 启动消息,请参阅[排除 Remote Control 故障](/docs/zh-CN/remote-control#troubleshooting)
1122 1138
1123<h3 id="remote-control-couldnt-refresh-your-login">1139<h3 id="remote-control-couldnt-refresh-your-login">
1124 Remote Control 无法刷新您的登录1140 Remote Control 无法刷新您的登录
1125</h3>1141</h3>
1126 1142
1127Claude Code 在短期凭证上运行实时 [Remote Control](/docs/zh-CN/remote-control) 连接,它使用您保存的 claude.ai 登录获取和更新这些凭证。当 claude.ai 停止接受该登录或 Claude Code 没有保存的登录时,Claude Code 停止 Remote Control 并需要您再次登录。任一故障都可能在 Claude Code 仍在连接时或稍后在更新凭证时发生。1143Claude Code 使用短期凭据运行实时的 [Remote Control](/docs/zh-CN/remote-control) 连接,这些凭据是它借助您已保存的 claude.ai 登录获取和续期的。当 claude.ai 不再接受该登录,或者 Claude Code 已没有任何已保存的登录时,Claude Code 会停止 Remote Control,需要您重新登录。这两种失败都可能发生在 Claude Code 仍在连接时,也可能发生在之后续期凭据时。
1128 1144
1129当 Claude Code 要求登录服务刷新您保存的登录并且没有得到答复时,它会保持 Remote Control 运行并在连接的当前凭证仍然有效时再次尝试刷新。当 Claude Code 无法到达登录服务、请求超时或服务在不拒绝您的登录的情况下失败时,刷新会得不到答复。如果当该凭证过期时登录服务仍然没有答复,Claude Code 会停止 Remote Control 并报告 `OAuth token refresh failed`。1145当 Claude Code 请求登录服务刷新您已保存的登录却没有得到响应时,它会保持 Remote Control 运行,并在连接的当前凭据仍然有效期间再次尝试刷新。当 Claude Code 无法访问登录服务、请求超时,或服务失败但并未拒绝您的登录时,刷新就会得不到响应。如果在该凭据过期时登录服务仍未响应,Claude Code 会停止 Remote Control 并报告 `OAuth token refresh failed`。
1130 1146
1131当 Claude Code 停止 Remote Control 时,它在警告和以 `Remote Control disconnected` 开头的成绩单行中显示原因。您的本地会话继续运行而没有 Remote Control。本部分涵盖这些行:1147当 Claude Code 停止 Remote Control 时,它会在警告以及一条以 `Remote Control disconnected` 开头的会话记录行中显示原因。您的本地会话会在没有 Remote Control 的情况下继续运行。本节涵盖以下消息行:
1132 1148
1133```text theme={null}1149```text theme={null}
1134Remote Control disconnected — Claude.ai login expired — run /login to restore Remote Control1150Remote Control disconnected — Claude.ai login expired — run /login to restore Remote Control
1140Remote Control disconnected — Signed out of Claude — run /login, then /remote-control1156Remote Control disconnected — Signed out of Claude — run /login, then /remote-control
1141```1157```
1142 1158
1143Claude Code 在消息中间命名原因:1159Claude Code 会在消息中间部分说明原因:
1144 1160
1145* ` Claude.ai login expired` 和 `Claude.ai login was rejected`:claude.ai 不再接受您保存的登录令牌,因为它已过期或被撤销1161* `Claude.ai login expired` 和 `Claude.ai login was rejected`:claude.ai 不再接受您已保存的登录令牌,因为它已过期或被撤销
1146* ` OAuth token unavailable`:当连接的凭证到期需要更新时,Claude Code 没有保存的登录令牌1162* `OAuth token unavailable`:当连接的凭据到期需要续期时,Claude Code 没有已保存的登录令牌
1147* `OAuth token refresh failed`:claude.ai 在 Claude Code 重新连接时拒绝了您保存的登录令牌,刷新令牌没有产生新令牌1163* `OAuth token refresh failed`:Claude Code 重新连接时,claude.ai 拒绝了您已保存的登录令牌,且刷新令牌没有产生新令牌
1148* `JWT refresh failed: no OAuth token`:Claude Code 找不到保存的登录令牌来更新1164* `JWT refresh failed: no OAuth token`:Claude Code 找不到可用于续期的已保存登录令牌
1149* ` Signed out of Claude`:您在此机器上登出,例如在另一个终端中运行 `/logout`,因此 Claude Code 没有保存的登录来更新连接1165* `Signed out of Claude`:您在这台机器上退出了登录,例如在另一个终端中运行了 `/logout`,因此 Claude Code 已没有可用于续期连接的已保存登录
1150 1166
1151**应该做什么:**1167**解决方法:**
1152 1168
1153* 运行 `/login` 再次登录1169* 运行 `/login` 重新登录
1154* 运行 `/remote-control` 重新连接会话。以 `run /login to restore Remote Control` 结尾的消息不需要此步骤:Claude Code 在您登录后自动重新连接。1170* 运行 `/remote-control` 重新连接会话。以 `run /login to restore Remote Control` 结尾的消息不需要此步骤:您登录后 Claude Code 会自动重新连接。
1155 1171
1156在 v2.1.224 之前,`OAuth token refresh failed — run /login to re-authenticate` 读作 `OAuth token refresh failed — re-authenticate, then re-enable Remote Control`,`JWT refresh failed: no OAuth token — run /login` 读作 `no OAuth token available for recovery (code <N>)`。` Claude.ai login expired`、`Claude.ai login was rejected` 和 `OAuth token unavailable` 消息在 v2.1.225 中添加。1172在 v2.1.224 之前,`OAuth token refresh failed — run /login to re-authenticate` 显示为 `OAuth token refresh failed — re-authenticate, then re-enable Remote Control`,`JWT refresh failed: no OAuth token — run /login` 显示为 `no OAuth token available for recovery (code <N>)`。`Claude.ai login expired`、`Claude.ai login was rejected` 和 `OAuth token unavailable` 消息是在 v2.1.225 中添加的。
1157 1173
1158在 v2.1.238 之前,Claude Code 将现在说 `Signed out of Claude` 的情况报告为 `JWT refresh failed: no OAuth token — run /login`,并在一次登录刷新没有得到答复后立即停止 Remote Control,显示 `Claude.ai login expired — run /login to restore Remote Control`。1174在 v2.1.238 之前,Claude Code 将现在显示为 `Signed out of Claude` 的情况报告为 `JWT refresh failed: no OAuth token — run /login`,并且只要有一次登录刷新未得到响应,就会以 `Claude.ai login expired — run /login to restore Remote Control` 停止 Remote Control。
1159 1175
1160<h3 id="remote-control-stopped-because-the-signed-in-account-changed">1176<h3 id="remote-control-stopped-because-the-signed-in-account-changed">
1161 Remote Control 停止,因为登录账户已更改1177 由于登录账户已更改,Remote Control 已停止
1162</h3>1178</h3>
1163 1179
1164Claude Code 在 [Remote Control](/docs/zh-CN/remote-control) 会话期间显示此行,当您在此机器上登录到不同的 claude.ai 账户或组织时。您在 Claude Code 会话外进行了切换,例如在另一个终端中运行 `/login`。1180在 [Remote Control](/docs/zh-CN/remote-control) 会话期间,当您在这台机器上登录到另一个 claude.ai 账户或组织时,Claude Code 会显示这行消息。这种切换是在 Claude Code 会话之外进行的,例如在另一个终端中运行了 `/login`。
1165 1181
1166您在通过 `/login` 登录时启动的 Remote Control 会话属于当时登录的 claude.ai 账户和组织。1182您在通过 `/login` 登录状态下启动的 Remote Control 会话,属于启动时所登录的 claude.ai 账户和组织。
1167 1183
1168```text theme={null}1184```text theme={null}
1169Remote Control disconnected — signed-in claude.ai account or organization changed on this machine — run /remote-control to start a session for the current account, or /login to switch back, then /remote-control1185Remote Control disconnected — signed-in claude.ai account or organization changed on this machine — run /remote-control to start a session for the current account, or /login to switch back, then /remote-control
1170```1186```
1171 1187
1172Claude Code 在 claude.ai 确认账户或组织已更改后立即停止 Remote Control 会话。您的本地会话继续运行而没有 Remote Control。1188一旦 claude.ai 确认账户或组织已更改,Claude Code 就会停止 Remote Control 会话。您的本地会话会在没有 Remote Control 的情况下继续运行。
1173 1189
1174**应该做什么:**1190**解决方法:**
1175 1191
1176* 运行 `/remote-control` 在当前账户或组织下启动新的 Remote Control 会话1192* 运行 `/remote-control`,在当前账户或组织下启动新的 Remote Control 会话
1177* 要切换回去,运行 `/login` 并再次登录到之前的账户或组织。然后运行 `/remote-control`。1193* 如需切换回去,请运行 `/login` 并重新登录之前的账户或组织,然后运行 `/remote-control`。
1178 1194
1179在 v2.1.234 之前,Claude Code 在您在 Claude Code 会话外切换到不同账户或组织时没有注意到。Claude Code 保持 Remote Control 会话连接,直到稍后对 Remote Control 服务器的请求失败,显示 `Remote Control server rejected the request (HTTP 404)`。该故障可能在切换后数小时发生。1195在 v2.1.234 之前,当您在 Claude Code 会话之外切换到其他账户或组织时,Claude Code 不会察觉。Claude Code 会保持 Remote Control 会话连接,直到之后某个发往 Remote Control 服务器的请求以 `Remote Control server rejected the request (HTTP 404)` 失败。该失败可能在切换后数小时才出现。
1180 1196
1181<h3 id="remote-control-stopped-because-the-app-running-the-session-signed-out-or-switched-accounts">1197<h3 id="remote-control-stopped-because-the-app-running-the-session-signed-out-or-switched-accounts">
1182 Remote Control 停止,因为运行会话的应用登出或切换了账户1198 由于运行会话的应用已退出登录或切换了账户,Remote Control 已停止
1183</h3>1199</h3>
1184 1200
1185当 Claude 桌面应用或 IDE 托管您的会话时,Claude Code 从该应用而不是从 `/login` 获取其登录令牌。当 claude.ai 拒绝该令牌时,Claude Code 要求应用提供新令牌。如果应用回答说它已登出或现在登录到不同的 Claude 账户,Claude Code 结束 [Remote Control](/docs/zh-CN/remote-control) 会话并向应用发送以下行之一:1201当 Claude 桌面应用或 IDE 托管您的会话时,Claude Code 会从该应用而不是从 `/login` 获取登录令牌。当 claude.ai 拒绝该令牌时,Claude Code 会向应用请求新令牌。如果应用回复它已退出登录,或者现在登录的是另一个 Claude 账户,Claude Code 会结束 [Remote Control](/docs/zh-CN/remote-control) 会话,并向应用发送以下消息行之一:
1186 1202
1187```text theme={null}1203```text theme={null}
1188Remote Control stopped — the app running this session is now signed in to a different Claude account1204Remote Control stopped — the app running this session is now signed in to a different Claude account
1189Remote Control stopped — the app running this session is signed out of Claude. Sign in there, then turn Remote Control back on1205Remote Control stopped — the app running this session is signed out of Claude. Sign in there, then turn Remote Control back on
1190```1206```
1191 1207
1192您的本地会话继续运行而没有 Remote Control。1208您的本地会话会在没有 Remote Control 的情况下继续运行。
1193 1209
1194**应该做什么:**1210**解决方法:**
1195 1211
1196* 如果应用已登出,再次登录,然后在应用中重新打开 Remote Control1212* 如果应用已退出登录,请在应用中重新登录,然后在应用中重新打开 Remote Control
1197* 如果应用切换了账户,Claude Code 无法在新账户下继续已结束的会话。在该账户下启动新的 Remote Control 会话。1213* 如果应用切换了账户,Claude Code 无法在新账户下继续已结束的会话。请在该账户下启动新的 Remote Control 会话。
1198 1214
1199在 v2.1.238 之前,Claude Code 在两种情况下都向应用发送了 [Remote Control 无法刷新您的登录](#remote-control-couldnt-refresh-your-login) 下列出的 `run /login` 消息。1215在 v2.1.238 之前,这两种情况下 Claude Code 都会向应用发送[Remote Control 无法刷新您的登录](#remote-control-couldnt-refresh-your-login)中列出的 `run /login` 消息。
1200 1216
1201<h3 id="oauth-token-revoked-or-expired">1217<h3 id="oauth-token-revoked-or-expired">
1202 OAuth 令牌被撤销或过期1218 OAuth 令牌已撤销或已过期
1203</h3>1219</h3>
1204 1220
1205您保存的登录不再有效。被撤销的令牌意味着您在任何地方登出或管理员删除了访问权限;过期的令牌意味着自动刷新在会话中失败。1221您已保存的登录不再有效。令牌被撤销意味着您在所有位置都退出了登录,或者管理员移除了访问权限;令牌过期意味着会话中途的自动刷新失败了。
1206 1222
1207两条消息都报告 API 为 Claude Code 发送的请求返回的拒绝。当保存的登录在失败的刷新后已被清除时,您会看到 [登录过期](#login-expired)。如果您使用 [`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 中的长期令牌进行身份验证,当该令牌过期或被撤销时,您会看到相同的消息。1223这两条消息报告的都是 API 对 Claude Code 所发送请求返回的拒绝。如果已保存的登录在刷新失败后已被清除,您看到的将是[登录已过期](#login-expired)。如果您在 [`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 中使用长期令牌进行身份验证,当该令牌过期或被撤销时,您也会看到同样的消息。
1208 1224
1209```text theme={null}1225```text theme={null}
1210OAuth token revoked · Please run /login1226OAuth token revoked · Please run /login
1211Please run /login · API Error: 401 OAuth token has expired ...1227Please run /login · API Error: 401 OAuth token has expired ...
1212```1228```
1213 1229
1214**应该做什么:**1230在[非交互模式](/docs/zh-CN/headless)(`-p`)和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,消息如下,结构化错误代码为 `authentication_failed`:
1231
1232```text theme={null}
1233Failed to authenticate: OAuth token revoked. Please log in again or contact your administrator.
1234Failed to authenticate. API Error: 401 OAuth token has expired ...
1235```
1236
1237在 v2.1.287 之前,非交互模式和 Agent SDK 中的撤销消息为 `Your account does not have access to Claude. Please login again or contact your administrator.`
1215 1238
1216* 运行 `/login` 再次登录1239**解决方法:**
1217* 如果您使用 `CLAUDE_CODE_OAUTH_TOKEN` 环境变量进行身份验证,Claude Code 在请求失败并显示 401 后会继续发送您设置的值,而不是切换到保存的登录的令牌。[`/status`](/docs/zh-CN/commands) 将此凭证显示为读取 `CLAUDE_CODE_OAUTH_TOKEN` 的 `Auth token` 行。使用 [`claude setup-token`](/docs/zh-CN/authentication#generate-a-long-lived-token) 生成新令牌并使用它重新启动,或取消设置变量并运行 `/login`。在 v2.1.225 之前,Claude Code 可以在会话中用保存的登录的短期访问令牌替换变量的值,一旦该令牌过期,会话再次失败并显示 401 错误。1240
1218* 对于跨启动的重复登录提示,请参阅 [故障排除](/docs/zh-CN/troubleshoot-install#not-logged-in-or-token-expired) 中的系统时钟检查和 macOS 凭证存储恢复步骤1241* 在 Claude Code 提示符下运行 `/login` 重新登录
1219* 对于其他故障,包括 `403 Forbidden` 和 OAuth 浏览器问题,请参阅 [登录和身份验证](/docs/zh-CN/troubleshoot-install#login-and-authentication)1242* 如果您的 `-p` 命令或 Agent SDK 程序使用已保存的登录,请在同一环境中运行 `claude`,完成 `/login`,然后再次运行该命令或程序。对于无法交互式登录的自动化场景,请使用 [`ANTHROPIC_API_KEY`](/docs/zh-CN/env-vars) 进行身份验证,或[使用 `claude setup-token` 生成长期令牌](/docs/zh-CN/authentication#generate-a-long-lived-token)。
1243* 如果您使用 `CLAUDE_CODE_OAUTH_TOKEN` 环境变量进行身份验证,在请求以 401 失败后,Claude Code 会继续发送您设置的值,而不会切换到已存储登录的令牌。[`/status`](/docs/zh-CN/commands) 会将此凭据显示为一个 `Auth token` 行,内容为 `CLAUDE_CODE_OAUTH_TOKEN`。请使用 [`claude setup-token`](/docs/zh-CN/authentication#generate-a-long-lived-token) 生成新令牌并用它重启,或取消设置该变量并运行 `/login`。在 v2.1.225 之前,Claude Code 可能会在会话中途用已存储登录的短期访问令牌替换该变量的值,一旦该令牌过期,会话就会再次因 401 错误而失败。
1244* 如果每次启动都反复提示您登录,请参阅[故障排除](/docs/zh-CN/troubleshoot-install#not-logged-in-or-token-expired)中的系统时钟检查和 macOS 凭据存储恢复步骤
1245* 对于其他失败,包括 `403 Forbidden` 和 OAuth 浏览器问题,请参阅[登录和身份验证](/docs/zh-CN/troubleshoot-install#login-and-authentication)
1220 1246
1221<h3 id="api-error-401-invalid-authentication-credentials">1247<h3 id="api-error-401-invalid-authentication-credentials">
1222 API 错误:401 无效的身份验证凭证1248 API Error: 401 Invalid authentication credentials
1223</h3>1249</h3>
1224 1250
1225API 识别了您凭证的格式,但拒绝了其背后的账户或组织。当凭证最近被撤销、组织被禁用或删除了您的访问权限或账户本身被停用时,Anthropic 返回此消息,因此过期的令牌不是原因。凭证可以是您保存的登录或批准的 `ANTHROPIC_API_KEY`,修复方式不同,因此首先运行 `/status` 查看哪个处于活跃状态。1251API 识别了您凭据的格式,但拒绝了其背后的账户或组织。当凭据最近被撤销、组织被停用或移除了您的访问权限,或账户本身被停用时,Anthropic 会返回此消息,因此原因并不是令牌过期。该凭据可能是您已保存的登录,也可能是已批准的 `ANTHROPIC_API_KEY`,两者的修复方法不同,因此请先运行 `/status` 查看当前生效的是哪一个。
1226 1252
1227```text theme={null}1253```text theme={null}
1228Please run /login · API Error: 401 Invalid authentication credentials1254Please run /login · API Error: 401 Invalid authentication credentials
1229```1255```
1230 1256
1231**应该做什么:**1257**解决方法:**
1232 1258
1233* 如果 `/status` 显示未标记为未使用的 `API key` 行,则批准的 [`ANTHROPIC_API_KEY`](/docs/zh-CN/authentication#authentication-precedence) 是活跃凭证并优先于您的登录,因此 `/login` 不会替换它。在 Claude Console 中轮换密钥,或通过运行 `unset ANTHROPIC_API_KEY` 回退到您的订阅,或在 PowerShell 中运行 `Remove-Item Env:ANTHROPIC_API_KEY`。1259* 如果 `/status` 显示一个未标记为未使用的 `API key` 行,说明已批准的 [`ANTHROPIC_API_KEY`](/docs/zh-CN/authentication#authentication-precedence) 是当前生效的凭据,并且优先于您的登录,因此 `/login` 不会替换它。请在 Claude Console 中轮换该密钥,或通过运行 `unset ANTHROPIC_API_KEY`(在 PowerShell 中为 `Remove-Item Env:ANTHROPIC_API_KEY`)回退到您的订阅。
1234* 如果 `/status` 仅显示您的登录,运行 `/login` 一次。如果凭证被撤销,新登录会替换它。1260* 如果 `/status` 只显示您的登录,请运行一次 `/login`。如果凭据已被撤销,新的登录会替换它。
1235* 如果相同的消息对相同的登录账户返回,则该账户或组织不再活跃。检查 `/status` 报告的账户和组织,并要求您的组织管理员恢复访问。1261* 如果同一登录账户再次出现相同消息,说明该账户或组织已不再活跃。请检查 `/status` 报告的账户和组织,并请您的组织管理员恢复访问权限。
1236* 如果 [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 指向 [LLM 网关](/docs/zh-CN/llm-gateway),`401` 之后的文本是您网关的消息而不是 Anthropic 的,`/login` 不会改变它。改为修复您的网关期望的凭证。1262* 如果 [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 指向 [LLM 网关](/docs/zh-CN/llm-gateway),`401` 之后的文本是您网关的消息而不是 Anthropic 的消息,`/login` 不会改变它。请改为修正网关所需的凭据。
1237 1263
1238<h3 id="login-expired">1264<h3 id="login-expired">
1239 登录过期1265 登录已过期
1240</h3>1266</h3>
1241 1267
1242Claude Code 尝试更新您保存的 claude.ai 登录,OAuth 服务拒绝了存储的刷新令牌,因此 Claude Code 清除了保存的凭证。之后,每个模型请求在到达 API 之前都会在本地停止,显示此消息,因为只有 `/login` 可以创建新凭证。1268Claude Code 尝试续期您已保存的 claude.ai 登录,但 OAuth 服务拒绝了已存储的刷新令牌,因此 Claude Code 清除了已保存的凭据。此后,每个模型请求都会在到达 API 之前于本地以此消息停止,因为只有 `/login` 才能创建新凭据。
1243 1269
1244在 v2.1.206 之前,Claude Code 无论如何都会发送模型请求,使用环境中剩余的任何凭证,每个模型都会失败,显示 [所选模型有问题](#theres-an-issue-with-the-selected-model) 或 401,而不是登录提示。1270在 v2.1.206 之前,Claude Code 仍会使用环境中剩余的任何凭据发送模型请求,然后每个模型都会以[所选模型存在问题](#theres-an-issue-with-the-selected-model)或 401 失败,而不是提示您登录。
1245 1271
1246```text theme={null}1272```text theme={null}
1247Login expired · Please run /login1273Login expired · Please run /login
1248```1274```
1249 1275
1250在 [非交互式模式](/docs/zh-CN/headless) (`-p`) 和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,消息如下所示,结构化错误代码为 `authentication_failed`:1276在[非交互模式](/docs/zh-CN/headless)(`-p`)和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,消息如下,结构化错误代码为 `authentication_failed`:
1251 1277
1252```text theme={null}1278```text theme={null}
1253Failed to authenticate: OAuth session expired and could not be refreshed1279Failed to authenticate: OAuth session expired and could not be refreshed
1254```1280```
1255 1281
1256这与 [OAuth 令牌被撤销或过期](#oauth-token-revoked-or-expired) 的状态不同。这些消息报告 API 返回的拒绝。Claude Code 本身为已失败更新的登录生成 `Login expired`,因此它不发送请求。当更新失败是因为账户本身被暂停而不是登录过时时,Claude Code 改为显示 [您的账户被冻结](#your-account-is-on-hold)。1282这与 [OAuth 令牌已撤销或已过期](#oauth-token-revoked-or-expired)并非同一状态。那些消息报告的是 API 返回的拒绝。而 `Login expired` 是 Claude Code 针对已续期失败的登录自行生成的,因此它不会发送任何请求。当续期失败是因为账户本身被暂停而不是登录过时,Claude Code 会改为显示[您的账户已被暂停](#your-account-is-on-hold)。
1257 1283
1258使用 API 密钥、[`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 或第三方提供商进行身份验证的会话不使用保存的登录,永远不会看到此消息。1284使用 API 密钥、[`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 或第三方提供商进行身份验证的会话不使用已保存的登录,永远不会看到此消息。
1259 1285
1260您可以在请求失败之前检查此状态:[`/status`](/docs/zh-CN/commands) 显示读取 `Expired — log in again` 的 `Login` 行,加上它为过期登录保存的组织和电子邮件。该行仅在保存的登录是您的活跃凭证且无法再刷新时出现。以其他方式进行身份验证的会话不显示该行,即使过期的登录仍然保存。在 v2.1.210 之前,`/status` 在此状态下没有指示登录曾经存在过,因为清除的凭证使其无法报告。1286您可以在请求失败之前检查是否处于此状态:[`/status`](/docs/zh-CN/commands) 会显示一个 `Login` 行,内容为 `Expired — log in again`,以及它为该过期登录保存的组织和电子邮件。只有当已保存的登录是您当前生效的凭据且无法再刷新时,才会显示该行。以其他方式进行身份验证的会话不会显示该行,即使仍保存着已过期的登录。在 v2.1.210 之前,`/status` 在此状态下不会提供任何曾存在登录的迹象,因为凭据已被清除,没有可报告的内容。
1261 1287
1262**应该做什么:**1288**解决方法:**
1263 1289
1264* 运行 `/login` 再次登录。在不登录的情况下重试会在每个请求上显示相同的消息。1290* 运行 `/login` 重新登录。不登录而直接重试,每个请求都会显示相同的消息。
1265* 在非交互式模式中,在同一环境中运行 `claude`,完成 `/login`,然后重新运行您的命令。对于无法交互式登录的自动化,使用 `ANTHROPIC_API_KEY` 进行身份验证或 [使用 `claude setup-token` 生成长期令牌](/docs/zh-CN/authentication#generate-a-long-lived-token)。1291* 如果您在另一个 Claude Code 窗口中使用 claude.ai 账户登录,请参阅[未登录](#not-logged-in),了解此会话何时会自动开始使用该登录。
1266* 如果登录持续失败,请参阅 [登录和身份验证](/docs/zh-CN/troubleshoot-install#login-and-authentication)1292* 在非交互模式下,请在同一环境中运行 `claude`,完成 `/login`,然后重新运行您的命令。对于无法交互式登录的自动化场景,请使用 `ANTHROPIC_API_KEY` 进行身份验证,或[使用 `claude setup-token` 生成长期令牌](/docs/zh-CN/authentication#generate-a-long-lived-token)。
1293* 如果登录一直失败,请参阅[登录和身份验证](/docs/zh-CN/troubleshoot-install#login-and-authentication)
1267 1294
1268<h3 id="could-not-refresh-your-login">1295<h3 id="could-not-refresh-your-login">
1269 无法刷新您的登录,因为另一个 Claude Code 进程正在刷新它1296 由于另一个 Claude Code 进程正在刷新您的登录,无法刷新
1270</h3>1297</h3>
1271 1298
1272此消息不意味着您的登录被拒绝。您保存的 claude.ai 登录已过期,需要更新。另一个 Claude Code 进程在同一机器上持有共享刷新锁,或退出并留下它,刷新在此会话等待时没有进展。Claude Code 在发送前停止请求:1299此消息并不表示您的登录被拒绝。您已保存的 claude.ai 登录已过期,需要续期。同一台机器上的另一个 Claude Code 进程持有共享的刷新锁,或者该进程已退出但遗留了该锁,在此会话等待期间刷新没有任何进展。Claude Code 会在发送前停止请求:
1273 1300
1274```text theme={null}1301```text theme={null}
1275Could not refresh your login because another Claude Code process is refreshing it (or exited mid-refresh) · Try again in a minute; if it keeps happening, close other Claude Code windows or sign in again with /login1302Could not refresh your login because another Claude Code process is refreshing it (or exited mid-refresh) · Try again in a minute; if it keeps happening, close other Claude Code windows or sign in again with /login
1276```1303```
1277 1304
1278在 [非交互式模式](/docs/zh-CN/headless) (`-p`) 和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,消息如下所示,结构化错误代码为 `server_error`:1305在[非交互模式](/docs/zh-CN/headless)(`-p`)和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,消息如下,结构化错误代码为 `server_error`:
1279 1306
1280```text theme={null}1307```text theme={null}
1281Failed to refresh OAuth token: another Claude Code process is refreshing it or exited mid-refresh. This is usually transient; retry in a minute, and if it persists close other Claude Code processes or sign in again1308Failed to refresh OAuth token: another Claude Code process is refreshing it or exited mid-refresh. This is usually transient; retry in a minute, and if it persists close other Claude Code processes or sign in again
1282```1309```
1283 1310
1284使用 API 密钥、[`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 或第三方提供商进行身份验证的会话不使用保存的登录,永远不会看到此消息。1311使用 API 密钥、[`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 或第三方提供商进行身份验证的会话不使用已保存的登录,永远不会看到此消息。
1285 1312
1286**应该做什么:**1313**解决方法:**
1287 1314
1288* 一分钟后重试。如果另一个进程首先完成刷新,此会话使用更新的登录。1315* 一分钟后重试。如果另一个进程先完成了刷新,此会话会使用续期后的登录。
1289* 如果消息持续返回,关闭其他 Claude Code 窗口和进程,然后重试。1316* 如果消息反复出现,请关闭其他 Claude Code 窗口和进程,然后重试。
1290* 如果在没有其他 Claude Code 进程运行的情况下返回,运行 `/login`。再次登录不会等待刷新锁。1317* 如果在没有其他 Claude Code 进程运行的情况下仍出现该消息,请运行 `/login`。重新登录不会等待刷新锁。
1291 1318
1292<h3 id="couldnt-save-your-login">1319<h3 id="couldnt-save-your-login">
1293 无法保存您的登录1320 无法保存您的登录
1294</h3>1321</h3>
1295 1322
1296您使用 claude.ai 登录,但 Claude Code 无法将登录保存到其凭证存储,因此登录未完成。在 macOS 上,当登录钥匙链锁定时(例如在睡眠或空闲时),在 Claude Code 已在同一会话中读取或保存凭证之后,可能会发生这种情况。1323您已使用 claude.ai 登录,但 Claude Code 无法将登录保存到其凭据存储中,因此登录未完成。在 macOS 上,如果 Claude Code 在同一会话中已经读取或保存过登录钥匙串中的凭据,之后钥匙串被锁定(例如在睡眠或空闲时),就可能发生这种情况。
1297 1324
1298```text theme={null}1325```text theme={null}
1299Couldn't save your login. If your Mac's keychain is locked, unlock it and log in again.1326Couldn't save your login. If your Mac's keychain is locked, unlock it and log in again.
1300Couldn't save your login. Try logging in again.1327Couldn't save your login. Try logging in again.
1301```1328```
1302 1329
1303第一种形式出现在 macOS 上,第二种形式出现在其他地方。临时凭证存储故障(例如超时或不可读的存储)会产生相同的消息。1330第一种形式出现在 macOS 上,第二种形式出现在其他所有平台上。暂时性的凭据存储失败(例如超时或存储无法读取)也会产生同样的消息。
1304 1331
1305**应该做什么:**1332**解决方法:**
1306 1333
1307* 在 macOS 上,解锁登录钥匙链,然后再次运行 `/login`1334* 在 macOS 上,解锁登录钥匙串,然后再次运行 `/login`
1308* 在其他平台上,再次运行 `/login`1335* 在其他平台上,再次运行 `/login`
1309* 如果登录仍然不保存,请参阅 [未登录或令牌过期](/docs/zh-CN/troubleshoot-install#not-logged-in-or-token-expired) 了解钥匙链解锁命令和其他凭证存储恢复步骤1336* 如果登录仍然无法保存,请参阅[未登录或令牌已过期](/docs/zh-CN/troubleshoot-install#not-logged-in-or-token-expired),了解钥匙串解锁命令和其他凭据存储恢复步骤
1310 1337
1311<h3 id="failed-to-start-oauth-callback-server">1338<h3 id="failed-to-start-oauth-callback-server">
1312 Failed to start OAuth callback server1339 无法启动 OAuth 回调服务器
1313</h3>1340</h3>
1314 1341
1315当 `/login`、`claude auth login` 或 `claude setup-token` 通过浏览器登录您时,Claude Code 在 `127.0.0.1` 上打开一个监听端口,以便您的浏览器可以将登录结果返回给它。此消息意味着 Claude Code 无法打开该端口,登录在浏览器窗口或登录 URL 出现之前停止:1342当 `/login`、`claude auth login` 或 `claude setup-token` 通过浏览器为您登录时,Claude Code 会在 `127.0.0.1` 上打开一个监听端口,以便浏览器将登录结果返回给它。此消息表示 Claude Code 无法打开该端口,登录会在浏览器窗口或登录 URL 出现之前停止:
1316 1343
1317```text theme={null}1344```text theme={null}
1318Failed to start OAuth callback server: Failed to start server. Is port 0 in use?1345Failed to start OAuth callback server: Failed to start server. Is port 0 in use?
1319```1346```
1320 1347
1321如果您的消息以 `Is port 0 in use?` 结尾,尝试在 IPv4 环回地址 `127.0.0.1` 上监听的尝试完全失败。因为故障发生在登录 URL 存在之前,`Paste code here if prompted` 流不可用作解决方法。1348如果您的消息以 `Is port 0 in use?` 结尾,说明在 IPv4 回环地址 `127.0.0.1` 上监听的尝试直接失败了。由于失败发生在登录 URL 生成之前,`Paste code here if prompted` 流程无法作为变通方案使用。
1322 1349
1323**应该做什么:**1350**解决方法:**
1324 1351
1325* 要立即登录而不需要本地监听器:如果您使用 claude.ai 订阅,在登录有效的机器上运行 [`claude setup-token`](/docs/zh-CN/authentication#generate-a-long-lived-token) 并将其打印的令牌设置为此机器上的 `CLAUDE_CODE_OAUTH_TOKEN`。否则将 `ANTHROPIC_API_KEY` 设置为来自 [Claude Console](https://platform.claude.com/settings/keys) 的密钥。[身份验证优先级](/docs/zh-CN/authentication#authentication-precedence) 解释了 Claude Code 在存在多个凭证时如何选择。1352* 如需不使用本地监听器立即登录:如果您使用 claude.ai 订阅,请在可以正常登录的机器上运行 [`claude setup-token`](/docs/zh-CN/authentication#generate-a-long-lived-token),并在这台机器上将它输出的令牌设置为 `CLAUDE_CODE_OAUTH_TOKEN`。否则,请将 `ANTHROPIC_API_KEY` 设置为来自 [Claude Console](https://platform.claude.com/settings/keys) 的密钥。[身份验证优先级](/docs/zh-CN/authentication#authentication-precedence)解释了 Claude Code 如何在多个凭据之间进行选择。
1326* 要在此机器上改用浏览器登录,Claude Code 必须能够在 `127.0.0.1` 上监听。如果它在沙箱内运行,检查沙箱的策略是否允许在本地端口上监听,然后再次运行 `/login`。如果它应该能够但仍然失败,运行 `/feedback` 以便报告包含您的环境详细信息。1353* 如果要改为在这台机器上使用浏览器登录,Claude Code 必须能够在 `127.0.0.1` 上监听。如果它在沙箱中运行,请检查沙箱策略是否允许监听本地端口,然后再次运行 `/login`。如果它本应能够监听却仍然失败,请运行 `/feedback`,以便报告中包含您的环境详细信息。
1327 1354
1328<h3 id="claude-login-not-accepted">1355<h3 id="claude-login-not-accepted">
1329 Claude login not accepted1356 Claude 登录未被接受
1330</h3>1357</h3>
1331 1358
1332您尝试启动 [云会话](/docs/zh-CN/claude-code-on-the-web),服务器拒绝使用 401 创建它:它不接受此机器发送的 Claude 登录,通常是因为登录过期或被撤销。1359您尝试启动一个[云端会话](/docs/zh-CN/claude-code-on-the-web),服务器以 401 拒绝创建它:服务器不接受这台机器发送的 Claude 登录,通常是因为该登录已过期或被撤销。
1333 1360
1334当服务器给出自己的原因时,行的第一部分是该原因。否则该行读作:1361如果服务器给出了原因,该行的第一部分就是服务器自己的原因。否则,该行显示为:
1335 1362
1336```text theme={null}1363```text theme={null}
1337Claude login not accepted · Run /login, then try again1364Claude login not accepted · Run /login, then try again
1338```1365```
1339 1366
1340**应该做什么:**1367**解决方法:**
1341 1368
1342* 运行 `/login`,完成登录,然后再次启动会话1369* 运行 `/login`,完成登录,然后再次启动会话
1343 1370
1344<h3 id="artifacts-need-a-claude-ai-login">1371<h3 id="artifacts-need-a-claude-ai-login">
1345 工件需要 claude.ai 登录1372 Artifact 需要 claude.ai 登录
1346</h3>1373</h3>
1347 1374
1348Claude Code 拒绝了 [工件](/docs/zh-CN/artifacts) 发布或读取,因为会话没有可用于工件的 claude.ai 登录。1375Claude Code 拒绝了 [Artifact](/docs/zh-CN/artifacts) 的发布或读取,因为该会话没有可用于 Artifact 的 claude.ai 登录。
1349 1376
1350消息的每种形式都以相同的词开头,然后是取决于您的会话如何进行身份验证的补救措施。没有竞争凭证时,它读作:1377该消息的每种形式都以相同的文字开头,后面跟着的补救措施取决于您的会话如何进行身份验证。没有竞争凭据时,消息显示为:
1351 1378
1352```text theme={null}1379```text theme={null}
1353Artifacts need a claude.ai login. Run /login and select "Claude account with subscription", then retry — the "Anthropic Console account" option does not provide claude.ai credentials.1380Artifacts need a claude.ai login. Run /login and select "Claude account with subscription", then retry — the "Anthropic Console account" option does not provide claude.ai credentials.
1354```1381```
1355 1382
1356**应该做什么:**1383**解决方法:**
1357 1384
1358* 运行 `/login` 并选择 **Claude account with subscription**。**Anthropic Console account** 选项不提供 claude.ai 凭证。1385* 运行 `/login` 并选择 **Claude account with subscription**。**Anthropic Console account** 选项不提供 claude.ai 凭据。
1359* 当消息命名优先的凭证(如 `ANTHROPIC_API_KEY`、`apiKeyHelper` 设置或之前 `/login` 保存的 Console 密钥)时,按消息说的方式删除它,然后运行 `/login`1386* 当消息指出某个优先级更高的凭据时,例如 `ANTHROPIC_API_KEY`、`apiKeyHelper` 设置或之前的 `/login` 保存的 Console 密钥,请按消息所述将其移除,然后运行 `/login`
1360* 当消息说此远程会话通过启动它的机器进行身份验证时,在该机器上登录到 claude.ai,然后重新连接会话1387* 当消息说明此远程会话通过启动它的机器进行身份验证时,请在那台机器上登录 claude.ai,然后重新连接会话
1361* 当消息说凭证由会话的主机环境注入时,您无法在该会话中更改它;启动登录到 claude.ai 的会话1388* 当消息说明凭据由会话的宿主环境注入时,您无法在该会话中更改它;请启动一个已登录 claude.ai 的会话
1362* 请参阅 [可用性](/docs/zh-CN/artifacts#availability) 了解工件具有的其他要求,例如计划、模型提供商和组织策略1389* 请参阅[可用性](/docs/zh-CN/artifacts#availability),了解 Artifact 的其他要求,例如套餐、模型提供商和组织策略
1363 1390
1364<h3 id="administrator-policy-requires-a-cloud-gateway-sign-in">1391<h3 id="administrator-policy-requires-a-cloud-gateway-sign-in">
1365 管理员策略需要 Cloud gateway 登录1392 管理员策略要求使用云网关登录
1366</h3>1393</h3>
1367 1394
1368管理员在此机器上的 [托管设置](/docs/zh-CN/managed-settings) 将 [`forceLoginMethod`](/docs/zh-CN/settings-reference#forceloginmethod) 设置为 `"gateway"` 或设置 [`forceLoginGatewayUrl`](/docs/zh-CN/settings-reference#forcelogingatewayurl)。除非您通过 `CLAUDE_CODE_USE_BEDROCK` 等变量选择云提供商,Claude Code 仅接受 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway) 登录。您会看到两条消息之一:1395这台机器上管理员的[托管设置](/docs/zh-CN/managed-settings)将 [`forceLoginMethod`](/docs/zh-CN/settings-reference#forceloginmethod) 设置为 `"gateway"`,或设置了 [`forceLoginGatewayUrl`](/docs/zh-CN/settings-reference#forcelogingatewayurl)。除非您通过 `CLAUDE_CODE_USE_BEDROCK` 等变量选择了云服务提供商,否则 Claude Code 只接受 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway) 登录。您会看到以下两种消息之一:
1369 1396
1370```text theme={null}1397```text theme={null}
1371Not signed in to the Cloud gateway — run /login.1398Not signed in to the Cloud gateway — run /login.
1372```1399```
1373 1400
1374当会话没有网关登录时,模型请求失败,显示此消息,例如因为您自策略到达机器后未运行 `/login`。1401当会话没有网关登录时,模型请求会以此消息失败,例如因为在该策略下发到这台机器后您还没有运行过 `/login`。
1375 1402
1376如果机器还持有 Anthropic 颁发的凭证且托管设置设置了 `forceLoginMethod` 或 `forceLoginOrgUUID`,Claude Code 在启动时改为以此消息退出:1403如果这台机器上还存在 Anthropic 签发的凭据,并且托管设置设置了 `forceLoginMethod` 或 `forceLoginOrgUUID`,Claude Code 则会在启动时退出。该凭据可能是 `ANTHROPIC_API_KEY` 或 `ANTHROPIC_AUTH_TOKEN` 变量、`apiKeyHelper` 设置,或之前的 Claude Console 登录保存的 API 密钥。
1404
1405启动消息会指出会话所配置的凭据、它的设置位置以及移除它的步骤。例如,当您在 shell 中设置了 `ANTHROPIC_API_KEY` 变量时,消息显示为:
1377 1406
1378```text theme={null}1407```text theme={null}
1379Administrator policy requires a Cloud gateway sign-in on this machine; the1408Administrator policy requires a Cloud gateway sign-in on this machine, but this session is configured with an API key from ANTHROPIC_API_KEY, which a gateway machine does not accept.
1380Anthropic-issued credential configured here (ANTHROPIC_API_KEY,1409
1381ANTHROPIC_AUTH_TOKEN, or apiKeyHelper) is not used.1410To continue: unset ANTHROPIC_API_KEY (or run in a shell without it), then run claude and sign in with /login.
1382```1411```
1383 1412
1384**应该做什么:**1413**解决方法:**
1414
1415* 对于 `Not signed in to the Cloud gateway`,请运行 `/login` 并在 **Cloud gateway** 界面上完成登录
1416* 对于启动消息,请按照消息末尾的步骤移除该凭据
1417* 如果您认为这台机器不应要求使用网关,请让管理该机器的管理员从其托管设置中移除 `forceLoginMethod` 和 `forceLoginGatewayUrl`
1385 1418
1386* 运行 `/login` 并在 **Cloud gateway** 屏幕上完成登录1419在 v2.1.284 之前,启动消息会列出可能的凭据,而不是指出已配置的那一个。它以 `Administrator policy requires a Cloud gateway sign-in on this machine; the Anthropic-issued credential configured here (ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, or apiKeyHelper) is not used.` 开头。如果您看到的是这种措辞且无法判断要移除哪个凭据,请更新到 v2.1.284 或更高版本,然后再次启动 `claude`。
1387* 对于启动消息,删除您配置的 `ANTHROPIC_API_KEY`、`ANTHROPIC_AUTH_TOKEN` 或 `apiKeyHelper` 设置。要删除保存的 Console API 密钥,运行 `claude auth logout`,这也会删除保存的 claude.ai 登录。如果您使用 `CLAUDE_CODE_USE_*` 选择云提供商,会话然后以无登录启动。否则启动 `claude` 并运行 `/login`
1388* 如果您认为机器不应该需要网关,请要求管理该机器的管理员从其托管设置中删除 `forceLoginMethod` 和 `forceLoginGatewayUrl`
1389 1420
1390在 v2.1.265 上,回归也在某些 LLM 网关和代理配置中显示第一条消息,这些配置使用 API 密钥、`apiKeyHelper` 或自定义标头进行身份验证,即使机器上没有管理员要求。更新到 v2.1.266 或更高版本。您不需要更改您的配置。1421在 v2.1.265 上,一个回归问题还会在某些使用 API 密钥、`apiKeyHelper` 或自定义标头进行身份验证的 LLM 网关和代理配置中显示第一条消息,即使机器上没有管理员要求也是如此。请更新到 v2.1.266 或更高版本。您无需更改配置。
1391 1422
1392在 v2.1.261 之前,在将 `forceLoginMethod` 设置为 `"gateway"` 的机器上,Claude Code 使用剩余的保存登录而不是失败模型请求,并使用 `This machine's managed settings require a first-party login` 而不是启动消息报告配置的环境凭证。在 v2.1.265 之前,其托管设置仅设置 `forceLoginGatewayUrl` 的机器不需要网关登录,Claude Code 在那里使用剩余凭证。1423在 v2.1.261 之前,在将 `forceLoginMethod` 设置为 `"gateway"` 的机器上,Claude Code 会使用遗留的已保存登录,而不是让模型请求失败,并且会以 `This machine's managed settings require a first-party login` 报告已配置的环境凭据,而不是显示启动消息。
1393 1424
1394<h3 id="your-account-is-on-hold">1425<h3 id="your-account-is-on-hold">
1395 您的账户被冻结1426 您的账户已被暂停
1396</h3>1427</h3>
1397 1428
1398您的 Claude 账户背后的登录已被暂停。Claude Code 在尝试更新您保存的登录并了解冻结时显示第一条消息,在您在浏览器中完成的登录报告时显示第二条消息:1429您登录所用的 Claude 账户已被暂停。当 Claude Code 尝试续期您已保存的登录并获知暂停时,会显示第一条消息;当您在浏览器中完成的登录报告暂停时,会显示第二条消息:
1399 1430
1400```text theme={null}1431```text theme={null}
1401Your account is on hold and can't use Claude Code. View details or appeal: https://claude.ai/restricted1432Your account is on hold and can't use Claude Code. View details or appeal: https://claude.ai/restricted
1402Your account is on hold and can't sign in to Claude Code. View details or appeal: https://claude.ai/restricted1433Your account is on hold and can't sign in to Claude Code. View details or appeal: https://claude.ai/restricted
1403```1434```
1404 1435
1405使用同一账户再次登录不会清除消息,因为冻结是在账户上而不是登录上。在 [非交互式模式](/docs/zh-CN/headless) (`-p`) 和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,结构化错误代码为 `account_on_hold`。在 v2.1.235 之前,Claude Code 将被冻结的账户报告为 [登录过期 · 请运行 /login](#login-expired),其恢复步骤无法清除冻结。1436使用同一账户重新登录不会清除该消息,因为暂停针对的是账户而不是登录。在[非交互模式](/docs/zh-CN/headless)(`-p`)和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,结构化错误代码为 `account_on_hold`。在 v2.1.235 之前,Claude Code 会将被暂停的账户报告为 [Login expired · Please run /login](#login-expired),而其恢复步骤无法解除暂停。
1406 1437
1407**应该做什么:**1438**解决方法:**
1408 1439
1409* 打开消息中的链接以查看冻结的详细信息或对其提出上诉1440* 打开消息中的链接,查看暂停的详细信息或提出申诉
1410* 如果您有另一个 Claude 账户或不受冻结影响的 API 密钥,您可以在冻结解决期间继续工作:使用该账户运行 `/login`,或使用 `ANTHROPIC_API_KEY` 设置密钥1441* 如果您有不受暂停影响的其他 Claude 账户或 API 密钥,可以在暂停解决期间继续工作:使用该账户运行 `/login`,或通过 `ANTHROPIC_API_KEY` 设置该密钥
1411 1442
1412<h3 id="anthropic-profile-login-expired">1443<h3 id="anthropic-profile-login-expired">
1413 Anthropic 配置文件登录过期1444 Anthropic 配置文件登录已过期
1414</h3>1445</h3>
1415 1446
1416Claude Code 通过 Anthropic 凭证配置文件进行身份验证,其保存的登录凭证已过期,且配置文件不包含 Claude Code 可用于更新它的刷新凭证。Claude Code 在本地停止每个请求而不重试,因为重试会读取相同的过期凭证。1447Claude Code 正在通过一个 Anthropic 凭据配置文件进行身份验证,该配置文件中已保存的登录凭据已过期,并且配置文件中没有 Claude Code 可用于续期的刷新凭据。Claude Code 会在本地停止每个请求且不重试,因为重试只会读取同一个已过期的凭据。
1417 1448
1418```text theme={null}1449```text theme={null}
1419Anthropic profile login expired · Re-authenticate your Anthropic profile1450Anthropic profile login expired · Re-authenticate your Anthropic profile
1420Anthropic profile login expired · Run /login to use your claude.ai account instead, or re-authenticate the profile1451Anthropic profile login expired · Run /login to use your claude.ai account instead, or re-authenticate the profile
1421```1452```
1422 1453
1423这仅在活跃凭证来自 Anthropic 凭证配置文件时出现,您使用 `ANTHROPIC_PROFILE` 环境变量选择该文件,Claude Code 从您的 Anthropic 配置目录中发现为活跃配置文件,或 Claude Code 在您 [不使用 API 密钥登录](/docs/zh-CN/authentication#sign-in-without-an-api-key) 时写入。使用 `/login` 的 claude.ai 选项、API 密钥、持有者令牌(如 `ANTHROPIC_AUTH_TOKEN`)或第三方提供商进行身份验证的会话永远不会看到此消息。1454只有当生效的凭据来自 Anthropic 凭据配置文件时才会出现此消息,该配置文件可以是您通过 `ANTHROPIC_PROFILE` 环境变量选择的、Claude Code 在您的 Anthropic 配置目录中发现为活跃配置文件的,或是您[在没有 API 密钥的情况下登录](/docs/zh-CN/authentication#sign-in-without-an-api-key)时 Claude Code 写入的。使用 API 密钥、bearer 令牌(例如 `ANTHROPIC_AUTH_TOKEN`)或第三方提供商进行身份验证的会话永远不会看到此消息。
1424 1455
1425在 [提供无密钥登录](/docs/zh-CN/authentication#sign-in-without-an-api-key) 的机器上,运行 `/login`,选择 Anthropic Console 账户,并再次登录以更新无密钥 Console 登录或 Claude Platform CLI 的 `ant auth login` 写入的配置文件。Claude Code 替换该配置文件中的过期凭证。对于联合配置文件或另一个工具创建的配置文件,`/login` 不会更新凭证。您看到的形式取决于您是否显式选择了配置文件或 Claude Code 发现了它:1456在[提供无密钥登录](/docs/zh-CN/authentication#sign-in-without-an-api-key)的机器上,运行 `/login`,选择 Anthropic Console 账户并重新登录,即可续期由无密钥 Console 登录或 Claude Platform CLI 的 `ant auth login` 写入的配置文件。Claude Code 会替换该配置文件中已过期的凭据。对于联合身份配置文件或由其他工具创建的配置文件,`/login` 不会续期凭据。您看到哪种形式,取决于配置文件是您选择的还是 Claude Code 发现的:
1426 1457
1427* 当您显式设置 `ANTHROPIC_PROFILE` 时,消息以 `Re-authenticate your Anthropic profile` 结尾。1458* 当您显式设置了 `ANTHROPIC_PROFILE` 时,消息以 `Re-authenticate your Anthropic profile` 结尾。
1428* 当 Claude Code 从您的配置目录发现配置文件时,消息提供 `/login`,因为 Claude Code 给予工作的 `/login` 优先于发现的配置文件,然后改为使用您的 claude.ai 或 Console 账户进行身份验证。在 v2.1.234 之前,Claude Code 在这种情况下也显示 `Re-authenticate your Anthropic profile` 形式。1459* 当 Claude Code 从您的配置目录中发现该配置文件时,消息会提供 `/login` 选项,因为 Claude Code 让可用的 `/login` 优先于所发现的配置文件,然后改用您的 claude.ai 或 Console 账户进行身份验证。在 v2.1.234 之前,这种情况下 Claude Code 也会显示 `Re-authenticate your Anthropic profile` 形式。
1429 1460
1430**应该做什么:**1461**解决方法:**
1431 1462
1432* 再次登录到配置文件,然后重试:在 [提供无密钥登录](/docs/zh-CN/authentication#sign-in-without-an-api-key) 的机器上,运行 `/login` 并为无密钥 Console 登录或 Claude Platform CLI 的 `ant auth login` 写入的配置文件选择 Anthropic Console 账户;对于其他配置文件,使用创建它们的工具1463* 重新登录该配置文件,然后重试:在[提供无密钥登录](/docs/zh-CN/authentication#sign-in-without-an-api-key)的机器上,对于由无密钥 Console 登录或 Claude Platform CLI 的 `ant auth login` 写入的配置文件,运行 `/login` 并选择 Anthropic Console 账户;对于其他配置文件,请使用创建它们的工具
1433* 如果管理员配置了配置文件的凭证,请要求他们颁发新凭证1464* 如果该配置文件的凭据由管理员预配,请让他们签发一个新的凭据
1434* 运行 `/status` 以确认活跃凭证源和配置文件名称1465* 运行 `/status`,确认当前生效的凭据来源和配置文件名称
1435* 要停止使用配置文件,如果您设置了 `ANTHROPIC_PROFILE`,则取消设置它,然后以其他方式进行身份验证,例如 `/login` 或 `ANTHROPIC_API_KEY`1466* 如需停止使用该配置文件,请取消设置 `ANTHROPIC_PROFILE`(如果您设置过),然后以其他方式进行身份验证,例如 `/login` 或 `ANTHROPIC_API_KEY`
1436 1467
1437<h3 id="oauth-scope-requirement">1468<h3 id="oauth-scope-requirement">
1438 OAuth 范围要求1469 OAuth 作用域要求
1439</h3>1470</h3>
1440 1471
1441存储的令牌早于较新功能需要的权限范围:1472已存储的令牌早于某个新功能所需的权限作用域:
1442 1473
1443```text theme={null}1474```text theme={null}
1444OAuth token does not meet scope requirement: user:profile1475OAuth token does not meet scope requirement: user:profile
1445```1476```
1446 1477
1447**应该做什么:**1478**解决方法:**
1448 1479
1449* 运行 `/login` 以获取具有当前范围的新令牌。您不需要先登出。1480* 运行 `/login` 获取具有当前作用域的新令牌。您无需先注销。
1450 1481
1451<h3 id="claude-ai-rejected-the-session-token">1482<h3 id="claude-ai-rejected-the-session-token">
1452 claude.ai 拒绝了会话令牌1483 claude.ai 拒绝了会话令牌
1453</h3>1484</h3>
1454 1485
1455[claude.ai 连接器](/docs/zh-CN/mcp#use-mcp-servers-from-claude-ai) 请求失败,因为 claude.ai 拒绝了您的 Claude Code 登录中的令牌。被拒绝的令牌是您的登录,而不是连接器在 claude.ai 中的自己的授权,因此再次授权连接器不会解决它。在 `/mcp` 中,连接器显示为 `session token rejected`,其详细视图读作:1486[claude.ai 连接器](/docs/zh-CN/mcp#use-mcp-servers-from-claude-ai)请求失败,因为 claude.ai 拒绝了来自您 Claude Code 登录的令牌。被拒绝的令牌是您的登录,而不是该连接器在 claude.ai 中自身的授权,因此重新授权连接器并不能解决问题。在 `/mcp` 中,该连接器显示为 `session token rejected`,其详细信息视图显示:
1456 1487
1457```text theme={null}1488```text theme={null}
1458claude.ai rejected the session token. Run /login, then reconnect.1489claude.ai rejected the session token. Run /login, then reconnect.
1459```1490```
1460 1491
1461**应该做什么:**1492**解决方法:**
1462 1493
1463* 运行 `/login` 再次登录1494* 运行 `/login` 重新登录
1464* 从 `/mcp` 重新连接连接器,或运行 `/mcp reconnect <server>`。在您再次登录之前重新连接会使连接器处于相同状态。`/mcp` 面板的 **Reconnect** 选项报告 `your claude.ai session token was rejected`;输入的 `/mcp reconnect <server>` 形式报告成功重新连接,即使令牌仍然被拒绝。1495* 从 `/mcp` 重新连接该连接器,或运行 `/mcp reconnect <server>`。在重新登录之前重新连接,连接器会保持相同状态。`/mcp` 面板的 **Reconnect** 选项会报告 `your claude.ai session token was rejected`;而键入的 `/mcp reconnect <server>` 形式会报告重新连接成功,尽管令牌仍然被拒绝。
1465 1496
1466在 v2.1.222 之前,Claude Code 改为将连接器标记为需要身份验证,这指向您连接器的授权流程,即使完成它也不会解决状态。1497在 v2.1.222 之前,Claude Code 会将该连接器标记为需要身份验证,这会引导您进入连接器的授权流程,而完成该流程并不能解决此状态。
1467 1498
1468<h3 id="mcp-server-needs-you-to-sign-in-again">1499<h3 id="mcp-server-needs-you-to-sign-in-again">
1469 MCP 服务器需要您再次登录1500 MCP 服务器需要您重新登录
1470</h3>1501</h3>
1471 1502
1472远程 [MCP 服务器](/docs/zh-CN/mcp) 在会话中期拒绝了工具调用上的凭证,通常是因为登录或令牌过期或令牌缺少工具需要的权限。工具调用失败,`/mcp` 将服务器标记为 [需要身份验证](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers)。1503某个远程 [MCP 服务器](/docs/zh-CN/mcp)在会话中途的工具调用中拒绝了凭据,通常是因为登录或令牌已过期,或令牌缺少工具所需的权限。该工具调用失败,`/mcp` 会将该服务器标记为[需要身份验证](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers)。
1473 1504
1474对于您从 Claude Code 登录的服务器,包括 claude.ai 连接器,登录已过期或被撤销:1505对于您从 Claude Code 登录的服务器(包括 claude.ai 连接器),登录已过期或被撤销:
1475 1506
1476```text theme={null}1507```text theme={null}
1477MCP server "<name>" needs you to sign in again (run /mcp to re-authenticate)1508MCP server "<name>" needs you to sign in again (run /mcp to re-authenticate)
1478```1509```
1479 1510
1480运行 `/mcp`,选择服务器,并从其菜单再次登录。1511运行 `/mcp`,选择该服务器,然后从其菜单中重新登录。
1481 1512
1482对于使用 [`headersHelper`](/docs/zh-CN/mcp#use-dynamic-headers-for-custom-authentication) 脚本配置的服务器,Claude Code 已在显示此之前重新运行 helper 并重试调用一次:1513对于配置了 [`headersHelper`](/docs/zh-CN/mcp#use-dynamic-headers-for-custom-authentication) 脚本的服务器,Claude Code 在显示以下消息之前已经重新运行过该 helper 并重试了一次调用:
1483 1514
1484```text theme={null}1515```text theme={null}
1485MCP server "<name>" rejected the credential from its headersHelper (check the helper and run /mcp to reconnect, or to authenticate if the server also uses OAuth)1516MCP server "<name>" rejected the credential from its headersHelper (check the helper and run /mcp to reconnect, or to authenticate if the server also uses OAuth)
1486```1517```
1487 1518
1488检查 helper 返回服务器接受的凭证,然后从 `/mcp` 重新连接,这会再次运行 helper。1519检查该 helper 是否返回服务器接受的凭据,然后从 `/mcp` 重新连接,这会再次运行该 helper。
1489 1520
1490对于在其配置中具有静态 `Authorization` 标头的服务器:1521对于在配置中带有静态 `Authorization` 标头的服务器:
1491 1522
1492```text theme={null}1523```text theme={null}
1493MCP server "<name>" rejected the Authorization header in its config (update it, then run /mcp to reconnect)1524MCP server "<name>" rejected the Authorization header in its config (update it, then run /mcp to reconnect)
1494```1525```
1495 1526
1496在配置服务器的位置更新标头值,然后从 `/mcp` 重新连接。1527在配置该服务器的位置更新标头值,然后从 `/mcp` 重新连接。
1497 1528
1498在 v2.1.273 之前,过期的登录、`headersHelper` 和 `Authorization` 标头情况都显示 `MCP server "<name>" requires re-authorization (token expired)`。1529在 v2.1.273 之前,登录过期、`headersHelper` 和 `Authorization` 标头这几种情况都显示 `MCP server "<name>" requires re-authorization (token expired)`。
1499 1530
1500服务器也可以使用 HTTP 403 `insufficient_scope` 拒绝工具调用,以要求您授权范围,有时是您的令牌已列出的范围。消息命名该范围:1531服务器也可能以 HTTP 403 `insufficient_scope` 拒绝工具调用,要求您授权某个作用域,有时该作用域甚至已列在您的令牌中。消息会指出该作用域:
1501 1532
1502```text theme={null}1533```text theme={null}
1503MCP server "<name>" needs additional permissions (scope: "<scope>") — run /mcp to re-authenticate1534MCP server "<name>" needs additional permissions (scope: "<scope>") — run /mcp to re-authenticate
1504```1535```
1505 1536
1506运行 `/mcp`,选择服务器,并从其菜单再次进行身份验证。1537运行 `/mcp`,选择该服务器,然后从其菜单中重新进行身份验证。
1507 1538
1508当服务器的配置既不设置 [`oauth.scopes`](/docs/zh-CN/mcp#restrict-oauth-scopes) 也不设置 [`authServerMetadataUrl`](/docs/zh-CN/mcp#override-oauth-metadata-discovery) 时,Claude Code 请求服务器命名的范围。使用任一设置,Claude Code 改为请求该设置的范围。如果您固定了 `oauth.scopes`,在再次进行身份验证之前将缺失的范围添加到该列表。1539当服务器的配置既未设置 [`oauth.scopes`](/docs/zh-CN/mcp#restrict-oauth-scopes) 也未设置 [`authServerMetadataUrl`](/docs/zh-CN/mcp#override-oauth-metadata-discovery) 时,Claude Code 会请求服务器指出的作用域。如果设置了其中任一项,Claude Code 会改为请求该设置中的作用域。如果您固定了 `oauth.scopes`,请在重新进行身份验证之前将缺失的作用域添加到该列表中。
1509 1540
1510在 v2.1.274 之前,这种情况显示 `needs you to sign in again` 消息,在 v2.1.273 之前它显示 `requires re-authorization (token expired)`,如其他情况。1541在 v2.1.274 之前,这种情况显示 `needs you to sign in again` 消息;在 v2.1.273 之前,它与其他情况一样显示 `requires re-authorization (token expired)`。
1511 1542
1512<h3 id="mcp-server-url-is-missing-or-not-a-valid-url">1543<h3 id="mcp-server-url-is-missing-or-not-a-valid-url">
1513 MCP 服务器 URL 缺失或不是有效的 URL1544 MCP 服务器 URL 缺失或不是有效的 URL
1514</h3>1545</h3>
1515 1546
1516Claude Code 拒绝为远程 MCP 服务器启动 OAuth 登录,因为服务器的配置 `url` 不解析为 URL。除非 Claude Code 有更具体的配置问题要为服务器报告,否则在您的 shell 中运行 [`claude mcp login <name>`](/docs/zh-CN/mcp#authenticate-from-the-command-line) 会将拒绝打印为:1547Claude Code 拒绝为某个远程 MCP 服务器启动 OAuth 登录,因为该服务器配置的 `url` 无法解析为 URL。除非 Claude Code 对该服务器有更具体的配置问题需要报告,否则在您的 shell 中运行 [`claude mcp login <name>`](/docs/zh-CN/mcp#authenticate-from-the-command-line) 会将该拒绝输出为:
1517 1548
1518```text theme={null}1549```text theme={null}
1519Couldn't complete authentication for "<name>": This server's URL is missing or not a valid URL, so sign-in can't start. Fix the URL in its MCP config (or set the environment variable it uses) and try again.1550Couldn't complete authentication for "<name>": This server's URL is missing or not a valid URL, so sign-in can't start. Fix the URL in its MCP config (or set the environment variable it uses) and try again.
1520```1551```
1521 1552
1522**应该做什么:**1553**解决方法:**
1523 1554
1524* 将条目的 `url` 设置为服务器的真实端点,其中配置服务器,或设置其 [`${VAR}` 引用](/docs/zh-CN/mcp#environment-variable-expansion-in-mcp-json) 命名的环境变量,然后再次运行登录。1555* 在配置该服务器的位置,将该条目的 `url` 设置为服务器的真实端点,或设置其 [`${VAR}` 引用](/docs/zh-CN/mcp#environment-variable-expansion-in-mcp-json)所指的环境变量,然后再次运行登录。
1525 1556
1526<h3 id="issuer-mismatch-in-authorization-response">1557<h3 id="issuer-mismatch-in-authorization-response">
1527 授权响应中的发行者不匹配1558 授权响应中的颁发者不匹配
1528</h3>1559</h3>
1529 1560
1530在 [MCP OAuth 登录](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers) 期间,授权服务器重定向回 Claude Code,其中 `iss` 参数不命名 Claude Code 从服务器的 OAuth 元数据期望的发行者。此步骤中的错误发行者是授权服务器混合攻击的样子,因此 Claude Code 失败登录而不是交换授权代码。Claude Code 在浏览器登录后在 `/mcp` 服务器菜单中显示错误:1561在 [MCP OAuth 登录](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers)期间,授权服务器重定向回 Claude Code 时所携带的 `iss` 参数与 Claude Code 根据服务器 OAuth 元数据所期望的颁发者不一致。此步骤中出现错误的颁发者正是授权服务器混淆攻击(mix-up attack)的表现形式,因此 Claude Code 会让登录失败,而不是交换授权码。Claude Code 会在浏览器登录后,在 `/mcp` 服务器菜单中显示该错误:
1531 1562
1532```text theme={null}1563```text theme={null}
1533Issuer mismatch in authorization response (RFC 9207): expected "https://auth.example.com", received "https://other.example.com"1564Issuer mismatch in authorization response (RFC 9207): expected "https://auth.example.com", received "https://other.example.com"
1534```1565```
1535 1566
1536`expected` 是来自服务器的 OAuth 元数据的发行者,`received` 是重定向携带的 `iss` 值。其重定向不携带 `iss` 参数的登录通过检查,除非服务器的元数据设置 `authorization_response_iss_parameter_supported`,在这种情况下 Claude Code 失败登录。1567`expected` 是来自服务器 OAuth 元数据的颁发者,`received` 是重定向所携带的 `iss` 值。重定向未携带 `iss` 参数的登录会通过检查,除非服务器的元数据设置了 `authorization_response_iss_parameter_supported`,这种情况下 Claude Code 会让登录失败。
1537 1568
1538**应该做什么:**1569**解决方法:**
1539 1570
1540* 从 `/mcp` 再次尝试登录1571* 从 `/mcp` 再次尝试登录
1541* 如果错误重复,将其报告给服务器操作员。修复是服务器端的:授权服务器必须在 `iss` 参数中返回与在其元数据中宣传的相同发行者1572* 如果错误重复出现,请向服务器运营方报告。需要在服务器端修复:授权服务器必须在 `iss` 参数中返回与其元数据中公布的相同的颁发者
1542* 要在修复服务器时连接,使用 [`MCP_SDK_GENERATION=v1`](/docs/zh-CN/env-vars) 启动 Claude Code,其 [运行时](/docs/zh-CN/mcp#mcp-client-runtimes) 不运行此检查。这消除了对混合攻击的保护,因此更喜欢服务器端修复1573* 如需在服务器修复期间进行连接,请使用 [`MCP_SDK_GENERATION=v1`](/docs/zh-CN/env-vars) 启动 Claude Code,其[运行时](/docs/zh-CN/mcp#mcp-client-runtimes)不执行此检查。这会移除一项针对混淆攻击的防护,因此请优先采用服务器端修复
1543 1574
1544在 v2.1.232 之前,Claude Code 仅在逐步推出中或当您设置 `MCP_SDK_GENERATION=v2` 时使用 v2 运行时。1575在 v2.1.232 之前,Claude Code 仅在逐步推出时或您设置 `MCP_SDK_GENERATION=v2` 时才使用 v2 运行时。
1545 1576
1546<h3 id="refusing-to-send-credentials-to-non-https-token-endpoint">1577<h3 id="refusing-to-send-credentials-to-non-https-token-endpoint">
1547 拒绝向非 https 令牌端点发送凭证1578 拒绝向非 https 令牌端点发送凭据
1548</h3>1579</h3>
1549 1580
1550在 [v2 运行时](/docs/zh-CN/mcp#mcp-client-runtimes) 上,Claude Code 仅向通过 HTTPS 或在 `localhost`、`127.0.0.1` 或 `::1` 处提供的令牌端点发送 [MCP OAuth](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers) 令牌请求。此消息意味着服务器的令牌端点都不是,因此 Claude Code 在发送请求前停止。这发生在浏览器登录之后,因此浏览器步骤首先成功,并且每当 Claude Code 刷新服务器的令牌时再次发生。1581在 [v2 运行时](/docs/zh-CN/mcp#mcp-client-runtimes)上,Claude Code 只会将 [MCP OAuth](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers) 令牌请求发送到通过 HTTPS 提供服务的令牌端点,或位于 `localhost`、`127.0.0.1` 或 `::1` 的令牌端点。此消息表示服务器的令牌端点两者都不是,因此 Claude Code 在发送请求前就停止了。这发生在浏览器登录之后,因此浏览器步骤会先成功,并且每当 Claude Code 刷新该服务器的令牌时都会再次发生。
1551 1582
1552在其完整形式中,消息来自 MCP SDK 并引用它拒绝的令牌端点。在调试日志中,它遵循 `Error during auth completion:` 用于登录或 `Token refresh failed:` 用于刷新。在您的 shell 中,`claude mcp login <name>` 在 `Couldn't complete authentication for "<name>":` 之后打印它,在会话中,`/mcp` 在服务器的菜单下显示它:1583该消息的完整形式来自 MCP SDK,并会引用它拒绝的令牌端点。在调试日志中,对于登录,它跟在 `Error during auth completion:` 之后;对于刷新,它跟在 `Token refresh failed:` 之后。在您的 shell 中,`claude mcp login <name>` 会在 `Couldn't complete authentication for "<name>":` 之后输出它;在会话中,`/mcp` 会在服务器菜单下显示它:
1553 1584
1554```text theme={null}1585```text theme={null}
1555Refusing to send credentials to non-https token endpoint 'http://192.168.1.50:8123/oauth/token'. OAuth token requests MUST use TLS (localhost / 127.0.0.1 / ::1 are exempt).1586Refusing to send credentials to non-https token endpoint 'http://192.168.1.50:8123/oauth/token'. OAuth token requests MUST use TLS (localhost / 127.0.0.1 / ::1 are exempt).
1556```1587```
1557 1588
1558Claude Code 将具有查询字符串或长随机外观路径段的服务器 URL 视为可能的秘密。对于这样的服务器,它在显示或记录它们之前会编辑 MCP SDK 引发的登录错误。此错误然后读作可能在版本之间更改的短名称,例如 `io`,后跟 `from the MCP SDK for` 和编辑的服务器 URL。MCP SDK 的其他错误在那里采用相同的形状。编辑的消息只能是此错误,当服务器的令牌端点是纯 `http://` 在 `localhost`、`127.0.0.1` 或 `::1` 以外的地址时。1589Claude Code 会将带有查询字符串或较长的随机外观路径段的服务器 URL 视为可能是机密的。对于此类服务器,它会在显示或记录 MCP SDK 引发的登录错误之前对其进行脱敏。此时该错误会显示为一个可能因版本而变化的简短名称(例如 `io`),后跟 `from the MCP SDK for` 和经过脱敏的服务器 URL。来自 MCP SDK 的其他错误在这种情况下也采用相同的形式。只有当服务器的令牌端点是位于 `localhost`、`127.0.0.1` 或 `::1` 以外地址的普通 `http://` 时,脱敏后的消息才可能是此错误。
1559 1590
1560**应该做什么:**1591**解决方法:**
1561 1592
1562* 通过 HTTPS 提供该令牌端点,例如通过将服务器放在终止 TLS 的反向代理或隧道后面,并配置服务器以宣传 `https://` 地址1593* 通过 HTTPS 提供该令牌端点,例如将服务器置于终止 TLS 的反向代理或隧道之后,并配置服务器公布 `https://` 地址
1563* 要在不更改服务器的情况下连接,使用 [`MCP_SDK_GENERATION=v1`](/docs/zh-CN/env-vars) 启动 Claude Code,其 [运行时](/docs/zh-CN/mcp#mcp-client-runtimes) 不应用此规则并通过纯 HTTP 发送令牌请求。该选择持续到您退出并应用于每个服务器。v1 运行时也跳过 [发行者检查](#issuer-mismatch-in-authorization-response),因此更喜欢通过 HTTPS 提供端点1594* 如需在不更改服务器的情况下进行连接,请使用 [`MCP_SDK_GENERATION=v1`](/docs/zh-CN/env-vars) 启动 Claude Code,其[运行时](/docs/zh-CN/mcp#mcp-client-runtimes)不应用此规则,会通过普通 HTTP 发送令牌请求。该选择会持续到您退出为止,并适用于所有服务器。v1 运行时还会跳过[颁发者检查](#issuer-mismatch-in-authorization-response),因此请优先通过 HTTPS 提供该端点
1564 1595
1565<h3 id="aws-credentials-expired-or-invalid">1596<h3 id="aws-credentials-expired-or-invalid">
1566 AWS 凭证已过期或无效1597 AWS 凭据已过期或无效
1567</h3>1598</h3>
1568 1599
1569您的 AWS 会话令牌已过期或被拒绝。此消息出现在来自 [Claude Platform on AWS](/docs/zh-CN/claude-platform-on-aws) 或 [Mantle 端点](/docs/zh-CN/amazon-bedrock#use-the-mantle-endpoint) 的 401,这是这些提供商报告过期安全令牌的方式。1600您的 AWS 会话令牌已过期或被拒绝。当 [Claude Platform on AWS](/docs/zh-CN/claude-platform-on-aws) 或 [Mantle 端点](/docs/zh-CN/amazon-bedrock#use-the-mantle-endpoint)返回 401 时会出现此消息,这是这些提供商报告安全令牌过期的方式。
1570 1601
1571中间的操作提示因您的设置而异。稳定部分是前导 `AWS credentials expired or invalid`:1602中间的操作提示因您的设置而异。稳定不变的部分是开头的 `AWS credentials expired or invalid`:
1572 1603
1573```text theme={null}1604```text theme={null}
1574AWS credentials expired or invalid · run /login and select "Claude Platform on AWS · refresh credentials", or run `aws sso login --profile myprofile` in another terminal · API Error: 401 ...1605AWS credentials expired or invalid · run /login and select "Claude Platform on AWS · refresh credentials", or run `aws sso login --profile myprofile` in another terminal · API Error: 401 ...
1575```1606```
1576 1607
1577在 v2.1.273 之前,仅当配置了 `awsAuthRefresh` 时才出现此消息。1608在 v2.1.273 之前,只有在配置了 `awsAuthRefresh` 时才会出现此消息。
1578 1609
1579**应该做什么:**1610**解决方法:**
1580 1611
1581* 如果提示说凭证由此环境管理,启动 Claude Code 的应用拥有凭证,此处的其他步骤不适用:重试或联系您的管理员1612* 如果提示说明凭据由此环境管理,则凭据归启动 Claude Code 的应用所有,此处的其他步骤不适用:请重试,或联系您的管理员
1582* 如果设置了 [`awsAuthRefresh`](/docs/zh-CN/amazon-bedrock#advanced-credential-configuration),在另一个终端中运行消息中命名的命令,例如 `aws sso login --profile myprofile`,并完成浏览器登录,然后重试。否则自己刷新您使用的 AWS 凭证:您的 SSO 登录、访问密钥、API 密钥或代理令牌1613* 如果设置了 [`awsAuthRefresh`](/docs/zh-CN/amazon-bedrock#advanced-credential-configuration),请在另一个终端中运行消息中指出的命令(例如 `aws sso login --profile myprofile`)并完成浏览器登录,然后重试。否则,请自行刷新您所使用的 AWS 凭据:您的 SSO 登录、访问密钥、API 密钥或代理令牌
1583* 在交互式会话中设置 `awsAuthRefresh`,您可以改为运行 `/login`,选择 **3rd-party platform**,然后在 **Using 3rd-party platforms** 下选择 **Claude Platform on AWS · refresh credentials** 以运行相同的命令而不重新启动 Claude Code。请参阅 [配置 AWS 凭证](/docs/zh-CN/claude-platform-on-aws#1-configure-aws-credentials)1614* 在设置了 `awsAuthRefresh` 的交互式会话中,您也可以运行 `/login`,选择 **3rd-party platform**,然后在 **Using 3rd-party platforms** 下选择 **Claude Platform on AWS · refresh credentials**,无需重启 Claude Code 即可运行同一命令。请参阅[配置 AWS 凭据](/docs/zh-CN/claude-platform-on-aws#1-configure-aws-credentials)
1584* 如果刷新命令成功后错误重复,通过在同一 shell 和配置文件中使用 `aws sts get-caller-identity` 在 Claude Code 外确认身份有效1615* 如果刷新命令成功后错误仍然重复出现,请在同一 shell 和 profile 中运行 `aws sts get-caller-identity`,确认该身份在 Claude Code 之外有效
1585 1616
1586<h3 id="aws-authentication-failed">1617<h3 id="aws-authentication-failed">
1587 AWS 身份验证失败1618 AWS 身份验证失败
1589 1620
1590您的 AWS 提供商返回了 403,或 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 返回了 401。1621您的 AWS 提供商返回了 403,或 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 返回了 401。
1591 1622
1592Amazon Bedrock 将过期的安全令牌报告为 403,但 403 也是它报告授权拒绝的方式,例如来自缺失 IAM 权限的 `AccessDeniedException`。Claude Code 无法区分这两个原因。1623Amazon Bedrock 将安全令牌过期报告为 403,但 403 也是它报告授权被拒绝的方式,例如因缺少 IAM 权限而产生的 `AccessDeniedException`。Claude Code 无法区分这两种原因。
1593 1624
1594来自 Amazon Bedrock 的 401 也在这里而不是在 [AWS 凭证已过期或无效](#aws-credentials-expired-or-invalid) 下,因为 Amazon Bedrock 不将过期令牌报告为 401。来自该端点的 401 通常来自请求路径中的其他内容,例如公司代理。1625来自 Amazon Bedrock 的 401 也会归到这里,而不是[AWS 凭据已过期或无效](#aws-credentials-expired-or-invalid),因为 Amazon Bedrock 不会将令牌过期报告为 401。来自该端点的 401 通常来自请求路径中的其他环节,例如企业代理。
1595 1626
1596凭证刷新修复过期令牌,无法修复其他原因,因此消息提供两者:1627刷新凭据可以修复令牌过期,但无法修复其他原因,因此消息同时提供了两种方案:
1597 1628
1598```text theme={null}1629```text theme={null}
1599AWS authentication failed · run /login and select "Claude Platform on AWS · refresh credentials", or run `aws sso login --profile myprofile` in another terminal · if credentials are current, check AWS permissions and model access · API Error: 403 ...1630AWS authentication failed · run /login and select "Claude Platform on AWS · refresh credentials", or run `aws sso login --profile myprofile` in another terminal · if credentials are current, check AWS permissions and model access · API Error: 403 ...
1600```1631```
1601 1632
1602中间的操作提示因您的设置而异。稳定部分是前导 `AWS authentication failed`。1633中间的操作提示因您的设置而异。稳定不变的部分是开头的 `AWS authentication failed`。
1603 1634
1604当 403 是 Amazon Bedrock 的答案,说您无权访问具有指定模型 ID 的模型时,提示改为告诉您在 Amazon Bedrock 控制台中为您的账户和区域启用模型。1635当 403 是 Amazon Bedrock 表示您无权访问指定模型 ID 的模型时,提示会改为告诉您在 Amazon Bedrock 控制台中为您的账户和区域启用该模型。
1605 1636
1606在 v2.1.273 之前,仅当配置了 `awsAuthRefresh` 时才出现此消息。1637在 v2.1.273 之前,只有在配置了 `awsAuthRefresh` 时才会出现此消息。
1607 1638
1608**应该做什么:**1639**解决方法:**
1609 1640
1610* 如果提示说凭证由此环境管理,启动 Claude Code 的应用拥有凭证,此处的其他步骤不适用:重试或联系您的管理员1641* 如果提示说明凭据由此环境管理,则凭据归启动 Claude Code 的应用所有,此处的其他步骤不适用:请重试,或联系您的管理员
1611* 刷新您的 AWS 凭证以防过期凭证是原因:运行消息中命名的 [`awsAuthRefresh`](/docs/zh-CN/amazon-bedrock#advanced-credential-configuration) 命令(当设置时),或自己刷新您的 SSO 登录、访问密钥、API 密钥或代理令牌1642* 刷新您的 AWS 凭据,以防原因是凭据过期:如果设置了 [`awsAuthRefresh`](/docs/zh-CN/amazon-bedrock#advanced-credential-configuration),请运行消息中指出的该命令;否则请自行刷新您的 SSO 登录、访问密钥、API 密钥或代理令牌
1612* 如果您的凭证是最新的,确认 [IAM 配置](/docs/zh-CN/amazon-bedrock#iam-configuration) 中的 IAM 权限已附加到您使用的身份,并且所选模型已为您的账户和区域启用1643* 如果您的凭据是最新的,请确认 [IAM 配置](/docs/zh-CN/amazon-bedrock#iam-configuration)中的 IAM 权限已附加到您正在使用的身份,并且所选模型已为您的账户和区域启用
1613* 运行 `aws sts get-caller-identity` 以确认您的请求使用哪个身份1644* 运行 `aws sts get-caller-identity`,确认您的请求使用的是哪个身份
1614 1645
1615<h3 id="google-cloud-credentials-expired-or-invalid">1646<h3 id="google-cloud-credentials-expired-or-invalid">
1616 Google Cloud 凭证已过期或无效1647 Google Cloud 凭据已过期或无效
1617</h3>1648</h3>
1618 1649
1619您的 [Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) Google Cloud 凭证已过期或被拒绝:请求返回了 401,这是 Agent Platform 报告凭证过期的方式。1650您用于 [Google Cloud's Agent Platform](/docs/zh-CN/google-vertex-ai) 的 Google Cloud 凭据已过期或被拒绝:请求返回了 401,这是 Agent Platform 报告凭据过期的方式。
1620 1651
1621中间的操作提示因您的设置而异。稳定部分是前导 `Google Cloud credentials expired or invalid`:1652中间的操作提示因您的设置而异。稳定不变的部分是开头的 `Google Cloud credentials expired or invalid`:
1622 1653
1623```text theme={null}1654```text theme={null}
1624Google Cloud credentials expired or invalid · refresh your Google Cloud credentials (application default sign-in, or the key file in GOOGLE_APPLICATION_CREDENTIALS) and retry · API Error: 401 ...1655Google Cloud credentials expired or invalid · refresh your Google Cloud credentials (application default sign-in, or the key file in GOOGLE_APPLICATION_CREDENTIALS) and retry · API Error: 401 ...
1625```1656```
1626 1657
1627**应该做什么:**1658**解决方法:**
1628 1659
1629* 如果提示说凭证由此环境管理,启动 Claude Code 的应用拥有凭证,此处的其他步骤不适用:重试或联系您的管理员1660* 如果提示说明凭据由此环境管理,则凭据归启动 Claude Code 的应用所有,此处的其他步骤不适用:请重试,或联系您的管理员
1630* 如果您使用应用默认凭证进行身份验证,运行消息中命名的 [`gcpAuthRefresh`](/docs/zh-CN/google-vertex-ai#advanced-credential-configuration) 命令或 `gcloud auth application-default login`,并完成登录,然后重试1661* 如果您使用应用默认凭据进行身份验证,请运行消息中指出的 [`gcpAuthRefresh`](/docs/zh-CN/google-vertex-ai#advanced-credential-configuration) 命令或 `gcloud auth application-default login` 并完成登录,然后重试
1631* 如果您通过设置了 `CLAUDE_CODE_SKIP_VERTEX_AUTH` 的 [LLM 网关](/docs/zh-CN/llm-gateway) 路由,刷新 `ANTHROPIC_AUTH_TOKEN` 或 `ANTHROPIC_CUSTOM_HEADERS` 中的网关令牌,然后重试1662* 如果您在设置了 `CLAUDE_CODE_SKIP_VERTEX_AUTH` 的情况下通过 [LLM 网关](/docs/zh-CN/llm-gateway)路由,请刷新 `ANTHROPIC_AUTH_TOKEN` 或 `ANTHROPIC_CUSTOM_HEADERS` 中的网关令牌,然后重试
1632* 如果您使用服务账户密钥文件进行身份验证,确认 `GOOGLE_APPLICATION_CREDENTIALS` 指向有效密钥。请参阅 [配置 GCP 凭证](/docs/zh-CN/google-vertex-ai#3-configure-gcp-credentials)1663* 如果您使用服务账号密钥文件进行身份验证,请确认 `GOOGLE_APPLICATION_CREDENTIALS` 指向有效的密钥。请参阅[配置 GCP 凭据](/docs/zh-CN/google-vertex-ai#3-configure-gcp-credentials)
1633* 如果刷新后错误重复,通过在同一 shell 中使用 `gcloud auth application-default print-access-token` 在 Claude Code 外确认身份有效1664* 如果刷新后错误仍然重复出现,请在同一 shell 中运行 `gcloud auth application-default print-access-token`,确认该身份在 Claude Code 之外可以正常工作
1634 1665
1635在 v2.1.273 之前,来自 Agent Platform 的 401 显示通用 `Please run /login` 或 `Failed to authenticate` 消息,无法刷新 Google Cloud 凭证。1666在 v2.1.273 之前,来自 Agent Platform 的 401 会改为显示通用的 `Please run /login` 或 `Failed to authenticate` 消息,而这些消息无法刷新 Google Cloud 凭据。
1636 1667
1637<h3 id="google-cloud-authentication-failed">1668<h3 id="google-cloud-authentication-failed">
1638 Google Cloud 身份验证失败1669 Google Cloud authentication failed
1639</h3>1670</h3>
1640 1671
1641[Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) 返回了 403,它用于授权拒绝而不是过期凭证。通常您进行身份验证的身份缺少 IAM 权限,或模型未为您的项目启用。1672[Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) 返回了 403,该平台使用此状态码表示授权被拒绝,而非凭据过期。通常是您用于身份验证的身份缺少某项 IAM 权限,或者您的项目未启用该模型。
1642 1673
1643中间的操作提示因您的设置而异。稳定部分是前导 `Google Cloud authentication failed`:1674中间的操作提示因您的设置而异。固定不变的部分是开头的 `Google Cloud authentication failed`:
1644 1675
1645```text theme={null}1676```text theme={null}
1646Google Cloud authentication failed · refresh your Google Cloud credentials (application default sign-in, or the key file in GOOGLE_APPLICATION_CREDENTIALS) and retry · if credentials are current, check GCP IAM permissions and Vertex AI model access · API Error: 403 ...1677Google Cloud authentication failed · refresh your Google Cloud credentials (application default sign-in, or the key file in GOOGLE_APPLICATION_CREDENTIALS) and retry · if credentials are current, check GCP IAM permissions and Vertex AI model access · API Error: 403 ...
1647```1678```
1648 1679
1649**应该做什么:**1680**解决方法:**
1650 1681
1651* 如果提示说凭证由此环境管理,启动 Claude Code 的应用拥有凭证,此处的其他步骤不适用:重试或联系您的管理员1682* 如果提示表明凭据由当前环境管理,则凭据归启动 Claude Code 的应用所有,此处的其他步骤不适用:请重试,或联系您的管理员
1652* 确认 [IAM 配置](/docs/zh-CN/google-vertex-ai#iam-configuration) 中的角色已授予您进行身份验证的身份1683* 确认 [IAM 配置](/docs/zh-CN/google-vertex-ai#iam-configuration)中的角色已授予您用于身份验证的身份
1653* 确认模型已为您的项目启用。请参阅 [请求模型访问](/docs/zh-CN/google-vertex-ai#2-request-model-access)1684* 确认您的项目已启用该模型。请参阅[申请模型访问权限](/docs/zh-CN/google-vertex-ai#2-request-model-access)
1654 1685
1655在 v2.1.273 之前,来自 Agent Platform 的 403 显示通用 `Please run /login` 或 `Failed to authenticate` 消息,无法刷新 Google Cloud 凭证。1686在 v2.1.273 之前,来自 Agent Platform 的 403 会改为显示通用的 `Please run /login` 或 `Failed to authenticate` 消息,而这些操作无法刷新 Google Cloud 凭据。
1656 1687
1657<h3 id="microsoft-foundry-authentication-failed">1688<h3 id="microsoft-foundry-authentication-failed">
1658 Microsoft Foundry 身份验证失败1689 Microsoft Foundry authentication failed
1659</h3>1690</h3>
1660 1691
1661[Microsoft Foundry](/docs/zh-CN/microsoft-foundry) 返回了 401 或 403:请求上的 Azure 凭证被拒绝,或其背后的身份无权访问 Foundry 资源。`/login` 无法铸造 Azure 凭证。中间的操作提示因您的设置而异。稳定部分是前导 `Microsoft Foundry authentication failed`:1692[Microsoft Foundry](/docs/zh-CN/microsoft-foundry) 返回了 401 或 403:请求中的 Azure 凭据被拒绝,或者其背后的身份无权访问 Foundry 资源。`/login` 无法生成 Azure 凭据。中间的操作提示因您的设置而异。固定不变的部分是开头的 `Microsoft Foundry authentication failed`:
1662 1693
1663```text theme={null}1694```text theme={null}
1664Microsoft Foundry authentication failed · refresh your Foundry credential (ANTHROPIC_FOUNDRY_AUTH_TOKEN, ANTHROPIC_FOUNDRY_API_KEY, Azure sign-in for Entra, or your proxy token) and retry · if credentials are current, check access to the Foundry resource · API Error: 401 ...1695Microsoft Foundry authentication failed · refresh your Foundry credential (ANTHROPIC_FOUNDRY_AUTH_TOKEN, ANTHROPIC_FOUNDRY_API_KEY, Azure sign-in for Entra, or your proxy token) and retry · if credentials are current, check access to the Foundry resource · API Error: 401 ...
1665```1696```
1666 1697
1667**应该做什么:**1698**解决方法:**
1668 1699
1669* 如果提示说凭证由此环境管理,启动 Claude Code 的应用拥有凭证,此处的其他步骤不适用:重试或联系您的管理员1700* 如果提示表明凭据由当前环境管理,则凭据归启动 Claude Code 的应用所有,此处的其他步骤不适用:请重试,或联系您的管理员
1670* 刷新您在 [配置 Azure 凭证](/docs/zh-CN/microsoft-foundry#2-configure-azure-credentials) 中配置的凭证:轮换 `ANTHROPIC_FOUNDRY_API_KEY`、铸造新的 `ANTHROPIC_FOUNDRY_AUTH_TOKEN` 或运行 `az login` 以便默认 Microsoft Entra 凭证链可以再次登录1701* 刷新您在[配置 Azure 凭据](/docs/zh-CN/microsoft-foundry#2-configure-azure-credentials)中配置的凭据:轮换 `ANTHROPIC_FOUNDRY_API_KEY`、生成新的 `ANTHROPIC_FOUNDRY_AUTH_TOKEN`,或运行 `az login` 以便默认的 Microsoft Entra 凭据链可以重新登录
1671* 如果凭证是最新的,确认身份有权访问 Foundry 资源。请参阅 [Azure RBAC 配置](/docs/zh-CN/microsoft-foundry#azure-rbac-configuration)1702* 如果凭据有效,请确认该身份有权访问 Foundry 资源。请参阅 [Azure RBAC 配置](/docs/zh-CN/microsoft-foundry#azure-rbac-configuration)
1672 1703
1673在 v2.1.273 之前,来自 Microsoft Foundry 的 401 或 403 显示通用 `Please run /login` 或 `Failed to authenticate` 消息,无法刷新 Azure 凭证。1704在 v2.1.273 之前,来自 Microsoft Foundry 的 401 或 403 会改为显示通用的 `Please run /login` 或 `Failed to authenticate` 消息,而这些操作无法刷新 Azure 凭据。
1674 1705
1675<h3 id="could-not-load-aws-or-google-cloud-credentials">1706<h3 id="could-not-load-aws-or-google-cloud-credentials">
1676 无法加载 AWS 或 Google Cloud 凭证1707 Could not load AWS or Google Cloud credentials
1677</h3>1708</h3>
1678 1709
1679Claude Code 无法从 AWS 凭证提供商链或从它运行的机器上的 Google 应用默认凭证获取可用凭证,因此没有请求到达您的云提供商。Claude Code 清除其缓存凭证并在显示此消息之前重试两次。`·` 之后的详细信息命名具体原因,例如过期的 SSO 会话、缺失的应用默认凭证报告为 `Could not load the default credentials` 或被撤销的登录报告为 `invalid_grant`:1710Claude Code 无法在其运行的机器上从 AWS 凭据提供程序链或 Google 应用默认凭据中获取可用的凭据,因此没有请求到达您的云提供商。Claude Code 会清除其缓存的凭据并重试两次,然后才显示此消息。`·` 之后的详细信息会指出具体原因,例如 SSO 会话已过期、缺少应用默认凭据(报告为 `Could not load the default credentials`),或登录已被撤销(报告为 `invalid_grant`):
1680 1711
1681```text theme={null}1712```text theme={null}
1682API Error: Could not load AWS credentials · Could not load credentials from any providers. Check or refresh your AWS credentials and try again.1713API Error: Could not load AWS credentials · Could not load credentials from any providers. Check or refresh your AWS credentials and try again.
1683API Error: Could not load Google Cloud credentials · invalid_grant. Check or refresh your Google Cloud credentials and try again.1714API Error: Could not load Google Cloud credentials · invalid_grant. Check or refresh your Google Cloud credentials and try again.
1684```1715```
1685 1716
1686在 [非交互式模式](/docs/zh-CN/headless) 中使用 `-p` 和在 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,结构化错误代码为 `cloud_credential_error`。在 v2.1.267 之前,消息仅显示 `API Error:` 之后的详细信息文本,结构化代码为 `server_error` 或 `unknown`。1717在使用 `-p` 的[非交互模式](/docs/zh-CN/headless)和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,结构化错误代码为 `cloud_credential_error`。在 v2.1.267 之前,该消息仅显示 `API Error:` 之后的详细文本,结构化代码为 `server_error` 或 `unknown`。
1687 1718
1688**应该做什么:**1719**解决方法:**
1689 1720
1690* 运行您的提供商的登录命令,例如 `aws sso login --profile myprofile` 或 `gcloud auth application-default login`,然后重试。[Bedrock、Agent Platform 或 Foundry 凭证未加载](/docs/zh-CN/troubleshoot-install#bedrock-agent-platform-or-foundry-credentials-not-loading) 显示如何在 Claude Code 外确认凭证1721* 运行您的提供商的登录命令,例如 `aws sso login --profile myprofile` 或 `gcloud auth application-default login`,然后重试。[Bedrock、Agent Platform 或 Foundry 凭据无法加载](/docs/zh-CN/troubleshoot-install#bedrock-agent-platform-or-foundry-credentials-not-loading)介绍了如何在 Claude Code 之外确认凭据
1691* 如果详细信息读作 `AWS default-chain credential resolve timed out`,链挂起而不是失败,因此改为遵循 [AWS default-chain credential resolve timed out](#aws-default-chain-credential-resolve-timed-out)1722* 如果详细信息为 `AWS default-chain credential resolve timed out`,则表示凭据链卡住了而非失败,请改为按照 [AWS default-chain credential resolve timed out](#aws-default-chain-credential-resolve-timed-out) 进行处理
1692 1723
1693<h3 id="aws-default-chain-credential-resolve-timed-out">1724<h3 id="aws-default-chain-credential-resolve-timed-out">
1694 AWS default-chain credential resolve 超时1725 AWS default-chain credential resolve timed out
1695</h3>1726</h3>
1696 1727
1697AWS 默认凭证提供商链在 60 秒内未生成凭证,因此 Claude Code 停止了解析并失败了请求。此超时是 [无法加载 AWS 或 Google Cloud 凭证](#could-not-load-aws-or-google-cloud-credentials) 的一个原因。故障是本地凭证解析:请求从未到达 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock)、[Claude Platform on AWS](/docs/zh-CN/claude-platform-on-aws) 或 [Mantle 端点](/docs/zh-CN/amazon-bedrock#use-the-mantle-endpoint)。Claude Code 在此错误出现之前清除其 [凭证缓存](/docs/zh-CN/amazon-bedrock#credential-caching-and-resolution-timeout) 并重试,因此当您看到它时链已在重复尝试中停滞。1728AWS 默认凭据提供程序链未能在 60 秒内生成凭据,因此 Claude Code 停止了解析并使请求失败。此超时是 [Could not load AWS or Google Cloud credentials](#could-not-load-aws-or-google-cloud-credentials) 的原因之一。失败发生在本地凭据解析阶段:请求从未到达 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock)、[Claude Platform on AWS](/docs/zh-CN/claude-platform-on-aws) 或 [Mantle 端点](/docs/zh-CN/amazon-bedrock#use-the-mantle-endpoint)。Claude Code 会在此错误出现之前清除其[凭据缓存](/docs/zh-CN/amazon-bedrock#credential-caching-and-resolution-timeout)并重试,因此当您看到此错误时,凭据链已在多次尝试中停滞。
1698 1729
1699```text theme={null}1730```text theme={null}
1700API Error: Could not load AWS credentials · AWS default-chain credential resolve timed out. Check or refresh your AWS credentials and try again.1731API Error: Could not load AWS credentials · AWS default-chain credential resolve timed out. Check or refresh your AWS credentials and try again.
1701```1732```
1702 1733
1703常见原因是您的 AWS 配置文件中的 `credential_process` 命令等待它无法接收的输入,以及其实例元数据服务 (IMDS) 从不回答链探针的容器或 VM。1734常见原因包括:AWS 配置文件中的 `credential_process` 命令在等待它无法接收的输入,以及容器或虚拟机的实例元数据服务(IMDS)始终未响应凭据链的探测。
1704 1735
1705在 v2.1.267 之前,消息读作 `API Error: AWS default-chain credential resolve timed out`。1736在 v2.1.267 之前,该消息为 `API Error: AWS default-chain credential resolve timed out`。
1706在 v2.1.207 之前,停滞的链使请求无限期等待而不是失败。1737在 v2.1.207 之前,停滞的凭据链会让请求无限期等待,而不是失败。
1707 1738
1708**应该做什么:**1739**解决方法:**
1709 1740
1710* 在同一 shell 中使用相同的 `AWS_PROFILE` 运行 `aws sts get-caller-identity`。如果它也挂起,修复配置文件;提示交互式的 `credential_process` 命令是常见原因。1741* 在同一 shell 中使用相同的 `AWS_PROFILE` 运行 `aws sts get-caller-identity`。如果它也卡住,请修复该配置文件;以交互方式提示输入的 `credential_process` 命令是常见原因。
1711* 在启动 Claude Code 之前完成登录步骤,例如 `aws sso login --profile myprofile`,以便链从本地 SSO 缓存而不是等待浏览器流解析1742* 在启动 Claude Code 之前完成登录步骤,例如 `aws sso login --profile myprofile`
1712* 如果您的链运行合法需要超过 60 秒的交互式登录,例如通过 `aws-vault` 等包装器的 SSO 与 MFA,使用 [`CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS`](/docs/zh-CN/env-vars) 以毫秒为单位提高限制1743* 如果您的凭据链运行的交互式登录确实需要超过 60 秒,例如通过 `aws-vault` 等包装工具进行带 MFA 的 SSO,请使用 [`CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS`](/docs/zh-CN/env-vars) 以毫秒为单位提高该限制
1713 1744
1714<h3 id="bedrock-setup-verification-timed-out-waiting-for-aws">1745<h3 id="bedrock-setup-verification-timed-out-waiting-for-aws">
1715 Bedrock 设置验证超时等待 AWS1746 Bedrock setup verification timed out waiting for AWS
1716</h3>1747</h3>
1717 1748
1718在 [Bedrock 设置向导](/docs/zh-CN/amazon-bedrock#sign-in-with-bedrock) 的凭证验证期间对 AWS 的调用,例如凭证查找或身份检查,未在 60 秒限制内完成。向导停止等待并失败验证步骤:1749在 [Bedrock 设置向导](/docs/zh-CN/amazon-bedrock#sign-in-with-bedrock)的凭据验证过程中,对 AWS 的某个调用(例如凭据查找或身份检查)未能在 60 秒限制内完成。向导停止等待,并使验证步骤失败:
1719 1750
1720```text theme={null}1751```text theme={null}
1721Timed out after 60s waiting for AWS. Check your network and proxy settings; if a credential helper needs longer to prompt you, raise CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS.1752Timed out after 60s waiting for AWS. Check your network and proxy settings; if a credential helper needs longer to prompt you, raise CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS.
1722```1753```
1723 1754
1724该数字反映您的限制:默认 60 秒,或您在 [`CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS`](/docs/zh-CN/env-vars) 中设置的值。1755其中的数字反映您的限制:默认为 60 秒,或您在 [`CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS`](/docs/zh-CN/env-vars) 中设置的值。
1725 1756
1726常见原因是停滞对 AWS 的请求的网络或代理,包括 SSO 令牌刷新,以及仍在等待您看不到的输入的凭证 helper。仅当 helper 合法需要更多时间时才提高限制。1757常见原因包括:网络或代理使发往 AWS 的请求(包括 SSO 令牌刷新)停滞,以及凭据助手仍在等待您看不到的输入。仅当助手确实需要更多时间时才提高该限制。
1727 1758
1728对 AWS 的单个停滞请求也可能在其自己的每请求超时上失败,这在同一步骤上显示较短的消息:1759发往 AWS 的单个停滞请求也可能因其自身的单次请求超时而失败,此时同一步骤会显示一条较短的消息:
1729 1760
1730```text theme={null}1761```text theme={null}
1731A request to AWS timed out. Check your network and proxy settings, then try again.1762A request to AWS timed out. Check your network and proxy settings, then try again.
1732```1763```
1733 1764
1734当相同的超时在模型固定步骤上发生时,向导将模型标记为 `unreachable` 而不是显示任一消息。1765当相同的超时发生在模型固定步骤时,向导会将模型标记为 `unreachable`,而不显示上述任一消息。
1735 1766
1736**应该做什么:**1767**解决方法:**
1737 1768
1738* 在同一 shell 中运行 `aws sts get-caller-identity`。如果它也挂起,停滞在 Claude Code 外,在您的网络、您的代理或您的 AWS 配置文件中的凭证 helper 中;首先修复它。1769* 在同一 shell 中运行 `aws sts get-caller-identity`。如果它也卡住,则停滞发生在 Claude Code 之外,位于您的网络、代理或 AWS 配置文件中的凭据助手;请先修复该问题。
1739* 在打开向导之前完成任何交互式登录,例如 `aws sso login --profile myprofile`1770* 在打开向导之前完成所有交互式登录,例如 `aws sso login --profile myprofile`
1740* 如果您的 AWS 配置文件中的凭证 helper 合法需要超过 60 秒来提示您,使用 [`CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS`](/docs/zh-CN/env-vars) 以毫秒为单位提高限制1771* 如果 AWS 配置文件中的凭据助手确实需要超过 60 秒来提示您,请使用 [`CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS`](/docs/zh-CN/env-vars) 以毫秒为单位提高该限制
1741 1772
1742<h3 id="cloud-gateway-session-expired">1773<h3 id="cloud-gateway-session-expired">
1743 Cloud gateway 会话已过期1774 Cloud gateway session expired
1744</h3>1775</h3>
1745 1776
1746您通过 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway) 登录,此机器上保存的网关会话已过期且无法更新,或网关不再接受它,例如在网关的 [JWT 密钥被替换](/docs/zh-CN/claude-apps-gateway-deploy#jwt-secret-rotation) 后。如果您在交互式启动 `claude` 时看到此行,会话已打开且未登录网关:1777您通过 [Claude apps 网关](/docs/zh-CN/claude-apps-gateway)登录,而保存在此机器上的网关会话已过期且无法续期,或者网关不再接受该会话,例如在网关的 [JWT 密钥被替换](/docs/zh-CN/claude-apps-gateway-deploy#jwt-secret-rotation)之后。如果您在以交互方式启动 `claude` 时看到这行消息,则表示会话已以未登录网关的状态打开:
1747 1778
1748```text theme={null}1779```text theme={null}
1749Cloud gateway session expired — run /login to reconnect.1780Cloud gateway session expired — run /login to reconnect.
1750```1781```
1751 1782
1752相同的行可能在会话中期出现,当网关凭证过期且 Claude Code 无法更新它时。1783当网关凭据过期且 Claude Code 无法续期时,同一行消息也可能在会话中途出现。
1753 1784
1754在 [非交互式](/docs/zh-CN/headless) 运行、后台或其他无人值守会话或 `claude` 子命令(除 `claude auth` 外)中,Claude Code 改为在网关不再接受会话时以此消息退出:1785在[非交互](/docs/zh-CN/headless)运行、后台或其他无人值守会话,或除 `claude auth` 以外的 `claude` 子命令中,当网关不再接受该会话时,Claude Code 会改为显示以下消息并退出:
1755 1786
1756```text theme={null}1787```text theme={null}
1757Cloud gateway <url> no longer accepts this session. Start `claude` and sign in again with /login.1788Cloud gateway <url> no longer accepts this session. Start `claude` and sign in again with /login.
1758```1789```
1759 1790
1760**应该做什么:**1791**解决方法:**
1761 1792
1762* 在会话中运行 `/login` 并完成浏览器登录1793* 在会话中运行 `/login` 并完成浏览器登录
1763* 对于非交互式启动,在同一环境中启动 `claude`,运行 `/login`,然后重新运行您的命令1794* 对于非交互式启动,请在同一环境中启动 `claude`,运行 `/login`,然后重新运行您的命令
1764 1795
1765<h3 id="sign-in-timed-out-while-waiting-for-you-to-continue">1796<h3 id="sign-in-timed-out-while-waiting-for-you-to-continue">
1766 登录超时,等待您继续1797 Sign-in timed out while waiting for you to continue
1767</h3>1798</h3>
1768 1799
1769在 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway) 登录期间,网关命名了登录的账户,Claude Code 要求您在保存凭证之前确认它。您将确认保持打开状态超过登录自己的过期,网关未颁发可更新它的刷新令牌,因此当您继续时 Claude Code 未存储任何内容:1800在 [Claude apps 网关](/docs/zh-CN/claude-apps-gateway)登录过程中,网关给出了已登录的账户,Claude Code 在保存凭据之前请您确认该账户。您让确认界面保持打开的时间超过了该次登录自身的有效期,且网关未签发可用于续期的刷新令牌,因此当您继续时,Claude Code 未存储任何内容:
1770 1801
1771```text theme={null}1802```text theme={null}
1772Sign-in timed out while waiting for you to continue. Try again.1803Sign-in timed out while waiting for you to continue. Try again.
1773```1804```
1774 1805
1775**应该做什么:**1806**解决方法:**
1776 1807
1777* 再次运行 `/login` 并在登录过期之前确认账户1808* 再次运行 `/login`,并在登录过期之前确认账户
1778 1809
1779<h3 id="gateway-refused-the-request">1810<h3 id="gateway-refused-the-request">
1780 Gateway 拒绝了请求1811 Gateway refused the request
1781</h3>1812</h3>
1782 1813
1783您通过 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway) 登录,请求返回了 403:网关或其背后的上游拒绝了它。再次登录不会改变拒绝,因此消息指向您的网关管理员:1814您通过 [Claude apps 网关](/docs/zh-CN/claude-apps-gateway)登录,而某个请求返回了 403:网关或其背后的上游拒绝了该请求。重新登录不会改变拒绝结果,因此消息会提示您联系网关管理员:
1784 1815
1785```text theme={null}1816```text theme={null}
1786Gateway refused the request · signing in again won't change this — check with your gateway administrator · API Error: 403 ...1817Gateway refused the request · signing in again won't change this — check with your gateway administrator · API Error: 403 ...
1787```1818```
1788 1819
1789**应该做什么:**1820**解决方法:**
1790 1821
1791* 要求您的网关管理员查找请求。`API Error:` 尾部携带网关返回的拒绝1822* 请您的网关管理员查询该请求。`API Error:` 之后的部分包含网关返回的拒绝信息
1792* 对于管理员:网关上的 [访问控制规则](/docs/zh-CN/claude-apps-gateway-config#http-tuning) 返回 403,[审计日志](/docs/zh-CN/claude-apps-gateway-deploy#logs) 记录其原因,上游的授权拒绝按 [上游错误消息](/docs/zh-CN/claude-apps-gateway-config#upstream-error-messages) 传递1823* 对于管理员:网关上的[访问控制规则](/docs/zh-CN/claude-apps-gateway-config#http-tuning)会返回 403,[审计日志](/docs/zh-CN/claude-apps-gateway-deploy#logs)会记录该 403 及其原因;上游的授权拒绝会按照[上游错误消息](/docs/zh-CN/claude-apps-gateway-config#upstream-error-messages)中的说明透传
1793 1824
1794在 v2.1.273 之前,网关会话上的 403 显示通用 `Please run /login` 或 `Failed to authenticate` 消息,再次登录不会清除拒绝。1825在 v2.1.273 之前,网关会话上的 403 会改为显示通用的 `Please run /login` 或 `Failed to authenticate` 消息,且重新登录无法消除该拒绝。
1795 1826
1796<h2 id="network-and-connection-errors">1827<h2 id="network-and-connection-errors">
1797 网络和连接错误1828 网络和连接错误
2317API Error: 400 ... Extra inputs are not permitted ... context_management2348API Error: 400 ... Extra inputs are not permitted ... context_management
2318```2349```
2319 2350
2320Claude Code 发送 `context_management` 和 `effort` 等仅限测试版的字段,以及启用它们的 `anthropic-beta` 头。当网关转发正文但删除头时,API 会看到它不识别的字段。2351Claude Code 发送 `context_management` 等仅限测试版的字段,以及启用它们的 `anthropic-beta` 头。当网关转发正文但删除头时,API 会看到它不识别的字段。
2321 2352
2322**要做什么:**2353**要做什么:**
2323 2354
2852 命令行错误2883 命令行错误
2853</h2>2884</h2>
2854 2885
2855这些错误来自 `claude` 命令行及其子命令、您在提示符处提交的命令名称,以及诸如 `/security-review` 之类的命令,这些命令在运行其提示之前通过运行 shell 命令来收集上下文。它们也来自 `/tui`,它会重新启动 CLI。2886这些错误来自 `claude` 命令行及其子命令、您在提示符处提交的命令名称,以及 `/security-review` 等在其提示词运行前通过执行 shell 命令收集上下文的命令。它们也可能来自会重新启动 CLI 的 `/tui`。
2856 2887
2857<h3 id="conflict-between-bg-and-print">2888<h3 id="conflict-between-bg-and-print">
2858 `--bg` 和 `--print` 之间的冲突2889 `--bg` 与 `--print` 冲突
2859</h3>2890</h3>
2860 2891
2861此消息需要 Claude Code v2.1.198 或更高版本。您在同一个 `claude` 调用中将 `--bg` 与 `-p` 或 `--print` 结合使用。`--bg` 启动一个[后台会话](/docs/zh-CN/agent-view#from-your-shell),您稍后可以使用 `claude agents` 附加到该会话,而 `--print` 以[非交互方式](/docs/zh-CN/headless)运行,永远不会启动 `claude agents` 附加到的交互会话。在 v2.1.198 之前,此组合会以静默方式创建一个永远无法附加的后台作业。2892此消息需要 Claude Code v2.1.198 或更高版本。您在同一次 `claude` 调用中将 `--bg` 与 `-p` 或 `--print` 组合使用。`--bg` 会启动一个[后台会话](/docs/zh-CN/agent-view#from-your-shell),之后您可以通过 `claude agents` 连接到该会话;而 `--print` 以[非交互方式](/docs/zh-CN/headless)运行,永远不会启动 `claude agents` 所连接的交互式会话。在 v2.1.198 之前,这种组合会静默创建一个永远无法连接的后台任务。
2862 2893
2863```text theme={null}2894```text theme={null}
2864--bg and --print conflict: --print never starts the interactive session that `claude agents` attaches to, so the job would be unattachable. The prompt is the positional — drop --print: `claude --bg '<task>'`.2895--bg and --print conflict: --print never starts the interactive session that `claude agents` attaches to, so the job would be unattachable. The prompt is the positional — drop --print: `claude --bg '<task>'`.
2865```2896```
2866 2897
2867**应该做什么:**2898**解决方法:**
2868 2899
2869* 删除 `-p` 或 `--print`。`--bg` 将提示作为其位置参数,所以 `claude --bg "<task>"` 是完整的命令。请参阅[从您的 shell 分派新代理](/docs/zh-CN/agent-view#from-your-shell)。2900* 去掉 `-p` 或 `--print`。`--bg` 将提示词作为其位置参数,因此 `claude --bg "<task>"` 就是完整的命令。请参阅[从 shell 分派新的 Agent](/docs/zh-CN/agent-view#from-your-shell)。
2870* 要以非交互方式运行提示并打印结果而不是创建后台会话,请删除 `--bg` 并运行 `claude -p "<task>"`2901* 若要以非交互方式运行提示词并打印结果,而不是创建后台会话,请去掉 `--bg` 并运行 `claude -p "<task>"`
2902
2903<h3 id="conflict-between-a-system-prompt-flag-and-its-file-form">
2904 系统提示词标志与其文件形式冲突
2905</h3>
2906
2907您在一次 `claude` 调用中同时传入了 [`--append-subagent-system-prompt`](/docs/zh-CN/cli-reference#cli-flags) 和 `--append-subagent-system-prompt-file`,因此 `claude` 以退出码 1 退出,而不会启动会话:
2908
2909```text theme={null}
2910Error: Cannot use both --append-subagent-system-prompt and --append-subagent-system-prompt-file. Please use only one.
2911```
2912
2913在 v2.1.283 之前,当您将 `--system-prompt` 与 `--system-prompt-file` 一起传入,或将 `--append-system-prompt` 与 `--append-system-prompt-file` 一起传入时,`claude` 也会以同样的方式退出,因为这些标志对会相互冲突,而不是[组合使用](/docs/zh-CN/cli-reference#system-prompt-flags)。在这些版本上,消息会指出您组合使用的那对标志。
2914
2915**解决方法:**
2916
2917* 保留该标志的一种形式,去掉另一种。若要将固定的提示词文件与每次运行的文本组合,请在启动前将文本合并到文件中,而不是同时传入两个标志
2871 2918
2872<h3 id="invalid-agents-configuration">2919<h3 id="invalid-agents-configuration">
2873 无效的 `--agents` 配置2920 无效的 `--agents` 配置
2874</h3>2921</h3>
2875 2922
2876您传递给 `--agents` 的值无效,所以 `claude` 以代码 1 退出,而不是启动会话。当您传递 `--safe-mode` 或设置 [`CLAUDE_CODE_SAFE_MODE`](/docs/zh-CN/env-vars#variables) 时,Claude Code 会完全忽略 `--agents`。使用 `--resume` 或 `--continue` 时,不会检查内联 JSON 值,会话会启动;从文件读取的值在每次启动时都会被检查。在 v2.1.242 之前,Claude Code 无论如何都会启动会话。2923您传给 `--agents` 的值无效,因此 `claude` 以退出码 1 退出,而不会启动会话。当您传入 `--safe-mode` 或设置 [`CLAUDE_CODE_SAFE_MODE`](/docs/zh-CN/env-vars#variables) 时,Claude Code 会完全忽略 `--agents`。使用 `--resume` 或 `--continue` 时,内联 JSON 值不会被检查,会话会启动;从文件读取的值在每次启动时都会被检查。在 v2.1.242 之前,Claude Code 仍会启动会话。
2877 2924
2878```text theme={null}2925```text theme={null}
2879Error: Invalid --agents configuration:2926Error: Invalid --agents configuration:
2880<what failed>2927<what failed>
2881```2928```
2882 2929
2883第一行之后的内容取决于值如何失败。Claude Code 按顺序运行这些检查,并在第一个失败的检查处停止。如果您的值有两种问题,您只有在修复第一个问题后才会看到第二个问题:2930第一行之后的内容取决于该值失败的方式。Claude Code 按顺序执行以下检查,并在第一个失败的检查处停止。如果您的值存在两类问题,只有在修复第一类之后才会看到第二类:
2884 2931
28851. 当值以 `{` 开头但不能解析为 JSON,或 `--agents` 文件的内容不能解析时,Claude Code 会打印一行 `invalid JSON:`,其中包含 JSON 解析器自己的消息29321. 当值以 `{` 开头但无法解析为 JSON,或 `--agents` 文件的内容无法解析时,Claude Code 会打印一行 `invalid JSON:`,其中包含 JSON 解析器自身的消息
28862. 当它解析但代理定义与 [CLI 定义的子代理](/docs/zh-CN/sub-agents#choose-the-subagent-scope)的架构不匹配时,Claude Code 会为每个问题打印一行29332. 当值可以解析,但某个 Agent 定义与 [CLI 定义的子代理](/docs/zh-CN/sub-agents#choose-the-subagent-scope)的 schema 不匹配时,Claude Code 会为每个问题打印一行
28873. 当代理名称以 `-` 开头时,Claude Code 会打印 `<name>: agent names must not start with '-'`29343. 当 Agent 名称以 `-` 开头时,Claude Code 会打印 `<name>: agent names must not start with '-'`
2888 2935
2889当有超过 20 行问题时,Claude Code 会打印前 20 行,并用 `…and N more` 替换其余部分。2936当问题行超过 20 行时,Claude Code 会打印前 20 行,并将其余部分替换为 `…and N more`。
2890 2937
2891使用 `--print` 时,`--agents` 也接受 [JSON 文件的路径](/docs/zh-CN/sub-agents#choose-the-subagent-scope)代替内联对象。在 v2.1.281 之前,`--agents` 仅接受内联 JSON,并将文件路径视为无效 JSON。文件形式有其自己的拒绝,打印在此消息的位置,包括这些:2938使用 `--print` 时,`--agents` 还接受 [JSON 文件的路径](/docs/zh-CN/sub-agents#choose-the-subagent-scope)来代替内联对象。在 v2.1.281 之前,`--agents` 只接受内联 JSON,并将文件路径视为无效 JSON。文件形式有其自身的拒绝情况,会打印在此消息的位置,包括以下几种:
2892 2939
2893* **`Error: --agents takes a JSON object, or a file path only with --print (-p)`**:Claude Code 在交互会话中将值读取为文件路径。将定义作为内联 JSON 传递,或添加 `-p` 从文件读取它们。2940* **`Error: --agents takes a JSON object, or a file path only with --print (-p)`**:Claude Code 在交互式会话中将该值读取为文件路径。请以内联 JSON 形式传入定义,或添加 `-p` 以从文件中读取。
2894* **`Error: --agents file not found: <path>`**:该路径不存在任何文件。不以 `{` 开头且不是有效 JSON 的值被读取为路径,所以您的 shell 损坏的内联 JSON 也可能以这种方式失败。检查路径或引号,然后再次运行命令。2941* **`Error: --agents file not found: <path>`**:该路径下不存在文件。不以 `{` 开头且不是有效 JSON 的值会被读取为路径,因此被 shell 破坏的内联 JSON 也可能以这种方式失败。请检查路径或引号,然后重新运行命令。
2895 2942
2896**应该做什么:**2943**解决方法:**
2897 2944
2898* 修复消息列出的每个问题,然后再次运行命令。请参阅 [CLI 定义的子代理采用的字段](/docs/zh-CN/sub-agents#choose-the-subagent-scope)。2945* 修复消息列出的每个问题,然后重新运行命令。请参阅 [CLI 定义的子代理可接受的字段](/docs/zh-CN/sub-agents#choose-the-subagent-scope)。
2899 2946
2900<h3 id="cloud-sessions-cannot-be-created-from-a-restricted-session">2947<h3 id="cloud-sessions-cannot-be-created-from-a-restricted-session">
2901 无法从 `--restricted` 会话创建云会话2948 无法从 `--restricted` 会话创建云端会话
2902</h3>2949</h3>
2903 2950
2904当您使用 [`--restricted`](/docs/zh-CN/cli-reference#cli-flags) 启动会话时,Claude Code 拒绝从中创建[云会话](/docs/zh-CN/claude-code-on-the-web#from-terminal-to-cloud),因为新会话将在受限进程之外运行,不会强制执行受限模式。Claude Code 在客户端拒绝,在联系服务器之前,所以不会创建云会话:2951当您使用 [`--restricted`](/docs/zh-CN/cli-reference#cli-flags) 启动会话时,Claude Code 会拒绝从该会话创建[云端会话](/docs/zh-CN/claude-code-on-the-web#from-terminal-to-cloud),因为新会话将在受限进程之外运行,不会强制执行受限模式。Claude Code 在客户端、联系服务器之前就会拒绝,因此不会创建云端会话:
2905 2952
2906```text theme={null}2953```text theme={null}
2907Cloud sessions cannot be created from a --restricted session: they would not enforce it.2954Cloud sessions cannot be created from a --restricted session: they would not enforce it.
2908```2955```
2909 2956
2910**应该做什么:**2957**解决方法:**
2911 2958
2912* 在受限会话中本地运行任务2959* 在受限会话中本地运行该任务
2913* 如果您控制会话的启动方式,请启动一个没有 `--restricted` 的新 `claude` 会话,并从那里创建云会话2960* 如果您能控制会话的启动方式,请启动一个不带 `--restricted` 的新 `claude` 会话,并从那里创建云端会话
2914 2961
2915在 v2.1.248 之前,Claude Code 没有 `--restricted` 标志;较早的版本会以未知选项错误拒绝该标志本身。2962在 v2.1.248 之前,Claude Code 没有 `--restricted` 标志;较早的版本会以未知选项错误拒绝该标志本身。
2916 2963
2917<h3 id="cloud-sessions-are-disabled-by-your-organizations-policy">2964<h3 id="cloud-sessions-are-disabled-by-your-organizations-policy">
2918 您的组织的策略禁用了云会话2965 云端会话已被您组织的策略禁用
2919</h3>2966</h3>
2920 2967
2921您的组织的 `allow_remote_sessions` 策略已关闭,所以[云会话](/docs/zh-CN/claude-code-on-the-web)和使用它们的命令不可用:2968您组织的 `allow_remote_sessions` 策略处于关闭状态,因此[云端会话](/docs/zh-CN/claude-code-on-the-web)以及使用云端会话的命令不可用:
2922 2969
2923```text theme={null}2970```text theme={null}
2924Cloud sessions are disabled by your organization's policy. Contact your organization admin to enable them.2971Cloud sessions are disabled by your organization's policy. Contact your organization admin to enable them.
2925```2972```
2926 2973
2927当您[从终端创建云会话](/docs/zh-CN/claude-code-on-the-web#from-terminal-to-cloud)时,消息会出现,当您提交需要云会话的命令时,例如 `/teleport`、`/remote-env` 或 `/web-setup`。在 v2.1.268 之前,提交其中一个命令会返回[`Unknown command`](#unknown-command)。2974当您[从终端创建云端会话](/docs/zh-CN/claude-code-on-the-web#from-terminal-to-cloud)时,以及当您提交需要云端会话的命令(例如 `/teleport`、`/remote-env` 或 `/web-setup`)时,会出现此消息。在 v2.1.268 之前,提交这些命令之一会返回 [`Unknown command`](#unknown-command)。
2928 2975
2929这是一个服务器端组织策略,所以它不能从本地设置、环境变量或 CLI 标志中被覆盖。2976这是服务器端的组织策略,因此无法通过本地设置、环境变量或 CLI 标志覆盖。
2930 2977
2931如果 Claude Code 还没有加载您的组织策略或无法获取它,这些命令会回答 `Couldn't verify your organization's policy for cloud sessions. Check your network connection, then restart Claude Code and try again.`。2978如果 Claude Code 尚未加载您组织的策略或无法获取该策略,这些命令会改为回复 `Couldn't verify your organization's policy for cloud sessions. Check your network connection, then restart Claude Code and try again.`。
2932 2979
2933**应该做什么:**2980**解决方法:**
2934 2981
2935* 请您的组织中的[所有者](/docs/zh-CN/server-managed-settings#access-control)在 [claude.ai/admin-settings/claude-code](https://claude.ai/admin-settings/claude-code) 的 Claude Code 管理员设置中启用云会话2982* 请您组织中的 [Owner](/docs/zh-CN/server-managed-settings#access-control) 在 [claude.ai/admin-settings/claude-code](https://claude.ai/admin-settings/claude-code) 的 Claude Code 管理设置中启用云端会话
2936* 如果消息说它无法验证策略,请检查您的网络连接,然后重新启动 Claude Code 并重试2983* 如果消息显示无法验证策略,请检查网络连接,然后重启 Claude Code 并重试
2937 2984
2938<h3 id="the-json-schema-value-is-not-a-valid-json-schema">2985<h3 id="the-json-schema-value-is-not-a-valid-json-schema">
2939 `--json-schema` 值不是有效的 JSON Schema2986 `--json-schema` 的值不是有效的 JSON Schema
2940</h3>2987</h3>
2941 2988
2942您传递给 [`--json-schema`](/docs/zh-CN/cli-reference#cli-flags) 的架构在[非交互模式](/docs/zh-CN/headless#get-structured-output)中失败了 JSON Schema 编译,所以 `claude` 以代码 1 退出,而不是运行提示。在 v2.1.205 之前,无效的架构会产生无结构的输出,没有错误,任何使用 `format` 关键字的架构都被视为无效。2989您在[非交互模式](/docs/zh-CN/headless#get-structured-output)下传给 [`--json-schema`](/docs/zh-CN/cli-reference#cli-flags) 的 schema 未能通过 JSON Schema 编译,因此 `claude` 以退出码 1 退出,而不会运行提示词。在 v2.1.205 之前,无效的 schema 会在没有错误的情况下产生非结构化输出,并且任何使用 `format` 关键字的 schema 都会被视为无效。
2943 2990
2944```text theme={null}2991```text theme={null}
2945Error: --json-schema is not a valid JSON Schema: data/type must be equal to one of the allowed values2992Error: --json-schema is not a valid JSON Schema: data/type must be equal to one of the allowed values
2946```2993```
2947 2994
2948第二个冒号后的文本是验证器的诊断,并命名失败的关键字或位置。使用 `format` 关键字的架构,例如 `"format": "email"`,是有效的:Claude Code 接受 `format` 作为注释,不强制执行它。2995第二个冒号之后的文本是验证器的诊断信息,指出了失败的关键字或位置。使用 `format` 关键字的 schema(例如 `"format": "email"`)是有效的:Claude Code 将 `format` 作为注解接受,但不会强制执行它。
2949 2996
2950Claude Code 在架构编译之前运行两个检查:它拒绝不可解析的 JSON 值,显示 `Error: --json-schema is not valid JSON`,以及不是对象的有效 JSON,显示 `Error: --json-schema must be a JSON object`。2997Claude Code 在 schema 编译之前会执行两项检查:对于无法解析为 JSON 的值,它会以 `Error: --json-schema is not valid JSON` 拒绝;对于不是对象的有效 JSON,它会以 `Error: --json-schema must be a JSON object` 拒绝。
2951 2998
2952**应该做什么:**2999**解决方法:**
2953 3000
2954* 修复诊断命名的架构部分,然后重新运行命令3001* 修复诊断信息所指出的 schema 部分,然后重新运行命令
2955* 请参阅[获取结构化输出](/docs/zh-CN/headless#get-structured-output)以获取工作架构和命令3002* 请参阅[获取结构化输出](/docs/zh-CN/headless#get-structured-output),了解可用的 schema 和命令
2956 3003
2957<h3 id="settings-file-exceeds-the-2mib-limit">3004<h3 id="settings-file-exceeds-the-2mib-limit">
2958 设置文件超过 2MiB 限制3005 设置文件超过 2MiB 限制
2959</h3>3006</h3>
2960 3007
2961您传递给 [`--settings`](/docs/zh-CN/cli-reference#cli-flags) 的文件大于 2 MiB,所以 `claude` 在启动时以代码 1 退出,而不是加载它。在 v2.1.214 之前,Claude Code 读取文件时没有大小检查,多 GB 文件或诸如 `/dev/zero` 之类的设备文件会无限增长内存。3008您传给 [`--settings`](/docs/zh-CN/cli-reference#cli-flags) 的文件大于 2 MiB,因此 `claude` 在启动时以退出码 1 退出,而不会加载该文件。在 v2.1.214 之前,Claude Code 读取该文件时不做大小检查,数 GB 大小的文件或 `/dev/zero` 之类的设备文件会导致内存无限增长。
2962 3009
2963```text theme={null}3010```text theme={null}
2964Error: Settings file exceeds the 2MiB limit: /path/to/settings.json3011Error: Settings file exceeds the 2MiB limit: /path/to/settings.json
2965```3012```
2966 3013
2967Claude Code 以相同的方式拒绝不是常规文件的 `--settings` 路径:设备、FIFO 或套接字报告 `Error: Cannot use settings file (Not a regular file (device, FIFO, or socket))`,后跟路径,目录报告 `EISDIR` 原因。3014对于不是常规文件的 `--settings` 路径,Claude Code 也会以同样的方式拒绝:设备、FIFO 或套接字会报告 `Error: Cannot use settings file (Not a regular file (device, FIFO, or socket))` 并附上路径,目录则会报告 `EISDIR` 原因。
2968 3015
2969**应该做什么:**3016**解决方法:**
2970 3017
2971* 将 `--settings` 指向 2 MiB 以下的常规 JSON 设置文件。请参阅[设置](/docs/zh-CN/settings)了解格式。3018* 将 `--settings` 指向一个小于 2 MiB 的常规 JSON 设置文件。有关格式,请参阅[设置](/docs/zh-CN/settings)。
2972 3019
2973<h3 id="the-current-directory-no-longer-exists">3020<h3 id="the-current-directory-no-longer-exists">
2974 当前目录不再存在3021 当前目录已不存在
2975</h3>3022</h3>
2976 3023
2977您从一个在您的 shell 进入后被删除或移动的目录启动了 `claude`,例如另一个 shell 删除的 worktree 或临时目录。Claude Code 无法读取其工作目录,所以它在启动会话之前以代码 1 退出,在交互和[非交互](/docs/zh-CN/headless)模式中都是如此。在 v2.1.239 之前,Claude Code 会因缩小的捆绑源和原始 `ENOENT ... uv_cwd` 堆栈在 stderr 上崩溃,而不是显示此消息。3024您从一个在 shell 进入后已被删除或移动的目录启动了 `claude`,例如被另一个 shell 删除的 worktree 或临时目录。Claude Code 无法读取其工作目录,因此在启动会话之前以退出码 1 退出,交互模式和[非交互](/docs/zh-CN/headless)模式均是如此。在 v2.1.239 之前,Claude Code 会崩溃,并在 stderr 上输出压缩后的打包源代码和原始的 `ENOENT ... uv_cwd` 堆栈,而不是显示此消息。
2978 3025
2979```text theme={null}3026```text theme={null}
2980The current directory no longer exists (it was deleted or moved). Start Claude Code from an existing directory.3027The current directory no longer exists (it was deleted or moved). Start Claude Code from an existing directory.
2981error: The current working directory was deleted, so that command didn't work. Please cd into a different directory and try again.3028error: The current working directory was deleted, so that command didn't work. Please cd into a different directory and try again.
2982```3029```
2983 3030
2984两种形式的原因和修复是相同的。3031这两种形式的原因和修复方法相同。
2985 3032
2986当 Claude Code 因其他原因(例如权限更改)无法读取工作目录时,消息会命名错误代码:`Can't read the current directory (EACCES). Start Claude Code from a different directory.`3033当 Claude Code 因其他原因(例如权限变更)无法读取工作目录时,消息会改为指出错误代码:`Can't read the current directory (EACCES). Start Claude Code from a different directory.`
2987 3034
2988在 macOS 上,`~/Desktop`、`~/Documents`、`~/Downloads` 或 iCloud Drive 中目录的 `EPERM` 通常意味着 macOS 阻止您的终端应用访问该文件夹。读取该文件夹的其他命令也会以相同的方式失败:即使使用 `sudo`,`ls` 也会报告 `Operation not permitted`。3035在 macOS 上,对于 `~/Desktop`、`~/Documents`、`~/Downloads` 或 iCloud Drive 中目录出现的 `EPERM`,通常意味着 macOS 阻止了您的终端应用访问该文件夹。读取该文件夹的其他命令也会以同样方式失败:在那里运行 `ls` 会报告 `Operation not permitted`,即使使用 `sudo` 也是如此。
2989 3036
2990**应该做什么:**3037**解决方法:**
2991 3038
2992* 更改为存在的目录,例如您的主目录或项目目录,然后再次运行 `claude`3039* 切换到一个存在的目录,例如您的主目录或项目目录,然后再次运行 `claude`
2993* 如果目录在同一路径被重新创建,您的 shell 仍然持有已删除的目录。运行 `cd "$PWD"` 或离开并重新进入目录,然后再次运行 `claude`3040* 如果该目录已在相同路径下重新创建,您的 shell 仍持有已删除的那个目录。请运行 `cd "$PWD"` 或离开后重新进入该目录,然后再次运行 `claude`
2994* 对于 macOS 上的 `EPERM`,使用 Cmd+Q 退出您的终端应用,重新打开它,返回该文件夹,然后运行 `claude`。如果该文件夹中的 `ls` 仍然失败,请打开**系统设置 > 隐私和安全 > 文件和文件夹**,为您的终端应用打开该文件夹,然后重新打开终端3041* 对于 macOS 上的 `EPERM`,请使用 Cmd+Q 退出终端应用,重新打开,返回该文件夹并运行 `claude`。如果在该文件夹中 `ls` 仍然失败,请打开 **System Settings > Privacy & Security > Files and Folders**,为您的终端应用启用该文件夹,然后重新打开终端
2995 3042
2996<h3 id="temp-directory-refused-or-cannot-be-created">3043<h3 id="temp-directory-refused-or-cannot-be-created">
2997 临时目录被拒绝或无法创建3044 临时目录被拒绝或无法创建
2998</h3>3045</h3>
2999 3046
3000在 macOS 和 Linux 上,Claude Code 在启动时创建一个私有临时目录 `claude-<uid>`,位于系统临时目录或 [`CLAUDE_CODE_TMPDIR`](/docs/zh-CN/env-vars) 覆盖下。当目录无法创建,或该路径处的现有条目未通过安全检查时,Claude Code 将失败打印到 stderr 并以代码 1 退出,而不是启动会话:3047在 macOS 和 Linux 上,Claude Code 在启动时会在系统临时目录或 [`CLAUDE_CODE_TMPDIR`](/docs/zh-CN/env-vars) 覆盖的位置下创建一个私有临时目录 `claude-<uid>`。当该目录无法创建,或该路径下已存在的条目未通过安全检查时,Claude Code 会将失败信息打印到 stderr 并以退出码 1 退出,而不会启动会话:
3001 3048
3002```text wrap theme={null}3049```text wrap theme={null}
3003ENOSPC: no space left on device, mkdir '/tmp/claude-501'3050ENOSPC: no space left on device, mkdir '/tmp/claude-501'
3009Temp directory /tmp/claude-501 is not readable (its mode may have been altered, or a path component denies search). Refusing to use it — restore its permissions (chmod 0700) or remove it. Set CLAUDE_CODE_TMPDIR to a directory you control, or ask an administrator to remove it.3056Temp directory /tmp/claude-501 is not readable (its mode may have been altered, or a path component denies search). Refusing to use it — restore its permissions (chmod 0700) or remove it. Set CLAUDE_CODE_TMPDIR to a directory you control, or ask an administrator to remove it.
3010```3057```
3011 3058
3012**应该做什么:**3059**解决方法:**
3013 3060
3014* 对于 `ENOSPC`,释放保存临时目录的卷上的磁盘空间3061* 对于 `ENOSPC`,请释放临时目录所在卷的磁盘空间
3015* 对于 `Refusing to use it` 形式,删除命名的条目本身,而不是链接指向的内容,然后再次启动 Claude Code;对于 `owned by uid` 形式,只有管理员或该用户可以删除它3062* 对于 `Refusing to use it` 形式,请删除所指出的条目本身(而不是链接指向的目标),然后再次启动 Claude Code;对于 `owned by uid` 形式,只有管理员或该用户才能删除它
3016* 对于 `is not readable`,在命名目录上运行 `chmod 0700`,或删除它并重新启动3063* 对于 `is not readable`,请对所指出的目录运行 `chmod 0700`,或将其删除后重新启动
3017* 在任何这些情况下,将 [`CLAUDE_CODE_TMPDIR`](/docs/zh-CN/env-vars) 设置为您控制的目录并启动 Claude Code,保留被拒绝的路径不变3064* 在上述任何情况下,都可以将 [`CLAUDE_CODE_TMPDIR`](/docs/zh-CN/env-vars) 设置为您控制的目录,然后再次启动 Claude Code,而不去处理被拒绝的路径
3018 3065
3019<h3 id="directory-couldnt-be-resolved-to-a-real-location">3066<h3 id="directory-couldnt-be-resolved-to-a-real-location">
3020 目录无法解析为真实位置3067 目录无法解析为真实位置
3021</h3>3068</h3>
3022 3069
3023您为工作目录的子目录运行了 `/add-dir`,Claude Code 无法将目录解析为其真实位置。3070您对工作目录的某个子目录运行了 `/add-dir`,而 Claude Code 无法将该目录解析为其真实位置。
3024 3071
3025您已经可以访问工作目录的子目录,所以 `/add-dir` 只加载其 skills、命令和代理。在加载它们之前,Claude Code 检查目录的真实位置(解析任何符号链接)是否在工作目录内。当 Claude Code 无法解析该位置时,它不加载任何内容并显示此消息:3072您已经拥有工作目录子目录的文件访问权限,因此 `/add-dir` 只会加载其中的 skill、命令和 Agent。在加载之前,Claude Code 会检查该目录的真实位置(解析所有符号链接后)是否位于工作目录内。当 Claude Code 无法解析该位置时,它不会加载任何内容,并显示以下消息:
3026 3073
3027```text theme={null}3074```text theme={null}
3028packages/app couldn't be resolved to a real location, so its skills, commands, and agents weren't loaded. Check that it is a directory inside the working directory and try again.3075packages/app couldn't be resolved to a real location, so its skills, commands, and agents weren't loaded. Check that it is a directory inside the working directory and try again.
3029```3076```
3030 3077
3031**应该做什么:**3078**解决方法:**
3032 3079
3033* 检查路径是否命名工作目录内的真实目录,然后再次运行 `/add-dir`3080* 检查该路径是否指向工作目录内的真实目录,然后再次运行 `/add-dir`
3034* 消息不会改变您的文件访问权限;它只报告目录的 `.claude/` 内容未被加载3081* 此消息不会改变您的文件访问权限;它只是报告该目录的 `.claude/` 内容未被加载
3035 3082
3036在 v2.1.261 之前,当工作目录在 `/net/<host>` 自动挂载上时,此消息也会为每个 `/add-dir <subdirectory>` 出现,Claude Code 按设计拒绝解析路径;目录很好,重试无法帮助。3083在 v2.1.261 之前,当工作目录位于 `/net/<host>` 自动挂载点上时,每次执行 `/add-dir <subdirectory>` 也会出现此消息,因为 Claude Code 按设计不会解析这类路径;目录本身没有问题,重试也无济于事。
3037 3084
3038<h3 id="workspace-not-trusted-when-starting-remote-control">3085<h3 id="workspace-not-trusted-when-starting-remote-control">
3039 启动远程控制时工作区不受信任3086 启动 Remote Control 时工作区不受信任
3040</h3>3087</h3>
3041 3088
3042您在未信任的目录中使用 `claude remote-control` 或其 `claude rc` 别名启动了[远程控制](/docs/zh-CN/remote-control)服务器模式,命令无法询问您是否信任它。例如,命令的标准输入或标准输出不是终端,因为其中一个被重定向或管道化。命令以代码 1 退出:3089您在尚未信任的目录中使用 `claude remote-control` 或其别名 `claude rc` 启动了 [Remote Control](/docs/zh-CN/remote-control) 服务器模式,而该命令无法询问您是否信任该目录。例如,命令的标准输入或标准输出不是终端,因为其中之一被重定向或通过管道传输。该命令以退出码 1 退出:
3043 3090
3044```text theme={null}3091```text theme={null}
3045Error: Workspace not trusted. Please run `claude` in /Users/you/project first to review and accept the workspace trust dialog.3092Error: Workspace not trusted. Please run `claude` in /Users/you/project first to review and accept the workspace trust dialog.
3046```3093```
3047 3094
3048两个也以 `Error: Workspace not trusted.` 开头的变体也出现在足够小的终端中,无法显示信任目录会打开什么,或一个没有报告其大小的终端。放大窗口或切换到正常终端窗口,然后再次运行 `claude rc`。3095另外两种同样以 `Error: Workspace not trusted.` 开头的变体会出现在以下终端中:终端太小,无法显示信任该目录会启用的内容,或者终端未报告其尺寸。请放大窗口或切换到普通终端窗口,然后再次运行 `claude rc`。
3049 3096
3050在您的主目录中,消息是不同的,因为工作区信任对话永远不会为主目录保存信任,所以在那里接受它无法满足此检查。在 v2.1.214 之前,主目录显示上面的消息,其建议在那里无法成功。3097在您的主目录中,消息会有所不同,因为工作区信任对话框永远不会为主目录保存信任,所以在主目录中接受信任无法满足此检查。在 v2.1.214 之前,主目录会显示上述消息,而其中的建议在主目录中无法奏效。
3051 3098
3052```text theme={null}3099```text theme={null}
3053Error: Workspace not trusted. /Users/you is your home directory, and for security home-directory trust is never saved, so running `claude` here first won't help. Run `claude rc` from a project directory instead (run `claude` there once to accept the trust dialog).3100Error: Workspace not trusted. /Users/you is your home directory, and for security home-directory trust is never saved, so running `claude` here first won't help. Run `claude rc` from a project directory instead (run `claude` there once to accept the trust dialog).
3054```3101```
3055 3102
3056如果您在 [`Trust <directory>?` 问题](/docs/zh-CN/remote-control#requirements)处回答 `n` 或按 Enter,命令会打印一条 `Remote Control did not start` 消息,命名目录并以代码 1 退出。再次运行 `claude rc` 以回答 `y`。3103如果您在 [`Trust <directory>?` 问题](/docs/zh-CN/remote-control#requirements)处回答 `n` 或按 Enter,该命令会打印一条指出该目录的 `Remote Control did not start` 消息,并以退出码 1 退出。再次运行 `claude rc` 并回答 `y` 即可。
3057 3104
3058**应该做什么:**3105**解决方法:**
3059 3106
3060* 首先从终端信任目录:在那里运行 `claude rc` 并回答 `y`,或运行 `claude` 并接受[工作区信任对话](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust),然后再次运行您的原始命令3107* 先从终端信任该目录:在该目录中运行 `claude rc` 并回答 `y`,或在该目录中运行 `claude` 并接受[工作区信任对话框](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust),然后再次运行原来的命令
3061* 在您的主目录中,更改为项目目录并在那里启动远程控制3108* 如果在主目录中,请切换到项目目录并在那里启动 Remote Control
3062 3109
3063在 v2.1.284 之前,命令从不询问,即使在终端中也是如此。3110在 v2.1.284 之前,即使在终端中,该命令也从不询问。
3064 3111
3065<h3 id="not-carried-over-to-the-sessions-remote-control-starts">3112<h3 id="not-carried-over-to-the-sessions-remote-control-starts">
3066 未被远程控制启动的会话继承3113 不会传递到 Remote Control 启动的会话
3067</h3>3114</h3>
3068 3115
3069您使用全局 `claude` 标志在 `remote-control` 动词之前启动了[远程控制](/docs/zh-CN/remote-control),该标志会限制或配置远程控制启动的会话,例如 `--settings`、`--setting-sources`、`--permission-mode`、`--disallowed-tools` 或 `--mcp-config`。放在动词之前的标志永远不会到达这些会话。Claude Code 拒绝启动,命名标志:3116您在 `remote-control` 动词之前使用了一个全局 `claude` 标志来启动 [Remote Control](/docs/zh-CN/remote-control),该标志会限制或配置 Remote Control 启动的会话,例如 `--settings`、`--setting-sources`、`--permission-mode`、`--disallowed-tools` 或 `--mcp-config`。放在动词之前的标志永远不会到达这些会话。Claude Code 会拒绝启动,并指出该标志:
3070 3117
3071```text theme={null}3118```text theme={null}
3072Error: `--settings` before `remote-control` is not carried over to the sessions Remote Control starts, so Remote Control refuses to start rather than drop it — remove it, and give Remote Control's own options after the verb (see `claude remote-control --help`).3119Error: `--settings` before `remote-control` is not carried over to the sessions Remote Control starts, so Remote Control refuses to start rather than drop it — remove it, and give Remote Control's own options after the verb (see `claude remote-control --help`).
3073```3120```
3074 3121
3075Claude Code 不拒绝无害的全局标志,例如 `--verbose`、`--model` 或包装器注入的 `--session-id` 或 `--plugin-dir`:它忽略它们,远程控制启动。3122对于丢弃后无害的全局标志,例如 `--verbose`、`--model`,或由包装器注入的 `--session-id` 或 `--plugin-dir`,Claude Code 不会拒绝:它会忽略这些标志,Remote Control 照常启动。
3076 3123
3077Claude Code 也拒绝启动一个它还不认识为无害的全局标志,所以较新版本中添加的标志可能会出现在此消息中,直到稍后的版本将其标记为无害。3124对于尚未被识别为无害的全局标志,Claude Code 也会拒绝启动,因此在较新版本中新增的标志可能会出现在此消息中,直到后续版本将其标记为无害。
3078 3125
3079**应该做什么:**3126**解决方法:**
3080 3127
3081* 从动词之前删除标志,并在其后传递[远程控制自己的选项](/docs/zh-CN/remote-control#start-a-remote-control-session);`claude remote-control --help` 列出它们3128* 移除动词之前的标志,并在动词之后传入 [Remote Control 自身的选项](/docs/zh-CN/remote-control#start-a-remote-control-session);`claude remote-control --help` 会列出这些选项
3082* 当被拒绝的标志是 `--permission-mode` 时,运行 `claude remote-control --permission-mode <mode>` 为远程控制启动的会话设置权限模式3129* 当被拒绝的标志是 `--permission-mode` 时,请运行 `claude remote-control --permission-mode <mode>` 来设置 Remote Control 启动的会话的权限模式
3083 3130
3084在 v2.1.248 之前,当全局标志首先出现时,`claude remote-control` 不接受其自己的标志,命令失败并显示未知选项错误。3131在 v2.1.248 之前,当全局标志位于前面时,`claude remote-control` 不接受其自身的标志,命令会以 `unknown option` 错误失败。
3085 3132
3086<h3 id="claude-import-is-not-yet-available-in-this-build">3133<h3 id="claude-import-is-not-yet-available-in-this-build">
3087 claude import 在此构建中尚不可用3134 此构建版本中尚不可用 claude import
3088</h3>3135</h3>
3089 3136
3090您运行了 [`claude import`](/docs/zh-CN/cli-reference#cli-commands),Claude Code 发现导入流已关闭,所以命令以代码 1 退出,而不是启动导入。在 v2.1.222 之前,关闭导入流的构建将 `import` 视为提示并启动交互会话,而不是打印此消息。3137您运行了 [`claude import`](/docs/zh-CN/cli-reference#cli-commands),而 Claude Code 发现导入流程处于关闭状态,因此该命令以退出码 1 退出,而不会开始导入。在 v2.1.222 之前,关闭了导入流程的构建版本会将 `import` 视为提示词并启动交互式会话,而不是打印此消息。
3091 3138
3092```text theme={null}3139```text theme={null}
3093`claude import` is not yet available in this build. Run `claude` and use /mcp or edit ~/.claude/settings.json directly.3140`claude import` is not yet available in this build. Run `claude` and use /mcp or edit ~/.claude/settings.json directly.
3094```3141```
3095 3142
3096Claude Code 通过从 Anthropic 获取并在磁盘上缓存的功能标志打开 `claude import`。此消息意味着缓存的值已关闭。原因通常是以下之一:3143Claude Code 通过从 Anthropic 获取并缓存到磁盘上的功能标志来启用 `claude import`。此消息表示缓存的值为关闭。原因通常是以下之一:
3097 3144
3098* 您自安装以来还没有启动会话,所以 Claude Code 还没有获取标志。第一个 `claude import` 即使功能对您可用,也可能打印此消息。3145* 安装后您尚未启动过会话,因此 Claude Code 还没有获取该标志。即使该功能对您可用,第一次运行 `claude import` 也可能打印此消息。
3099* 您通过 Amazon Bedrock、Google Cloud 的 Agent Platform、Microsoft Foundry 或 AWS 上的 Claude Platform,或通过[Claude 应用网关](/docs/zh-CN/claude-apps-gateway#availability-and-limitations)使用 Claude Code。Claude Code 在这些会话中不获取功能标志,所以 `claude import` 保持不可用。3146* 您通过 Amazon Bedrock、Google Cloud's Agent Platform、Microsoft Foundry 或 Claude Platform on AWS 使用 Claude Code,或者通过 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway#availability-and-limitations) 使用。Claude Code 在这些会话中不会获取功能标志,因此 `claude import` 保持不可用。
3100* 您设置了 `DISABLE_TELEMETRY`、`DO_NOT_TRACK`、`DISABLE_GROWTHBOOK` 或 [`CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`](/docs/zh-CN/env-vars),它们关闭功能标志获取,所以 `claude import` 保持不可用。3147* 您设置了 `DISABLE_TELEMETRY`、`DO_NOT_TRACK`、`DISABLE_GROWTHBOOK` 或 [`CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`](/docs/zh-CN/env-vars),这些设置会关闭功能标志的获取,因此 `claude import` 保持不可用。
3101 3148
3102**应该做什么:**3149**解决方法:**
3103 3150
3104* 在新安装上,启动 `claude`,等待会话加载,退出,然后再次运行 `claude import`3151* 在全新安装中,启动 `claude`,等待会话加载完成后退出,然后再次运行 `claude import`
3105* 在功能标志获取保持关闭的地方,自己设置配置:使用 [`claude mcp add`](/docs/zh-CN/mcp#installing-mcp-servers) 添加 MCP 服务器,并创建您想要继承的 [`CLAUDE.md` 文件](/docs/zh-CN/memory#how-claude-md-files-load)、[skills 和命令](/docs/zh-CN/skills#where-skills-live)以及[子代理](/docs/zh-CN/sub-agents#choose-the-subagent-scope)。消息也命名 `~/.claude/settings.json`。在 `claude import` 继承的配置中,该文件仅保存[权限模式](/docs/zh-CN/settings-reference#permission-settings);Claude Code 不从中读取 MCP 服务器。3152* 在功能标志获取保持关闭的情况下,请自行完成配置:使用 [`claude mcp add`](/docs/zh-CN/mcp#installing-mcp-servers) 添加 MCP 服务器,并创建您想要迁移的 [`CLAUDE.md` 文件](/docs/zh-CN/memory#how-claude-md-files-load)、[skill 和命令](/docs/zh-CN/skills#where-skills-live)以及[子代理](/docs/zh-CN/sub-agents#choose-the-subagent-scope)。消息中还提到了 `~/.claude/settings.json`。在 `claude import` 所迁移的配置中,该文件只保存[权限模式](/docs/zh-CN/settings-reference#permission-settings);Claude Code 不会从中读取 MCP 服务器。
3106 3153
3107<h3 id="could-not-read-claude-code-config">3154<h3 id="could-not-read-claude-code-config">
3108 无法读取 Claude Code 配置3155 无法读取 Claude Code 配置
3109</h3>3156</h3>
3110 3157
3111您在 Claude Code 无法解析 `~/.claude.json` 时运行了 [`claude import`](/docs/zh-CN/cli-reference#cli-commands),这是它存储您的登录和每个项目状态的文件。子命令读取该文件以检查可用性,但不显示交互会话显示的恢复对话,所以它以代码 1 退出。在 v2.1.222 之前,`claude import` 使用不可读的配置文件启动交互会话,其恢复对话处理该文件。3158您运行了 [`claude import`](/docs/zh-CN/cli-reference#cli-commands),而 Claude Code 无法解析 `~/.claude.json`,即它存储您的登录信息和各项目状态的文件。该子命令会读取该文件以检查可用性,但不会显示交互式会话所显示的恢复对话框,因此以退出码 1 退出。在 v2.1.222 之前,在配置文件无法读取的情况下运行 `claude import` 会启动交互式会话,由其恢复对话框处理该文件。
3112 3159
3113```text theme={null}3160```text theme={null}
3114Could not read Claude Code config — run `claude` with no arguments to recover it.3161Could not read Claude Code config — run `claude` with no arguments to recover it.
3115```3162```
3116 3163
3117**应该做什么:**3164**解决方法:**
3118 3165
3119* 运行不带参数的 `claude`。Claude Code 检测无效文件并提供重置它。然后再次运行 `claude import`。3166* 不带参数运行 `claude`。Claude Code 会检测到无效文件并提供重置选项。然后再次运行 `claude import`。
3120* 要保留您所做的手动编辑,请在编辑器中修复 `~/.claude.json` 中的 JSON 语法,然后重新运行 `claude import`3167* 若要保留您手动所做的编辑,请改为在编辑器中修复 `~/.claude.json` 中的 JSON 语法,然后重新运行 `claude import`
3121 3168
3122<h3 id="could-not-import-a-server-from-claude-desktop">3169<h3 id="could-not-import-a-server-from-claude-desktop">
3123 无法从 Claude Desktop 导入服务器3170 无法从 Claude Desktop 导入服务器
3124</h3>3171</h3>
3125 3172
3126Claude Code 无法添加您在 `claude mcp add-from-claude-desktop` 中选择的其中一个服务器。命令仍然导入其他选定的服务器,并为每个无法添加的服务器打印一行。在 v2.1.205 之前,第一个失败的服务器停止了导入。3173Claude Code 无法添加您在 `claude mcp add-from-claude-desktop` 中选择的某个服务器。该命令仍会导入其他选中的服务器,并为每个无法添加的服务器打印一行。在 v2.1.205 之前,第一个失败的服务器会中止整个导入。
3127 3174
3128```text theme={null}3175```text theme={null}
3129Could not import my server: Invalid name my server. Names can only contain letters, numbers, hyphens, and underscores.3176Could not import my server: Invalid name my server. Names can only contain letters, numbers, hyphens, and underscores.
3130```3177```
3131 3178
3132服务器名称后的文本是原因。最常见的是名称检查:Claude Desktop 允许服务器名称中的字符,例如空格和句号,而 `claude mcp` 限制为字母、数字、连字符和下划线。其他原因包括失败验证的服务器配置和被您的组织的 [MCP 策略](/docs/zh-CN/managed-mcp)阻止的服务器。3179服务器名称之后的文本是原因。最常见的是名称检查:Claude Desktop 允许服务器名称中包含空格和句点等字符,而 `claude mcp` 将其限制为字母、数字、连字符和下划线。其他原因包括服务器配置未通过验证,以及服务器被您组织的 [MCP 策略](/docs/zh-CN/managed-mcp)阻止。
3133 3180
3134**应该做什么:**3181**解决方法:**
3135 3182
3136* 在 `claude_desktop_config.json` 中重命名服务器以仅使用字母、数字、连字符和下划线,然后再次运行 `claude mcp add-from-claude-desktop`3183* 在 `claude_desktop_config.json` 中将服务器重命名为仅包含字母、数字、连字符和下划线的名称,然后再次运行 `claude mcp add-from-claude-desktop`
3137* 使用 `claude mcp add` 或 `claude mcp add-json` 在有效名称下直接添加该服务器。请参阅[从 Claude Desktop 导入 MCP 服务器](/docs/zh-CN/mcp#import-mcp-servers-from-claude-desktop)。3184* 使用有效名称通过 `claude mcp add` 或 `claude mcp add-json` 直接添加该服务器。请参阅[从 Claude Desktop 导入 MCP 服务器](/docs/zh-CN/mcp#import-mcp-servers-from-claude-desktop)。
3138 3185
3139<h3 id="cannot-add-mcp-server-to-the-managed-scope">3186<h3 id="cannot-add-mcp-server-to-the-managed-scope">
3140 无法将 MCP 服务器添加到托管范围3187 无法将 MCP 服务器添加到 managed 作用域
3141</h3>3188</h3>
3142 3189
3143您使用 `--scope managed` 运行了 `claude mcp add` 或 `claude mcp add-json`。该范围保存您的组织通过 [`managedMcpServers`](/docs/zh-CN/settings-reference#managedmcpservers) 托管设置提供的服务器。Claude Code 仅从托管设置读取它们,所以命令无法向该范围写入服务器。3190您使用 `--scope managed` 运行了 `claude mcp add` 或 `claude mcp add-json`。该作用域保存的是您的组织通过 [`managedMcpServers`](/docs/zh-CN/settings-reference#managedmcpservers) 托管设置提供的服务器。Claude Code 只从托管设置中读取这些服务器,因此该命令无法将服务器写入该作用域。
3144 3191
3145```text theme={null}3192```text theme={null}
3146Cannot add MCP server to scope: managed3193Cannot add MCP server to scope: managed
3147```3194```
3148 3195
3149**应该做什么:**3196**解决方法:**
3197
3198* 将服务器添加到您可以写入的作用域:`local`、`user` 或 `project`。不带 `--scope` 时,该命令使用 `local`。请参阅 [MCP 安装作用域](/docs/zh-CN/mcp#mcp-installation-scopes)
3199* 若要将服务器提供给组织中的每个用户,请将其添加到您部署的托管设置中的 [`managedMcpServers`](/docs/zh-CN/settings-reference#managedmcpservers)
3200
3201<h3 id="cannot-add-mcp-server-when-managed-settings-allow-only-plugin-servers">
3202 托管设置仅允许插件服务器时无法添加 MCP 服务器
3203</h3>
3150 3204
3151* 将服务器添加到您可以写入的范围:`local`、`user` 或 `project`。不带 `--scope` 时,命令使用 `local`。请参阅 [MCP 安装范围](/docs/zh-CN/mcp#mcp-installation-scopes)3205您运行了 `claude mcp add` 或 `claude mcp add-json`,而您组织的托管设置将 [`strictPluginOnlyCustomization`](/docs/zh-CN/settings-reference#strictpluginonlycustomization) 设置为 `true` 或包含 `mcp` 的列表。在该设置下,Claude Code 不会从 `~/.claude.json` 或 `.mcp.json` 加载 MCP 服务器,因此该命令以退出码 1 退出,而不会保存一个永远不会加载的服务器:
3152* 要为您的组织中的每个用户提供服务器,请将其添加到您部署的托管设置中的 [`managedMcpServers`](/docs/zh-CN/settings-reference#managedmcpservers)3206
3207```text theme={null}
3208Cannot add MCP server: your organization's managed settings allow only MCP servers that plugins provide. Install a plugin that provides this server, or ask your administrator to make it available.
3209```
3210
3211`claude mcp add-from-claude-desktop` 会将您选择的每个服务器报告为未导入,原因即为此消息。[`/import`](/docs/zh-CN/commands#all-commands) 会针对它尝试添加的每个 MCP 服务器报告此消息,但仍会导入它找到的其他项目。
3212
3213在 v2.1.284 之前,这些命令会保存服务器并报告成功,但服务器永远不会加载。
3214
3215**解决方法:**
3216
3217* 安装提供该服务器的[插件](/docs/zh-CN/plugins/install)
3218* 请管理员通过[插件](/docs/zh-CN/plugins/org)分发该服务器,或者如果它是远程 HTTP 或 SSE 服务器,则通过 [`managedMcpServers`](/docs/zh-CN/settings-reference#managedmcpservers) 提供它
3153 3219
3154<h3 id="cant-read-mcp-json">3220<h3 id="cant-read-mcp-json">
3155 无法读取 .mcp.json3221 无法读取 .mcp.json
3156</h3>3222</h3>
3157 3223
3158读取项目的 [`.mcp.json`](/docs/zh-CN/mcp#project-scope) 的命令,例如 `claude mcp add` 或 `claude mcp add-json` 使用 `--scope project`,或 `claude mcp remove`,发现您当前目录中的文件不是常规文件或大于 2 MiB,所以它以此错误退出,而不是读取文件。3224读取项目 [`.mcp.json`](/docs/zh-CN/mcp#project-scope) 的命令(例如带 `--scope project` 的 `claude mcp add` 或 `claude mcp add-json`,或 `claude mcp remove`)发现当前目录中的该文件不是常规文件或大于 2 MiB,因此以此错误退出,而不会读取该文件。
3159 3225
3160```text theme={null}3226```text theme={null}
3161Can't read .mcp.json: it isn't a regular file or is larger than 2097152 bytes. Fix or remove it, then run the command again.3227Can't read .mcp.json: it isn't a regular file or is larger than 2097152 bytes. Fix or remove it, then run the command again.
3162```3228```
3163 3229
3164在 v2.1.257 之前,`.mcp.json` 处的 FIFO 使命令永远等待,没有输出,指向诸如 `/dev/zero` 之类的设备文件的符号链接会增长内存,直到进程被杀死。3230在 v2.1.257 之前,位于 `.mcp.json` 的 FIFO 会使命令无限等待且没有任何输出,而指向 `/dev/zero` 之类设备文件的符号链接会使内存不断增长,直到进程被终止。
3165 3231
3166**应该做什么:**3232**解决方法:**
3167 3233
3168* 检查您当前目录中 `.mcp.json` 处的内容。将其替换为 [project-scope 格式](/docs/zh-CN/mcp#project-scope)中的普通 JSON 文件,或删除它,然后再次运行命令。3234* 检查当前目录中 `.mcp.json` 是什么。将其替换为采用[项目作用域格式](/docs/zh-CN/mcp#project-scope)的普通 JSON 文件,或将其删除,然后再次运行命令。
3169 3235
3170<h3 id="mcp-server-was-not-saved-or-removed">3236<h3 id="mcp-server-was-not-saved-or-removed">
3171 MCP 服务器未被保存或删除3237 MCP 服务器未被保存或移除
3172</h3>3238</h3>
3173 3239
3174您为 `user` 或 `local` [范围](/docs/zh-CN/mcp#mcp-installation-scopes)中的服务器运行了 `claude mcp add`、`claude mcp add-json` 或 `claude mcp remove`。两个范围都存储在 `~/.claude.json` 中,当 Claude Code 在写入后读取该文件时,更改不在该文件中。命令以此错误退出,而不是其成功行。3240您针对 `user` 或 `local` [作用域](/docs/zh-CN/mcp#mcp-installation-scopes)中的服务器运行了 `claude mcp add`、`claude mcp add-json` 或 `claude mcp remove`。这两个作用域都存储在 `~/.claude.json` 中,而 Claude Code 在写入后重新读取该文件时,发现其中没有该更改。该命令以此错误退出,而不是输出成功信息。
3175 3241
3176```text theme={null}3242```text theme={null}
3177MCP server "example" was not saved to /home/user/.claude.json. If that file is read-only or protected by a sandbox, make it writable or run the command outside the sandbox, then add the server again.3243MCP server "example" was not saved to /home/user/.claude.json. If that file is read-only or protected by a sandbox, make it writable or run the command outside the sandbox, then add the server again.
3178```3244```
3179 3245
3180删除后,消息读取 `was not removed from` 并以 `then remove the server again` 结尾。对于 `local` 范围服务器,路径后跟项目目录条目所属的,如 `(local scope for /path/to/project)`。3246执行移除操作后,消息会显示为 `was not removed from`,并以 `then remove the server again` 结尾。对于 `local` 作用域的服务器,路径后会附上该条目所属的项目目录,形式为 `(local scope for /path/to/project)`。
3181 3247
3182在 v2.1.283 之前,`claude mcp add`、`claude mcp add-json` 和 `claude mcp remove` 即使更改没有到达文件也报告成功。3248在 v2.1.283 之前,即使更改未写入文件,`claude mcp add`、`claude mcp add-json` 和 `claude mcp remove` 也会报告成功。
3183 3249
3184**应该做什么:**3250**解决方法:**
3185 3251
3186* 使消息命名的文件可写,或在沙箱外运行命令,然后再次运行相同的添加或删除命令。3252* 使消息中指出的文件可写,或在沙箱之外运行命令,然后再次运行相同的添加或移除命令。
3187 3253
3188<h3 id="mcp-server-may-not-have-been-saved-or-removed">3254<h3 id="mcp-server-may-not-have-been-saved-or-removed">
3189 MCP 服务器可能未被保存或删除3255 MCP 服务器可能未被保存或移除
3190</h3>3256</h3>
3191 3257
3192您为 `user` 或 `local` [范围](/docs/zh-CN/mcp#mcp-installation-scopes)中的服务器运行了 `claude mcp add`、`claude mcp add-json` 或 `claude mcp remove`,Claude Code 无法读取 `~/.claude.json` 回来确认更改。更改可能在磁盘上,也可能不在。括号中的文本是该读取的错误。3258您针对 `user` 或 `local` [作用域](/docs/zh-CN/mcp#mcp-installation-scopes)中的服务器运行了 `claude mcp add`、`claude mcp add-json` 或 `claude mcp remove`,而 Claude Code 无法重新读取 `~/.claude.json` 来确认更改。该更改可能已写入磁盘,也可能没有。括号中的文本是该次读取的错误。
3193 3259
3194```text theme={null}3260```text theme={null}
3195MCP server "example" may not have been saved: /home/user/.claude.json could not be read to confirm the change (EACCES: permission denied, open '/home/user/.claude.json'). Run `claude mcp get example` to check, then add the server again if it is missing.3261MCP server "example" may not have been saved: /home/user/.claude.json could not be read to confirm the change (EACCES: permission denied, open '/home/user/.claude.json'). Run `claude mcp get example` to check, then add the server again if it is missing.
3196```3262```
3197 3263
3198删除后,消息读取 `may not have been removed` 并以 `then remove the server again if it is still listed` 结尾。3264执行移除操作后,消息会显示为 `may not have been removed`,并以 `then remove the server again if it is still listed` 结尾。
3199 3265
3200在 v2.1.283 之前,命令即使更改无法确认也报告成功。3266在 v2.1.283 之前,即使无法确认更改,这些命令也会报告成功。
3201 3267
3202**应该做什么:**3268**解决方法:**
3203 3269
3204* 运行 `claude mcp get <name>` 检查更改是否在磁盘上。对于 `local` 范围服务器,从服务器所属的项目目录运行它,因为本地范围是每个项目的。3270* 运行 `claude mcp get <name>` 检查更改是否已写入磁盘。对于 `local` 作用域的服务器,请从该服务器所属的项目目录中运行,因为本地作用域是按项目划分的。
3205* 如果服务器在添加后丢失,或在删除后仍然列出,请再次运行相同的添加或删除命令。3271* 如果添加后服务器不存在,或移除后服务器仍被列出,请再次运行相同的添加或移除命令。
3206 3272
3207<h3 id="anthropic-hosted-and-doesnt-support-local-oauth">3273<h3 id="anthropic-hosted-and-doesnt-support-local-oauth">
3208 服务器是 Anthropic 托管的,不支持本地 OAuth3274 服务器由 Anthropic 托管,不支持本地 OAuth
3209</h3>3275</h3>
3210 3276
3211您为 MCP 服务器启动了登录,其 URL 指向通过第三方身份提供商进行身份验证的 Anthropic 托管连接器主机。这些主机包括 `microsoft365.mcp.claude.com`、`gmail.mcp.claude.com` 和 `gcal.mcp.claude.com`。Claude Code 拒绝为这些主机从 `/mcp` 面板和 `claude mcp login` 启动其本地 OAuth 流,因为[它们的登录仅通过 claude.ai 工作](/docs/zh-CN/mcp#use-mcp-servers-from-claude-ai)。3277您为某个 MCP 服务器发起了登录,而该服务器的 URL 指向通过第三方身份提供商进行身份验证的 Anthropic 托管连接器主机。这些主机包括 `microsoft365.mcp.claude.com`、`gmail.mcp.claude.com` 和 `gcal.mcp.claude.com`。无论是从 `/mcp` 面板还是 `claude mcp login`,Claude Code 都会拒绝为这些主机启动本地 OAuth 流程,因为[它们的登录只能通过 claude.ai 完成](/docs/zh-CN/mcp#use-mcp-servers-from-claude-ai)。
3212 3278
3213```text theme={null}3279```text theme={null}
3214"gmail" is Anthropic-hosted and doesn't support local OAuth. Connect it via Settings → Connectors on claude.ai (requires `claude login`), then it'll be available here automatically.3280"gmail" is Anthropic-hosted and doesn't support local OAuth. Connect it via Settings → Connectors on claude.ai (requires `claude login`), then it'll be available here automatically.
3215```3281```
3216 3282
3217**应该做什么:**3283**解决方法:**
3218 3284
3219* 使用 `claude mcp remove <name>` 删除您的条目,以便它不能隐藏同一 URL 处的 claude.ai 连接器3285* 使用 `claude mcp remove <name>` 移除您的条目,以免它遮蔽同一 URL 上的 claude.ai 连接器
3220* 删除后,在 [claude.ai/customize/connectors](https://claude.ai/customize/connectors) 连接服务,同时登录到您在 Claude Code 中使用的帐户。连接后,如果您的活跃身份验证方法是 claude.ai 订阅登录,[连接器会自动出现在 Claude Code 中](/docs/zh-CN/mcp#use-mcp-servers-from-claude-ai)3286* 移除之后,在登录您在 Claude Code 中使用的账户的情况下,在 [claude.ai/customize/connectors](https://claude.ai/customize/connectors) 连接该服务。连接后,如果您当前的身份验证方式是 claude.ai 订阅登录,[该连接器会自动出现在 Claude Code 中](/docs/zh-CN/mcp#use-mcp-servers-from-claude-ai)
3221 3287
3222<h3 id="server-rejected-the-authorization-header-minted-by-the-configured-headershelper">3288<h3 id="server-rejected-the-authorization-header-minted-by-the-configured-headershelper">
3223 服务器拒绝了由配置的 headersHelper 生成的 Authorization 标头3289 服务器拒绝了所配置 headersHelper 生成的 Authorization 标头
3224</h3>3290</h3>
3225 3291
3226其 [`headersHelper`](/docs/zh-CN/mcp#use-dynamic-headers-for-custom-authentication) 提供 `Authorization` 标头的 MCP 服务器以 HTTP 401 或 403 回答连接,所以 Claude Code 将连接报告为失败。因为助手提供 `Authorization` 标头,Claude Code [不会回退到 OAuth](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers) 对于服务器:3292某个由 [`headersHelper`](/docs/zh-CN/mcp#use-dynamic-headers-for-custom-authentication) 提供 `Authorization` 标头的 MCP 服务器以 HTTP 401 或 403 响应了连接,因此 Claude Code 报告连接失败。由于该 helper 提供了 `Authorization` 标头,Claude Code 对该服务器[不会回退到 OAuth](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers):
3227 3293
3228```text theme={null}3294```text theme={null}
3229Server rejected the Authorization header minted by the configured headersHelper (HTTP 401). Check that the helper command returns a valid credential for this MCP endpoint — OAuth fallback is disabled when the helper supplies Authorization.3295Server rejected the Authorization header minted by the configured headersHelper (HTTP 401). Check that the helper command returns a valid credential for this MCP endpoint — OAuth fallback is disabled when the helper supplies Authorization.
3230```3296```
3231 3297
3232Claude Code 在每次连接尝试时重新运行助手,所以在短暂拒绝后重试,例如令牌轮换竞争,可以使用新凭证成功。3298Claude Code 在每次连接尝试时都会重新运行该 helper,因此在暂时性拒绝(例如令牌轮换竞争)之后重试,可能会凭借新的凭据成功。
3233 3299
3234**应该做什么:**3300**解决方法:**
3235 3301
3236* 按照 Claude Code 运行它的方式自己运行 `headersHelper` 命令:从 [Claude Code 运行它的目录](/docs/zh-CN/mcp#where-the-helper-runs),使用 [Claude Code 为其设置的环境变量](/docs/zh-CN/mcp#use-dynamic-headers-for-custom-authentication),以及不使用 [Claude Code 为来自项目 `.mcp.json`、插件或项目代理文件的服务器删除的凭证变量](/docs/zh-CN/mcp#which-variables-a-helper-can-read)。检查它是否打印服务器端点接受的 `Authorization` 值3302* 按照 Claude Code 运行它的方式自行运行 `headersHelper` 命令:在 [Claude Code 运行它的目录](/docs/zh-CN/mcp#where-the-helper-runs)中运行,使用 [Claude Code 为它设置的环境变量](/docs/zh-CN/mcp#use-dynamic-headers-for-custom-authentication),并且对于来自项目 `.mcp.json`、插件或项目 Agent 文件的服务器,不带有 [Claude Code 移除的凭据变量](/docs/zh-CN/mcp#which-variables-a-helper-can-read)。检查它是否输出了服务器端点所接受的 `Authorization` 值
3237* 修复助手或其凭证源后,在 `/mcp` 中选择服务器并选择**重新连接**3303* 修复 helper 或其凭据来源后,在 `/mcp` 中选择该服务器并选择 **Reconnect**
3238 3304
3239在 v2.1.248 之前,Claude Code 为其助手提供 `Authorization` 标头的服务器运行 OAuth 发现。该发现可能失败,显示 `Incompatible auth server: does not support dynamic client registration` 而不是报告被拒绝的凭证。3305在 v2.1.248 之前,对于由 helper 提供 `Authorization` 标头的服务器,Claude Code 会运行 OAuth 发现。该发现可能会以 `Incompatible auth server: does not support dynamic client registration` 失败,而不是报告被拒绝的凭据。
3240 3306
3241<h3 id="mcp-permission-prompt-tool-not-found">3307<h3 id="mcp-permission-prompt-tool-not-found">
3242 未找到 MCP 权限提示工具3308 未找到 MCP 权限提示工具
3243</h3>3309</h3>
3244 3310
3245您传递给 [`--permission-prompt-tool`](/docs/zh-CN/cli-reference#cli-flags) 的工具在运行首次需要权限决定时不在连接的 MCP 工具中,要么因为其服务器从未连接,要么因为没有连接的服务器公开该名称的工具。Claude Code 仍然发送您的提示:[非交互](/docs/zh-CN/headless)运行在第一个工具调用时以此错误和退出代码 1 退出,所以即使请求已发出,它也不会产生答案。在第一个提示之前,Claude Code 等待最多由 [`MCP_TIMEOUT`](/docs/zh-CN/env-vars) 设置的每个服务器连接超时 30 秒,以便该服务器连接。在 v2.1.206 之前,启动不等待服务器完成连接,所以启动缓慢但健康的服务器也会产生此错误。3311当运行首次需要权限决策时,您传给 [`--permission-prompt-tool`](/docs/zh-CN/cli-reference#cli-flags) 的工具不在已连接的 MCP 工具之中,原因可能是其服务器从未连接,或者没有已连接的服务器公开该名称的工具。Claude Code 仍会发送您的提示词:[非交互](/docs/zh-CN/headless)运行会在第一次工具调用时以此错误和退出码 1 退出,因此即使请求已经发出,也不会产生回答。在第一个提示词之前,Claude Code 会等待该服务器连接,最长等待时间为 [`MCP_TIMEOUT`](/docs/zh-CN/env-vars) 设置的每服务器连接超时时间 30 秒。在 v2.1.206 之前,启动时不会等待服务器完成连接,因此启动较慢但运行正常的服务器也会产生此错误。
3246 3312
3247```text theme={null}3313```text theme={null}
3248Error: MCP tool mcp__permissions__approve (passed via --permission-prompt-tool) not found. Available MCP tools: none3314Error: MCP tool mcp__permissions__approve (passed via --permission-prompt-tool) not found. Available MCP tools: none
3249```3315```
3250 3316
3251`Available MCP tools:` 后的列表命名已连接的 MCP 工具。3317`Available MCP tools:` 之后的列表列出了已连接的 MCP 工具。
3252 3318
3253**应该做什么:**3319**解决方法:**
3254 3320
3255* 检查服务器启动并保持连接:在同一目录中运行 `claude mcp list` 并确认服务器列为已连接3321* 检查服务器是否能启动并保持连接:在同一目录中运行 `claude mcp list`,确认该服务器显示为已连接
3256* 确认工具名称与服务器公开的 `mcp__<server>__<tool>` 名称匹配3322* 确认工具名称与服务器公开的 `mcp__<server>__<tool>` 名称一致
3257* 如果服务器需要超过 30 秒才能启动,请提高 [`MCP_TIMEOUT`](/docs/zh-CN/env-vars)3323* 如果服务器启动需要超过 30 秒,请调高 [`MCP_TIMEOUT`](/docs/zh-CN/env-vars)
3258 3324
3259<h3 id="oauth-callback-port-is-already-in-use">3325<h3 id="oauth-callback-port-is-already-in-use">
3260 OAuth 回调端口已在使用中3326 OAuth 回调端口已被占用
3261</h3>3327</h3>
3262 3328
3263当您使用 OAuth 登录远程 MCP 服务器时,Claude Code 启动本地侦听器以接收登录回调。如果该侦听器需要的端口被另一个进程持有,登录失败,显示此消息。这主要发生在[固定回调端口](/docs/zh-CN/mcp#use-a-fixed-oauth-callback-port)通过 [`MCP_OAUTH_CALLBACK_PORT`](/docs/zh-CN/env-vars) 变量或 `--callback-port` 设置时,因为没有一个 Claude Code 会选择可用端口。3329当您使用 OAuth 登录远程 MCP 服务器时,Claude Code 会启动一个本地监听器来接收登录回调。如果该监听器所需的端口被另一个进程占用,登录会以此消息失败。这种情况主要发生在通过 [`MCP_OAUTH_CALLBACK_PORT`](/docs/zh-CN/env-vars) 变量或 `--callback-port` 设置了[固定回调端口](/docs/zh-CN/mcp#use-a-fixed-oauth-callback-port)时,因为如果没有设置,Claude Code 会选择一个可用端口。
3264 3330
3265```text theme={null}3331```text theme={null}
3266OAuth callback port <port> is already in use — another process may be holding it. Run `lsof -ti:<port> -sTCP:LISTEN` to find it.3332OAuth callback port <port> is already in use — another process may be holding it. Run `lsof -ti:<port> -sTCP:LISTEN` to find it.
3267```3333```
3268 3334
3269在 Windows 上,建议的命令是 `netstat -ano | findstr :<port>`。3335在 Windows 上,建议的命令改为 `netstat -ano | findstr :<port>`。
3270 3336
3271**应该做什么:**3337**解决方法:**
3272 3338
3273* 运行消息中的命令以找到持有端口的进程,并停止它或等待它完成3339* 运行消息中的命令,找到占用该端口的进程,然后停止它或等待它结束
3274* 如果另一个程序永久需要该端口,请向服务器注册不同的重定向 URI,并使用 `MCP_OAUTH_CALLBACK_PORT` 或 `--callback-port` 设置其端口,以及您使用的任何一个3340* 如果另一个程序需要长期占用该端口,请向服务器注册一个不同的重定向 URI,并使用 `MCP_OAUTH_CALLBACK_PORT` 或 `--callback-port`(取决于您使用的是哪一个)设置其端口
3275* 然后再次启动登录,例如通过在 `/mcp` 中选择服务器3341* 然后重新发起登录,例如在 `/mcp` 中选择该服务器
3276 3342
3277<h3 id="no-available-ports-for-oauth-redirect">3343<h3 id="no-available-ports-for-oauth-redirect">
3278 OAuth 重定向没有可用的端口3344 没有可用于 OAuth 重定向的端口
3279</h3>3345</h3>
3280 3346
3281当您使用[OAuth](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers)登录远程 MCP 服务器时,Claude Code 启动本地侦听器以接收登录回调。当 Claude Code 无法为其绑定本地端口时,登录失败,显示此消息。机器上的某些内容阻止它在 `127.0.0.1` 上侦听,例如安全软件或拒绝本地侦听器的沙箱策略。3347当您使用 [OAuth](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers) 登录远程 MCP 服务器时,Claude Code 会启动一个本地监听器来接收登录回调。当 Claude Code 无法为其绑定本地端口时,登录会以此消息失败。这说明计算机上的某些东西阻止它在 `127.0.0.1` 上监听,例如拒绝本地监听器的安全软件或沙箱策略。
3282 3348
3283```text theme={null}3349```text theme={null}
3284No available ports for OAuth redirect3350No available ports for OAuth redirect
3285```3351```
3286 3352
3287在 v2.1.268 之前,Claude Code 不会回退到操作系统分配的端口,所以消息也会在仅其自选端口无法绑定时出现。这可能发生在 Hyper-V 保留覆盖 Claude Code 选择的端口的端口范围的 Windows 主机上。3353在 v2.1.268 之前,Claude Code 不会回退到由操作系统分配的端口,因此当只是它自行选择的端口无法绑定时,也会出现此消息。这种情况可能发生在 Hyper-V 保留了覆盖 Claude Code 选择范围的端口区间的 Windows 主机上。
3288 3354
3289**应该做什么:**3355**解决方法:**
3290 3356
3291* 检查安全软件或沙箱策略是否阻止进程在 `127.0.0.1` 上侦听,并允许 Claude Code 绑定本地端口3357* 检查是否有安全软件或沙箱策略阻止进程在 `127.0.0.1` 上监听,并允许 Claude Code 绑定本地端口
3292* 然后再次启动登录,例如通过在 `/mcp` 中选择服务器3358* 然后重新发起登录,例如在 `/mcp` 中选择该服务器
3293 3359
3294<h3 id="security-review-fails-without-origin-head">3360<h3 id="security-review-fails-without-origin-head">
3295 /security-review 在没有 origin/HEAD 时失败3361 缺少 origin/HEAD 时 /security-review 失败
3296</h3>3362</h3>
3297 3363
3298[`/security-review`](/docs/zh-CN/commands#all-commands) 通过将您的分支与 `origin/HEAD` 进行比较来构建其审查上下文,这是记录您的 `origin` 远程上哪个分支是默认分支的本地 ref。当该 ref 不存在时,收集差异的 git 命令失败,审查在启动前停止。3364[`/security-review`](/docs/zh-CN/commands#all-commands) 通过将您的分支与 `origin/HEAD` 进行 diff 来构建审查上下文,`origin/HEAD` 是记录 `origin` 远程默认分支的本地引用。当该引用不存在时,收集 diff 的 git 命令会失败,审查在开始之前就会停止。
3299 3365
3300```text theme={null}3366```text theme={null}
3301Error: Shell command failed for pattern "!`git diff --name-only origin/HEAD...`": [stderr]3367Error: Shell command failed for pattern "!`git diff --name-only origin/HEAD...`": [stderr]
3304'git <command> [<revision>...] -- [<file>...]'3370'git <command> [<revision>...] -- [<file>...]'
3305```3371```
3306 3372
3307消息可能引用 `git log` 或不同的 `git diff`。Git 仅在远程通告默认分支且您的获取 refspec 覆盖它时创建 `origin/HEAD`,完整的远程克隆带有提交时会这样做。在这些设置中 ref 丢失:3373消息中引用的也可能是 `git log` 或其他 `git diff` 命令。只有当远程公布了默认分支且您的 fetch refspec 覆盖了该分支时,Git 才会创建 `origin/HEAD`;对含有提交的远程执行完整的 `git clone` 就满足这一点。在以下设置中会缺少该引用:
3308 3374
3309* 单分支或 CI 检出,它获取太窄的 refspec3375* 单分支或 CI 检出,其 fetch refspec 范围过窄
3310* 远程服务器端 HEAD 指向没有人推送的分支3376* 服务器端 HEAD 指向一个无人推送过的分支的远程
3311* 没有 `origin` 远程的存储库,或您从未获取的存储库3377* 没有 `origin` 远程的仓库,或您从未 fetch 过的仓库
3312 3378
3313Claude Code 为任何 [injects dynamic context](/docs/zh-CN/skills#when-an-injected-command-fails) 的 skill 显示相同的错误,失败的注入命令会中止该 skill 的调用。两个兄弟字符串在命令运行之前就会触发:3379对于任何[注入动态上下文](/docs/zh-CN/skills#when-an-injected-command-fails)的 skill,Claude Code 都会显示相同的错误,并且注入的命令失败会中止该 skill 的调用。另有两条相关消息会在命令实际运行之前触发:
3314 3380
3315* `Shell command permission check failed for pattern "..."`:命令的权限检查不允许它。[Permission checks on injected commands](/docs/zh-CN/skills#permission-checks-on-injected-commands) 涵盖在每个权限模式中哪些结果会中止,以及如何使用 `allowed-tools` 预先批准命令3381* `Shell command permission check failed for pattern "..."`:命令的权限检查未允许它运行。[注入命令的权限检查](/docs/zh-CN/skills#permission-checks-on-injected-commands)介绍了在各权限模式下哪些结果会导致中止,以及如何使用 `allowed-tools` 预先批准命令
3316* ``Skill <name> requires bash (`shell: bash` in frontmatter) but Git Bash was not found``:skill 的 frontmatter 在没有它的机器上要求 bash。安装 Git for Windows 或将 frontmatter 更改为 `shell: powershell`。请参阅[注入命令如何运行](/docs/zh-CN/skills#how-injected-commands-run)3382* ``Skill <name> requires bash (`shell: bash` in frontmatter) but Git Bash was not found``:该 skill 的 frontmatter 要求使用 bash,但计算机上没有 bash。请安装 Git for Windows,或将 frontmatter 改为 `shell: powershell`。请参阅[注入命令的运行方式](/docs/zh-CN/skills#how-injected-commands-run)
3317 3383
3318**应该做什么:**3384**解决方法:**
3319 3385
3320* 通过命名您的远程默认分支创建 ref:`git remote set-head origin <default-branch>`。只要本地跟踪 ref `origin/<default-branch>` 存在,这就有效。如果它不存在,如在单分支克隆中,首先获取分支:运行 `git remote set-branches --add origin <branch>`,然后 `git fetch origin`,然后重新运行 set-head 命令。重新运行 `/security-review`。3386* 通过指定远程的默认分支来创建该引用:`git remote set-head origin <default-branch>`。只要本地跟踪引用 `origin/<default-branch>` 存在,此方法就有效。如果它不存在(例如在单分支克隆中),请先 fetch 该分支:运行 `git remote set-branches --add origin <branch>`,然后运行 `git fetch origin`,再重新运行 set-head 命令。然后重新运行 `/security-review`。
3321* 如果您不想命名分支,运行 `git fetch origin` 然后 `git remote set-head origin --auto`,它询问远程其默认分支是什么。当远程不通告默认分支时它失败,显示 `error: Cannot determine remote HEAD`,因为它是空的或其 HEAD 指向没有人推送的分支;改为显式命名分支。当您的克隆不获取该分支时它失败,显示 `error: Not a valid ref`;首先按上面的方式扩大 refspec。3387* 如果您不想指定分支名称,请运行 `git fetch origin`,然后运行 `git remote set-head origin --auto`,它会向远程查询哪个分支是默认分支。当远程未公布默认分支时(因为远程为空,或其 HEAD 指向无人推送过的分支),它会以 `error: Cannot determine remote HEAD` 失败;此时请显式指定分支。当您的克隆不 fetch 该分支时,它会以 `error: Not a valid ref` 失败;请先按上述方法扩大 refspec。
3322* 如果存储库没有远程,使用 `git remote add origin <url>` 添加一个并在创建 ref 之前获取。如果远程是空的,首先使用 `git push -u origin HEAD` 推送您的分支,并在 set-head 命令中命名该分支;`origin/HEAD` 然后指向您刚推送的分支,所以 `/security-review` 看到空差异,直到分支与其分歧。3388* 如果仓库没有远程,请使用 `git remote add origin <url>` 添加一个,并在创建引用之前执行 fetch。如果远程为空,请先使用 `git push -u origin HEAD` 推送您的分支,并在 set-head 命令中指定该分支;之后 `origin/HEAD` 会指向您刚推送的分支,因此在您的分支与其产生分歧之前,`/security-review` 看到的 diff 为空。
3323 3389
3324<h3 id="input-must-be-provided-when-using-print">3390<h3 id="input-must-be-provided-when-using-print">
3325 使用 `--print` 时必须提供输入3391 使用 `--print` 时必须提供输入
3326</h3>3392</h3>
3327 3393
3328裸 `claude` 需要 stdout 是终端才能启动交互 UI。当 stdout 被重定向,或控制台不是真实终端时,例如 PowerShell ISE 和某些 IDE 输出窗格,`claude` 改为以[非交互](/docs/zh-CN/headless)模式运行。这与 `claude -p` 相同,它需要提示,所以消息命名 `--print`,即使您没有传递标志。在任何地方传递 `-p`/`--print` 而不带提示且 stdin 上没有任何内容会产生相同的错误。3394直接运行 `claude` 需要 stdout 是终端才能启动交互式 UI。当 stdout 被重定向,或控制台不是真正的终端(例如 PowerShell ISE 和某些 IDE 输出窗格)时,`claude` 会改为以[非交互方式](/docs/zh-CN/headless)运行。这与 `claude -p` 的模式相同,而该模式需要提示词,因此即使您没有传入该标志,消息中也会提到 `--print`。在任何环境中,传入 `-p`/`--print` 却不提供提示词且 stdin 上没有管道输入,都会产生同样的错误。
3329 3395
3330```text theme={null}3396```text theme={null}
3331Error: Input must be provided either through stdin or as a prompt argument when using --print3397Error: Input must be provided either through stdin or as a prompt argument when using --print
3332```3398```
3333 3399
3334**应该做什么:**3400**解决方法:**
3335 3401
3336* 对于交互使用,在真实终端中运行 `claude`:Windows Terminal 或 PowerShell 控制台而不是 ISE,以及您的 IDE 的集成终端而不是输出窗格3402* 若要交互式使用,请在真正的终端中运行 `claude`:使用 Windows Terminal 或 PowerShell 控制台而不是 ISE,使用 IDE 的集成终端而不是输出窗格
3337* 对于一次性使用,传递提示:`claude -p "your question"`,或使用 `echo "your question" | claude -p` 管道它3403* 若要一次性使用,请传入提示词:`claude -p "your question"`,或通过管道传入:`echo "your question" | claude -p`
3338 3404
3339<h3 id="input-contained-only-whitespace">3405<h3 id="input-contained-only-whitespace">
3340 输入仅包含空格3406 输入仅包含空白字符
3341</h3>3407</h3>
3342 3408
3343在[非交互模式](/docs/zh-CN/headless)中,Claude Code 拒绝完全由空格、制表符或换行符组成的提示,而不是发送它,因为 API 拒绝没有可见文本的消息。您看到的消息取决于空白提示来自何处:3409在[非交互模式](/docs/zh-CN/headless)下,Claude Code 会拒绝完全由空格、制表符或换行符组成的提示词,而不会发送它,因为 API 会拒绝没有可见文本的消息。您看到的消息取决于空白提示词的来源:
3344 3410
3345* **`claude -p` 的提示参数或管道 stdin**:`claude` 以 `Error: Input contained only whitespace. Provide a prompt with text through stdin or as a prompt argument when using --print` 退出3411* **`claude -p` 的提示词参数或通过管道传入的 stdin**:`claude` 以 `Error: Input contained only whitespace. Provide a prompt with text through stdin or as a prompt argument when using --print` 退出
3346* **提交给运行 `--input-format stream-json` 或 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 会话的消息**:Claude Code 在不调用模型的情况下结束轮次,会话保持可用。拒绝作为信息消息和轮次的结果文本到达:`Blank prompt — the message was only whitespace, so nothing was sent to the model.`3412* **提交到正在运行的 `--input-format stream-json` 或 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 会话的消息**:Claude Code 会在不调用模型的情况下结束该轮次,会话仍可继续使用。拒绝信息会以信息性消息以及该轮次结果文本的形式出现:`Blank prompt — the message was only whitespace, so nothing was sent to the model.`
3347 3413
3348在 v2.1.229 之前,Claude Code 将仅空格消息发送到 API,API 以 400 错误拒绝请求。3414在 v2.1.229 之前,Claude Code 会将仅含空白字符的消息发送到 API,而 API 会以 400 错误拒绝该请求。
3349 3415
3350**应该做什么:**3416**解决方法:**
3351 3417
3352* 在提示中包含可见文本。如果脚本从变量或文件构建提示,请在调用 Claude Code 之前检查源是否不为空。3418* 在提示词中包含可见文本。如果脚本从变量或文件构建提示词,请在调用 Claude Code 之前检查来源是否为空。
3353 3419
3354<h3 id="stream-json-input-carried-over-256m-characters-with-no-newline">3420<h3 id="stream-json-input-carried-over-256m-characters-with-no-newline">
3355 stream-json 输入在没有换行符的情况下超过 256M 个字符3421 stream-json 输入超过 256M 个字符且没有换行符
3356</h3>3422</h3>
3357 3423
3358您的程序在没有换行符的情况下在 stdin 上发送了超过 268,435,456 个字符到 `claude -p --input-format stream-json` 运行,所以 Claude Code 将此错误打印到 stderr 并以代码 1 退出,而不是缓冲更多输入。消息将该预算表示为 `256M`。在 v2.1.257 之前,Claude Code 无限制地缓冲此类输入,增长内存直到进程崩溃或被杀死。3424您的程序向 `claude -p --input-format stream-json` 运行的 stdin 发送了超过 268,435,456 个字符且没有换行符,因此 Claude Code 会将此错误打印到 stderr 并以退出码 1 退出,而不会继续缓冲更多输入。消息将该上限表述为 `256M`。在 v2.1.257 之前,Claude Code 会无限制地缓冲此类输入,内存不断增长,直到进程崩溃或被终止。
3359 3425
3360```text theme={null}3426```text theme={null}
3361Error: stream-json input carried over 256M characters with no newline. Each stream-json message must be a single newline-terminated JSON line: either the producer is not newline-terminating its messages, or one message exceeded this budget.3427Error: stream-json input carried over 256M characters with no newline. Each stream-json message must be a single newline-terminated JSON line: either the producer is not newline-terminating its messages, or one message exceeded this budget.
3362```3428```
3363 3429
3364没有换行符的这么长的输入通常意味着生产者根本不是 stream-json 生产者,例如二进制文件或意外管道的纯日志输出。超过预算的单个消息失败相同的检查。3430这么长却没有换行符的输入通常意味着生成方根本不是 stream-json 生成方,例如意外通过管道传入的二进制文件或纯日志输出。单条超过上限的消息也会在同一检查中失败。
3365 3431
3366**应该做什么:**3432**解决方法:**
3367 3433
3368* 检查什么被管道到 stdin。使用 [`--input-format stream-json`](/docs/zh-CN/cli-reference#cli-flags),每条消息必须是一个换行符终止的 JSON 行3434* 检查通过管道传入 stdin 的内容。使用 [`--input-format stream-json`](/docs/zh-CN/cli-reference#cli-flags) 时,每条消息都必须是一行以换行符结尾的 JSON
3369* 要改为发送纯文本,请删除 `--input-format stream-json`;`claude -p` 默认从 stdin 读取纯文本提示3435* 若要改为发送纯文本,请去掉 `--input-format stream-json`;`claude -p` 默认从 stdin 读取纯文本提示词
3370 3436
3371<h3 id="unknown-command">3437<h3 id="unknown-command">
3372 未知命令3438 未知命令
3373</h3>3439</h3>
3374 3440
3375在交互终端会话中,您提交了一个 `/` 名称,它与此会话中的任何命令都不匹配,所以 Claude Code 报告该名称而不是运行任何内容:3441在交互式终端会话中,您提交了一个与本会话中任何命令都不匹配的 `/` 名称,因此 Claude Code 会报告该名称,而不会运行任何内容:
3376 3442
3377```text theme={null}3443```text theme={null}
3378Unknown command: /hepl. Did you mean /help?3444Unknown command: /hepl. Did you mean /help?
3379```3445```
3380 3446
3381Claude Code 建议此会话中菜单列出的最接近的命令名称或别名。当没有接近的时候,消息在名称后结束。原因通常是以下之一:3447Claude Code 会建议本会话菜单中列出的最接近的命令名称或别名。当没有接近的匹配时,消息会在名称之后结束。原因通常是以下之一:
3382 3448
3383* 打字错误,例如 `/hepl` 代替 `/help`。[How the command menu matches what you type](/docs/zh-CN/commands#how-the-command-menu-matches-what-you-type) 涵盖在提交前选择接近的匹配3449* 拼写错误,例如将 `/help` 输成 `/hepl`。[命令菜单如何匹配您的输入](/docs/zh-CN/commands#how-the-command-menu-matches-what-you-type)介绍了如何在提交前选择接近的匹配项
3384* 存在但在此会话中不可用的命令,因为不满足要求,例如您的平台、计划或身份验证方法。[`/web-setup`](/docs/zh-CN/web-quickstart#web-setup-shows-no-commands-match-or-unknown-command) 和 [`/schedule`](/docs/zh-CN/routines#schedule-returns-unknown-command) 的故障排除条目演示两个常见情况。某些命令在您的组织的策略禁用它们时用自己的消息回答,例如 [`Cloud sessions are disabled by your organization's policy`](#cloud-sessions-are-disabled-by-your-organizations-policy)3450* 命令存在,但由于未满足某项要求(例如您的平台、套餐或身份验证方式)而在本会话中不可用。[`/web-setup`](/docs/zh-CN/web-quickstart#web-setup-shows-no-commands-match-or-unknown-command) 和 [`/schedule`](/docs/zh-CN/routines#schedule-returns-unknown-command) 的故障排除条目介绍了两种常见情况。当您组织的策略禁用某些命令时,这些命令会以其自身的消息回复,例如 [`Cloud sessions are disabled by your organization's policy`](#cloud-sessions-are-disabled-by-your-organizations-policy)
3385* 来自[插件](/docs/zh-CN/plugins/overview)或[MCP 服务器](/docs/zh-CN/mcp#use-mcp-prompts-as-commands)的命令,在此会话中未安装或连接3451* 来自[插件](/docs/zh-CN/plugins/overview)或 [MCP 服务器](/docs/zh-CN/mcp#use-mcp-prompts-as-commands)的命令,但该插件或服务器未在本会话中安装或连接
3386 3452
3387Claude Code 仅在交互终端会话中以这种方式回答不匹配的 `/` 名称。在所有其他会话中,它将提示作为正常消息发送给 Claude,并注意命令未运行以及 Claude 可以在会话中运行的命令列表。这些会话包括:3453只有在交互式终端会话中,Claude Code 才会以这种方式回应不匹配的 `/` 名称。在其他所有会话中,它会改为将提示词作为普通消息发送给 Claude,并附上一条说明该命令未运行的备注,以及 Claude 在该会话中可以运行的命令列表。这些会话包括:
3388 3454
3389* `-p` 运行3455* `-p` 运行
3390* [Agent SDK](/docs/zh-CN/agent-sdk/overview) 应用程序3456* [Agent SDK](/docs/zh-CN/agent-sdk/overview) 应用程序
3391* [Desktop 应用](/docs/zh-CN/desktop)的代码选项卡3457* [桌面应用](/docs/zh-CN/desktop)的 Code 选项卡
3392* [VS Code 扩展](/docs/zh-CN/vs-code)的聊天面板3458* [VS Code 扩展](/docs/zh-CN/vs-code)的聊天面板
3393* [云会话](/docs/zh-CN/claude-code-on-the-web)和[例程](/docs/zh-CN/routines)3459* [云端会话](/docs/zh-CN/claude-code-on-the-web)和 [Routine](/docs/zh-CN/routines)
3394 3460
3395对于无法在这些会话之一中运行的内置命令,Claude Code 仍然回答命令不可用,而不是将其发送给 Claude。在 v2.1.274 之前,仅云会话和例程将不匹配的名称发送给 Claude。在 v2.1.273 之前,它们也回答 `Unknown command`。3461对于无法在这些会话之一中运行的内置命令,Claude Code 仍会回复该命令不可用,而不是将其发送给 Claude。在 v2.1.274 之前,只有云端会话和 Routine 会将不匹配的名称发送给 Claude。在 v2.1.273 之前,它们也会回复 `Unknown command`。
3396 3462
3397Claude Code 不将每个以 `/` 开头的提示视为命令。当 `/` 后的第一个单词以标点符号开头时,它将提示作为正常消息发送给 Claude,例如打开 Lean doc 注释的 `/--`,或是路径,例如 `/var/log/syslog`。3463Claude Code 并不会将每个以 `/` 开头的提示词都视为命令。当 `/` 之后的第一个单词以标点符号开头(例如开启 Lean 文档注释的 `/--`),或者是 `/var/log/syslog` 之类的路径时,它会将提示词作为普通消息发送给 Claude。
3398 3464
3399在 v2.1.236 之前,如果您在命令菜单列出您键入的名称的接近匹配时按 `Enter`,Claude Code 会运行该匹配,所以 `/hepl` 之类的打字错误会运行 `/help` 而不是产生此消息。3465在 v2.1.236 之前,如果您在命令菜单列出与您输入的名称相近的匹配项时按下 `Enter`,Claude Code 会运行该匹配项,因此 `/hepl` 之类的拼写错误会运行 `/help`,而不是产生此消息。
3400 3466
3401**应该做什么:**3467**解决方法:**
3402 3468
3403* 运行建议的名称,或键入 `/` 后跟名称的一部分以查看此会话中可用的内容3469* 运行建议的名称,或输入 `/` 后跟名称的一部分,查看本会话中可用的内容
3404* 如果 Claude Code 将记录的命令报告为未知,请检查[命令参考](/docs/zh-CN/commands)中的其行以了解它命名的要求3470* 如果 Claude Code 将某个有文档记录的命令报告为未知,请在[命令参考](/docs/zh-CN/commands)中查看该命令所在行指出的要求
3405 3471
3406<h3 id="diff-is-too-large-for-ultrareview">3472<h3 id="diff-is-too-large-for-ultrareview">
3407 Diff 对于 ultrareview 来说太大了3473 diff 过大,无法进行 ultrareview
3408</h3>3474</h3>
3409 3475
3410您的分支和基础分支之间的差异,包括未提交和暂存的更改,超过了 [ultrareview](/docs/zh-CN/ultrareview) 的大小限制,所以 `/code-review ultra` 和 `claude ultrareview` 子命令在云会话启动前拒绝审查。被拒绝的审查不使用免费运行,也不计费使用信用。消息命名有效的限制、您的差异大小以及贡献最多更改行的文件。在 v2.1.216 之前,消息仅显示原始差异统计。3476您的分支与基础分支之间的 diff(包括未提交和已暂存的更改)超出了 [ultrareview](/docs/zh-CN/ultrareview) 的大小限制,因此 `/code-review ultra` 和 `claude ultrareview` 子命令会在云端会话启动之前拒绝审查。被拒绝的审查不会消耗免费运行次数,也不会扣除使用额度。消息会列出当前生效的限制、您的 diff 大小,以及贡献更改行数最多的文件。在 v2.1.216 之前,消息只显示原始的 diff 统计信息。
3411 3477
3412```text theme={null}3478```text theme={null}
3413Diff is too large for ultrareview: 812 files, 96,410 lines changed (limits: 500 files, 8,000 lines). Largest files: package-lock.json (41,904 lines), dist/bundle.js (18,210 lines), src/generated/api.ts (9,876 lines). Pass a closer base branch (`/code-review ultra <branch>`) to narrow the scope, or split the change.3479Diff is too large for ultrareview: 812 files, 96,410 lines changed (limits: 500 files, 8,000 lines). Largest files: package-lock.json (41,904 lines), dist/bundle.js (18,210 lines), src/generated/api.ts (9,876 lines). Pass a closer base branch (`/code-review ultra <branch>`) to narrow the scope, or split the change.
3414```3480```
3415 3481
3416审查拉取请求应用相同的限制;该形式的消息以 `PR #<N> is too large for ultrareview` 开头,并命名 PR 的文件和行数。3482审查 Pull Request 时也适用相同的限制;该形式的消息以 `PR #<N> is too large for ultrareview` 开头,并列出该 PR 的文件数和行数。
3417 3483
3418**应该做什么:**3484**解决方法:**
3419 3485
3420* 传递更接近您的工作的基础分支,例如 `/code-review ultra develop`,以便审查仅涵盖与该分支的差异3486* 传入一个更接近您工作内容的基础分支,例如 `/code-review ultra develop`,使审查只覆盖相对于该分支的 diff
3421* 将更改分成较小的分支并审查每一个。消息命名的文件贡献最多更改行,所以首先将这些移到它们自己的分支。3487* 将更改拆分为较小的分支并分别审查。消息中列出的文件贡献了最多的更改行数,因此可以先将这些文件移到单独的分支中。
3422 3488
3423<h3 id="could-not-find-merge-base-with-the-base-branch">3489<h3 id="could-not-find-merge-base-with-the-base-branch">
3424 无法找到与基础分支的合并基础3490 无法找到与基础分支的 merge-base
3425</h3>3491</h3>
3426 3492
3427`/code-review ultra` 和 `claude ultrareview` 子命令审查您的分支和基础分支之间的差异,这需要两者共享的提交。当 `git merge-base` 找不到时,Claude Code 在云会话启动前拒绝审查。在 Claude Code 可以验证完整的克隆上,至少有一个分支,它改为回退到[审查每个跟踪文件](/docs/zh-CN/ultrareview#diff-limits-and-fallbacks)而不是拒绝。您在基础分支根本找不到时、Claude Code 无法验证您的克隆完整时,或在罕见的存储库中看到此拒绝,其中整个树差异不可能,例如 SHA-256 对象格式。3493`/code-review ultra` 和 `claude ultrareview` 子命令会审查您的分支与基础分支之间的 diff,这需要两者共有的一个提交。当 `git merge-base` 找不到这样的提交时,Claude Code 会在云端会话启动之前拒绝审查。在 Claude Code 能够验证为完整且至少有一个分支的克隆上,它会回退为[审查每个被跟踪的文件](/docs/zh-CN/ultrareview#diff-limits-and-fallbacks),而不是拒绝。当根本找不到基础分支、Claude Code 无法验证您的克隆是否完整,或在少数无法进行全树 diff 的仓库中(例如使用 SHA-256 对象格式的仓库),您会看到此拒绝。
3428 3494
3429```text theme={null}3495```text theme={null}
3430Could not find merge-base with main. Pass the base branch explicitly (e.g. `/code-review ultra develop`) or make sure you're in a git repo with a main branch.3496Could not find merge-base with main. Pass the base branch explicitly (e.g. `/code-review ultra develop`) or make sure you're in a git repo with a main branch.
3431```3497```
3432 3498
3433第一句后的提示取决于 Claude Code 观察到的内容:3499第一句之后的提示取决于 Claude Code 观察到的情况:
3434 3500
3435* **您没有传递基础分支**:Claude Code 与存储库的默认分支进行了比较,并建议显式传递您的基础,如上面的示例3501* **您未传入基础分支**:Claude Code 与仓库的默认分支进行了比较,并建议您显式传入基础分支,如上例所示
3436* **您传递的基础分支已在您的克隆中**:提示读取 ``Make sure <branch> exists locally or on origin (try `git fetch origin <branch>`)``3502* **您传入的基础分支已存在于您的克隆中**:提示为 ``Make sure <branch> exists locally or on origin (try `git fetch origin <branch>`)``
3437* **您传递的基础分支不在您的克隆中**:Claude Code 在比较前从 origin 获取了它。提示读取 ``<branch> was fetched from origin but shares no history with HEAD. If another branch is your real base, pass it explicitly (`/code-review ultra <branch>`)``;当 Claude Code 无法判断您的克隆是否浅时,它改为建议 `git fetch --unshallow origin`。在 v2.1.221 之前,提示为每个获取的基础分支建议 `git fetch --unshallow origin`,在完整克隆上该命令失败,显示 `fatal: --unshallow on a complete repository does not make sense`。3503* **您传入的基础分支不在您的克隆中**:Claude Code 在比较之前从 origin fetch 了该分支。提示为 ``<branch> was fetched from origin but shares no history with HEAD. If another branch is your real base, pass it explicitly (`/code-review ultra <branch>`)``;当 Claude Code 无法判断您的克隆是否为浅克隆时,它会改为建议 `git fetch --unshallow origin`。在 v2.1.221 之前,对于每个被 fetch 的基础分支,提示都会建议 `git fetch --unshallow origin`,而在完整克隆上,该命令会以 `fatal: --unshallow on a complete repository does not make sense` 失败。
3438 3504
3439**应该做什么:**3505**解决方法:**
3440 3506
3441* 如果另一个分支是您的真实基础,显式传递它:`/code-review ultra <branch>`3507* 如果您真正的基础分支是另一个分支,请显式传入:`/code-review ultra <branch>`
3442* 如果您的克隆可能没有完整历史,运行 `git fetch --unshallow origin` 并重新运行审查3508* 如果您的克隆可能没有完整历史,请运行 `git fetch --unshallow origin` 并重新运行审查
3443 3509
3444<h3 id="your-checkout-has-no-branches">3510<h3 id="your-checkout-has-no-branches">
3445 您的检出没有分支3511 您的检出没有分支
3446</h3>3512</h3>
3447 3513
3448检出可以有提交但没有分支:如果您运行 `git init` 后跟 `git fetch <url>` 和 `git checkout FETCH_HEAD`,您会得到一个分离的 HEAD,没有 refs。Claude Code 将您的存储库打包为 git 包以上传它进行 [ultrareview](/docs/zh-CN/ultrareview),它无法打包没有分支或其他 refs 的存储库,所以 `/code-review ultra` 和 `claude ultrareview` 子命令在云会话启动前拒绝审查。3514检出可能有提交但没有分支:如果您运行 `git init`,然后运行 `git fetch <url>` 和 `git checkout FETCH_HEAD`,就会得到一个没有任何引用的分离 HEAD。Claude Code 会将您的仓库打包为 git bundle 并上传以进行 [ultrareview](/docs/zh-CN/ultrareview),而它无法打包没有分支或其他引用的仓库,因此 `/code-review ultra` 和 `claude ultrareview` 子命令会在云端会话启动之前拒绝审查。
3449 3515
3450```text theme={null}3516```text theme={null}
3451Your checkout has no branches (detached HEAD only), which cloud review can't bundle. Create one first — `git checkout -b <name>` — then rerun /code-review ultra.3517Your checkout has no branches (detached HEAD only), which cloud review can't bundle. Create one first — `git checkout -b <name>` — then rerun /code-review ultra.
3452```3518```
3453 3519
3454在 v2.1.221 之前,Claude Code 尝试审查此检出中的每个跟踪文件,上传失败。3520在 v2.1.221 之前,Claude Code 会尝试审查此检出中每个被跟踪的文件,而上传会失败。
3455 3521
3456**应该做什么:**3522**解决方法:**
3457 3523
3458* 使用 `git checkout -b <name>` 在您当前的提交处创建分支,然后重新运行审查3524* 使用 `git checkout -b <name>` 在当前提交处创建一个分支,然后重新运行审查
3459 3525
3460<h3 id="no-github-account-is-connected-to-your-claude-account">3526<h3 id="no-github-account-is-connected-to-your-claude-account">
3461 没有 GitHub 帐户连接到您的 Claude 帐户3527 您的 Claude 账户未连接 GitHub 账户
3462</h3>3528</h3>
3463 3529
3464您运行了 `/code-review ultra <PR#>` 或 `claude ultrareview <PR#>`,在创建云会话前 Claude Code 询问服务器[连接到您的 Claude 帐户的 GitHub 帐户](/docs/zh-CN/ultrareview#review-a-pull-request)是否可以到达 PR 的存储库。没有帐户连接,或连接已过期,所以云克隆会失败,Claude Code 拒绝启动。Claude Code 不为被拒绝的启动花费免费运行或计费使用信用。3530您运行了 `/code-review ultra <PR#>` 或 `claude ultrareview <PR#>`,在创建云端会话之前,Claude Code 会询问服务器[连接到您 Claude 账户的 GitHub 账户](/docs/zh-CN/ultrareview#review-a-pull-request)是否能访问该 PR 的仓库。由于没有连接账户,或连接已过期,云端克隆将会失败,因此 Claude Code 拒绝启动。对于被拒绝的启动,Claude Code 不会消耗免费运行次数,也不会扣除使用额度。
3465 3531
3466```text theme={null}3532```text theme={null}
3467Ultrareview clones <owner>/<repo> in the cloud with the GitHub account connected to your Claude account, and none is connected (or the connection expired). To fix: run /web-setup to reuse your GitHub CLI login, or connect an account at https://claude.ai/connect-github — then re-run /code-review ultra 1234 (allow a minute after connecting).3533Ultrareview clones <owner>/<repo> in the cloud with the GitHub account connected to your Claude account, and none is connected (or the connection expired). To fix: run /web-setup to reuse your GitHub CLI login, or connect an account at https://claude.ai/connect-github — then re-run /code-review ultra 1234 (allow a minute after connecting).
3468```3534```
3469 3535
3470当 [`/web-setup`](/docs/zh-CN/web-quickstart#connect-from-your-terminal) 在您的会话中不可用时,消息仅命名 claude.ai 链接。3536当 [`/web-setup`](/docs/zh-CN/web-quickstart#connect-from-your-terminal) 在您的会话中不可用时,消息只会提到 claude.ai 链接。
3471 3537
3472**应该做什么:**3538**解决方法:**
3473 3539
3474* 运行 `/web-setup` 将您的 GitHub CLI 登录连接到您的 Claude 帐户,或在 [claude.ai/connect-github](https://claude.ai/connect-github) 连接帐户3540* 运行 `/web-setup` 将您的 GitHub CLI 登录连接到 Claude 账户,或在 [claude.ai/connect-github](https://claude.ai/connect-github) 连接账户
3475* 连接后一分钟重新运行审查3541* 连接后等待一分钟再重新运行审查
3476 3542
3477在 v2.1.248 之前,Claude Code 在启动前不检查这个。3543在 v2.1.248 之前,Claude Code 在启动前不会进行此检查。
3478 3544
3479<h3 id="your-connected-github-account-cant-see-the-repository">3545<h3 id="your-connected-github-account-cant-see-the-repository">
3480 您连接的 GitHub 帐户看不到存储库3546 您连接的 GitHub 账户无法看到该仓库
3481</h3>3547</h3>
3482 3548
3483您运行了 `/code-review ultra <PR#>` 或 `claude ultrareview <PR#>`,[连接到您的 Claude 帐户的 GitHub 帐户](/docs/zh-CN/ultrareview#review-a-pull-request)无法读取 PR 的存储库,所以云克隆会失败,Claude Code 拒绝启动。Claude Code 不为被拒绝的启动花费免费运行或计费使用信用。3549您运行了 `/code-review ultra <PR#>` 或 `claude ultrareview <PR#>`,而[连接到您 Claude 账户的 GitHub 账户](/docs/zh-CN/ultrareview#review-a-pull-request)无法读取该 PR 的仓库,因此云端克隆将会失败,Claude Code 拒绝启动。对于被拒绝的启动,Claude Code 不会消耗免费运行次数,也不会扣除使用额度。
3484 3550
3485```text theme={null}3551```text theme={null}
3486Your connected GitHub account can't see <owner>/<repo> — usually the Claude GitHub app isn't installed on <owner> or wasn't granted this repo (web-connected accounts need it for private repos), or a different GitHub account is connected. To fix: run /web-setup to reuse your GitHub CLI login, or install the app at https://github.com/apps/claude/installations/new — then re-run /code-review ultra 1234.3552Your connected GitHub account can't see <owner>/<repo> — usually the Claude GitHub app isn't installed on <owner> or wasn't granted this repo (web-connected accounts need it for private repos), or a different GitHub account is connected. To fix: run /web-setup to reuse your GitHub CLI login, or install the app at https://github.com/apps/claude/installations/new — then re-run /code-review ultra 1234.
3487```3553```
3488 3554
3489当 [`/web-setup`](/docs/zh-CN/web-quickstart#connect-from-your-terminal) 在您的会话中不可用时,消息仅命名应用安装。3555当 [`/web-setup`](/docs/zh-CN/web-quickstart#connect-from-your-terminal) 在您的会话中不可用时,消息只会提到应用安装。
3490 3556
3491**应该做什么:**3557**解决方法:**
3492 3558
3493* 如果您的本地 `gh` CLI 可以读取存储库,运行 `/web-setup` 将该登录连接到您的 Claude 帐户3559* 如果您本地的 `gh` CLI 可以读取该仓库,请运行 `/web-setup` 将该登录连接到您的 Claude 账户
3494* 更改后重新运行审查3560* 更改后重新运行审查
3495 3561
3496在 v2.1.248 之前,Claude Code 在启动前不检查这个。3562在 v2.1.248 之前,Claude Code 在启动前不会进行此检查。
3497 3563
3498<h3 id="the-github-app-preflight-failed-transiently">3564<h3 id="the-github-app-preflight-failed-transiently">
3499 GitHub App 预检暂时失败3565 GitHub App 预检暂时失败
3500</h3>3566</h3>
3501 3567
3502您从本地存储库启动了[云会话](/docs/zh-CN/claude-code-on-the-web),两个步骤一起失败了。Claude Code 无法构建或上传您的存储库包。在上传之前,它检查了云服务是否可以从 GitHub 克隆存储库,而不是明确的答案,该检查以重试可能清除的错误结束,例如网络错误、超时或临时服务器错误。完整消息以停止包的内容开头,例如 `Could not upload repo bundle (<error>)`,并以预检句子结尾:3568您从本地仓库启动了一个[云端会话](/docs/zh-CN/claude-code-on-the-web),而两个步骤同时失败。Claude Code 无法构建或上传您仓库的 bundle。在上传之前,它检查了云服务能否从 GitHub 克隆该仓库,而该检查没有得到明确答案,而是以一个重试可能消除的错误结束,例如网络错误、超时或临时服务器错误。完整消息以导致 bundle 失败的原因开头,例如 `Could not upload repo bundle (<error>)`,并以预检相关的句子结尾:
3503 3569
3504```text theme={null}3570```text theme={null}
3505Could not upload repo bundle (<error>). The GitHub App preflight failed transiently (network or service hiccup) — retry in a moment to start from GitHub instead3571Could not upload repo bundle (<error>). The GitHub App preflight failed transiently (network or service hiccup) — retry in a moment to start from GitHub instead
3506```3572```
3507 3573
3508**应该做什么:**3574**解决方法:**
3509 3575
3510* 片刻后重新运行命令。当 GitHub 检查通过时,Claude Code 可以从 GitHub 克隆启动会话,所以失败的上传不再阻止启动3576* 稍后重新运行命令。当 GitHub 检查通过时,Claude Code 可以从 GitHub 克隆启动会话,因此上传失败将不再阻止启动
3511* 如果重试继续失败,消息的开头命名停止上传的内容。当该原因是您可以修复的内容时,修复它以便会话可以从您的本地存储库启动3577* 如果重试一直失败,消息开头会指出导致上传失败的原因。如果该原因是您可以修复的,请修复它,以便会话可以改为从您的本地仓库启动
3512 3578
3513在 v2.1.251 之前,Claude Code 以 `Please set up GitHub on https://claude.ai/code` 结束消息,即使 GitHub 检查仅暂时失败,设置建议无法清除暂时失败。3579在 v2.1.251 之前,即使 GitHub 检查只是暂时失败,Claude Code 也会以 `Please set up GitHub on https://claude.ai/code` 结束消息,而设置建议无法消除暂时性故障。
3514 3580
3515<h3 id="the-repository-upload-cant-follow-a-git-setting">3581<h3 id="the-repository-upload-cant-follow-a-git-setting">
3516 存储库上传无法遵循 git 设置3582 仓库上传无法遵循某项 git 设置
3517</h3>3583</h3>
3518 3584
3519您启动了[上传您的本地存储库的云会话](/docs/zh-CN/claude-code-on-the-web#send-local-repositories-without-github),或分支的 [ultrareview](/docs/zh-CN/ultrareview),上传无法遵循决定哪个属性规则适用于您的文件的 git 设置之一。如果上传继续并错过了规则,git 在存储它之前转换的文件,例如清理过滤器加密的文件,可能会到达云端,因为它在磁盘上。Claude Code 拒绝上传,什么都不上传:3585您启动了一个[上传本地仓库的云端会话](/docs/zh-CN/claude-code-on-the-web#send-local-repositories-without-github),或对某个分支进行 [ultrareview](/docs/zh-CN/ultrareview),而上传无法遵循决定哪些属性规则适用于您文件的某项 git 设置。如果上传继续进行并遗漏了某条规则,那么 git 在存储前会转换的文件(例如经 clean 过滤器加密的文件)可能会以其在磁盘上的原样到达云端。因此 Claude Code 会拒绝上传,不会上传任何内容:
3520 3586
3521```text theme={null}3587```text theme={null}
3522Not uploading this working tree: core.ignoreCase (which decides whether .gitattributes patterns match file names regardless of letter case) is set in <file>, and the upload cannot follow that setting, so a file git would change before storing it (to encrypt it, for example) could be uploaded as it is on disk. Move the core.ignoreCase line into this repository's .git/config or directly into your ~/.gitconfig, then retry.3588Not uploading this working tree: core.ignoreCase (which decides whether .gitattributes patterns match file names regardless of letter case) is set in <file>, and the upload cannot follow that setting, so a file git would change before storing it (to encrypt it, for example) could be uploaded as it is on disk. Move the core.ignoreCase line into this repository’s .git/config or directly into your ~/.gitconfig, then retry.
3523```3589```
3524 3590
3525消息命名设置和它的设置位置,并以该情况的修复结尾。相同的拒绝出现在 `core.attributesFile` 和 `attr.tree`,每个都有自己的修复。3591消息会指出该设置及其设置位置,并以针对您所遇情况的修复方法结尾。对于 `core.attributesFile` 和 `attr.tree`,也会出现同样的拒绝,各自附有对应的修复方法。
3526 3592
3527消息可以命名您的 git 配置通过 `include` 或 `includeIf` 指令拉入的配置文件,即使该指令的条件不适用于此存储库。3593消息中指出的配置文件可能是您的 git 配置通过 `include` 或 `includeIf` 指令引入的,即使该指令的条件并不适用于此仓库。
3528 3594
3529**应该做什么:**3595**解决方法:**
3530 3596
3531* 应用消息最后一句中的修复3597* 按照消息最后一句中的修复方法操作
3532 3598
3533<h3 id="github-isnt-connected-to-your-claude-account">3599<h3 id="github-isnt-connected-to-your-claude-account">
3534 GitHub 未连接到您的 Claude 帐户3600 GitHub 未连接到您的 Claude 账户
3535</h3>3601</h3>
3536 3602
3537您从本地存储库启动了[云会话](/docs/zh-CN/claude-code-on-the-web),例如使用 `/autofix-pr`。没有 GitHub 帐户连接到您的 Claude 帐户,或连接已过期,所以 Claude Code 拒绝启动:3603您从本地仓库启动了一个[云端会话](/docs/zh-CN/claude-code-on-the-web),例如使用 `/autofix-pr`。您的 Claude 账户未连接 GitHub 账户,或连接已过期,因此 Claude Code 拒绝启动:
3538 3604
3539```text theme={null}3605```text theme={null}
3540GitHub isn't connected to your Claude account, so this repository can't be cloned in the cloud. Run /web-setup to connect with your GitHub CLI login, or connect on the web at https://claude.ai/connect-github3606GitHub isn't connected to your Claude account, so this repository can't be cloned in the cloud. Run /web-setup to connect with your GitHub CLI login, or connect on the web at https://claude.ai/connect-github
3541```3607```
3542 3608
3543当您使用 [`/schedule`](/docs/zh-CN/routines) 创建例程时,相同的消息作为命名存储库的设置注释出现;注释不会阻止创建例程。3609当您使用 [`/schedule`](/docs/zh-CN/routines) 创建 Routine 时,同样的消息会作为指出该仓库的设置说明出现;该说明不会阻止创建 Routine。
3544 3610
3545**应该做什么:**3611**解决方法:**
3546 3612
3547* 运行 `/web-setup` 将您的 GitHub CLI 登录连接到您的 Claude 帐户,或在 [claude.ai/connect-github](https://claude.ai/connect-github) 连接帐户。请参阅[GitHub 身份验证选项](/docs/zh-CN/claude-code-on-the-web#github-authentication-options)了解两者的区别。3613* 运行 `/web-setup` 将您的 GitHub CLI 登录连接到 Claude 账户,或在 [claude.ai/connect-github](https://claude.ai/connect-github) 连接账户。有关两者的区别,请参阅 [GitHub 身份验证选项](/docs/zh-CN/claude-code-on-the-web#github-authentication-options)。
3548* 连接后一分钟重新运行命令3614* 连接后等待一分钟再重新运行命令
3549 3615
3550在 v2.1.268 之前,Claude Code 将此报告为 Claude GitHub App 检查的临时失败,并建议重试或安装应用;两者都不连接 GitHub 帐户。3616在 v2.1.268 之前,Claude Code 会将此情况报告为 Claude GitHub App 检查的暂时性失败,并建议重试或安装该应用;但这两种做法都无法连接 GitHub 账户。
3551 3617
3552<h3 id="single-sign-on-authorization-needed">3618<h3 id="single-sign-on-authorization-needed">
3553 需要单点登录授权3619 需要单点登录授权
3554</h3>3620</h3>
3555 3621
3556您运行了 [`/install-github-app`](/docs/zh-CN/github-actions#quick-setup),并选择了其组织强制执行 SAML 单点登录的存储库。在设置之前,Claude Code 使用 GitHub CLI 检查您对存储库的访问权限,GitHub 拒绝了该检查,因为您的 `gh` 令牌还没有为组织授权。向导显示警告和授权步骤:3622您运行了 [`/install-github-app`](/docs/zh-CN/github-actions#quick-setup),并选择了一个其组织强制执行 SAML 单点登录的仓库。在设置之前,Claude Code 会使用 GitHub CLI 检查您对该仓库的访问权限,而 GitHub 拒绝了该检查,因为您的 `gh` 令牌尚未获得该组织的授权。向导会显示警告以及授权步骤:
3557 3623
3558```text theme={null}3624```text theme={null}
3559Single sign-on authorization needed3625Single sign-on authorization needed
3560<owner>/<repo> belongs to an organization that enforces SAML single sign-on, and your GitHub CLI token isn't authorized for it yet.3626<owner>/<repo> belongs to an organization that enforces SAML single sign-on, and your GitHub CLI token isn't authorized for it yet.
3561```3627```
3562 3628
3563**应该做什么:**3629**解决方法:**
3564 3630
3565* 通过运行 `gh auth refresh -h github.com -s repo,workflow` 使用 `repo` 和 `workflow` 范围重新授权您的 GitHub CLI 登录,并在 GitHub 提示单点登录时授权组织3631* 运行 `gh auth refresh -h github.com -s repo,workflow`,以 `repo` 和 `workflow` 作用域重新授权您的 GitHub CLI 登录,并在 GitHub 提示单点登录时授权该组织
3566* 如果您使用 `GH_TOKEN` 中的个人访问令牌进行身份验证,请打开 [github.com/settings/tokens](https://github.com/settings/tokens),在令牌上选择**配置 SSO**,并授权组织3632* 如果您使用 `GH_TOKEN` 中的个人访问令牌进行身份验证,请打开 [github.com/settings/tokens](https://github.com/settings/tokens),在该令牌上选择 **Configure SSO**,并授权该组织
3567* 再次运行 `/install-github-app`3633* 再次运行 `/install-github-app`
3568 3634
3569在 v2.1.273 之前,Claude Code 为此条件显示 `Admin permissions required` 警告。3635在 v2.1.273 之前,Claude Code 在这种情况下会改为显示 `Admin permissions required` 警告。
3570 3636
3571<h3 id="failed-to-resume-the-conversation">3637<h3 id="failed-to-resume-the-conversation">
3572 无法恢复对话3638 恢复对话失败
3573</h3>3639</h3>
3574 3640
3575Claude Code 无法读取或处理您从 [`claude --resume` 选择器](/docs/zh-CN/sessions#use-the-session-picker)选择的会话的保存成绩单,所以它结束进程而不是在部分加载状态下继续。消息包括重试的命令:3641Claude Code 无法读取或处理您从 [`claude --resume` 选择器](/docs/zh-CN/sessions#use-the-session-picker)中选择的会话的已保存会话记录,因此会结束进程,而不是在部分加载的状态下继续。消息中包含用于重试的命令:
3576 3642
3577```text theme={null}3643```text theme={null}
3578Failed to resume the conversation.3644Failed to resume the conversation.
3579Run claude --resume <session-id> to retry, or claude to start a new session.3645Run claude --resume <session-id> to retry, or claude to start a new session.
3580```3646```
3581 3647
3582Claude Code 显示消息后以代码 1 退出。运行会话内的 `/resume` 选择器报告对话中的 `Failed to resume conversation`,您当前的会话保持运行。在 v2.1.216 之前,来自 `claude --resume` 选择器的失败恢复在 `Resuming conversation…` 微调器上无限期停留,而不是显示此消息。3648显示该消息后,Claude Code 以退出码 1 退出。正在运行的会话中的 `/resume` 选择器则会在对话中报告 `Failed to resume conversation`,而您当前的会话会继续运行。在 v2.1.216 之前,从 `claude --resume` 选择器恢复失败时,会一直停留在 `Resuming conversation…` 加载动画上,而不是显示此消息。
3583 3649
3584**应该做什么:**3650**解决方法:**
3585 3651
3586* 使用消息中的会话 ID 运行 `claude --resume <session-id>` 重试3652* 使用消息中的会话 ID 运行 `claude --resume <session-id>` 进行重试
3587* 如果每次重试都以相同的方式失败,运行 `claude update` 并再次恢复。v2.1.275 之前的版本在保存的成绩单包含它们无法读取的条目时恢复失败。3653* 在 v2.1.285 之前的版本上,如果重试以同样的方式失败,请运行 `claude update` 后再次恢复。当已保存的会话记录包含这些版本无法读取的条目时,这些版本会恢复失败。
3588* 如果重试再次失败,运行 `claude` 启动新会话3654* 如果重试再次失败,请运行 `claude` 启动新会话
3589 3655
3590<h3 id="no-conversation-found-with-the-session-id">3656<h3 id="no-conversation-found-with-the-session-id">
3591 未找到具有会话 ID 的对话3657 No conversation found with the session ID
3592</h3>3658</h3>
3593 3659
3594您将会话 ID 传递给 `claude --resume <session-id>`,没有保存的成绩单与其匹配:3660您向 `claude --resume <session-id>` 传入了一个会话 ID,但没有任何已保存的会话记录与之匹配:
3595 3661
3596```text theme={null}3662```text theme={null}
3597No conversation found with session ID: <session-id>3663No conversation found with session ID: <session-id>
3598```3664```
3599 3665
3600Claude Code 显示消息后以代码 1 退出。Claude Code [首先搜索当前项目,然后搜索此机器上的所有其他项目](/docs/zh-CN/sessions#resume-a-session)以查找 ID。在 v2.1.223 之前,查找停止在当前项目目录及其 git worktrees,所以从会话最后工作的目录恢复。3666显示该消息后,Claude Code 以退出码 1 退出。Claude Code 会[先在当前项目中搜索该 ID,然后在本机的所有其他项目中搜索](/docs/zh-CN/sessions#resume-a-session)。在 v2.1.223 之前,查找范围仅限于当前项目目录及其 git worktree,因此需要从该会话最后工作的目录中恢复会话。
3601 3667
3602常见原因:3668常见原因:
3603 3669
3604* **打字错误的 ID**:对于非交互运行,ID 是 [`--output-format json` 输出](/docs/zh-CN/headless#get-structured-output)的 `session_id` 字段3670* **ID 输入错误**:对于非交互式运行,ID 是 [`--output-format json` 输出](/docs/zh-CN/headless#get-structured-output)中的 `session_id` 字段
3605* **删除的成绩单**:Claude Code 在[保留期](/docs/zh-CN/sessions#where-transcripts-are-stored)后删除成绩单,默认 30 天,遵循[保留扫描规则](/docs/zh-CN/claude-directory#cleaned-up-automatically)3671* **会话记录已删除**:Claude Code 会在[保留期](/docs/zh-CN/sessions#where-transcripts-are-stored)(默认 30 天)之后按照[保留清理规则](/docs/zh-CN/claude-directory#cleaned-up-automatically)删除会话记录
3606* **不同的机器**:Claude Code 在本地存储成绩单,所以在运行它的机器上恢复会话3672* **不同的机器**:Claude Code 将会话记录存储在本地,因此请在运行该会话的机器上恢复它
3607* **重复副本**:如果您在 `~/.claude/projects` 下复制了项目目录,所以两个成绩单携带相同的 ID,Claude Code 报告此消息而不是任意恢复一个副本3673* **重复副本**:如果您复制了 `~/.claude/projects` 下的某个项目目录,导致两个会话记录带有相同的 ID,Claude Code 会报告此消息,而不是任意恢复其中一个副本
3608 3674
3609**应该做什么:**3675**处理方法:**
3610 3676
3611* 对于交互会话,使用 `claude --resume` 打开[会话选择器](/docs/zh-CN/sessions#use-the-session-picker),按 `Ctrl+A` 将其扩展到此机器上的每个项目,然后选择会话3677* 对于交互式会话,使用 `claude --resume` 打开[会话选择器](/docs/zh-CN/sessions#use-the-session-picker),按 `Ctrl+A` 将范围扩大到本机的所有项目,然后选择该会话
3612* 使用 `claude -p` 或 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 创建的会话不会出现在选择器中,所以重新检查 ID 与您的原始运行打印的 `session_id`3678* 使用 `claude -p` 或 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 创建的会话不会出现在选择器中,因此请对照原始运行输出的 `session_id` 重新核对 ID
3613 3679
3614<h3 id="windows-reported-an-error-ebadf">3680<h3 id="windows-reported-an-error-ebadf">
3615 Windows 在 Claude Code 读取此会话的成绩单文件时报告了错误 (EBADF)3681 Windows reported an error (EBADF) when Claude Code read this session's transcript file
3616</h3>3682</h3>
3617 3683
3618您在 Windows 上恢复了会话,其保存的[成绩单文件](/docs/zh-CN/sessions#where-transcripts-are-stored)正常打开,读取它然后失败,显示系统错误 EBADF。系统错误没有说读取失败的原因,所以消息建议可能的原因和要尝试的内容:3684您在 Windows 上恢复了一个会话,其已保存的[会话记录文件](/docs/zh-CN/sessions#where-transcripts-are-stored)正常打开,但随后读取时因系统错误 EBADF 而失败。该系统错误并未说明读取失败的原因,因此该消息会列出可能的原因以及可尝试的操作:
3619 3685
3620```text theme={null}3686```text theme={null}
3621Windows reported an error (EBADF) when Claude Code read this session's transcript file, although the file had opened normally. This can happen when other software intercepts file reads — security, encryption or endpoint-management tools, for example. If it keeps happening for this conversation, try excluding the folder that holds Claude Code's session transcripts from such software (the .claude folder in your user profile, unless the app or CLAUDE_CONFIG_DIR points Claude Code elsewhere), or adding Claude Code to its allowed applications, then resume again.3687Windows reported an error (EBADF) when Claude Code read this session's transcript file, although the file had opened normally. This can happen when other software intercepts file reads — security, encryption or endpoint-management tools, for example. If it keeps happening for this conversation, try excluding the folder that holds Claude Code's session transcripts from such software (the .claude folder in your user profile, unless the app or CLAUDE_CONFIG_DIR points Claude Code elsewhere), or adding Claude Code to its allowed applications, then resume again.
3622```3688```
3623 3689
3624消息遵循命令自己的失败行,例如 `Failed to resume session <session-id>`。`claude --resume` 或 [`claude -p`](/docs/zh-CN/headless) 命令显示它后以代码 1 退出。在会话内的 `/resume` 后,您当前的会话保持运行。3690该消息紧跟在命令自身的失败行之后,例如 `Failed to resume session <session-id>`。`claude --resume` 或 [`claude -p`](/docs/zh-CN/headless) 命令在显示该消息后以退出码 1 退出。如果是在会话中执行 `/resume`,您当前的会话会继续运行。
3625 3691
3626**应该做什么:**3692**处理方法:**
3627 3693
3628* 从扫描或拦截文件读取的软件(例如安全、加密或端点管理工具)中排除保存会话成绩单的文件夹。成绩单默认位于 `%USERPROFILE%\.claude\projects` 下,或位于 [`CLAUDE_CONFIG_DIR`](/docs/zh-CN/env-vars) 命名的目录下3694* 将存放会话记录的文件夹从扫描或拦截文件读取的软件(例如安全、加密或终端管理工具)中排除。会话记录默认位于 `%USERPROFILE%\.claude\projects` 下,或位于 [`CLAUDE_CONFIG_DIR`](/docs/zh-CN/env-vars) 指定的目录下
3629* 如果您无法添加排除,请改为将 Claude Code 添加到该软件的允许应用程序3695* 如果无法添加排除项,请改为将 Claude Code 添加到该软件的允许应用程序中
3630* 再次恢复会话3696* 再次恢复该会话
3631 3697
3632在 v2.1.282 之前,失败没有解释:`claude --resume <session-id>` 在 `Failed to resume session <session-id>` 处结束,`-p` 运行仅打印系统错误文本,例如 `Failed to resume session: EBADF: bad file descriptor, read`。3698在 v2.1.282 之前,该失败不附带任何说明:`claude --resume <session-id>` 以 `Failed to resume session <session-id>` 结束,而 `-p` 运行只输出系统错误文本,例如 `Failed to resume session: EBADF: bad file descriptor, read`。
3633 3699
3634<h3 id="cannot-switch-renderers-in-this-session">3700<h3 id="cannot-switch-renderers-in-this-session">
3635 无法在此会话中切换渲染器3701 Cannot switch renderers in this session
3636</h3>3702</h3>
3637 3703
3638当您切换渲染器时,Claude Code 重新启动其进程。您在 Claude Code 拒绝重新启动的会话中运行了 [`/tui`](/docs/zh-CN/fullscreen#enable-fullscreen-rendering),所以它不切换并保存任何内容。您看到的消息告诉您原因:3704切换渲染器时,Claude Code 会重启其进程。您在一个 Claude Code 拒绝重启的会话中运行了 [`/tui`](/docs/zh-CN/fullscreen#enable-fullscreen-rendering),因此它不会切换,也不会保存任何内容。您看到的消息会指明原因:
3639 3705
3640* `Cannot switch renderers while work is running in the background`:您有在后台运行的工作,重新启动会放弃,例如后台 shell 或子代理。等待工作完成或使用 [`/tasks`](/docs/zh-CN/commands) 停止它,然后再次运行 `/tui fullscreen` 或 `/tui default`3706* `Cannot switch renderers while work is running in the background`:您有正在运行的后台工作,重启会将其丢弃,例如后台 shell 或子代理。请等待工作完成或使用 [`/tasks`](/docs/zh-CN/commands) 停止它,然后再次运行 `/tui fullscreen` 或 `/tui default`
3641* `Cannot switch renderers in this session`:会话有 Claude Code 无法传递给重新启动的进程的限制。在 v2.1.234 之前,Claude Code 无论如何都会重新启动,重新启动的会话运行时没有它们3707* `Cannot switch renderers in this session`:该会话带有 Claude Code 无法传递给重启后进程的限制。在 v2.1.234 之前,Claude Code 仍会重启,而重新启动的会话将不带这些限制运行
3642 3708
3643在限制消息中,括号中的部分命名 Claude Code 找到的限制:3709在限制相关的消息中,括号内的部分列出了 Claude Code 发现的限制:
3644 3710
3645```text theme={null}3711```text theme={null}
3646Cannot switch renderers in this session — it has restrictions a restart can't carry over (permission rules set for this session only). Nothing was changed. Running /tui fullscreen in a session started without them switches every later session too.3712Cannot switch renderers in this session — it has restrictions a restart can't carry over (permission rules set for this session only). Nothing was changed. Running /tui fullscreen in a session started without them switches every later session too.
3647```3713```
3648 3714
3649消息可以在括号中显示的每个原因:3715该消息括号中可能显示的各项原因:
3650 3716
3651* `launch flags: a custom system prompt, a tool allowlist, or restricted settings`:您使用 Claude Code 不传递回重新启动的进程的标志启动了会话。这些标志包括 [`--system-prompt`](/docs/zh-CN/cli-reference#cli-flags)、`--system-prompt-file`、`--append-system-prompt-file`、[`--tools`](/docs/zh-CN/cli-reference#cli-flags) 允许列表、[`--setting-sources`](/docs/zh-CN/cli-reference#cli-flags) 和 [`--permission-prompt-tool`](/docs/zh-CN/cli-reference#cli-flags)3717* `launch flags: a custom system prompt, a tool allowlist, or restricted settings`:您使用了 Claude Code 不会传回给重启后进程的标志启动会话。这些标志包括 [`--system-prompt`](/docs/zh-CN/cli-reference#cli-flags)、`--system-prompt-file`、`--append-system-prompt-file`、[`--tools`](/docs/zh-CN/cli-reference#cli-flags) 允许列表、[`--setting-sources`](/docs/zh-CN/cli-reference#cli-flags) 和 [`--permission-prompt-tool`](/docs/zh-CN/cli-reference#cli-flags)
3652* `permission rules set for this session only`:来自钩子或 SDK 调用者的[权限更新](/docs/zh-CN/hooks#permission-update-entries)添加了带有 `session` 目标的拒绝或询问规则。会话范围的允许规则不会触发拒绝。重新启动会删除它们,Claude Code 改为再次提示3718* `permission rules set for this session only`:来自 hook 或 SDK 调用方的[权限更新](/docs/zh-CN/hooks#permission-update-entries)添加了目标为 `session` 的 deny 或 ask 规则。会话范围的 allow 规则不会触发拒绝。重启会丢弃这些规则,Claude Code 会改为再次提示
3653* `ask-before-running rules with no command-line form`:来自钩子或 SDK 调用者的权限更新添加了询问规则以及 Claude Code 作为 `--allowed-tools` 和 `--disallowed-tools` 传递回的规则。不存在询问规则的标志3719* `ask-before-running rules with no command-line form`:来自 hook 或 SDK 调用方的权限更新在 Claude Code 以 `--allowed-tools` 和 `--disallowed-tools` 传回的规则之外添加了 ask 规则。ask 规则没有对应的标志
3654* `permission rules a command line cannot carry intact` 和 `added directories a command line cannot carry intact`:权限更新在会话中期添加了规则或目录路径。重新启动的进程的命令行无法将其文本作为相同的值继承3720* `permission rules a command line cannot carry intact` 和 `added directories a command line cannot carry intact`:权限更新在会话中途添加了规则或目录路径。重启后进程的命令行无法将其文本作为相同的值传递
3655 3721
3656**应该做什么:**3722**处理方法:**
3657 3723
3658* 在没有这些限制的会话中,运行 `/tui fullscreen`,或 `/tui default` 切换回。Claude Code 在那里保存 [`tui` 设置](/docs/zh-CN/settings-reference#tui)3724* 在不带这些限制启动的会话中运行 `/tui fullscreen`,或运行 `/tui default` 切换回来。Claude Code 会在该会话中保存 [`tui` 设置](/docs/zh-CN/settings-reference#tui)
3659 3725
3660<h3 id="couldnt-open-claude-desktop">3726<h3 id="couldnt-open-claude-desktop">
3661 无法打开 Claude Desktop3727 Couldn't open Claude Desktop
3662</h3>3728</h3>
3663 3729
3664您在会话中运行了 [`/desktop`](/docs/zh-CN/desktop#coming-from-the-cli) 或其别名 `/app`,或在您的 shell 中运行了 [`claude --desktop`](/docs/zh-CN/cli-reference#cli-flags),Claude Code 用来打开 Claude Desktop 的系统命令失败了。在 `/desktop` 后,会话保持在终端中;`claude --desktop` 打印消息而不带 `Error:` 前缀,并以状态 1 退出。3730您在会话中运行了 [`/desktop`](/docs/zh-CN/desktop#coming-from-the-cli) 或其别名 `/app`,或在 shell 中运行了 [`claude --desktop`](/docs/zh-CN/cli-reference#cli-flags),而 Claude Code 用于打开 Claude Desktop 的系统命令失败了。执行 `/desktop` 后,会话仍停留在终端中;`claude --desktop` 会输出不带 `Error:` 前缀的消息并以状态 1 退出。
3665 3731
3666括号中的文本命名失败的命令,带有其退出状态和其错误输出的第一行(如果它产生了)。在 macOS 上该命令是 `open`,如本例所示;在 Windows 上它是 `rundll32`:3732括号中的文本指明失败的命令,以及该命令产生的退出状态和错误输出的第一行(如有)。在 macOS 上,该命令为 `open`,如下例所示;在 Windows 上为 `rundll32`:
3667 3733
3668```text theme={null}3734```text theme={null}
3669Error: Couldn't open Claude Desktop (`open` exited 1: LSOpenURLsWithRole() failed for the URL claude://resume?session=<session-id> with error -10814). Open Claude Desktop and try again.3735Error: Couldn't open Claude Desktop (`open` exited 1: LSOpenURLsWithRole() failed for the URL claude://resume?session=<session-id> with error -10814). Open Claude Desktop and try again.
3670```3736```
3671 3737
3672**应该做什么:**3738**处理方法:**
3673 3739
3674* 自己打开 Claude Desktop,然后再次运行 `/desktop` 或 `claude --desktop`3740* 手动打开 Claude Desktop,然后再次运行 `/desktop` 或 `claude --desktop`
3675* 要读取失败命令的完整错误输出,使用 `/debug` 打开调试日志并再次运行 `/desktop`,或运行 `claude --desktop --debug-file <path>`,然后检查调试日志3741* 要查看失败命令的完整错误输出,请使用 `/debug` 启用调试日志并再次运行 `/desktop`,或运行 `claude --desktop --debug-file <path>`,然后查看调试日志
3676 3742
3677在 v2.1.285 之前,消息以 `Open Claude Desktop and run /desktop again.` 结尾。在 v2.1.275 之前,它是 `Failed to open Claude Desktop. Please try opening it manually.`,没有说什么失败了。3743在 v2.1.285 之前,该消息以 `Open Claude Desktop and run /desktop again.` 结尾。在 v2.1.275 之前,该消息为 `Failed to open Claude Desktop. Please try opening it manually.`,且不说明失败的内容。
3678 3744
3679<h3 id="terminal-setup-left-your-zed-keymap-unchanged">3745<h3 id="terminal-setup-left-your-zed-keymap-unchanged">
3680 /terminal-setup 保持您的 Zed 快捷键不变3746 /terminal-setup left your Zed keymap unchanged
3681</h3>3747</h3>
3682 3748
3683您在 Zed 中运行了 [`/terminal-setup`](/docs/zh-CN/terminal-config#enter-multiline-prompts),Claude Code 无法完成对您的 Zed `keymap.json` 的更新,所以它保持文件不变。3749您在 Zed 中运行了 [`/terminal-setup`](/docs/zh-CN/terminal-config#enter-multiline-prompts),但 Claude Code 无法完成对 Zed `keymap.json` 的更新,因此保留了该文件原样。
3684 3750
3685每条消息命名您的快捷键的路径,并以您自己添加的快捷键块结尾:3751每条消息都会给出您的 keymap 路径,并在末尾附上需要您自行添加的快捷键块:
3686 3752
3687```text theme={null}3753```text theme={null}
3688Couldn't update your Zed keymap, so it was left unchanged.3754Couldn't update your Zed keymap, so it was left unchanged.
3690{ "context": "Terminal", "bindings": { "shift-enter": ["terminal::SendText", "\u001b\r"] } }3756{ "context": "Terminal", "bindings": { "shift-enter": ["terminal::SendText", "\u001b\r"] } }
3691```3757```
3692 3758
3693消息的第一行命名原因:3759消息的第一行指明原因:
3694 3760
3695* `Couldn't read your Zed keymap, so it was left unchanged.`:Claude Code 无法读取文件,例如由于文件权限3761* `Couldn't read your Zed keymap, so it was left unchanged.`:Claude Code 无法读取该文件,例如由于文件权限问题
3696* `Your Zed keymap isn't a readable list of keybindings, so it was left unchanged.`:文件读取正常但不解析为快捷键块数组,即使允许 `//` 注释和尾随逗号3762* `Your Zed keymap isn't a readable list of keybindings, so it was left unchanged.`:文件读取正常,但即使允许 `//` 注释和尾随逗号,也无法解析为快捷键块数组
3697* `Couldn't back up your Zed keymap; not modifying it.`:Claude Code 无法将文件复制到其旁边的 `.bak` 备份,所以它没有更改任何内容3763* `Couldn't back up your Zed keymap; not modifying it.`:Claude Code 无法将该文件复制为同目录下的 `.bak` 备份,因此未做任何更改
3698* `Couldn't update your Zed keymap, so it was left unchanged.`:合并的结果没有验证为携带绑定的有效快捷键,所以 Claude Code 丢弃它而不是写入。具有重复键的快捷键块可能导致这种情况3764* `Couldn't update your Zed keymap, so it was left unchanged.`:合并后的结果未能验证为包含该绑定的有效 keymap,因此 Claude Code 将其丢弃而未写入。包含重复键的快捷键块可能导致此问题
3699 3765
3700**应该做什么:**3766**处理方法:**
3701 3767
3702* 将消息中的块复制到消息命名的路径处 `keymap.json` 中的顶级数组3768* 将消息中的块复制到消息所指路径下 `keymap.json` 的顶层数组中
3703* 对于 `isn't a readable list of keybindings`,修复语法错误,或使文件的顶级值成为数组,然后再次运行 `/terminal-setup`3769* 对于 `isn't a readable list of keybindings`,请修复语法错误,或将文件的顶层值改为数组,然后再次运行 `/terminal-setup`
3704 3770
3705在 v2.1.247 之前,`/terminal-setup` 无法解析使用 `//` 注释或尾随逗号的 Zed 快捷键,它用仅其自己的绑定替换整个文件,同时报告绑定已安装。要恢复较早版本替换的快捷键,请使用[输入多行提示](/docs/zh-CN/terminal-config#enter-multiline-prompts)下描述的 `.bak` 备份文件。3771在 v2.1.247 之前,`/terminal-setup` 无法解析使用 `//` 注释或尾随逗号的 Zed keymap,并且会用仅包含其自身绑定的内容替换整个文件,同时报告绑定已安装。要恢复被早期版本替换的 keymap,请使用[输入多行提示词](/docs/zh-CN/terminal-config#enter-multiline-prompts)中所述的 `.bak` 备份文件。
3706 3772
3707<h3 id="skill-usage-reports-are-not-available-on-this-connection">3773<h3 id="skill-usage-reports-are-not-available-on-this-connection">
3708 Skill 使用报告在此连接上不可用3774 Skill usage reports are not available on this connection
3709</h3>3775</h3>
3710 3776
3711您在[远程控制](/docs/zh-CN/remote-control)上、从您的手机或浏览器运行了 [`/skill-doctor`](/docs/zh-CN/skills#find-unused-skills)。Claude Code 不通过远程控制发送 skill 使用报告,改为用此消息回复:3777您通过 [Remote Control](/docs/zh-CN/remote-control) 从手机或浏览器运行了 [`/skill-doctor`](/docs/zh-CN/skills#find-unused-skills)。Claude Code 不会通过 Remote Control 发送 skill 使用报告,而是回复以下消息:
3712 3778
3713```text theme={null}3779```text theme={null}
3714Skill usage reports are not available on this connection.3780Skill usage reports are not available on this connection.
3715```3781```
3716 3782
3717**应该做什么:**3783**处理方法:**
3718 3784
3719* 在会话运行的机器上的终端中运行 `/skill-doctor`,或在那里运行 `claude -p "/skill-doctor"`3785* 在运行该会话的机器的终端中运行 `/skill-doctor`,或在该机器上运行 `claude -p "/skill-doctor"`
3720 3786
3721<h3 id="custom-output-styles-cant-be-selected-over-remote-control">3787<h3 id="custom-output-styles-cant-be-selected-over-remote-control">
3722 无法通过远程控制选择自定义输出样式3788 Custom output styles can't be selected over Remote Control
3723</h3>3789</h3>
3724 3790
3725您从移动应用或网络通过[远程控制](/docs/zh-CN/remote-control)运行了 [`/output-style`](/docs/zh-CN/output-styles#change-your-output-style),或命令在中继到会话的消息中到达。因为此类轮次可能不来自帐户所有者,Claude Code 仅在其上列出并选择[内置样式](/docs/zh-CN/output-styles#built-in-output-styles),并在命令列出样式或不识别您给出的名称时添加此通知。[自定义样式](/docs/zh-CN/output-styles#create-a-custom-output-style)名称获得与不存在的名称相同的回复:3791您通过 [Remote Control](/docs/zh-CN/remote-control) 从移动应用或网页运行了 [`/output-style`](/docs/zh-CN/output-styles#change-your-output-style),或者该命令来自转发到会话中的消息。由于此类轮次可能并非来自账户所有者,Claude Code 在该轮次中只列出和选择[内置样式](/docs/zh-CN/output-styles#built-in-output-styles),并在命令列出样式或无法识别您提供的名称时附加此提示。[自定义样式](/docs/zh-CN/output-styles#create-a-custom-output-style)名称得到的回复与不存在的名称相同:
3726 3792
3727```text theme={null}3793```text theme={null}
3728Custom output styles can't be selected over Remote Control or from a relayed message. Select one in the session itself, or pick a built-in style here.3794Custom output styles can't be selected over Remote Control or from a relayed message. Select one in the session itself, or pick a built-in style here.
3729```3795```
3730 3796
3731**应该做什么:**3797**处理方法:**
3732 3798
3733* 选择内置样式,例如 `/output-style concise`3799* 选择一个内置样式,例如 `/output-style concise`
3734* 要使用自定义样式,在项目的 `.claude/settings.local.json` 中设置 [`outputStyle`](/docs/zh-CN/settings-reference#outputstyle),或在会话自己的终端中运行 `/output-style <style>`(如果它有的话)3800* 要使用自定义样式,请在项目的 `.claude/settings.local.json` 中设置 [`outputStyle`](/docs/zh-CN/settings-reference#outputstyle),或者如果会话有自己的终端,在该终端中运行 `/output-style <style>`
3735 3801
3736<h3 id="output-styles-are-saved-to-local-settings-which-this-session-doesnt-load">3802<h3 id="output-styles-are-saved-to-local-settings-which-this-session-doesnt-load">
3737 输出样式保存到此会话不加载的本地设置3803 Output styles are saved to local settings which this session doesn't load
3738</h3>3804</h3>
3739 3805
3740您尝试在其设置源排除 `local` 的会话中使用 `/output-style <style>` 或 `/config outputStyle=<style>` 切换[输出样式](/docs/zh-CN/output-styles)。示例是 [`settingSources`](/docs/zh-CN/agent-sdk/typescript#options) 留出 `"local"` 的 [Agent SDK](/docs/zh-CN/agent-sdk/typescript) 会话,以及使用 [`--setting-sources`](/docs/zh-CN/cli-reference#cli-flags) 值启动的 CLI 会话,该值留出 `local`。两个命令都将样式保存到 `.claude/settings.local.json`,此类会话从不读取回的文件,所以 Claude Code 拒绝而不是写入无效的设置:3806您在一个设置来源不包含 `local` 的会话中,尝试使用 `/output-style <style>` 或 `/config outputStyle=<style>` 切换[输出样式](/docs/zh-CN/output-styles)。例如 [`settingSources`](/docs/zh-CN/agent-sdk/typescript#options) 中省略了 `"local"` 的 [Agent SDK](/docs/zh-CN/agent-sdk/typescript) 会话,以及使用省略了 `local` 的 [`--setting-sources`](/docs/zh-CN/cli-reference#cli-flags) 值启动的 CLI 会话。这两个命令都会将样式保存到 `.claude/settings.local.json`,而此类会话从不读取该文件,因此 Claude Code 会拒绝操作,而不是写入一个不会生效的设置:
3741 3807
3742```text theme={null}3808```text theme={null}
3743Output styles are saved to local settings (.claude/settings.local.json), which this session doesn't load, so the style can't be changed here.3809Output styles are saved to local settings (.claude/settings.local.json), which this session doesn't load, so the style can't be changed here.
3744```3810```
3745 3811
3746**应该做什么:**3812**处理方法:**
3813
3814* 将 `local` 添加到会话的设置来源中,然后再次切换
3815* 在会话确实会加载的设置文件中设置 [`outputStyle`](/docs/zh-CN/settings-reference#outputstyle) 键,例如项目中的 `.claude/settings.json` 或 `~/.claude/settings.json`。在 TypeScript SDK 中,请改为在内联 `settings` 对象中设置 `outputStyle`;请参阅[激活输出样式](/docs/zh-CN/agent-sdk/modifying-system-prompts#activate-an-output-style)
3816
3817<h3 id="recap-only-runs-when-you-ask-for-it-yourself">
3818 /recap only runs when you ask for it yourself
3819</h3>
3820
3821该 [`/recap`](/docs/zh-CN/interactive-mode#session-recap) 请求并非来自您自己的输入。它来自从 Slack、Teams 或[项目](/docs/zh-CN/claude-projects)线程转发到会话中的消息,或来自 [Routine](/docs/zh-CN/routines) 或其他程序发送的提示词。
3747 3822
3748* 将 `local` 添加到会话的设置源并再次切换3823即使转发的消息是您自己写的,也会收到此通知。Claude Code 无法判断转发或自动发送的消息是否来自运行该会话的账户所有者,因此会以此通知代替摘要进行回复:
3749* 在会话确实加载的设置文件中设置 [`outputStyle`](/docs/zh-CN/settings-reference#outputstyle) 键,例如项目中的 `.claude/settings.json` 或 `~/.claude/settings.json`。在 TypeScript SDK 中,改为在内联 `settings` 对象内设置 `outputStyle`;请参阅[激活输出样式](/docs/zh-CN/agent-sdk/modifying-system-prompts#activate-an-output-style)3824
3825```text theme={null}
3826/recap only runs when you ask for it yourself in this session: from the terminal, the Claude app or claude.ai/code, or over Remote Control. A message relayed from Slack, Teams or a project thread, or sent by a routine or another program, can't request it.
3827```
3828
3829您传给 `claude -p` 的 `/recap`,或由您自己的 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 应用程序发送到其所启动会话中的 `/recap`,都算作您自己的输入。
3830
3831**解决方法:**
3832
3833* 自行打开该会话并在其中运行 `/recap`:在其终端中、在 [Desktop 应用](/docs/zh-CN/desktop)或[移动应用](/docs/zh-CN/mobile)中、在 [claude.ai/code](https://claude.ai/code) 上,或通过 [Remote Control](/docs/zh-CN/remote-control)
3834* 如果是 Routine 或其他程序发送的,请从该提示词中删除 `/recap`
3750 3835
3751<h2 id="plugin-errors">3836<h2 id="plugin-errors">
3752 插件错误3837 插件错误
4474 后台会话错误4559 后台会话错误
4475</h2>4560</h2>
4476 4561
4477[后台会话](/docs/zh-CN/agent-view)在没有自己的交互式终端的情况下运行,因此需要终端的命令在那里的行为会有所不同。这些消息出现在后台会话的记录中、附加到后台会话的终端中、您分派的会话或 shell 中,或者对于下面的[worktree-guard 条目](#write-or-command-blocked-because-the-path-cannot-be-safely-resolved),出现在任何在 worktree 中隔离的会话或运行 worktree 隔离子代理中;当消息特定于一个表面时,其条目会说明这一点。4562[后台会话](/docs/zh-CN/agent-view)在没有自己的交互式终端的情况下运行,因此需要终端的命令在那里的行为会有所不同。这些消息出现在后台会话的会话记录中、附加到后台会话的终端中、您分派的会话或 shell 中,或者对于下面的[worktree-guard 条目](#write-or-command-blocked-because-the-path-cannot-be-safely-resolved),出现在任何在 worktree 中隔离的会话或运行 worktree 隔离子代理中;当消息特定于一个使用入口时,其条目会说明这一点。
4478 4563
4479<h3 id="commands-refused-in-a-background-session">4564<h3 id="commands-refused-in-a-background-session">
4480 后台会话中拒绝的命令4565 后台会话中拒绝的命令
4481</h3>4566</h3>
4482 4567
4483打开交互式对话框的命令在没有终端附加到后台会话时无法执行。`/install-github-app`、`/mcp` 设置列表和 MCP 服务器菜单中的身份验证操作会响应一条消息。对于 `/install-github-app` 和 `/mcp` 设置列表,该会话也在[代理视图](/docs/zh-CN/agent-view)中的**需要输入**下显示,以便您可以找到它、附加并再次运行该命令。附加终端时,这些命令正常工作。4568打开交互式对话框的命令在没有终端附加到后台会话时无法执行。`/install-github-app`、`/mcp` 设置列表和 MCP 服务器菜单中的身份验证操作会响应一条消息。对于 `/install-github-app` 和 `/mcp` 设置列表,该会话也在 [Agent 视图](/docs/zh-CN/agent-view)中的**需要输入**下显示,以便您可以找到它、附加并再次运行该命令。附加终端时,这些命令正常工作。
4484 4569
4485在 v2.1.216 之前,会话在拒绝 `/install-github-app` 或 `/mcp` 设置列表后不会在**需要输入**下显示。在 v2.1.213 到 v2.1.215 中,附加终端时命令仍然有效,拒绝消息告诉您附加并再次运行该命令。从 v2.1.208 到 v2.1.212,Claude Code 即使附加了终端也拒绝了它们,消息如 `Can't open MCP settings in a background session`;在这些版本上,从常规 `claude` 会话运行该命令,或升级。在 v2.1.208 之前,它们在后台会话内打开了对话框。在仅 v2.1.208 中,Claude Code 也拒绝了后台会话中的 `/model` 选择器,`/upgrade` 打印了升级 URL 而不是打开浏览器。4570在 v2.1.216 之前,会话在拒绝 `/install-github-app` 或 `/mcp` 设置列表后不会在**需要输入**下显示。在 v2.1.213 到 v2.1.215 中,附加终端时命令仍然有效,拒绝消息告诉您附加并再次运行该命令。从 v2.1.208 到 v2.1.212,Claude Code 即使附加了终端也拒绝了它们,消息如 `Can't open MCP settings in a background session`;在这些版本上,从常规 `claude` 会话运行该命令,或升级。在 v2.1.208 之前,它们在后台会话内打开了对话框。在仅 v2.1.208 中,Claude Code 也拒绝了后台会话中的 `/model` 选择器,`/upgrade` 打印了升级 URL 而不是打开浏览器。
4486 4571
4492 4577
4493**要做什么:**4578**要做什么:**
4494 4579
4495* 从代理视图附加到会话并再次运行该命令4580* 从 Agent 视图附加到会话并再次运行该命令
4496* 或使用消息命名的形式,例如 `/mcp reconnect <server>`、`/mcp enable` 或 `/mcp disable`,这些不需要附加即可工作4581* 或使用消息命名的形式,例如 `/mcp reconnect <server>`、`/mcp enable` 或 `/mcp disable`,这些不需要附加即可工作
4497 4582
4498<h3 id="write-or-command-blocked-because-the-path-cannot-be-safely-resolved">4583<h3 id="write-or-command-blocked-because-the-path-cannot-be-safely-resolved">
4509 4594
4510**要做什么:**4595**要做什么:**
4511 4596
4512* 通常什么都不做:完整消息作为工具错误发送给 Claude,Claude 使用它命名的直接路径重试。对于被阻止的文件编辑,对话视图仅显示简短的 `Error editing file` 行;完整消息出现在您使用 `Ctrl+O` 打开的记录视图中。被阻止的命令在其命令输出中打印它。4597* 通常什么都不做:完整消息作为工具错误发送给 Claude,Claude 使用它命名的直接路径重试。对于被阻止的文件编辑,对话视图仅显示简短的 `Error editing file` 行;完整消息出现在您使用 `Ctrl+O` 打开的会话记录视图中。被阻止的命令在其命令输出中打印它。
4513* 如果同一文件上的块重复,路径可能通过包含 `..` 的已提交符号链接运行,例如 `docs/current -> ../README.md`;要求 Claude 通过其真实路径而不是通过链接编辑目标文件4598* 如果同一文件上的阻止重复出现,路径可能通过包含 `..` 的已提交符号链接运行,例如 `docs/current -> ../README.md`;要求 Claude 通过其真实路径而不是通过链接编辑目标文件
4514 4599
4515<h3 id="write-or-command-blocked-because-the-path-names-a-network-location">4600<h3 id="write-or-command-blocked-because-the-path-names-a-network-location">
4516 写入或命令被阻止,因为路径命名网络位置4601 写入或命令被阻止,因为路径命名网络位置
4550* 要有意对主检出采取行动,在会话外的终端中自己运行该命令4635* 要有意对主检出采取行动,在会话外的终端中自己运行该命令
4551 4636
4552<h3 id="this-session-has-no-saved-transcript">4637<h3 id="this-session-has-no-saved-transcript">
4553 此会话没有保存的记录4638 此会话没有保存的会话记录
4554</h3>4639</h3>
4555 4640
4556您附加到一个停止的[后台会话](/docs/zh-CN/agent-view),该会话从另一个对话中用 `←` 或 `/background` 后台化,并在其第一个响应完成之前停止。在该第一个响应完成之前,对话仍然仅存在于后台化它的会话中,因此 `claude attach` 拒绝启动停止的会话,而不是在相同的会话 ID 下开始空白对话。消息以此会话的 `claude respawn` 命令结尾:4641您附加到一个停止的[后台会话](/docs/zh-CN/agent-view),该会话从另一个对话中用 `←` 或 `/background` 后台化,并在其第一个回复完成之前停止。在该第一个回复完成之前,对话仍然仅存在于后台化它的会话中,因此 `claude attach` 拒绝启动停止的会话,而不是在相同的会话 ID 下开始空白对话。消息以此会话的 `claude respawn` 命令结尾:
4557 4642
4558```text theme={null}4643```text theme={null}
4559This session has no saved transcript — it was stopped before its first response finished. If it was backgrounded from another conversation, that one is still intact; `claude respawn <id>` starts this one fresh.4644This session has no saved transcript — it was stopped before its first response finished. If it was backgrounded from another conversation, that one is still intact; `claude respawn <id>` starts this one fresh.
4560```4645```
4561 4646
4562在[代理视图](/docs/zh-CN/agent-view)中打开相同会话的行显示 `Press enter again to restart this session fresh` 在列表下方,在该行上第二次 `Enter` 使用空对话重启会话。在 v2.1.212 之前,打开该行显示拒绝消息,无法从代理视图重启。在 v2.1.211 之前,打开停止的会话无声地启动了该空白对话,并可能重新运行会话的原始提示。4647在 [Agent 视图](/docs/zh-CN/agent-view)中打开相同会话的行会在列表下方显示 `Press enter again to restart this session fresh`,在该行上第二次按 `Enter` 会使用空对话重启会话。在 v2.1.212 之前,打开该行显示拒绝消息,无法从 Agent 视图重启。在 v2.1.211 之前,打开停止的会话会无声地启动该空白对话,并可能重新运行会话的原始提示词。
4563 4648
4564**要做什么:**4649**要做什么:**
4565 4650
4566* 您后台化的对话是完整的:使用 [`claude --resume`](/docs/zh-CN/sessions) 恢复它或继续在其中工作4651* 您后台化的对话是完整的:使用 [`claude --resume`](/docs/zh-CN/sessions) 恢复它或继续在其中工作
4567* 要无论如何启动停止的会话,请使用消息中的 ID 运行 `claude respawn <id>`,或在代理视图中的其行上按 `Enter` 两次4652* 要无论如何启动停止的会话,请使用消息中的 ID 运行 `claude respawn <id>`,或在 Agent 视图中的其行上按 `Enter` 两次
4568* 如果会话确实完成了响应,您仍然在 v2.1.214 之前的版本上看到此拒绝,`~/.claude/projects` 中的不可读文件夹可能会使记录扫描错过保存的对话;更新到 v2.1.214 或更高版本,它在扫描期间容忍不可读的文件夹4653* 如果会话确实完成了回复,您仍然在 v2.1.214 之前的版本上看到此拒绝,`~/.claude/projects` 中的不可读文件夹可能会使会话记录扫描错过保存的对话;更新到 v2.1.214 或更高版本,它在扫描期间容忍不可读的文件夹
4569 4654
4570<h3 id="this-session-is-running-in-another-terminal">4655<h3 id="this-session-is-running-in-another-terminal">
4571 此会话在另一个终端中运行4656 此会话在另一个终端中运行
4572</h3>4657</h3>
4573 4658
4574您在[代理视图](/docs/zh-CN/agent-view)中打开了停止的会话的行,其保存的对话已在此机器上的另一个实时 Claude Code 进程中打开,因此 Claude Code 拒绝启动将写入相同记录的第二个进程。您看到的消息取决于[什么持有对话](/docs/zh-CN/agent-view#opening-a-session-says-the-conversation-is-already-open):4659您在 [Agent 视图](/docs/zh-CN/agent-view)中打开了停止的会话的行,其保存的对话已在此机器上的另一个实时 Claude Code 进程中打开,因此 Claude Code 拒绝启动将写入相同会话记录的第二个进程。您看到的消息取决于[什么持有对话](/docs/zh-CN/agent-view#opening-a-session-says-the-conversation-is-already-open):
4575 4660
4576```text theme={null}4661```text theme={null}
4577Can't open — this session is running in another terminal4662Can't open — this session is running in another terminal
4581* **`running in another terminal`**:终端持有对话,例如您使用 `claude --resume` 或 `/resume` 恢复它的终端。该行也显示 `Open in a terminal`。4666* **`running in another terminal`**:终端持有对话,例如您使用 `claude --resume` 或 `/resume` 恢复它的终端。该行也显示 `Open in a terminal`。
4582* **`already open in another running Claude session`**:另一个非交互式 Claude Code 进程持有它,例如相同对话的[后台会话](/docs/zh-CN/agent-view#the-supervisor-process)进程尚未退出。4667* **`already open in another running Claude session`**:另一个非交互式 Claude Code 进程持有它,例如相同对话的[后台会话](/docs/zh-CN/agent-view#the-supervisor-process)进程尚未退出。
4583 4668
4584Claude Code 保存您在打开行时键入的回复,并在会话下次启动时将其作为会话的下一个提示发送。4669Claude Code 保存您在打开行时键入的回复,并在会话下次启动时将其作为会话的下一个提示词发送。
4585 4670
4586**要做什么:**4671**要做什么:**
4587 4672
4593 此会话的保存对话不再在磁盘上4678 此会话的保存对话不再在磁盘上
4594</h3>4679</h3>
4595 4680
4596您打开了一个[后台会话](/docs/zh-CN/agent-view),该会话在后台服务关闭时结束,[记录清理](/docs/zh-CN/settings-reference#cleanupperioddays)随后删除了其保存的对话,例如在机器关闭数周后。通常打开这样的行会[恢复其保存的对话](/docs/zh-CN/agent-view#sessions-show-as-failed-after-shutdown)。没有什么可恢复的,Claude Code 拒绝而不是在不询问的情况下重新运行会话的原始提示:4681您打开了一个[后台会话](/docs/zh-CN/agent-view),该会话在后台服务关闭时结束,[会话记录清理](/docs/zh-CN/settings-reference#cleanupperioddays)随后删除了其保存的对话,例如在机器关闭数周后。通常打开这样的行会[恢复其保存的对话](/docs/zh-CN/agent-view#sessions-show-as-failed-after-shutdown)。没有什么可恢复的,Claude Code 拒绝而不是在不询问的情况下重新运行会话的原始提示词:
4597 4682
4598```text theme={null}4683```text theme={null}
4599This session's saved conversation is no longer on disk (it ended while the background service was off, and old transcripts are cleaned up), so there is nothing to resume. `claude rm 7c5dcf5d` deletes the row; `claude respawn 7c5dcf5d` runs its original prompt again instead.4684This session's saved conversation is no longer on disk (it ended while the background service was off, and old transcripts are cleaned up), so there is nothing to resume. `claude rm 7c5dcf5d` deletes the row; `claude respawn 7c5dcf5d` runs its original prompt again instead.
4600```4685```
4601 4686
4602`claude attach <id>` 打印此文本。在代理视图中,页脚更短,以 `ctrl+x deletes the row` 结尾。4687`claude attach <id>` 打印此文本。在 Agent 视图中,页脚更短,以 `ctrl+x deletes the row` 结尾。
4603 4688
4604**要做什么:**4689**要做什么:**
4605 4690
4606* 运行 `claude rm <id>` 删除该行。当[保留的情况](/docs/zh-CN/agent-view#what-deleting-a-session-removes)之一适用时,`claude rm` 保留该行和 worktree,并命名原因4691* 运行 `claude rm <id>` 删除该行。当[保留的情况](/docs/zh-CN/agent-view#what-deleting-a-session-removes)之一适用时,`claude rm` 保留该行和 worktree,并命名原因
4607* 要再次运行会话的原始提示作为新对话,请运行 `claude respawn <id>`4692* 要再次运行会话的原始提示词作为新对话,请运行 `claude respawn <id>`
4608 4693
4609在 v2.1.248 之前,打开这样的行会重新运行会话的原始提示,而不是拒绝,将数周前的任务拉回前景。4694在 v2.1.248 之前,打开这样的行会重新运行会话的原始提示词,而不是拒绝,将数周前的任务拉回前台。
4610 4695
4611<h3 id="worktree-has-commits-that-are-not-pushed-anywhere">4696<h3 id="worktree-has-commits-that-are-not-pushed-anywhere">
4612 Worktree 有未推送到任何地方的提交4697 Worktree 有未推送到任何地方的提交
4613</h3>4698</h3>
4614 4699
4615您尝试删除一个[后台会话](/docs/zh-CN/agent-view#what-deleting-a-session-removes),其 worktree 持有 Claude Code 无法确认保存在其他地方的提交。Claude Code 保留 worktree 和会话行,而不是销毁提交。`claude rm` 命名分支和未推送的提交,并说明如何继续:4700您尝试删除一个[后台会话](/docs/zh-CN/agent-view#what-deleting-a-session-removes),其 worktree 持有 Claude Code 无法确认保存在其他地方的提交。Claude Code 保留 worktree 和会话行,而不是在未查看的情况下销毁提交。`claude rm` 命名分支和未推送的提交,并说明如何继续:
4616 4701
4617```text theme={null}4702```text theme={null}
4618kept 7c5dcf5d — its worktree is still at "/home/you/project/.claude/worktrees/fix-login"4703kept 7c5dcf5d — its worktree is still at “/home/you/project/.claude/worktrees/fix-login”
4619 2 unpushed commits on "claude/fix-login": a1b2c3d "Fix login flow" and 1 more. They exist on no remote, so deleting the worktree would lose them.4704 2 unpushed commits on “claude/fix-login”: a1b2c3d “Fix login flow” and 1 more. They exist on no remote, so deleting the worktree would lose them.
4620 push them and run 'claude rm 7c5dcf5d' again, or discard the worktree and its commits: claude rm 7c5dcf5d --discard-unpushed a1b2c3d000000000000000000000000000000000@0123456789abcdef0123456789abcdef4705 push them and run 'claude rm 7c5dcf5d' again, or discard the worktree and its commits: claude rm 7c5dcf5d --discard-unpushed a1b2c3d000000000000000000000000000000000@0123456789abcdef0123456789abcdef
4621```4706```
4622 4707
4623当 Claude Code 无法总结提交时,详细行读取 `The worktree has unpushed commits`。在[代理视图](/docs/zh-CN/agent-view)中,会话的行显示 `not deleted` 和相同的原因。4708当 Claude Code 无法总结提交时,详细行读取 `The worktree has unpushed commits`。在 [Agent 视图](/docs/zh-CN/agent-view)中,会话的行显示 `not deleted` 和相同的原因。
4624 4709
4625远程上的提交不会阻止删除。本地副本中您的 `origin` 远程的默认分支上的提交也不会,只要该分支在您的主检出中检出,即存储库目录本身而不是 worktree。4710远程上的提交不会阻止删除。本地副本中您的 `origin` 远程的默认分支上的提交也不会,只要该分支在您的主检出中检出,即仓库目录本身而不是 worktree。
4626 4711
4627**要做什么:**4712**要做什么:**
4628 4713
4629* 要保留提交,推送 worktree 的分支,或将其合并到在主检出中检出的默认分支,然后再次删除会话4714* 要保留提交,推送 worktree 的分支,或将其合并到在主检出中检出的默认分支,然后再次删除会话
4630* 要丢弃提交,运行消息打印的 `claude rm <id> --discard-unpushed` 命令,或在代理视图中的会话行上再次按 `Ctrl+X`。这会删除会话和 worktree 以及其分支、未推送的提交和任何未提交的更改。如果 worktree 自拒绝以来获得了提交,Claude Code 再次保留它并显示更新的状态4715* 要丢弃提交,运行消息打印的 `claude rm <id> --discard-unpushed` 命令,或在 Agent 视图中的会话行上再次按 `Ctrl+X` 两次。这会删除会话和 worktree 以及其分支、未推送的提交和任何未提交的更改。如果 worktree 自拒绝以来获得了提交,Claude Code 再次保留它并显示更新的状态
4631* 当消息说 worktree 也由另一个完成的会话记录时,再次删除不会丢弃它:推送提交,然后再次删除会话4716* 当消息说 worktree 也由另一个完成的会话记录时,再次删除不会丢弃它:推送提交,然后再次删除会话
4632 4717
4633在 v2.1.268 之前,`claude rm` 将提交摘要放在 `kept` 行本身上。当 `claude rm` 无法总结提交时,`kept` 行读取 `worktree has commits that are not pushed anywhere` 代替摘要。4718在 v2.1.268 之前,`claude rm` 将提交摘要放在 `kept` 行本身上。当 `claude rm` 无法总结提交时,`kept` 行读取 `worktree has commits that are not pushed anywhere` 代替摘要。
4642 4727
4643每个[后台会话的](/docs/zh-CN/agent-view)终端在后台服务下的主机进程中运行,该进程在服务仍然持有其连接时死亡,因此无法到达会话。4728每个[后台会话的](/docs/zh-CN/agent-view)终端在后台服务下的主机进程中运行,该进程在服务仍然持有其连接时死亡,因此无法到达会话。
4644 4729
4645在 Linux 和 WSL 上,后台服务每隔几秒检查每个主机进程,当进程已退出但其与服务的连接从未关闭时标记会话失败,并在[代理视图](/docs/zh-CN/agent-view#read-session-state)中的其行上显示原因:4730在 Linux 和 WSL 上,后台服务每隔几秒检查每个主机进程,当进程已退出但其与服务的连接从未关闭时标记会话失败,并在 [Agent 视图](/docs/zh-CN/agent-view#read-session-state)中的其行上显示原因:
4646 4731
4647```text theme={null}4732```text theme={null}
4648terminal host process died — press Enter to restart4733terminal host process died — press Enter to restart
4656 4741
4657对话无论如何都被保存。4742对话无论如何都被保存。
4658 4743
4659运行[shell 命令](/docs/zh-CN/agent-view#run-a-shell-command)的行显示 `terminal host process died — its output is gone; the command was not run again`,`claude attach` 打印 `This command's terminal host process died — its output is gone and the command was not run again`。Claude Code 从不为您重新运行该命令。4744运行 [shell 命令](/docs/zh-CN/agent-view#run-a-shell-command)的行显示 `terminal host process died — its output is gone; the command was not run again`,`claude attach` 打印 `This command's terminal host process died — its output is gone and the command was not run again`。Claude Code 从不为您重新运行该命令。
4660 4745
4661**要做什么:**4746**要做什么:**
4662 4747
4663* 在代理视图中,在失败的行上按 `Enter`;会话在新的主机进程上重启,对话恢复4748* 在 Agent 视图中,在失败的行上按 `Enter`;会话在新的主机进程上重启,对话恢复
4664* 从 shell,再次运行 `claude attach <id>`。Claude Code 打印 `Session <id>'s terminal host died — restarting it on a fresh one…` 并重新打开会话4749* 从 shell,再次运行 `claude attach <id>`。Claude Code 打印 `Session <id>'s terminal host died — restarting it on a fresh one…` 并重新打开会话
4665* 您无法以这种方式重启 shell 命令行;再次分派命令以重新运行它4750* 您无法以这种方式重启 shell 命令行;再次分派命令以重新运行它
4666 4751
4672 4757
4673您打开了一个[后台会话](/docs/zh-CN/agent-view),后台服务接受了打开,但大约十秒钟内没有输出到达,因此 Claude Code 得出结论,中继会话终端的进程无法传递输出,并结束尝试而不是等待。4758您打开了一个[后台会话](/docs/zh-CN/agent-view),后台服务接受了打开,但大约十秒钟内没有输出到达,因此 Claude Code 得出结论,中继会话终端的进程无法传递输出,并结束尝试而不是等待。
4674 4759
4675在代理视图中,Claude Code 在页脚中提供重启:4760在 Agent 视图中,Claude Code 在页脚中提供重启:
4676 4761
4677```text theme={null}4762```text theme={null}
4678Press enter again to restart this session — it isn't responding (its conversation is saved and resumes).4763Press enter again to restart this session — it isn't responding (its conversation is saved and resumes).
4684Couldn't attach to <id> — Session isn't responding — `claude stop <id>`, then `claude attach <id>` restarts it (the conversation is saved).4769Couldn't attach to <id> — Session isn't responding — `claude stop <id>`, then `claude attach <id>` restarts it (the conversation is saved).
4685```4770```
4686 4771
4687Claude Code 从不为您重启运行[shell 命令](/docs/zh-CN/agent-view#run-a-shell-command)的行,因为重启会再次运行该命令。4772Claude Code 从不为您重启运行 [shell 命令](/docs/zh-CN/agent-view#run-a-shell-command)的行,因为重启会再次运行该命令。
4688 4773
4689**要做什么:**4774**要做什么:**
4690 4775
4691* 在代理视图中,在同一行上再次按 `Enter`。Claude Code 停止无响应的进程并重启会话,对话恢复。没有第二次按下就不会停止任何东西4776* 在 Agent 视图中,在同一行上再次按 `Enter`。Claude Code 停止无响应的进程并重启会话,对话恢复。没有第二次按下就不会停止任何东西
4692* 从 shell,运行 `claude stop <id>`,然后 `claude attach <id>`4777* 从 shell,运行 `claude stop <id>`,然后 `claude attach <id>`
4693* 对于 shell 命令行,在代理视图中按 `Ctrl+X` 或运行 `claude stop <id>` 停止它;再次分派命令以重新运行它4778* 对于 shell 命令行,在 Agent 视图中按 `Ctrl+X` 或运行 `claude stop <id>` 停止它;再次分派命令以重新运行它
4694 4779
4695<h3 id="session-was-stopped-while-the-respawn-was-in-flight">4780<h3 id="session-was-stopped-while-the-respawn-was-in-flight">
4696 会话在 respawn 进行中时被停止4781 会话在 respawn 进行中时被停止
4702Session <id> was stopped while the respawn was in flight4787Session <id> was stopped while the respawn was in flight
4703```4788```
4704 4789
4705打开您刚刚分派的会话,当其进程仍在启动时,等待进程。在 v2.1.246 之前,在那一刻打开它可能会停止它并显示此消息。4790打开您刚刚分派的会话,当其进程仍在启动时,会改为等待进程。在 v2.1.246 之前,在那一刻打开它可能会停止它并显示此消息。
4706 4791
4707**要做什么:**4792**要做什么:**
4708 4793
4709* 如果您没有停止会话,在代理视图中再次打开其行或运行 `claude respawn <id>` 重启它4794* 如果您没有停止会话,在 Agent 视图中再次打开其行或运行 `claude respawn <id>` 重启它
4710* 如果您自己停止了它,没有什么剩下要做的:会话保持停止4795* 如果您自己停止了它,没有什么剩下要做的:会话保持停止
4711 4796
4712<h3 id="session-agent-no-longer-available">4797<h3 id="session-agent-no-longer-available">
4713 会话代理不再可用4798 会话 Agent 不再可用
4714</h3>4799</h3>
4715 4800
4716您恢复了一个正在运行[自定义代理](/docs/zh-CN/sub-agents#invoke-subagents-explicitly)的会话,使用 `--agent` 或 `agent` 设置启动,Claude Code 没有找到具有该名称的代理。它首先搜索会话的原始目录,当您[信任该工作区](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)时,然后搜索您恢复的目录。会话仍然恢复,但使用默认工具,因此代理的工具限制不再适用:4801您恢复了一个正在运行[自定义 Agent](/docs/zh-CN/sub-agents#invoke-subagents-explicitly) 的会话,该会话使用 `--agent` 或 `agent` 设置启动,Claude Code 没有找到具有该名称的 Agent。它首先搜索会话的原始目录(当您已[信任该工作区](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)时),然后搜索您恢复的目录。会话仍然恢复,但使用默认工具,因此 Agent 的工具限制不再适用:
4717 4802
4718```text theme={null}4803```text theme={null}
4719This session was running agent 'code-reviewer', which is no longer available (no agent by that name in /home/you/project). Continuing with the default tools and system prompt — the agent's tool restrictions no longer apply. To restore it, re-create the agent, or resume with an explicit --agent <name>.4804This session was running agent 'code-reviewer', which is no longer available (no agent by that name in /home/you/project). Continuing with the default tools and system prompt — the agent's tool restrictions no longer apply. To restore it, re-create the agent, or resume with an explicit --agent <name>.
4720```4805```
4721 4806
4722警告仅命名 Claude Code 搜索的目录,它出现在恢复的对话中,无论您唤醒[后台会话](/docs/zh-CN/agent-view)、运行 `/resume` 或 `claude --resume`,还是在[非交互式模式](/docs/zh-CN/headless)中恢复,它也发送到 stderr。使用 `--input-format stream-json` 的会话不显示它,因为 Agent SDK 在启动后提供代理。4807警告仅命名 Claude Code 搜索的目录,它出现在恢复的对话中,无论您唤醒[后台会话](/docs/zh-CN/agent-view)、运行 `/resume` 或 `claude --resume`,还是在[非交互模式](/docs/zh-CN/headless)中恢复,在非交互模式中它也会发送到 stderr。使用 `--input-format stream-json` 的会话不显示它,因为 Agent SDK 在启动后提供 Agent。
4723 4808
4724Claude Code 不保存回退到会话,因此警告在每次恢复时重复,直到您采取行动。内置 `claude` 代理不触发警告,因为回退到默认工具集对它没有改变。在 v2.1.216 之前,Claude Code 无声地继续作为默认代理,查找仅覆盖您恢复的目录,因此项目范围的代理在从另一个目录恢复时丢失。4809Claude Code 不会将回退保存到会话,因此警告在每次恢复时重复,直到您采取行动。内置 `claude` Agent 不触发警告,因为回退到默认工具集对它没有改变。在 v2.1.216 之前,Claude Code 无声地继续作为默认 Agent,查找仅覆盖您恢复的目录,因此项目范围的 Agent 在从另一个目录恢复时丢失。
4725 4810
4726**要做什么:**4811**要做什么:**
4727 4812
4728* 在会话的项目中的 `.claude/agents/<name>.md` 或个人代理的 `~/.claude/agents/<name>.md` 重新创建代理文件,然后再次恢复4813* 在会话的项目中的 `.claude/agents/<name>.md` 或个人 Agent 的 `~/.claude/agents/<name>.md` 重新创建 Agent 文件,然后再次恢复
4729* 或使用 `--agent <name>` 恢复,命名确实存在的代理,以改为作为该代理运行会话4814* 或使用 `--agent <name>` 恢复,命名确实存在的 Agent,以改为作为该 Agent 运行会话
4730* 如果代理是项目范围的,您还没有信任会话的原始目录,在那里运行一次 Claude Code,接受信任对话,然后再次恢复4815* 如果 Agent 是项目范围的,您还没有信任会话的原始目录,在那里运行一次 Claude Code,接受信任对话框,然后再次恢复
4731 4816
4732<h3 id="claude_code_process_wrapper-launcher-errors">4817<h3 id="claude_code_process_wrapper-launcher-errors">
4733 CLAUDE\_CODE\_PROCESS\_WRAPPER 启动器错误4818 CLAUDE\_CODE\_PROCESS\_WRAPPER 启动器错误
4739CLAUDE_CODE_PROCESS_WRAPPER: launcher `/opt/corp/launcher` is not an executable regular file4824CLAUDE_CODE_PROCESS_WRAPPER: launcher `/opt/corp/launcher` is not an executable regular file
4740```4825```
4741 4826
4742启动但在用 Claude Code 替换自己之前退出的启动器会使其启动的会话失败,会话在代理视图中的行报告启动器 `must exec, not daemonize`,后跟启动器打印的任何内容。无法启动或到达后台服务的会话因启动器报告启动器问题作为 `Couldn't reach the background service (...)` 内的原因。4827启动但在用 Claude Code 替换自己之前退出的启动器会使其启动的会话失败,会话在 Agent 视图中的行报告启动器 `must exec, not daemonize`,后跟启动器打印的任何内容。因启动器而无法启动或到达后台服务的会话会将启动器问题作为 `Couldn't reach the background service (...)` 内的原因报告。
4743 4828
4744**要做什么:**4829**要做什么:**
4745 4830
4746* 将变量设置为以调用 `exec "$@"` 结尾的可执行文件的绝对路径。有关完整合同,请参阅[启动器合同](/docs/zh-CN/corporate-launcher#the-launcher-contract)4831* 将变量设置为以调用 `exec "$@"` 结尾的可执行文件的绝对路径。有关完整合同,请参阅[启动器合同](/docs/zh-CN/corporate-launcher#the-launcher-contract)
4747* 检查 `/status`,它在其 Self-exec 条目中显示解析的启动命令,并在运行的后台服务不匹配时警告,或从 shell 运行 `claude daemon status`4832* 检查 `/status`,它在其 Self-exec 条目中显示解析的启动命令,并在运行的后台服务不匹配时警告,或从 shell 运行 `claude daemon status`
4748* 在[设置](/docs/zh-CN/corporate-launcher#set-up-the-launcher)的 `env` 块中修复值后,使用 `claude daemon stop --any` 重启后台服务,以便下一次分派启动一个包装的4833* 在[设置](/docs/zh-CN/corporate-launcher#set-up-the-launcher)的 `env` 块中修复值后,使用 `claude daemon stop --any` 重启后台服务,以便下一次分派启动一个包装的后台服务
4749 4834
4750<h3 id="eunknown-when-starting-a-background-session">4835<h3 id="eunknown-when-starting-a-background-session">
4751 启动后台会话时 EUNKNOWN4836 启动后台会话时 EUNKNOWN
4767 4852
4768**要做什么:**4853**要做什么:**
4769 4854
4770* 如果消息读取 `Couldn't start the session`,升级到 v2.1.212 或更高版本。在早期版本上,您也可以在单独的终端中首先运行 `claude daemon run`,然后再次启动后台会话。该命令在终端的前景中运行后台服务,因此服务仅在该终端保持打开时持续。4855* 如果消息读取 `Couldn't start the session`,升级到 v2.1.212 或更高版本。在早期版本上,您也可以在单独的终端中首先运行 `claude daemon run`,然后再次启动后台会话。该命令在终端的前台运行后台服务,因此服务仅在该终端保持打开时持续。
4771* 如果 npm 安装正在替换二进制文件,等待它完成,然后再次启动后台会话4856* 如果 npm 安装正在替换二进制文件,等待它完成,然后再次启动后台会话
4772* 如果错误在 v2.1.212 或更高版本上出现,而没有 npm 安装运行,请要求您的 Windows 管理员在限制策略中允许 Claude Code 可执行文件4857* 如果错误在 v2.1.212 或更高版本上出现,而没有 npm 安装运行,请向您的 Windows 管理员确认是否有限制策略阻止了 Claude Code 可执行文件
4773* 如果关闭终端时后台服务停止,Claude Code 在没有 PowerShell 的情况下启动了它。安装 PowerShell 7,或要求您的管理员解除对 PowerShell 的阻止,以便服务可以超越终端。4858* 如果关闭终端时后台服务停止,Claude Code 在没有 PowerShell 的情况下启动了它。安装 PowerShell 7,或要求您的管理员解除对 PowerShell 的阻止,以便服务可以超越终端。
4774 4859
4775<h3 id="eacces-when-starting-a-background-session">4860<h3 id="eacces-when-starting-a-background-session">
4776 启动后台会话时 EACCES4861 启动后台会话时 EACCES
4777</h3>4862</h3>
4778 4863
4779Claude Code 无法运行其自己的二进制文件来启动[后台服务](/docs/zh-CN/agent-view#the-supervisor-process),该服务托管后台会话。在 npm 安装上,这通常意味着 `npm install -g @anthropic-ai/claude-code` 在那一刻替换二进制文件,无论您运行它还是[自动更新程序](/docs/zh-CN/setup#auto-updates)运行。当您从[代理视图](/docs/zh-CN/agent-view)打开会话时,错误出现:4864Claude Code 无法运行其自己的二进制文件来启动[后台服务](/docs/zh-CN/agent-view#the-supervisor-process),该服务托管后台会话。在 npm 安装上,这通常意味着 `npm install -g @anthropic-ai/claude-code` 在那一刻替换二进制文件,无论您运行它还是[自动更新程序](/docs/zh-CN/setup#auto-updates)运行。当您从 [Agent 视图](/docs/zh-CN/agent-view)打开会话时,错误出现:
4780 4865
4781```text theme={null}4866```text theme={null}
4782Couldn't start the background service — spawn background service: EACCES: permission denied, posix_spawn '/usr/local/lib/node_modules/@anthropic-ai/claude-code/bin/claude'4867Couldn't start the background service — spawn background service: EACCES: permission denied, posix_spawn '/usr/local/lib/node_modules/@anthropic-ai/claude-code/bin/claude'
4795**要做什么:**4880**要做什么:**
4796 4881
4797* 等待几秒钟,然后打开会话或再次分派。当消息说 Claude Code 正在更新时,在更新完成后重试。4882* 等待几秒钟,然后打开会话或再次分派。当消息说 Claude Code 正在更新时,在更新完成后重试。
4798* 如果错误在没有 npm 安装运行时持续,您的用户无法运行已安装的二进制文件。检查其权限及其目录的,或重新安装 Claude Code。4883* 如果错误在没有 npm 安装运行时持续,您的用户无法运行已安装的二进制文件。检查其权限及其目录的权限,或重新安装 Claude Code。
4799 4884
4800<h3 id="background-service-exited-before-it-became-reachable">4885<h3 id="background-service-exited-before-it-became-reachable">
4801 后台服务在变得可达之前退出4886 后台服务在变得可达之前退出
4802</h3>4887</h3>
4803 4888
4804Claude Code 启动的进程作为[后台服务](/docs/zh-CN/agent-view#the-supervisor-process)在变得可达之前退出,因此 Claude Code 无法打开您的会话。当服务在退出前打印错误时,括号中的原因给出退出代码或信号以及服务打印的第一行,它命名停止它的内容:4889Claude Code 作为[后台服务](/docs/zh-CN/agent-view#the-supervisor-process)启动的进程在接受连接之前退出,因此 Claude Code 无法打开您的会话。当服务在退出前打印错误时,括号中的原因给出退出码或信号以及服务打印的第一行,它命名停止它的内容:
4805 4890
4806```text theme={null}4891```text theme={null}
4807Couldn't reach the background service (background service exited before it became reachable (exit code N): <the service's first error line>) — run 'claude daemon status'4892Couldn't reach the background service (background service exited before it became reachable (exit code N): <the service's first error line>) — run 'claude daemon status'
4808```4893```
4809 4894
4810当您从[代理视图](/docs/zh-CN/agent-view)打开会话时,相同的原因跟随 `Couldn't start the background service —`。当服务在退出前没有打印任何内容时,消息说 `nothing on stderr`。4895当您从 [Agent 视图](/docs/zh-CN/agent-view)打开会话时,相同的原因跟随 `Couldn't start the background service —`。当服务在退出前没有打印任何内容时,消息说 `nothing on stderr`。
4811 4896
4812Claude Code 使用服务的错误行报告失败。在 v2.1.246 之前,失败仅在 45 秒等待后显示,作为 `background service did not become reachable within 45s`,没有服务的错误行。4897Claude Code 使用服务的错误行报告失败。在 v2.1.246 之前,失败仅在 45 秒等待后显示,作为 `background service did not become reachable within 45s`,没有服务的错误行。
4813 4898
4814两个引用的原因有已知的原因:4899两个引用的原因有已知的成因:
4815 4900
4816* `Error: claude native binary not installed.`:npm 安装在那一刻替换 Claude Code 二进制文件,因此服务运行了 npm 的占位符。在安装完成后重试;如果没有安装运行的行持续,[完成 npm 安装](/docs/zh-CN/troubleshoot-install#native-binary-not-found-after-npm-install)。在 v2.1.257 之前,macOS npm 自更新在安装窗口期间的每次启动时产生此失败。4901* `Error: claude native binary not installed.`:npm 安装在那一刻替换 Claude Code 二进制文件,因此服务运行了 npm 的占位符。在安装完成后重试;如果在没有安装运行时该行持续出现,[完成 npm 安装](/docs/zh-CN/troubleshoot-install#native-binary-not-found-after-npm-install)。在 v2.1.257 之前,macOS npm 自更新在安装窗口期间的每次启动时产生此失败。
4817* 在 Windows 上,`nothing on stderr` 和退出代码 1,每次启动:`daemon.lock` 命名一个 Claude Code 既无法发信号也无法证明已消失的进程,因此每个新服务得出结论另一个持有锁并退出。Claude Code 可以证明其编写者已消失的锁会自动替换,不会产生此失败。当失败在每次启动时重复时,删除 `~/.claude/daemon.lock`,然后打开会话或再次分派。在 v2.1.257 之前,这样的锁阻止了每次启动,直到您删除了文件。4902* 在 Windows 上,`nothing on stderr` 和退出码 1,每次启动:`daemon.lock` 命名一个 Claude Code 既无法发信号也无法证明已消失的进程,因此每个新服务得出结论另一个持有锁并退出。Claude Code 可以证明其编写者已消失的锁会自动替换,不会产生此失败。当失败在每次启动时重复时,删除 `~/.claude/daemon.lock`,然后打开会话或再次分派。在 v2.1.257 之前,这样的锁阻止了每次启动,直到您删除了文件。
4818 4903
4819**要做什么:**4904**要做什么:**
4820 4905
4825 启动后台会话时工作目录不再存在4910 启动后台会话时工作目录不再存在
4826</h3>4911</h3>
4827 4912
4828您尝试在不再存在的目录中启动[后台会话](/docs/zh-CN/agent-view)。Claude Code 不启动会话,消息命名缺失的目录:4913您启动[后台会话](/docs/zh-CN/agent-view)所在的目录在会话启动期间被删除。Claude Code 不启动会话,消息命名缺失的目录:
4829 4914
4830```text theme={null}4915```text theme={null}
4831Couldn't start a background session (working directory no longer exists or is not accessible: /tmp/demo)4916Couldn't start a background session (working directory no longer exists or is not accessible: /tmp/demo)
4832```4917```
4833 4918
4834在 v2.1.257 之前,会话似乎启动,然后在代理视图中显示为具有相同原因的失败行。4919在 v2.1.257 之前,会话似乎启动,然后在 Agent 视图中显示为具有相同原因的失败行。
4835 4920
4836在 v2.1.281 之前,当您启动会话之前目录已经消失时,此消息也出现。该情况报告[`could not be resolved on disk`](#workspace-not-trusted-when-dispatching-a-background-session)。4921在 v2.1.281 之前,当您启动会话之前目录已经消失时,此消息也出现。该情况报告 [`could not be resolved on disk`](#workspace-not-trusted-when-dispatching-a-background-session)。
4837 4922
4838**要做什么:**4923**要做什么:**
4839 4924
4843 分派后台会话时工作区不受信任4928 分派后台会话时工作区不受信任
4844</h3>4929</h3>
4845 4930
4846您在未[信任](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)的目录中启动或重启[后台会话](/docs/zh-CN/agent-view),工作区信任对话无法出现以询问您。Claude Code 不启动会话:4931您在未[信任](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)的目录中启动或重启[后台会话](/docs/zh-CN/agent-view),工作区信任对话框无法出现以询问您。Claude Code 不启动会话:
4847 4932
4848```text theme={null}4933```text theme={null}
4849Workspace not trusted. Run `claude` in /path/to/project once and accept the trust prompt, then retry.4934Workspace not trusted. Run `claude` in /path/to/project once and accept the trust prompt, then retry.
4850```4935```
4851 4936
4852从会话自己的目录中的终端,相同的命令显示信任对话,并在您接受后启动会话。此消息出现在无法显示对话的地方,例如在脚本中,或当您从不同于其自己的目录重启会话时。4937从会话自己的目录中的终端,相同的命令会改为显示信任对话框,并在您接受后启动会话。此消息出现在无法显示对话框的地方,例如在脚本中,或当您从不同于其自己的目录重启会话时。
4853 4938
4854两个变体命名不同的原因:4939两个变体命名不同的原因:
4855 4940
4856* **`The home directory is trusted one session at a time`**:会话的目录是您的主目录。Claude Code 从不保存主目录的信任,因此在早期会话中接受那里的对话不计数。4941* **`The home directory is trusted one session at a time`**:会话的目录是您的主目录。Claude Code 从不保存主目录的信任,因此在早期会话中在那里接受对话框不计数。
4857* **`<path> could not be resolved on disk`**:Claude Code 无法在磁盘上找到会话的目录。4942* **`<path> could not be resolved on disk`**:Claude Code 无法在磁盘上找到会话的目录。
4858 4943
4944在 v2.1.286 之前,在 Windows 上,如果某个您已信任的目录的信任记录是以不同字母大小写的路径保存的,此消息也可能在该目录中出现。请更新到 v2.1.286 或更高版本。
4945
4859**要做什么:**4946**要做什么:**
4860 4947
4861* 在消息命名的目录中运行 `claude` 并接受信任对话,然后再次运行该命令4948* 在消息命名的目录中运行 `claude` 并接受信任对话框,然后再次运行该命令
4862* 对于主目录消息,从您的主目录中的终端运行该命令,以便对话可以出现,或改为从项目目录启动会话4949* 对于主目录消息,从您的主目录中的终端运行该命令,以便对话框可以出现,或改为从项目目录启动会话
4863* 对于 `could not be resolved on disk` 消息,重新创建目录,或从存在的目录启动新会话4950* 对于 `could not be resolved on disk` 消息,重新创建目录,或从存在的目录启动新会话
4864 4951
4865<h2 id="wrapper-and-ide-errors">4952<h2 id="wrapper-and-ide-errors">
5067在 v2.1.236 之前,Claude Code 在此类错误后退出而不打印消息。5154在 v2.1.236 之前,Claude Code 在此类错误后退出而不打印消息。
5068 5155
5069<h3 id="agent-descriptions-are-over-the-15000-token-limit">5156<h3 id="agent-descriptions-are-over-the-15000-token-limit">
5070 代理描述超过 15.0k 令牌限制5157 Agent 描述超过 15.0k token 限制
5071</h3>5158</h3>
5072 5159
5073Claude Code 将此警告显示为对话视图中的启动通知,而不是在 stderr 上。您的[子代理](/docs/zh-CN/sub-agents)(除了内置代理)的组合描述超过 Claude Code 估计的 15,000 个令牌。每个代理计算其名称加上其 `description` frontmatter。Claude Code 加载每个代理,无论总数是否超过限制,因此警告不会改变加载的内容。5160Claude Code 将此警告显示为对话视图中的启动通知,而不是在 stderr 上。您的[子代理](/docs/zh-CN/sub-agents)(内置子代理除外)的组合描述超过 Claude Code 估计的 15,000 个 token。每个 Agent 计算其名称加上其 `description` frontmatter。Claude Code 加载每个 Agent,无论总数是否超过限制,因此警告不会改变加载的内容。
5074 5161
5075```text theme={null}5162```text theme={null}
5076Agent descriptions are over the 15.0k-token limit (~16.2k tokens) · ask Claude to trim agent descriptions in .claude/agents/5163Agent descriptions are over the 15.0k-token limit (~16.2k tokens) · ask Claude to trim agent descriptions in .claude/agents/
5078 5165
5079**要做什么:**5166**要做什么:**
5080 5167
5081* 缩短您的代理文件的 `description` frontmatter,或要求 Claude 为您修剪它们。5168* 缩短您的 Agent 文件的 `description` frontmatter,或要求 Claude 为您修剪它们。
5082* 删除您不再使用的代理文件。5169* 删除您不再使用的 Agent 文件。
5083 5170
5084<h3 id="a-skill-command-or-workflow-wasnt-loaded-because-its-name-is-reserved">5171<h3 id="a-skill-command-or-workflow-wasnt-loaded-because-its-name-is-reserved">
5085 技能、命令或工作流未被加载,因为其名称是保留的5172 skill、命令或工作流未被加载,因为其名称是保留的
5086</h3>5173</h3>
5087 5174
5088技能文件夹、frontmatter `name`、`.claude/commands/` 中的文件或子文件夹,或[保存的工作流](/docs/zh-CN/workflows#save-the-workflow-for-reuse)使用名称 `anthropic-skills` 或以 `anthropic-skills:` 开头的名称。Claude Code [为从 claude.ai 同步的技能保留该名称](/docs/zh-CN/skills#names-reserved-for-synced-skills),不加载该项。5175skill 文件夹、frontmatter `name`、`.claude/commands/` 中的文件或子文件夹,或[保存的工作流](/docs/zh-CN/workflows#save-the-workflow-for-reuse)使用名称 `anthropic-skills` 或以 `anthropic-skills:` 开头的名称。Claude Code [为从 claude.ai 同步的 skill 保留该名称](/docs/zh-CN/skills#names-reserved-for-synced-skills),不加载该项。
5089 5176
5090Claude Code 将此警告显示为对话视图中的启动通知,而不是在 stderr 上:5177Claude Code 将此警告显示为对话视图中的启动通知,而不是在 stderr 上:
5091 5178
5093Not loaded: rename .claude/skills/anthropic-skills, then restart — its name uses "anthropic-skills", a name reserved for the skills synced from your claude.ai account5180Not loaded: rename .claude/skills/anthropic-skills, then restart — its name uses "anthropic-skills", a name reserved for the skills synced from your claude.ai account
5094```5181```
5095 5182
5096通知命名它拒绝的第一项:要重命名的文件夹或文件、要编辑的 `name:` 行,或要重命名的工作流。当拒绝多个项时,通知以计数结尾,例如 `· 2 more`,[调试日志](/docs/zh-CN/debug-your-config)命名每一个。5183通知命名它拒绝的第一项需要更改的内容:要重命名的文件夹或文件、要编辑的 `name:` 行,或要重命名的工作流。当拒绝多个项时,通知以计数结尾,例如 `· 2 more`,[调试日志](/docs/zh-CN/debug-your-config)命名每一个。
5097 5184
5098**要做什么:**5185**要做什么:**
5099 5186
5100* 重命名通知命名的项,或编辑它指向的 `name:` 行,然后重启会话。5187* 重命名通知命名的项,或编辑它指向的 `name:` 行,然后重启会话。
5101 5188
5102在 v2.1.282 之前,Claude Code 加载具有这些名称的技能和命令。5189在 v2.1.282 之前,Claude Code 加载具有这些名称的 skill 和命令。
5103 5190
5104<h3 id="workspace-has-not-been-trusted">5191<h3 id="workspace-has-not-been-trusted">
5105 工作区尚未被信任5192 工作区尚未被信任
5115 5202
5116* 在目录中运行 `claude` 并接受信任对话框。[项目允许规则和工作区信任](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)说明该接受涵盖的文件夹。5203* 在目录中运行 `claude` 并接受信任对话框。[项目允许规则和工作区信任](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)说明该接受涵盖的文件夹。
5117* 在[非交互模式](/docs/zh-CN/headless)中使用 `-p` 不显示对话框。使用消息打印的确切 `projects` 键在 `~/.claude.json` 中设置 `hasTrustDialogAccepted` 条目。5204* 在[非交互模式](/docs/zh-CN/headless)中使用 `-p` 不显示对话框。使用消息打印的确切 `projects` 键在 `~/.claude.json` 中设置 `hasTrustDialogAccepted` 条目。
5118* 如果消息命名 `.claude/settings.local.json` 并且您在 git 存储库外或主目录中启动了 Claude Code,请更新到 v2.1.200 或更高版本。版本 2.1.196 至 2.1.199 在这些工作区中将您自己的 `.claude/settings.local.json` 视为存储库提供的。在 v2.1.207 及更高版本上,如果您尚未信任该文件夹,在 git 存储库外更新是不够的:确定文件夹不在存储库内会运行 git,Claude Code 仅在您接受信任对话框后才运行该检查,因此请使用第一步。您的主目录和任何其他[配置主目录](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)是豁免的,不等待对话框。请参阅[项目允许规则和工作区信任](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)。5205* 如果消息命名 `.claude/settings.local.json` 并且您在 git 仓库外或主目录中启动了 Claude Code,请更新到 v2.1.200 或更高版本。版本 2.1.196 至 2.1.199 在这些工作区中将您自己的 `.claude/settings.local.json` 视为仓库提供的。在 v2.1.207 及更高版本上,如果您尚未信任该文件夹,在 git 仓库外仅更新是不够的:确定文件夹不在仓库内会运行 git,Claude Code 仅在您接受信任对话框后才运行该检查,因此请使用第一步。您的主目录和任何其他[配置主目录](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)是豁免的,不等待对话框。请参阅[项目允许规则和工作区信任](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)。
5119 5206
5120<h3 id="working-directory-is-a-network-path">5207<h3 id="working-directory-is-a-network-path">
5121 工作目录是网络路径5208 工作目录是网络路径
5122</h3>5209</h3>
5123 5210
5124Claude Code 不将网络路径添加为工作目录。查找网络路径可以联系它命名的主机,在 Windows 上该联系可以向主机发送您的凭据,因此 Claude Code 拒绝该路径而不查找它。当您使用此类路径运行 `/add-dir` 时,或作为启动时的警告,您会看到此消息。当它在启动时出现时,Claude Code 启动时不包含该目录。5211Claude Code 不将网络路径添加为工作目录。查找网络路径可能会联系它命名的主机,在 Windows 上该联系可能会向主机发送您的凭据,因此 Claude Code 拒绝该路径而不查找它。当您使用此类路径运行 `/add-dir` 时,或作为启动时的警告,您会看到此消息。当它在启动时出现时,Claude Code 启动时不包含该目录。
5125 5212
5126```text theme={null}5213```text theme={null}
5127\\server\share is a network path, which cannot be added as a working directory. On Windows, map the share to a drive letter and pass it at launch with --add-dir (a drive letter added mid-session does not yet carry remote-read trust).5214\\server\share is a network path, which cannot be added as a working directory. On Windows, map the share to a drive letter and pass it at launch with --add-dir (a drive letter added mid-session does not yet carry remote-read trust).
5131 5218
5132* UNC 共享,例如 `\\server\share`5219* UNC 共享,例如 `\\server\share`
5133* 自动挂载路径,例如 `/net/<host>`,除非您从该主机的自动挂载下的目录启动了 Claude Code5220* 自动挂载路径,例如 `/net/<host>`,除非您从该主机的自动挂载下的目录启动了 Claude Code
5134* 通过符号链接或连接到达网络位置的本地路径5221* 通过符号链接或连接点到达网络位置的本地路径
5135 5222
5136映射的驱动器号和 `\\wsl$` 路径不计为网络路径。5223映射的驱动器号和 `\\wsl$` 路径不计为网络路径。
5137 5224
5149 5236
5150您的会话符合[服务器托管设置](/docs/zh-CN/server-managed-settings)的条件,但 Claude Code 无法获取它们或无法应用服务器返回的内容,因此在交互式会话中显示此警告。5237您的会话符合[服务器托管设置](/docs/zh-CN/server-managed-settings)的条件,但 Claude Code 无法获取它们或无法应用服务器返回的内容,因此在交互式会话中显示此警告。
5151 5238
5152括号中的原因命名失败的内容,例如 `network error`、`request timed out` 或 `authentication rejected (401)`。原因 `no setting in the server response could be applied as written` 意味着服务器已应答,但它返回的设置都没有通过[验证](/docs/zh-CN/server-managed-settings#invalid-entries-in-delivered-settings)。在 v2.1.282 之前,此原因读取 `server returned invalid settings`。5239括号中的原因命名失败的内容,例如 `network error`、`request timed out` 或 `authentication rejected (401)`。原因 `no setting in the server response could be applied as written` 意味着服务器已应答,但它返回的设置都没有通过[验证](/docs/zh-CN/server-managed-settings#invalid-entries-in-delivered-settings)。在 v2.1.282 之前,此原因显示为 `server returned invalid settings`。
5153 5240
5154该行的其余部分说明会话运行的策略:5241该行的其余部分说明会话运行的策略:
5155 5242
5156* **从较早的成功获取缓存的设置**:Claude Code 在该缓存策略上运行会话,除了[扣留的环境变量](/docs/zh-CN/server-managed-settings#fetch-and-caching-behavior),行读取 `using cached policy`。5243* **从较早的成功获取缓存的设置**:Claude Code 在该缓存策略上运行会话,但[扣留的环境变量](/docs/zh-CN/server-managed-settings#fetch-and-caching-behavior)除外,该行显示 `using cached policy`。
5157* **无缓存**:Claude Code 在没有服务器托管设置的情况下运行会话,行读取 `no remote policy applied`。5244* **无缓存**:Claude Code 在没有服务器托管设置的情况下运行会话,该行显示 `no remote policy applied`。
5158 5245
5159**要做什么:**5246**要做什么:**
5160 5247
5176 5263
5177**要做什么:**5264**要做什么:**
5178 5265
5179* 再次启动 Claude Code 并批准对话框以在您的组织设置下继续。拒绝的对话框不被记住,因此在下一次启动时再次出现。5266* 再次启动 Claude Code 并批准对话框以在您的组织设置下继续。拒绝的对话框不会被记住,因此在下一次启动时会再次出现。
5180* 如果您对对话框列出的设置不确定,请在批准前询问维护您的组织托管设置的人5267* 如果您对对话框列出的设置不确定,请在批准前询问维护您的组织托管设置的人
5181 5268
5182<h3 id="managed-settings-block-the-default-model">5269<h3 id="managed-settings-block-the-default-model">
5183 托管设置阻止默认模型5270 托管设置阻止默认模型
5184</h3>5271</h3>
5185 5272
5186您的组织的[托管设置](/docs/zh-CN/managed-settings)阻止默认选项解析到的模型以及它可以降级到的每个模型。将在默认选项上启动的会话在启动时退出,而不是运行被阻止的模型。您看到的消息取决于阻止它的设置。当 [`deniedModels`](/docs/zh-CN/model-config#block-specific-models-or-versions) 列表阻止它时,消息读取:5273您的组织的[托管设置](/docs/zh-CN/managed-settings)阻止默认选项解析到的模型以及它可以降级到的每个模型。将在默认选项上启动的会话在启动时退出,而不是运行被阻止的模型。您看到的消息取决于阻止它的设置。当 [`deniedModels`](/docs/zh-CN/model-config#block-specific-models-or-versions) 列表阻止它时,消息显示为:
5187 5274
5188```text theme={null}5275```text theme={null}
5189Claude Code can't start: your organization's managed settings block the default model (claude-opus-5-5) in "deniedModels", and none of the models they allow can be used as the default instead. Ask your administrator to update "deniedModels" or "availableModels".5276Claude Code can't start: your organization's managed settings block the default model (claude-opus-5-5) in "deniedModels", and none of the models they allow can be used as the default instead. Ask your administrator to update "deniedModels" or "availableModels".
5190```5277```
5191 5278
5192当 `availableModels` 列表与 [`availableModelsMatch`](/docs/zh-CN/settings-reference#availablemodelsmatch) 设置为 `"exact"` 省略它时,消息读取:5279当 [`availableModelsMatch`](/docs/zh-CN/settings-reference#availablemodelsmatch) 设置为 `"exact"` 的 `availableModels` 列表省略它时,消息显示为:
5193 5280
5194```text theme={null}5281```text theme={null}
5195Claude Code can't start: your organization allows only the models listed in "availableModels", and none of them can be used as the default model (claude-opus-5-5 isn't listed). Ask your administrator to update "availableModels".5282Claude Code can't start: your organization allows only the models listed in "availableModels", and none of them can be used as the default model (claude-opus-5-5 isn't listed). Ask your administrator to update "availableModels".
5197 5284
5198**要做什么:**5285**要做什么:**
5199 5286
5200* 如果您管理设置,请将您的用户可以运行的模型添加到 `availableModels`,或缩小阻止每个回退的 `deniedModels` 条目。[阻止特定模型或版本](/docs/zh-CN/model-config#block-specific-models-or-versions)描述默认选项如何降级5287* 如果您管理设置,请将您的用户可以运行的模型添加到 `availableModels`,或缩小阻止每个备用模型的 `deniedModels` 条目。[阻止特定模型或版本](/docs/zh-CN/model-config#block-specific-models-or-versions)描述默认选项如何降级
5201* 如果您不管理它们,请将消息发送给您的管理员。您自己的设置文件无法扩大托管的 `availableModels` 或 `deniedModels` 列表5288* 如果您不管理它们,请将消息发送给您的管理员。您自己的设置文件无法扩大托管的 `availableModels` 或 `deniedModels` 列表
5202 5289
5203<h3 id="managed-settings-dont-allow-this-api-provider">5290<h3 id="managed-settings-dont-allow-this-api-provider">
5204 托管设置不允许此 API 提供商5291 托管设置不允许此 API 提供商
5205</h3>5292</h3>
5206 5293
5207您的组织的[托管设置](/docs/zh-CN/managed-settings)设置了 [`allowedProviders`](/docs/zh-CN/settings-reference#allowedproviders) 列表,会话的 API 提供商不在其上,或会话使用的端点不是按该条目要求的方式固定的。Claude Code 在启动前、登录前或会话下次联系 API 时拒绝。消息以允许的提供商开头:5294您的组织的[托管设置](/docs/zh-CN/managed-settings)设置了 [`allowedProviders`](/docs/zh-CN/settings-reference#allowedproviders) 列表,会话的 API 提供商不在其上,或会话使用的端点不是按该条目要求的方式固定的。Claude Code 在启动时、登录前或会话下次联系 API 时拒绝。消息以允许的提供商开头:
5208 5295
5209```text theme={null}5296```text theme={null}
5210Your organization's managed settings allow Claude Code to use: Anthropic API, Amazon Bedrock.5297Your organization's managed settings allow Claude Code to use: Anthropic API, Amazon Bedrock.
5211```5298```
5212 5299
5213当列表为空时,消息改为读取:5300当列表为空时,消息改为显示:
5214 5301
5215```text theme={null}5302```text theme={null}
5216Your organization's managed settings allow Claude Code to use no API provider at all (allowedProviders is an empty list), so it cannot start on this machine.5303Your organization's managed settings allow Claude Code to use no API provider at all (allowedProviders is an empty list), so it cannot start on this machine.
5217```5304```
5218 5305
5219当每个条目都无法识别时,括号读取 `(allowedProviders lists only unrecognized entries)` 代替。5306当每个条目都无法识别时,括号内容改为 `(allowedProviders lists only unrecognized entries)`。
5220 5307
5221**要做什么:**5308**要做什么:**
5222 5309
5223* 按照消息的 `To continue:` 步骤进行5310* 按照消息的 `To continue:` 步骤进行
5224* 如果您管理设置,消息的以 `Admins:` 开头的行命名要添加的条目或要固定的值,[`allowedProviders`](/docs/zh-CN/settings-reference#allowedproviders) 条目说明哪个源的 `env` 块可以固定它5311* 如果您管理设置,消息中以 `Admins:` 开头的行命名要添加的条目或要固定的值,[`allowedProviders`](/docs/zh-CN/settings-reference#allowedproviders) 条目说明哪个源的 `env` 块可以固定它
5225 5312
5226<h3 id="mcp-server-is-blocked-by-enterprise-managed-policy">5313<h3 id="mcp-server-is-blocked-by-enterprise-managed-policy">
5227 MCP 服务器被企业托管策略阻止5314 MCP 服务器被企业托管策略阻止
5228</h3>5315</h3>
5229 5316
5230您在 `/mcp` 中的服务器上选择了**重新连接**,或在那里重新打开了禁用的服务器,[限制 MCP 服务器](/docs/zh-CN/managed-mcp)的设置阻止了该服务器。Claude Code 拒绝连接它并显示:5317您在 `/mcp` 中的服务器上选择了**重新连接**,或在那里重新打开了禁用的服务器,而[限制 MCP 服务器](/docs/zh-CN/managed-mcp)的设置阻止了该服务器。Claude Code 拒绝连接它并显示:
5231 5318
5232```text theme={null}5319```text theme={null}
5233MCP server <name> is blocked by enterprise managed policy5320MCP server <name> is blocked by enterprise managed policy
5234```5321```
5235 5322
5236这些设置中的任何一个都可以产生消息:5323这些设置中的任何一个都可以产生该消息:
5237 5324
5238* 与服务器匹配的 [`deniedMcpServers`](/docs/zh-CN/managed-mcp#policy-based-control-with-allowlists-and-denylists) 条目,包括您自己的 `~/.claude/settings.json` 或项目的 `.claude/settings.json` 中的条目5325* 与服务器匹配的 [`deniedMcpServers`](/docs/zh-CN/managed-mcp#policy-based-control-with-allowlists-and-denylists) 条目,包括您自己的 `~/.claude/settings.json` 或项目的 `.claude/settings.json` 中的条目
5239* 服务器不匹配的 [`allowedMcpServers`](/docs/zh-CN/managed-mcp#policy-based-control-with-allowlists-and-denylists) 列表5326* 服务器不匹配的 [`allowedMcpServers`](/docs/zh-CN/managed-mcp#policy-based-control-with-allowlists-and-denylists) 列表
5240* [`strictPluginOnlyCustomization`](/docs/zh-CN/settings-reference#strictpluginonlycustomization) 与 `mcp` 锁定,这阻止在 `~/.claude.json` 和 `.mcp.json` 中配置的服务器5327* 锁定了 `mcp` 的 [`strictPluginOnlyCustomization`](/docs/zh-CN/settings-reference#strictpluginonlycustomization),这会阻止在 `~/.claude.json` 和 `.mcp.json` 中配置的服务器
5241* [`disableClaudeAiConnectors`](/docs/zh-CN/mcp#disable-claude-ai-connectors),当服务器是 claude.ai 连接器时5328* [`disableClaudeAiConnectors`](/docs/zh-CN/mcp#disable-claude-ai-connectors),当服务器是 claude.ai 连接器时
5242 5329
5243**要做什么:**5330**要做什么:**
5244 5331
5245* 检查您自己的用户和项目设置文件中的这些设置之一,并更改或删除它5332* 检查您自己的用户和项目设置文件中是否有这些设置之一,并更改或删除它
5246* 如果您自己的设置都不能解释该阻止,请询问您的管理员哪个托管设置阻止了服务器5333* 如果您自己的设置都不能解释该阻止,请询问您的管理员哪个托管设置阻止了服务器
5247 5334
5248在 v2.1.257 之前,`/mcp` 中的**重新连接**和重新启用可以连接中途策略更新阻止的服务器。5335在 v2.1.257 之前,`/mcp` 中的**重新连接**和重新启用可以连接被会话中途策略更新阻止的服务器。
5249 5336
5250<h3 id="managed-settings-document-could-not-be-parsed">5337<h3 id="managed-settings-document-could-not-be-parsed">
5251 托管设置文档无法解析5338 托管设置文档无法解析
5252</h3>5339</h3>
5253 5340
5254您的组织部署[托管设置](/docs/zh-CN/managed-settings),其中一个部署的文档存在但无法解析为 JSON 对象,因此 Claude Code 在启动时以代码 1 退出,而不是在没有文档携带的策略的情况下运行。该行在消息前命名失败的源:5341您的组织部署了[托管设置](/docs/zh-CN/managed-settings),其中一个部署的文档存在但无法解析为 JSON 对象,因此 Claude Code 在启动时以退出码 1 退出,而不是在没有该文档所携带策略的情况下运行。该行在消息前命名失败的源:
5255 5342
5256```text theme={null}5343```text theme={null}
5257/Library/Application Support/ClaudeCode/managed-settings.json: Managed settings document could not be parsed as a JSON object; none of its settings are in effect. Fix or remove it.5344/Library/Application Support/ClaudeCode/managed-settings.json: Managed settings document could not be parsed as a JSON object; none of its settings are in effect. Fix or remove it.
5260源是以下之一:5347源是以下之一:
5261 5348
5262* `managed-settings.json` 文件的路径或 `managed-settings.d` 下的放入文件5349* `managed-settings.json` 文件的路径或 `managed-settings.d` 下的放入文件
5263* macOS 托管首选项配置文件、`per-user managed preferences` 或 `device-level managed preferences`5350* macOS 托管首选项配置文件,`per-user managed preferences` 或 `device-level managed preferences`
5264* Windows 注册表值、`Registry: HKLM\SOFTWARE\Policies\ClaudeCode\Settings`5351* Windows 注册表值,`Registry: HKLM\SOFTWARE\Policies\ClaudeCode\Settings`
5265 5352
5266[查找 Claude Code 删除的条目](/docs/zh-CN/managed-settings#find-entries-claude-code-dropped)列出了使每个源无法解析的原因。5353[查找 Claude Code 删除的条目](/docs/zh-CN/managed-settings#find-entries-claude-code-dropped)列出了使每个源无法解析的原因。
5267 5354
5268Claude Code 拒绝启动,即使另一个管理员源提供有效策略。您在交互式会话、`claude -p`、Agent SDK 会话、[后台会话](/docs/zh-CN/agent-view)和大多数子命令(包括 `claude doctor`)中看到此错误。拒绝故意失败关闭:Claude Code 无法解析的文档中的设置无法被强制执行,启动时不运行会话会在没有组织控制的情况下运行。5355即使另一个管理员源提供了有效策略,Claude Code 也会拒绝启动。您在交互式会话、`claude -p`、Agent SDK 会话、[后台会话](/docs/zh-CN/agent-view)和大多数子命令(包括 `claude doctor`)中都会看到此错误。该拒绝有意采用失败关闭:Claude Code 无法解析的文档中的设置无法被强制执行,强行启动会在没有组织控制的情况下运行会话。
5269 5356
5270可解析文档中的架构问题不会产生此错误。[查找 Claude Code 删除的条目](/docs/zh-CN/managed-settings#find-entries-claude-code-dropped)涵盖 Claude Code 对其所做的操作。5357可解析文档中的 schema 问题不会产生此错误。[查找 Claude Code 删除的条目](/docs/zh-CN/managed-settings#find-entries-claude-code-dropped)涵盖 Claude Code 对此类问题的处理方式。
5271 5358
5272当 `managed-settings.d/` 目录存在但无法列出时,Claude Code 报告 `Managed settings drop-in directory could not be read:` 后跟基础错误。[查找 Claude Code 删除的条目](/docs/zh-CN/managed-settings#find-entries-claude-code-dropped)涵盖读取失败在启动时退出的时间。5359当 `managed-settings.d/` 目录存在但无法列出时,Claude Code 改为报告 `Managed settings drop-in directory could not be read:`,后跟底层错误。[查找 Claude Code 删除的条目](/docs/zh-CN/managed-settings#find-entries-claude-code-dropped)涵盖读取失败何时会在启动时退出。
5273 5360
5274**要做什么:**5361**要做什么:**
5275 5362
5276* 如果您管理计算机,修复命名的文档使其解析为 JSON 对象,或删除文件、配置文件或注册表值。空的 `managed-settings.json` 计为 `{}` 并不阻止启动。5363* 如果您管理计算机,请修复命名的文档使其解析为 JSON 对象,或删除文件、配置文件或注册表值。空的 `managed-settings.json` 计为 `{}`,不会阻止启动。
5277* 如果您不管理,请要求您的管理员修复部署的文档。您自己的设置文件中的任何内容都不会导致或清除此错误。5364* 如果您不管理,请要求您的管理员修复部署的文档。您自己的设置文件中的任何内容都不会导致或清除此错误。
5278 5365
5279<h3 id="unable-to-read-managed-policy-settings">5366<h3 id="unable-to-read-managed-policy-settings">
5280 无法读取托管策略设置5367 无法读取托管策略设置
5281</h3>5368</h3>
5282 5369
5283您的组织部署[托管设置](/docs/zh-CN/managed-settings),其中一个部署的源存在但无法读取,原因例如 I/O 错误而不是操作系统拒绝读取。没有其他管理员源提供策略,Claude Code 在启动时退出,而不是在没有源可能携带的策略的情况下运行:5370您的组织部署了[托管设置](/docs/zh-CN/managed-settings),其中一个部署的源存在但无法读取,原因例如 I/O 错误,而不是操作系统拒绝读取。在没有其他管理员源提供策略的情况下,Claude Code 在启动时退出,而不是在没有该源可能携带的策略的情况下运行:
5284 5371
5285```text theme={null}5372```text theme={null}
5286Unable to read managed policy settings.5373Unable to read managed policy settings.
5290Detail: <source>: <reason>5377Detail: <source>: <reason>
5291```5378```
5292 5379
5293在相同的状态下,登录流、来自已运行的会话的 API 请求和 [`claude gateway`](/docs/zh-CN/claude-apps-gateway) 服务器被拒绝,其中第一行的变体命名 [`allowedProviders`](/docs/zh-CN/settings-reference#allowedproviders)。5380在相同的状态下,登录流程、来自已运行会话的 API 请求和 [`claude gateway`](/docs/zh-CN/claude-apps-gateway) 服务器会被拒绝,并显示第一行的一个变体,其中命名 [`allowedProviders`](/docs/zh-CN/settings-reference#allowedproviders)。
5294 5381
5295操作系统拒绝的读取,例如在仅限 root 的文件上,不会产生此退出:[会话启动时不使用该源的策略](/docs/zh-CN/managed-settings#find-entries-claude-code-dropped)。对于无法解析的源,Claude Code 以[不同的消息命名源](#managed-settings-document-could-not-be-parsed)退出。5382操作系统拒绝的读取(例如对仅限 root 的文件)不会导致此退出:[会话启动时不使用该源的策略](/docs/zh-CN/managed-settings#find-entries-claude-code-dropped)。对于无法解析的源,Claude Code 以[命名该源的不同消息](#managed-settings-document-could-not-be-parsed)退出。
5296 5383
5297**要做什么:**5384**要做什么:**
5298 5385
5299* 如果您管理计算机,修复 `Detail:` 行命名的问题,以便部署的源可以被读取,或删除源5386* 如果您管理计算机,请修复 `Detail:` 行命名的问题,以便部署的源可以被读取,或删除该源
5300* 如果您不管理,请将消息发送给您的管理员。您自己的设置文件中的任何内容都不会导致或清除此错误5387* 如果您不管理,请将消息发送给您的管理员。您自己的设置文件中的任何内容都不会导致或清除此错误
5301 5388
5302在 v2.1.285 之前,仅使用 claude.ai 或 Claude Console 凭据登录的会话以此消息退出,操作系统拒绝的读取也产生了它。5389在 v2.1.285 之前,仅使用 claude.ai 或 Claude Console 凭据登录的会话以此消息退出,并且操作系统拒绝的读取也会产生它。
5303 5390
5304<h3 id="otelheadershelper-failed">5391<h3 id="otelheadershelper-failed">
5305 otelHeadersHelper 失败5392 otelHeadersHelper 失败
5307 5394
5308当 [`otelHeadersHelper`](/docs/zh-CN/settings-reference#otelheadershelper) 脚本失败或打印不符合[脚本要求](/docs/zh-CN/monitoring-usage#script-requirements)的输出时,Claude Code 将此警告显示为终端界面中的通知,每个交互式会话一次。5395当 [`otelHeadersHelper`](/docs/zh-CN/settings-reference#otelheadershelper) 脚本失败或打印不符合[脚本要求](/docs/zh-CN/monitoring-usage#script-requirements)的输出时,Claude Code 将此警告显示为终端界面中的通知,每个交互式会话一次。
5309 5396
5310当脚本继续失败时,导出失败,您的遥测后端从会话中接收不到任何内容。5397当脚本持续失败时,导出失败,您的遥测后端从会话中接收不到任何内容。
5311 5398
5312`See /status:` 后的文本说明失败的内容,例如脚本的退出代码后跟其错误输出:5399`See /status:` 后的文本说明失败的内容,例如脚本的退出码后跟其错误输出:
5313 5400
5314```text theme={null}5401```text theme={null}
5315otelHeadersHelper failed; telemetry is not being exported. See /status: exited 1: token service unreachable5402otelHeadersHelper failed; telemetry is not being exported. See /status: exited 1: token service unreachable
5318**要做什么:**5405**要做什么:**
5319 5406
5320* 运行 `/status` 以读取失败详情。5407* 运行 `/status` 以读取失败详情。
5321* 修复脚本使其在 30 秒内退出 0 并在 stdout 上打印字符串标头值的 JSON 对象。请参阅[脚本要求](/docs/zh-CN/monitoring-usage#script-requirements)。5408* 修复脚本使其在 30 秒内以 0 退出,并在 stdout 上打印由字符串标头值组成的 JSON 对象。请参阅[脚本要求](/docs/zh-CN/monitoring-usage#script-requirements)。
5322* 如果您的组织通过[托管设置](/docs/zh-CN/managed-settings)部署脚本,请要求维护它们的人修复它。5409* 如果您的组织通过[托管设置](/docs/zh-CN/managed-settings)部署脚本,请要求维护它们的人修复它。
5323 5410
5324在[非交互模式](/docs/zh-CN/headless)中使用 `-p`,相同的失败在 stderr 上显示为 `otelHeadersHelper failed (OpenTelemetry export headers unavailable): <error>`。5411在[非交互模式](/docs/zh-CN/headless)中使用 `-p` 时,相同的失败改为在 stderr 上显示为 `otelHeadersHelper failed (OpenTelemetry export headers unavailable): <error>`。
5325 5412
5326<h3 id="headershelper-not-run">5413<h3 id="headershelper-not-run">
5327 headersHelper 未运行5414 headersHelper 未运行
5328</h3>5415</h3>
5329 5416
5330Claude Code 仅使用 MCP 服务器的静态 `headers` 连接了它,并跳过了服务器的 [`headersHelper`](/docs/zh-CN/mcp#use-dynamic-headers-for-custom-authentication),因为助手是 shell 命令,文件夹没有保存的信任。当您手动在 `~/.claude.json` 中设置其条目时,或在主目录外,当您在交互式会话中为其接受信任对话框时,文件夹获得保存的信任。请参阅[在 headersHelper 运行前信任文件夹](/docs/zh-CN/mcp#trust-a-folder-before-its-headershelper-runs)了解此检查适用于哪些服务器。5417Claude Code 仅使用 MCP 服务器的静态 `headers` 连接了它,并跳过了服务器的 [`headersHelper`](/docs/zh-CN/mcp#use-dynamic-headers-for-custom-authentication),因为该助手是 shell 命令,而该文件夹没有保存的信任。当您手动在 `~/.claude.json` 中设置其条目时,或在主目录外,当您在交互式会话中为其接受信任对话框时,文件夹获得保存的信任。请参阅[在 headersHelper 运行前信任文件夹](/docs/zh-CN/mcp#trust-a-folder-before-its-headershelper-runs)了解此检查适用于哪些服务器。
5331 5418
5332Claude Code 仅在[非交互模式](/docs/zh-CN/headless)中写入此行,每个服务器一次。在交互式会话中,它将相同的拒绝写入调试日志。5419Claude Code 仅在[非交互模式](/docs/zh-CN/headless)中写入此行,每个服务器一次。在交互式会话中,它改为将相同的拒绝写入调试日志。
5333 5420
5334```text theme={null}5421```text theme={null}
5335MCP server 'internal-api': headersHelper not run — this workspace has no persisted trust; accept the trust dialog here once interactively, or set projects["/Users/you/project"].hasTrustDialogAccepted in /Users/you/.claude.json.5422MCP server 'internal-api': headersHelper not run — this workspace has no persisted trust; accept the trust dialog here once interactively, or set projects["/Users/you/project"].hasTrustDialogAccepted in /Users/you/.claude.json.
5336```5423```
5337 5424
5338消息打印的 `projects` 键是文件夹[项目允许规则和工作区信任](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)说明 Claude Code 在其上键入信任的。为父文件夹接受信任对话框不满足检查,`-p` 或 SDK 会话也不满足。5425消息打印的 `projects` 键就是[项目允许规则和工作区信任](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)中说明的 Claude Code 用来记录信任的文件夹。为父文件夹接受信任对话框不满足该检查,`-p` 或 SDK 会话也不满足。
5339 5426
5340**要做什么:**5427**要做什么:**
5341 5428
5347 格式错误的 Tool(content) 规则5434 格式错误的 Tool(content) 规则
5348</h3>5435</h3>
5349 5436
5350您的一个设置文件中的[权限规则](/docs/zh-CN/permissions#permission-rule-syntax)没有 `Tool` 或 `Tool(content)` 的形状,例如因为文本跟在右括号后或其中一个括号缺失。Claude Code 跳过规则,当交互式会话启动时在无效设置对话框中列出它,以及在 [`claude doctor`](/docs/zh-CN/debug-your-config#check-resolved-settings) 输出中:5437您的某个设置文件中的[权限规则](/docs/zh-CN/permissions#permission-rule-syntax)不具有 `Tool` 或 `Tool(content)` 的形式,例如因为右括号后跟有文本或缺少其中一个括号。Claude Code 跳过该规则,并在交互式会话启动时的无效设置对话框中以及 [`claude doctor`](/docs/zh-CN/debug-your-config#check-resolved-settings) 输出中列出它:
5351 5438
5352```text theme={null}5439```text theme={null}
5353Invalid permission rule "Bash(ls) x" was skipped: Malformed Tool(content) rule. Rules take the form Tool or Tool(content) and must end at the closing ")"; parentheses inside the content are literal5440Invalid permission rule "Bash(ls) x" was skipped: Malformed Tool(content) rule. Rules take the form Tool or Tool(content) and must end at the closing ")"; parentheses inside the content are literal
5356**要做什么:**5443**要做什么:**
5357 5444
5358* 在消息列出的设置文件中,重写规则使其在其右括号处结束,例如用 `Bash(ls *)` 代替 `Bash(ls) x`5445* 在消息列出的设置文件中,重写规则使其在其右括号处结束,例如用 `Bash(ls *)` 代替 `Bash(ls) x`
5359* 将内容内的括号保留原样。它们是字面的,因此诸如 `Edit(./Finance (2024)/**)` 的规则在没有转义的情况下是有效的5446* 将内容内的括号保留原样。它们是字面量,因此诸如 `Edit(./Finance (2024)/**)` 的规则无需转义即有效
5360 5447
5361在 v2.1.260 之前,Claude Code 将具有不匹配括号的规则报告为 `Mismatched parentheses`。5448在 v2.1.260 之前,Claude Code 将具有不匹配括号的规则报告为 `Mismatched parentheses`。
5362 5449
5364 不匹配文件权限检查5451 不匹配文件权限检查
5365</h3>5452</h3>
5366 5453
5367Claude Code 在您的[设置文件](/docs/zh-CN/settings#where-settings-live)、[托管设置](/docs/zh-CN/managed-settings)或 `--allowedTools`、`--disallowedTools` 或 `--settings` 标志值中找到了 `Write`、`NotebookEdit`、`MultiEdit` 或 `Glob` [权限规则](/docs/zh-CN/permissions#read-and-edit),其中包含路径。它仅针对 `Edit` 和 `Read` 规则检查文件权限,因此它从不查询命名其他文件工具之一的路径规则。它保留规则并不改变其他任何内容;警告命名规则、其括号中的源和要写入的替换:5454Claude Code 在您的某个[设置文件](/docs/zh-CN/settings#where-settings-live)、[托管设置](/docs/zh-CN/managed-settings)或 `--allowedTools`、`--disallowedTools` 或 `--settings` 标志值中找到了带有路径的 `Write`、`NotebookEdit`、`MultiEdit` 或 `Glob` [权限规则](/docs/zh-CN/permissions#read-and-edit)。它仅针对 `Edit` 和 `Read` 规则检查文件权限,因此从不查询命名其他文件工具之一的路径规则。它保留该规则且不改变其他任何内容;警告命名该规则、括号中的来源以及要写入的替换内容:
5368 5455
5369```text theme={null}5456```text theme={null}
5370Permission deny rule (.claude/settings.json): Write(docs/**) is not matched by file permission checks — only Edit(path) rules are. Use Edit(docs/**) instead (Edit rules cover all file-editing tools).5457Permission deny rule (.claude/settings.json): Write(docs/**) is not matched by file permission checks — only Edit(path) rules are. Use Edit(docs/**) instead (Edit rules cover all file-editing tools).
5373**要做什么:**5460**要做什么:**
5374 5461
5375* 将 `Write(path)`、`NotebookEdit(path)` 和旧版 `MultiEdit(path)` 规则替换为 `Edit(path)`。`Edit` 规则涵盖所有文件编辑工具。5462* 将 `Write(path)`、`NotebookEdit(path)` 和旧版 `MultiEdit(path)` 规则替换为 `Edit(path)`。`Edit` 规则涵盖所有文件编辑工具。
5376* 除了在 `--allowedTools` 中,Claude Code 接受 `Glob` 规则而不警告,将 `Glob(path)` 规则替换为 `Read(path)`。5463* 除了在 `--allowedTools` 中(Claude Code 接受 `Glob` 规则而不警告),将 `Glob(path)` 规则替换为 `Read(path)`。
5377* 在警告括号中命名的源处修复规则:设置文件路径,或 `--allowed-tools` 和 `--disallowed-tools` 的标志本身。不存在于磁盘上的 `claude-settings-<hash>.json` 路径代表内联 `--settings` 值。修复您传递给该标志的 JSON。5464* 在警告括号中命名的来源处修复规则:设置文件路径,或对于 `--allowed-tools` 和 `--disallowed-tools` 则是标志本身。磁盘上不存在的 `claude-settings-<hash>.json` 路径代表内联 `--settings` 值。请修复您传递给该标志的 JSON。
5378* 将诸如 `Write` 或 `Glob` 的裸工具名称规则保留原样。Claude Code 在[工具级别](/docs/zh-CN/permissions#match-all-uses-of-a-tool)匹配它们,不对它们发出警告。5465* 将诸如 `Write` 或 `Glob` 的裸工具名称规则保留原样。Claude Code 在[工具级别](/docs/zh-CN/permissions#match-all-uses-of-a-tool)匹配它们,不对它们发出警告。
5379* 如果源读取 `managed policy settings`,将警告转发给维护您的托管设置的人,因为您无法自己清除它。5466* 如果来源显示为 `managed policy settings`,请将警告转发给维护您的托管设置的人,因为您无法自己清除它。
5380 5467
5381在[后台会话](/docs/zh-CN/agent-view)中或使用 `--output-format json` 或 `stream-json`,Claude Code 将警告写入调试日志而不是 stderr,因此机器读取输出保持干净。使用 `--debug` 运行以在 `~/.claude/debug/<session-id>.txt` 处捕获它。在 v2.1.210 之前,Claude Code 接受这些规则而不警告。5468在[后台会话](/docs/zh-CN/agent-view)中或使用 `--output-format json` 或 `stream-json` 时,Claude Code 将警告写入调试日志而不是 stderr,以保持机器读取的输出干净。使用 `--debug` 运行以在 `~/.claude/debug/<session-id>.txt` 处捕获它。在 v2.1.210 之前,Claude Code 接受这些规则而不警告。
5382 5469
5383<h3 id="has-a-wildcard-before-the-rest-of-the-command">5470<h3 id="has-a-wildcard-before-the-rest-of-the-command">
5384 在命令的其余部分之前有通配符5471 在命令的其余部分之前有通配符
5385</h3>5472</h3>
5386 5473
5387Claude Code 找到了一个 `Bash` 允许规则,其 `*` 在后来的单词之前,该单词确定它是哪个命令,例如 `Bash(git * main)` 或 `Bash(git -C * status *)`,在您的[设置文件](/docs/zh-CN/settings#where-settings-live)、[托管设置](/docs/zh-CN/managed-settings)或 `--allowedTools` 或 `--settings` 标志值中。`*` 匹配任何文本,包括在该位置插入的选项:`Bash(git * main)` 也批准 `git -c core.fsmonitor=<script> diff main`,其中 `-c` 使 git 运行命令命名的程序。[通配符模式](/docs/zh-CN/permissions#wildcard-patterns)显示匹配规则。5474Claude Code 在您的某个[设置文件](/docs/zh-CN/settings#where-settings-live)、[托管设置](/docs/zh-CN/managed-settings)或 `--allowedTools` 或 `--settings` 标志值中找到了一个 `Bash` 允许规则,其 `*` 出现在决定命令类型的后续单词之前,例如 `Bash(git * main)` 或 `Bash(git -C * status *)`。`*` 匹配任何文本,包括在该位置插入的选项:`Bash(git * main)` 也会批准 `git -c core.fsmonitor=<script> diff main`,其中 `-c` 会使 git 运行命令所命名的程序。[通配符模式](/docs/zh-CN/permissions#wildcard-patterns)显示匹配规则。
5388 5475
5389警告存在是为了让您缩小通配符比您打算的更宽的规则。Claude Code 保留规则并不改变它如何匹配;警告命名规则及其括号中的源:5476此警告的目的是让您缩小通配符范围超出预期的规则。Claude Code 保留该规则且不改变其匹配方式;警告命名该规则及括号中的来源:
5390 5477
5391```text theme={null}5478```text theme={null}
5392Permission allow rule (.claude/settings.json): Bash(git -C * status *) has a wildcard before the rest of the command, so it also matches any options inserted at that position and approves them without a prompt. For git, options such as -c and --exec-path can run arbitrary commands. Replace that * with the exact value you mean, or only use * after the subcommand (for example Bash(git status *)).5479Permission allow rule (.claude/settings.json): Bash(git -C * status *) has a wildcard before the rest of the command, so it also matches any options inserted at that position and approves them without a prompt. For git, options such as -c and --exec-path can run arbitrary commands. Replace that * with the exact value you mean, or only use * after the subcommand (for example Bash(git status *)).
5394 5481
5395**要做什么:**5482**要做什么:**
5396 5483
5397* 将子命令前的 `*` 替换为您的确切值:用 `Bash(git checkout main)` 代替 `Bash(git * main)`。5484* 将子命令前的 `*` 替换为您想要的确切值:用 `Bash(git checkout main)` 代替 `Bash(git * main)`。
5398* 将每个 `*` 移到子命令后:用 `Bash(git status *)` 代替 `Bash(git -C * status *)`。为您想允许的每个子命令写一个规则。5485* 将每个 `*` 移到子命令后:用 `Bash(git status *)` 代替 `Bash(git -C * status *)`。为您想允许的每个子命令写一条规则。
5399* 在警告括号中命名的源处修复规则:设置文件路径,或 `--allowed-tools` 标志本身。不存在于磁盘上的 `claude-settings-<hash>.json` 路径代表内联 `--settings` 值。修复您传递给该标志的 JSON。5486* 在警告括号中命名的来源处修复规则:设置文件路径,或 `--allowed-tools` 标志本身。磁盘上不存在的 `claude-settings-<hash>.json` 路径代表内联 `--settings` 值。请修复您传递给该标志的 JSON。
5400* 如果源读取 `managed policy settings`,将警告转发给维护您的托管设置的人,因为您无法自己清除它。5487* 如果来源显示为 `managed policy settings`,请将警告转发给维护您的托管设置的人,因为您无法自己清除它。
5401 5488
5402Claude Code 不对具有相同形状的拒绝和询问规则发出警告:它拒绝或提示它们匹配的额外命令,而不是批准它们。它也不对子命令在第一个 `*` 之前的规则发出警告,例如 `Bash(git commit *)`,或规则中除了选项之外没有其他单词跟在 `*` 后的规则,例如 `Bash(git *)`,或关于 `:*` 前缀规则的规则,例如 `Bash(git:*)`。5489在[后台会话](/docs/zh-CN/agent-view)中或使用 `--output-format json` 或 `stream-json` 时,Claude Code 将警告写入调试日志而不是 stderr,以保持机器读取的输出干净。使用 `--debug` 运行以在 `~/.claude/debug/<session-id>.txt` 处捕获它。在 v2.1.246 之前,Claude Code 接受这些规则而不警告。
5403
5404在[后台会话](/docs/zh-CN/agent-view)中或使用 `--output-format json` 或 `stream-json`,Claude Code 将警告写入调试日志而不是 stderr,因此机器读取输出保持干净。使用 `--debug` 运行以在 `~/.claude/debug/<session-id>.txt` 处捕获它。在 v2.1.246 之前,Claude Code 接受这些规则而不警告。
5405 5490
5406<h3 id="crosssessioninbound-must-be-one-of-accept-hold-refuse">5491<h3 id="crosssessioninbound-must-be-one-of-accept-hold-refuse">
5407 crossSessionInbound 必须是 accept、hold 或 refuse 之一5492 crossSessionInbound 必须是 accept、hold 或 refuse 之一
5408</h3>5493</h3>
5409 5494
5410设置文件将 [`crossSessionInbound`](/docs/zh-CN/settings-reference#crosssessioninbound) 设置为 Claude Code 不识别的值,例如拼写错误 `"reject"`。警告的第二句取决于哪个文件保存该值;在用户、项目、本地或 `--settings` 文件中,它读取:5495某个设置文件将 [`crossSessionInbound`](/docs/zh-CN/settings-reference#crosssessioninbound) 设置为 Claude Code 无法识别的值,例如拼写错误 `"reject"`。警告的第二句取决于哪个文件包含该值;在用户、项目、本地或 `--settings` 文件中,它显示为:
5411 5496
5412```text theme={null}5497```text theme={null}
5413"crossSessionInbound" must be one of "accept", "hold", "refuse"; received "reject". This value was ignored; while it is present, cross-session messages are held for your approval instead of being delivered. Set it to one of the values above.5498"crossSessionInbound" must be one of "accept", "hold", "refuse"; received "reject". This value was ignored; while it is present, cross-session messages are held for your approval instead of being delivered. Set it to one of the values above.
5414```5499```
5415 5500
5416在[托管设置](/docs/zh-CN/managed-settings)中,Claude Code 将无法识别的值视为 `refuse`(最严格的值),警告说跨会话消息被拒绝,直到管理员修复它。有关保留如何与您的其他设置文件中的值结合,请参阅 [`crossSessionInbound`](/docs/zh-CN/settings-reference#crosssessioninbound)。5501在[托管设置](/docs/zh-CN/managed-settings)中,Claude Code 将无法识别的值视为 `refuse`(最严格的值),警告说明跨会话消息将被拒绝,直到管理员修复它。有关保留行为如何与您的其他设置文件中的值结合,请参阅 [`crossSessionInbound`](/docs/zh-CN/settings-reference#crosssessioninbound)。
5417 5502
5418**要做什么:**5503**要做什么:**
5419 5504
5420* 将键设置为 `"accept"`、`"hold"` 或 `"refuse"`,或删除它5505* 将该键设置为 `"accept"`、`"hold"` 或 `"refuse"`,或删除它
5421* 当警告命名托管设置时,要求管理员修复该值5506* 当警告命名托管设置时,要求管理员修复该值
5422 5507
5423在 v2.1.248 之前,Claude Code 忽略无法识别的值而不警告。5508在 v2.1.248 之前,Claude Code 忽略无法识别的值而不警告。
5424 5509
5510<h3 id="anthropic-foundry-resource-must-be-a-foundry-resource-name">
5511 ANTHROPIC\_FOUNDRY\_RESOURCE 必须是 Foundry 资源名称
5512</h3>
5513
5514您将 [`ANTHROPIC_FOUNDRY_RESOURCE`](/docs/zh-CN/env-vars) 设置为了裸 [Microsoft Foundry](/docs/zh-CN/microsoft-foundry) 资源名称以外的内容,例如端点 URL 或其主机名。Claude Code 在发送请求前拒绝了该值。该消息出现在 Claude 回复的位置,而不是作为启动警告:
5515
5516```text theme={null}
5517API Error: ANTHROPIC_FOUNDRY_RESOURCE must be a Foundry resource name (2-64 letters, digits and hyphens, not starting or ending with a hyphen, such as my-resource), not a URL or host name. To use a full URL, set ANTHROPIC_FOUNDRY_BASE_URL instead.
5518```
5519
5520**要做什么:**
5521
5522* 将 `ANTHROPIC_FOUNDRY_RESOURCE` 仅设置为资源名称,然后重启 Claude Code。对于端点 `https://my-resource.services.ai.azure.com/anthropic`,名称为 `my-resource`。
5523* 若要改为提供完整的端点 URL,请将 [`ANTHROPIC_FOUNDRY_BASE_URL`](/docs/zh-CN/env-vars) 设置为该 URL 并删除 `ANTHROPIC_FOUNDRY_RESOURCE`,然后重启 Claude Code。Claude Code 只接受这两个变量之一。
5524
5425<h3 id="the-200k-limit-isnt-enforced">5525<h3 id="the-200k-limit-isnt-enforced">
5426 200K 限制未被强制执行5526 200K 限制未被强制执行
5427</h3>5527</h3>
5428 5528
5429您设置了 [`CLAUDE_CODE_DISABLE_1M_CONTEXT=1`](/docs/zh-CN/env-vars),这通常使[自动压缩](/docs/zh-CN/model-config#default-auto-compact-thresholds)将 1M 上下文模型上的会话保持在 200K 窗口,但没有压缩阈值将此会话限制在或低于 200K,因此对话可以超过它。5529您设置了 [`CLAUDE_CODE_DISABLE_1M_CONTEXT=1`](/docs/zh-CN/env-vars),这通常使[自动压缩](/docs/zh-CN/model-config#default-auto-compact-thresholds)将 1M 上下文模型上的会话保持在 200K 窗口内,但没有压缩阈值将此会话限制在 200K 或以下,因此对话可以超过它。
5430 5530
5431```text theme={null}5531```text theme={null}
5432CLAUDE_CODE_DISABLE_1M_CONTEXT is set, but the 200K limit isn't enforced for <model>, so this session can grow past it. To enforce it, set CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000 (or the autoCompactWindow setting).5532CLAUDE_CODE_DISABLE_1M_CONTEXT is set, but the 200K limit isn't enforced for <model>, so this session can grow past it. To enforce it, set CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000 (or the autoCompactWindow setting).
5433```5533```
5434 5534
5435Claude Code 为它识别为具有本机 1M 窗口的每个模型自己强制执行 200K 限制,对于它不识别的模型 ID,它在它假设的窗口处压缩。当其他配置击败该强制执行时出现警告:5535Claude Code 会为它识别为具有原生 1M 窗口的每个模型自行强制执行 200K 限制,对于它无法识别的模型 ID,它会在其假设的窗口处压缩。当其他配置使该强制执行失效时,会出现此警告:
5436 5536
5437* 模型 ID 不是 Claude Code 识别的,例如[LLM 网关](/docs/zh-CN/llm-gateway)别名,并且您设置了 [`CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT=1`](/docs/zh-CN/env-vars) 或使用 [`CLAUDE_CODE_MAX_CONTEXT_TOKENS`](/docs/zh-CN/env-vars) 将假设的窗口提高到 200K 以上。在这种情况下,消息也提供 `or update to a Claude Code version that recognizes <model>` 作为补救。5537* 模型 ID 不是 Claude Code 能识别的,例如 [LLM 网关](/docs/zh-CN/llm-gateway)别名,并且您设置了 [`CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT=1`](/docs/zh-CN/env-vars) 或使用 [`CLAUDE_CODE_MAX_CONTEXT_TOKENS`](/docs/zh-CN/env-vars) 将假设的窗口提高到 200K 以上。在这种情况下,消息还会提供 `or update to a Claude Code version that recognizes <model>` 作为补救措施。
5438* 通过 [`ANTHROPIC_BETAS`](/docs/zh-CN/env-vars) 或 [`--betas`](/docs/zh-CN/cli-reference#cli-flags) 标志请求的 `context-1m` 测试版仍然要求 API 在接受该测试版的模型上使用 1M 窗口,而没有任何东西在 200K 处压缩会话5538* 通过 [`ANTHROPIC_BETAS`](/docs/zh-CN/env-vars) 或 [`--betas`](/docs/zh-CN/cli-reference#cli-flags) 标志请求的 `context-1m` 测试版仍然会在接受该测试版的模型上向 API 请求 1M 窗口,而没有任何机制在 200K 处压缩会话
5439 5539
5440**要做什么:**5540**要做什么:**
5441 5541
5442* 设置 [`CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000`](/docs/zh-CN/env-vars),或 [`autoCompactWindow`](/docs/zh-CN/settings-reference#autocompactwindow) 设置为 `200000`,以便自动压缩在 200K 边界处压缩5542* 设置 [`CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000`](/docs/zh-CN/env-vars),或将 [`autoCompactWindow`](/docs/zh-CN/settings-reference#autocompactwindow) 设置为 `200000`,以便自动压缩在 200K 边界处压缩
5443* 如果消息命名此版本不识别的模型 ID,运行 `claude update`。识别 ID 为 1M 上下文模型的版本在没有进一步配置的情况下强制执行限制。5543* 如果消息命名了此版本无法识别的模型 ID,请运行 `claude update`。能够将该 ID 识别为 1M 上下文模型的版本会强制执行该限制,无需进一步配置。
5444* 如果您希望会话使用模型的完整窗口,请取消设置 `CLAUDE_CODE_DISABLE_1M_CONTEXT`;警告仅报告 200K 限制未被强制执行5544* 如果您希望会话改为使用模型的完整窗口,请取消设置 `CLAUDE_CODE_DISABLE_1M_CONTEXT`;该警告仅报告 200K 限制未被强制执行
5445 5545
5446在[后台会话](/docs/zh-CN/agent-view)中或使用 `--output-format json` 或 `stream-json`,Claude Code 将警告写入调试日志而不是 stderr。5546在[后台会话](/docs/zh-CN/agent-view)中或使用 `--output-format json` 或 `stream-json` 时,Claude Code 将警告写入调试日志而不是 stderr。
5447 5547
5448<h3 id="unrecognized-model-id-on-a-request">5548<h3 id="unrecognized-model-id-on-a-request">
5449 请求上无法识别的模型 ID5549 请求上无法识别的模型 ID
5450</h3>5550</h3>
5451 5551
5452Claude Code 为您的 Claude Code 版本不识别的模型 ID 发送了请求,并找不到将该 ID 映射到它识别的模型的 [`modelOverrides`](/docs/zh-CN/model-config#override-model-ids-per-version) 条目。Claude Code 仍然使用您配置的 ID 发送请求,不退出或切换模型。5552Claude Code 为您的 Claude Code 版本无法识别的模型 ID 发送了请求,并且找不到将该 ID 映射到它能识别的模型的 [`modelOverrides`](/docs/zh-CN/model-config#override-model-ids-per-version) 条目。Claude Code 仍然使用您配置的 ID 发送请求,不会退出或切换模型。
5453 5553
5454```text theme={null}5554```text theme={null}
5455[claude-code:unrecognized_model] {"model":"my-proxy-model","query_source":"sdk"}5555[claude-code:unrecognized_model] {"model":"my-proxy-model","query_source":"sdk"}
5456```5556```
5457 5557
5458在读取 stderr 的脚本或工具中,匹配 `[claude-code:unrecognized_model]` 前缀。在前缀和一个空格之后,Claude Code 写入一行 JSON 对象。Claude Code 可以在更高版本中向其添加字段,因此忽略您不期望的任何字段。它至少写入这两个:5558在读取 stderr 的脚本或测试工具中,请匹配 `[claude-code:unrecognized_model]` 前缀。在前缀和一个空格之后,Claude Code 写入单行 JSON 对象。Claude Code 可能在更高版本中向其添加字段,因此请忽略任何您未预期的字段。它至少写入以下两个字段:
5459 5559
5460* `model`:您配置的模型字符串5560* `model`:您配置的模型字符串
5461* `query_source`:使用模型的请求路径。Claude Code 为 `-p` 运行报告 `sdk`,为以 `agent:` 开头的值报告子代理。5561* `query_source`:使用该模型的请求路径。对于 `-p` 运行,Claude Code 报告 `sdk`;对于子代理,报告以 `agent:` 开头的值。
5462 5562
5463Claude Code 根据您运行它的方式将行写入两个位置之一:5563Claude Code 根据您的运行方式将该行写入以下两个位置之一:
5464 5564
5465* 在[非交互模式](/docs/zh-CN/headless)中使用 `-p`,Claude Code 在每个 `--output-format` 下将其写入 stderr,因此您可以解析 stdout 而不过滤该行5565* 在[非交互模式](/docs/zh-CN/headless)中使用 `-p` 时,Claude Code 在每种 `--output-format` 下都将其写入 stderr,因此您可以解析 stdout 而无需过滤掉该行
5466* 在交互式会话或[后台会话](/docs/zh-CN/agent-view)中,Claude Code 将其写入调试日志;使用 `--debug` 运行以在 `~/.claude/debug/<session-id>.txt` 处捕获它5566* 在交互式会话或[后台会话](/docs/zh-CN/agent-view)中,Claude Code 改为将其写入调试日志;使用 `--debug` 运行以在 `~/.claude/debug/<session-id>.txt` 处捕获它
5467 5567
5468Claude Code 每个模型字符串每个进程写入该行一次。它为每个进一步的无法识别的 ID 写入单独的行,例如[子代理](/docs/zh-CN/sub-agents#choose-a-model)或[后台功能](/docs/zh-CN/costs#background-token-usage)使用的 ID。5568Claude Code 每个进程为每个模型字符串写入该行一次。对于每个其他无法识别的 ID,例如[子代理](/docs/zh-CN/sub-agents#choose-a-model)或[后台功能](/docs/zh-CN/costs#background-token-usage)使用的 ID,它会写入单独的一行。
5469 5569
5470Claude Code 不为它解析为它识别的模型的提供商 ID 写入该行,例如 Amazon Bedrock `us.anthropic.claude-...` ID、Google Cloud 的 Agent Platform ID 带有 `@` 版本后缀,以及包含 Claude 模型 ID 的 Microsoft Foundry 部署名称。Claude Code 检查 Amazon Bedrock [应用推理配置文件 ARN](/docs/zh-CN/amazon-bedrock#map-each-model-version-to-an-inference-profile) 后面的模型,而不是 ARN 本身。它为无法解析的 ARN(例如拼写错误的 ARN)不写入行。5570对于它能解析为可识别模型的提供商 ID,Claude Code 不写入该行,例如 Amazon Bedrock `us.anthropic.claude-...` ID、带有 `@` 版本后缀的 Google Cloud Agent Platform ID,以及包含 Claude 模型 ID 的 Microsoft Foundry 部署名称。Claude Code 检查 Amazon Bedrock [应用推理配置文件 ARN](/docs/zh-CN/amazon-bedrock#map-each-model-version-to-an-inference-profile) 背后的模型,而不是 ARN 本身。对于无法解析的 ARN(例如拼写错误的 ARN),它不写入任何行。
5471 5571
5472**要做什么:**5572**要做什么:**
5473 5573
5474* 如果您故意设置了 ID,例如[LLM 网关](/docs/zh-CN/llm-gateway)别名,请在您的[设置文件](/docs/zh-CN/settings#where-settings-live)中添加 [`modelOverrides`](/docs/zh-CN/model-config#override-model-ids-per-version) 条目,其中 ID 作为其值。使用 Anthropic 模型 ID 作为键,而不是系列别名,例如 `opus`。对于示例行中的 `my-proxy-model`,添加此条目:5574* 如果您是有意设置该 ID 的,例如 [LLM 网关](/docs/zh-CN/llm-gateway)别名,请在您的[设置文件](/docs/zh-CN/settings#where-settings-live)中添加一个以该 ID 为值的 [`modelOverrides`](/docs/zh-CN/model-config#override-model-ids-per-version) 条目。使用 Anthropic 模型 ID 作为键,而不是诸如 `opus` 的系列别名。对于示例行中的 `my-proxy-model`,添加此条目:
5475 5575
5476 ```json theme={null}5576 ```json theme={null}
5477 {5577 {
5481 }5581 }
5482 ```5582 ```
5483 5583
5484 Claude Code 然后将 `my-proxy-model` 视为 `claude-opus-4-6` 并停止写入该行。5584 然后 Claude Code 会将 `my-proxy-model` 视为 `claude-opus-4-6` 并停止写入该行。
5485 5585
5486* 如果 ID 命名比您的 Claude Code 版本更新的模型,运行 `claude update`5586* 如果该 ID 命名的模型比您的 Claude Code 版本更新,请运行 `claude update`
5487 5587
5488* 如果 ID 是拼写错误,在您可以设置模型的[位置](/docs/zh-CN/model-config#setting-your-model)或[别名变量](/docs/zh-CN/model-config#environment-variables)中修复它。如果 `query_source` 以 `agent:` 开头,改为在您设置[子代理模型](/docs/zh-CN/sub-agents#choose-a-model)的地方修复它。5588* 如果该 ID 是拼写错误,请在包含它的[可设置模型的位置](/docs/zh-CN/model-config#setting-your-model)或[别名变量](/docs/zh-CN/model-config#environment-variables)中修复它。如果 `query_source` 以 `agent:` 开头,请改为在您设置[子代理模型](/docs/zh-CN/sub-agents#choose-a-model)的地方修复它。
5489 5589
5490在 v2.1.233 之前,Claude Code 在为它不识别的模型 ID 发送请求时不写入行。5590在 v2.1.233 之前,Claude Code 在为无法识别的模型 ID 发送请求时不写入任何行。
5491 5591
5492<h3 id="stale-sandbox-mask-files-left-by-a-killed-session">5592<h3 id="stale-sandbox-mask-files-left-by-a-killed-session">
5493 被杀死的会话留下的陈旧沙箱掩码文件5593 被终止的会话留下的陈旧沙箱掩码文件
5494</h3>5594</h3>
5495 5595
5496`claude doctor` 在其诊断中打印此警告,`/status` 列出相同的行。当[沙箱](/docs/zh-CN/sandboxing)在文件系统隔离打开的情况下启用时,它在 Linux 和 WSL2 上出现。5596`claude doctor` 在其诊断中打印此警告,`/status` 也列出相同的行。当启用了[沙箱隔离](/docs/zh-CN/sandboxing)并打开文件系统隔离时,它会在 Linux 和 WSL2 上出现。
5497 5597
5498当沙箱命令运行时,沙箱通过在那里创建 0 字节只读占位符来保持对尚不存在的文件的写入拒绝,并在之后删除它。在该清理运行前被杀死的会话,例如通过 SIGKILL,会留下占位符。后来的会话在每次启动时再次只读绑定它们,因此诸如保存"是,不要再问"之类的设置写入失败。5598当沙箱中的命令运行时,沙箱通过在尚不存在的文件位置创建 0 字节只读占位符来保持对该文件的写入拒绝,并在之后删除它。在该清理运行前被终止的会话(例如通过 SIGKILL)会留下这些占位符。之后的会话在每次启动时都会再次以只读方式绑定它们,因此在占位符所在位置的设置写入(例如保存"是,不要再问")会失败。
5499 5599
5500```text theme={null}5600```text theme={null}
5501- Stale sandbox mask files left by a killed session: /home/you/project/.claude/settings.local.json5601- Stale sandbox mask files left by a killed session: /home/you/project/.claude/settings.local.json
5504 5604
5505**要做什么:**5605**要做什么:**
5506 5606
5507* 退出在该项目中运行的任何其他 Claude Code 会话,然后使用 `rm` 删除每个列出的文件。警告列出最多三个文件并计数其余的,因此在删除后重新运行 `claude doctor` 直到警告不再出现。另一个会话的沙箱仍在使用的占位符是该会话写入保护的活跃部分5607* 退出在该项目中运行的任何其他 Claude Code 会话,然后使用 `rm` 删除每个列出的文件。警告最多列出三个文件并对其余文件计数,因此删除后请重新运行 `claude doctor`,直到警告不再出现。另一个会话的沙箱仍在使用的占位符是该会话写入保护的有效组成部分
5508* 如果您使用"是,不要再问"保存的权限选择没有坚持,请在删除占位符后再次保存5608* 如果您使用"是,不要再问"保存的权限选择没有生效,请在删除占位符后再次保存
5509 5609
5510在 v2.1.257 之前,`claude doctor` 没有标记这些文件;较早的版本在会话被杀死时留下相同的占位符。5610在 v2.1.257 之前,`claude doctor` 不会标记这些文件;较早的版本在会话被终止时会留下相同的占位符。
5511 5611
5512<h2 id="responses-seem-lower-quality-than-usual">5612<h2 id="responses-seem-lower-quality-than-usual">
5513 回复质量似乎低于预期5613 回复质量似乎低于预期