diff --git a/zh-CN/errors.md b/zh-CN/errors.md index ed7a4cddd66e40396eb6ddabc1bbe8b54d08c1ff..b18afc537164fe2eeba8f6656af955154eec5815 100644 --- a/zh-CN/errors.md +++ b/zh-CN/errors.md @@ -6,147 +6,400 @@ > 查找 Claude Code 运行时错误消息,了解每个错误的含义以及如何修复。 -本页列出了 Claude Code 显示的运行时错误以及如何从每个错误中恢复,以及当响应似乎有问题但没有错误时要检查的内容。对于安装错误(如 `command not found` 或设置期间的 TLS 故障),请参阅[故障排除安装和登录](/docs/zh-CN/troubleshoot-install)。 +本页列出 Claude Code 显示的运行时错误以及如何从每个错误中恢复,以及当响应似乎有问题但没有错误时要检查的内容。对于安装错误(如 `command not found` 或设置期间的 TLS 失败),请参阅[排查安装和登录问题](/docs/zh-CN/troubleshoot-install)。 -这些错误和恢复命令适用于 CLI、[桌面应用](/docs/zh-CN/desktop)和[网络上的 Claude Code](/docs/zh-CN/claude-code-on-the-web),因为这三个都包装了相同的 Claude Code CLI。对于特定于表面的问题,请参阅该表面页面上的故障排除部分。 +除了[包装器和 IDE 错误](#wrapper-and-ide-errors)(由启动程序打印而不是 Claude Code 本身打印)外,这些错误和恢复命令适用于 CLI、[桌面应用](/docs/zh-CN/desktop)和[云会话](/docs/zh-CN/claude-code-on-the-web),因为这三个都包装相同的 Claude Code CLI。对于其他表面特定的问题,请参阅该表面页面上的故障排除部分。 - Claude Code 调用 Claude API 获取模型响应,因此大多数运行时错误映射到底层 API 错误代码。本页介绍了每个错误在 Claude Code 中的含义以及如何恢复。有关原始 HTTP 状态代码定义,请参阅 [Claude Platform 错误参考](https://platform.claude.com/docs/en/api/errors)。 + Claude Code 调用 Claude API 来获取模型响应,因此大多数运行时错误映射到底层 API 错误代码。本页介绍每个错误在 Claude Code 中的含义以及如何恢复。有关原始 HTTP 状态代码定义,请参阅 [Claude Platform 错误参考](https://platform.claude.com/docs/en/api/errors)。

查找您的错误

-将您在终端中看到的消息与下面的部分相匹配。 +将您看到的消息与下面的部分相匹配。 | 消息 | 部分 | -| :------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------- | +| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------- | | `API Error: 500 Internal server error` | [服务器错误](#api-error-500-internal-server-error) | | `API Error: Repeated 529 Overloaded errors` | [服务器错误](#api-error-repeated-529-overloaded-errors) | -| `Request timed out` | [服务器错误](#request-timed-out),或[网络](#unable-to-connect-to-api)(如果消息提到您的互联网连接) | +| `Request timed out` | [服务器错误](#request-timed-out),或如果消息提到您的互联网连接,则为[网络](#unable-to-connect-to-api) | +| `API Error: No response from API` | [服务器错误](#no-response-from-api) | | `Server error mid-response. The response above may be incomplete.` | [服务器错误](#the-response-above-may-be-incomplete) | +| `Connection lost mid-response` / `Your computer went to sleep mid-response` / `The response stopped arriving` | [服务器错误](#the-response-above-may-be-incomplete) | | `Connection closed mid-response` / `Response stalled mid-stream` | [服务器错误](#the-response-above-may-be-incomplete) | +| `Connection lost before a response was produced` / `Your computer went to sleep before a response was produced` / `The response stalled before a response was produced` | [自动重试](#automatic-retries) | +| `Connection closed while thinking` / `Response stalled while thinking` | [自动重试](#automatic-retries) | +| `Connection lost while your computer was asleep` | [自动重试](#automatic-retries) | | ` is temporarily unavailable, so auto mode cannot determine the safety of...` | [服务器错误](#auto-mode-cannot-determine-the-safety-of-an-action) | | `Auto mode could not evaluate this action and is blocking it for safety` | [服务器错误](#auto-mode-cannot-determine-the-safety-of-an-action) | | `Auto mode classifier transcript exceeded context window` | [服务器错误](#auto-mode-cannot-determine-the-safety-of-an-action) | +| `Agent aborted: auto mode classifier request refused by the safety safeguard` | [服务器错误](#auto-mode-cannot-determine-the-safety-of-an-action) | +| `The server-side auto mode classifier gave no verdict` | [服务器错误](#the-server-returned-no-safety-verdict) | +| `Auto mode is unavailable — the server returned no safety verdict for the last 10 responses` | [服务器错误](#the-server-returned-no-safety-verdict) | | `Agent terminated early due to an API error` | [服务器错误](#agent-terminated-early-due-to-an-api-error) | -| `You've hit your session limit` / `You've hit your weekly limit` | [使用限制](#youve-hit-your-session-limit) | +| `You've hit your session limit` / `You've hit your weekly limit` / `You've hit your Opus limit` / `You've hit your Sonnet limit` | [使用限制](#youve-hit-your-session-limit) | | `Usage credits required for 1M context` | [使用限制](#usage-credits-required-for-1m-context) | +| `the prompt to confirm went unanswered — nothing was sent` | [使用限制](#the-prompt-to-confirm-went-unanswered) | | `Server is temporarily limiting requests` | [使用限制](#server-is-temporarily-limiting-requests) | | `Request rejected (429)` | [使用限制](#request-rejected-429) | | `Credit balance is too low` | [使用限制](#credit-balance-is-too-low) | +| `You've hit your monthly spend limit` / `You've hit your individual spend limit` / `You've hit your org's monthly spend limit` / `You've hit your channel's monthly spend limit` / `You've hit your team's shared budget` / `You've hit your individual usage limit` | [使用限制](#youve-hit-your-monthly-spend-limit) | +| `Could not update your spend limit` | [使用限制](#could-not-update-your-spend-limit) | +| `spend limit reached` / `spend limit unavailable` | [使用限制](#spend-limit-reached) | | `Not logged in · Please run /login` | [身份验证](#not-logged-in) | | `Could not resolve authentication method` | [身份验证](#could-not-resolve-authentication-method) | | `Invalid API key` | [身份验证](#invalid-api-key) | | `Your apiKeyHelper script is failing` | [身份验证](#your-apikeyhelper-script-is-failing) | +| `Invalid auth token · Fix external auth token` | [身份验证](#invalid-request-header-value) | +| `Invalid ANTHROPIC_CUSTOM_HEADERS · Fix the environment variable` | [身份验证](#invalid-request-header-value) | +| `Invalid request header from the environment · Fix the environment variable` | [身份验证](#invalid-request-header-value) | | `This organization has been disabled` | [身份验证](#this-organization-has-been-disabled) | | `Your organization has disabled API key authentication` | [身份验证](#your-organization-has-disabled-api-key-authentication) | | `Your organization has disabled Claude subscription access` | [身份验证](#your-organization-has-disabled-claude-subscription-access) | | `Routines are disabled by your organization's policy` | [身份验证](#routines-are-disabled-by-your-organizations-policy) | | `Remote Control is only available when using Claude via api.anthropic.com` | [身份验证](#remote-control-requires-the-anthropic-api) | +| `OAuth token refresh failed — run /login to re-authenticate` | [身份验证](#remote-control-couldnt-refresh-your-login) | +| `JWT refresh failed: no OAuth token — run /login` | [身份验证](#remote-control-couldnt-refresh-your-login) | +| `Claude.ai login expired` | [身份验证](#remote-control-couldnt-refresh-your-login) | +| `Claude.ai login was rejected — run /login, then /remote-control` | [身份验证](#remote-control-couldnt-refresh-your-login) | +| `OAuth token unavailable — run /login to restore Remote Control` | [身份验证](#remote-control-couldnt-refresh-your-login) | +| `Signed out of Claude — run /login, then /remote-control` | [身份验证](#remote-control-couldnt-refresh-your-login) | +| `signed-in claude.ai account or organization changed on this machine` | [身份验证](#remote-control-stopped-because-the-signed-in-account-changed) | +| `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) | +| `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) | | `OAuth token revoked` / `OAuth token has expired` | [身份验证](#oauth-token-revoked-or-expired) | +| `API Error: 401 Invalid authentication credentials` | [身份验证](#api-error-401-invalid-authentication-credentials) | | `Login expired · Please run /login` | [身份验证](#login-expired) | +| `Claude login not accepted · Run /login, then try again` | [身份验证](#claude-login-not-accepted) | +| `Artifacts need a claude.ai login` | [身份验证](#artifacts-need-a-claude-ai-login) | +| `Not signed in to the Cloud gateway — run /login.` | [身份验证](#administrator-policy-requires-a-cloud-gateway-sign-in) | +| `Administrator policy requires a Cloud gateway sign-in on this machine` | [身份验证](#administrator-policy-requires-a-cloud-gateway-sign-in) | | `Failed to authenticate: OAuth session expired and could not be refreshed` | [身份验证](#login-expired) | +| `Your account is on hold and can't use Claude Code. View details or appeal: https://claude.ai/restricted` | [身份验证](#your-account-is-on-hold) | +| `Your account is on hold and can't sign in to Claude Code. View details or appeal: https://claude.ai/restricted` | [身份验证](#your-account-is-on-hold) | +| `Anthropic profile login expired · Re-authenticate your Anthropic profile` | [身份验证](#anthropic-profile-login-expired) | +| `Anthropic profile login expired · Run /login to use your claude.ai account instead, or re-authenticate the profile` | [身份验证](#anthropic-profile-login-expired) | | `does not meet scope requirement user:profile` | [身份验证](#oauth-scope-requirement) | +| `claude.ai rejected the session token` / `session token rejected` | [身份验证](#claude-ai-rejected-the-session-token) | +| `MCP server "" needs you to sign in again (run /mcp to re-authenticate)` | [身份验证](#mcp-server-needs-you-to-sign-in-again) | +| `rejected the credential from its headersHelper` / `rejected the Authorization header in its config` | [身份验证](#mcp-server-needs-you-to-sign-in-again) | +| `MCP server "" needs additional permissions (scope: "") — run /mcp to re-authenticate` | [身份验证](#mcp-server-needs-you-to-sign-in-again) | +| `MCP server "" requires re-authorization (token expired)` | [身份验证](#mcp-server-needs-you-to-sign-in-again) | +| `Issuer mismatch in authorization response (RFC 9207)` | [身份验证](#issuer-mismatch-in-authorization-response) | +| `Cloud gateway session expired — run /login to reconnect.` | [身份验证](#cloud-gateway-session-expired) | +| `Cloud gateway no longer accepts this session` | [身份验证](#cloud-gateway-session-expired) | +| `Sign-in timed out while waiting for you to continue. Try again.` | [身份验证](#sign-in-timed-out-while-waiting-for-you-to-continue) | | `AWS credentials expired or invalid` | [身份验证](#aws-credentials-expired-or-invalid) | | `AWS authentication failed` | [身份验证](#aws-authentication-failed) | +| `Google Cloud credentials expired or invalid` | [身份验证](#google-cloud-credentials-expired-or-invalid) | +| `Google Cloud authentication failed` | [身份验证](#google-cloud-authentication-failed) | +| `Microsoft Foundry authentication failed` | [身份验证](#microsoft-foundry-authentication-failed) | +| `Gateway refused the request` | [身份验证](#gateway-refused-the-request) | +| `Could not load AWS credentials` / `Could not load Google Cloud credentials` | [身份验证](#could-not-load-aws-or-google-cloud-credentials) | | `AWS default-chain credential resolve timed out` | [身份验证](#aws-default-chain-credential-resolve-timed-out) | +| `Timed out after 60s waiting for AWS` | [身份验证](#bedrock-setup-verification-timed-out-waiting-for-aws) | +| `A request to AWS timed out. Check your network and proxy settings, then try again.` | [身份验证](#bedrock-setup-verification-timed-out-waiting-for-aws) | +| `Could not load the default credentials` on Google Cloud's Agent Platform | [身份验证](#could-not-load-aws-or-google-cloud-credentials) | | `Unable to connect to API` | [网络](#unable-to-connect-to-api) | -| `Waiting for API response · will retry in` | [自动重试](#automatic-retries),或[网络](#unable-to-connect-to-api)(如果问题持续) | +| `Connection refused —` / `Can't reach the API server —` / `No internet route —` / `Couldn't connect through your proxy` / `Connection dropped`,每个都带有括号中的错误代码 | [网络](#unable-to-connect-to-api) | +| `Unable to connect to Anthropic services` during setup | [网络](#unable-to-connect-to-anthropic-services) | +| `Socket is closed` | [网络](#socket-is-closed) | +| `Waiting for API response · will retry in` | [自动重试](#automatic-retries),或如果持续存在,则为[网络](#unable-to-connect-to-api) | +| `API returned an empty or malformed response` | [网络](#api-returned-an-empty-or-malformed-response) | +| `Streaming response ended before any complete data was received` | [网络](#streaming-response-ended-before-any-complete-data-was-received) | | `Bedrock streaming response has content-type "..."; expected "application/vnd.amazon.eventstream"` | [网络](#bedrock-streaming-response-has-an-unexpected-content-type) | | `SSL certificate verification failed` | [网络](#ssl-certificate-errors) | | `SSL certificate error (...)` during login or startup | [网络](#ssl-certificate-errors) | +| `unable to get local issuer certificate` | [网络](#ssl-certificate-errors) | | `403` with `x-deny-reason: host_not_allowed` in a cloud or routine session | [网络](#host-not-allowed-in-a-cloud-session) | +| `proxy refused the connection` | [网络](#the-proxy-refused-the-connection) | +| `403` with `This GraphQL query is not enabled for this session` in a cloud session | [GitHub proxy](/docs/zh-CN/cloud-environments#github-proxy) | +| `The cloud environments service returned an empty response` / `The cloud environments service returned a response in an unexpected format` | [网络](#the-cloud-environments-service-returned-an-empty-or-unexpected-response) | | `Couldn't reconnect to your Remote Control session` | [网络](#couldnt-reconnect-to-your-remote-control-session) | -| `Prompt is too long` | [请求错误](#prompt-is-too-long) | +| `N sessions ended while this machine was offline — the environment was cleaned up on the server and can't be resumed.` | [网络](#sessions-ended-while-this-machine-was-offline) | +| `Couldn't share the transcript.` | [网络](#couldnt-share-the-transcript) | +| `Prompt is too long` / `Input is too long for requested model` | [请求错误](#prompt-is-too-long) | +| `Prompt is too long · automatic compaction failed:` | [请求错误](#prompt-is-too-long) | +| `Prompt is too long · this conversation is a single exchange` / `A single-exchange conversation cannot be compacted` | [请求错误](#prompt-is-too-long) | +| `Context limit reached · /compact or /clear to continue` | [请求错误](#prompt-is-too-long) | +| `Context limit reached · /clear to continue` | [请求错误](#prompt-is-too-long) | +| `capability_rejected: prompt_too_long` on a Claude apps gateway session | [请求错误](#prompt-is-too-long) | +| `upstream rejected the request` / `request too large for this upstream` on a Claude apps gateway session | [上游错误消息](/docs/zh-CN/claude-apps-gateway-config#upstream-error-messages) | +| `upstream rate limit exceeded` on a Claude apps gateway session | [上游错误消息](/docs/zh-CN/claude-apps-gateway-config#upstream-error-messages) | +| `all upstreams failed (N attempted)` on a Claude apps gateway session | [上游错误消息](/docs/zh-CN/claude-apps-gateway-config#upstream-error-messages) | +| `Claude Code may not be enabled for your organization` after a Claude apps gateway sign-in | [Claude apps gateway 故障排除](/docs/zh-CN/claude-apps-gateway-deploy#troubleshooting) | +| `Context exceeds the ...-token limit by ... tokens` in `/context` output | [请求错误](#context-exceeds-the-token-limit) | | `Error during compaction: Conversation too long` | [请求错误](#error-during-compaction-conversation-too-long) | | `Request too large` | [请求错误](#request-too-large) | +| `Request too large for the API's 32MB request limit` | [请求错误](#request-too-large) | | `Image was too large` | [请求错误](#image-was-too-large) | | `Unable to resize image` | [请求错误](#unable-to-resize-image) | | `PDF too large` / `PDF is password protected` | [请求错误](#pdf-errors) | | `Extra inputs are not permitted` | [请求错误](#extra-inputs-are-not-permitted) | +| `API Error: 400 ... tools.N.custom.input_schema: JSON schema is invalid` / `Property keys should match pattern` | [请求错误](#tool-input-schema-is-invalid) | | `There's an issue with the selected model` | [请求错误](#theres-an-issue-with-the-selected-model) | | `Model ... is not a recognized model id` | [请求错误](#model-is-not-a-recognized-model-id) | +| `Model ... not found` | [请求错误](#model-not-found) | | `Claude Opus is not available with the Claude Pro plan` | [请求错误](#claude-opus-is-not-available-with-the-claude-pro-plan) | +| `Claude Code ... does not support this model; version ... or newer is required` | [请求错误](#claude-code-does-not-support-this-model) | +| `Claude Code ... is older than the minimum version required by your organization's policy` | [请求错误](#claude-code-does-not-support-this-model) | | `Model ... is restricted by your organization's settings` | [请求错误](#model-is-restricted-by-your-organizations-settings) | +| `Model switch ... blocked by a PreModelSwitch hook` | [请求错误](#model-switch-was-blocked-by-a-premodelswitch-hook) | +| `couldn't save it as your default` / `couldn't confirm it was saved as your default` | [请求错误](#couldnt-save-it-as-your-default) | | `thinking.type.enabled is not supported for this model` | [请求错误](#thinking-type-enabled-is-not-supported-for-this-model) | +| `Effort '' isn't available with thinking turned off on this model` | [请求错误](#effort-isnt-available-with-thinking-turned-off) | +| `effort '' is not supported when thinking is disabled` | [请求错误](#effort-isnt-available-with-thinking-turned-off) | | `max_tokens must be greater than thinking.budget_tokens` | [请求错误](#thinking-budget-exceeds-output-limit) | | `API Error: 400 due to tool use concurrency issues` | [请求错误](#tool-use-or-thinking-block-mismatch) | +| `API Error: 400 orphaned tool_result in conversation history` | [请求错误](#tool-use-or-thinking-block-mismatch) | +| `API Error: 400 duplicate tool_use ID in conversation history` | [请求错误](#tool-use-or-thinking-block-mismatch) | +| `[Unsupported tool content removed]` | [请求错误](#unsupported-tool-content-removed) | +| `role 'system' must precede an 'assistant' message` | [请求错误](#role-system-must-precede-an-assistant-message) | +| `Invalid encrypted_content in search_result block` / `Invalid encrypted_index in text block` / `Failed to decrypt web search result content` | [请求错误](#invalid-encrypted-content-in-search-result-block) | +| `server_tool_use.name: Input should be` on every turn of a resumed session | [请求错误](#unsupported-tool-content-removed) | +| ` can't help with this. Start a new session to continue` | [请求错误](#usage-policy-refusal) | | `Claude Code is unable to respond to this request, which appears to violate our Usage Policy` | [请求错误](#usage-policy-refusal) | +| `'s safeguards flagged this message` | [请求错误](#safety-measures-flagged-a-cybersecurity-topic) | +| `Opus 5.5's safeguards flagged this session` | [请求错误](#safety-measures-flagged-a-cybersecurity-topic) | | ` has safety measures that flagged this message for a cybersecurity topic` | [请求错误](#safety-measures-flagged-a-cybersecurity-topic) | | `Installation was killed before it could finish (exit code 137)` | [安装错误](#installation-was-killed-before-it-could-finish) | | `The connection dropped while downloading the update` | [安装错误](#the-connection-dropped-while-downloading-the-update) | | `Download timed out: exceeded the total deadline` | [安装错误](#the-connection-dropped-while-downloading-the-update) | | `--bg and --print conflict` | [命令行错误](#command-line-errors) | +| `Cloud sessions cannot be created from a --restricted session` | [命令行错误](#cloud-sessions-cannot-be-created-from-a-restricted-session) | +| `Cloud sessions are disabled by your organization's policy` | [命令行错误](#cloud-sessions-are-disabled-by-your-organizations-policy) | +| `Couldn't verify your organization's policy for cloud sessions` | [命令行错误](#cloud-sessions-are-disabled-by-your-organizations-policy) | | `Error: --json-schema is not a valid JSON Schema` | [命令行错误](#command-line-errors) | +| `Error: Invalid --agents configuration:` | [命令行错误](#invalid-agents-configuration) | +| `Error: Settings file exceeds the 2MiB limit` | [命令行错误](#settings-file-exceeds-the-2mib-limit) | +| `The current directory no longer exists (it was deleted or moved)` / `Can't read the current directory` | [命令行错误](#the-current-directory-no-longer-exists) | +| `Temp directory ... Refusing to use it` / `ENOSPC: no space left on device, mkdir ''` | [命令行错误](#temp-directory-refused-or-cannot-be-created) | +| `couldn't be resolved to a real location, so its skills, commands, and agents weren't loaded` | [命令行错误](#directory-couldnt-be-resolved-to-a-real-location) | +| `Error: Workspace not trusted` when starting Remote Control | [命令行错误](#workspace-not-trusted-when-starting-remote-control) | +| `` `` before `remote-control` is not carried over to the sessions Remote Control starts `` | [命令行错误](#not-carried-over-to-the-sessions-remote-control-starts) | +| `` `claude import` is not yet available in this build `` | [命令行错误](#claude-import-is-not-yet-available-in-this-build) | +| `Could not read Claude Code config` | [命令行错误](#could-not-read-claude-code-config) | | `Could not import : ` | [命令行错误](#could-not-import-a-server-from-claude-desktop) | +| `Cannot add MCP server to scope: managed` | [命令行错误](#cannot-add-mcp-server-to-the-managed-scope) | +| `is Anthropic-hosted and doesn't support local OAuth` | [命令行错误](#anthropic-hosted-and-doesnt-support-local-oauth) | +| `Can't read .mcp.json: it isn't a regular file or is larger than 2097152 bytes` | [命令行错误](#cant-read-mcp-json) | +| `Server rejected the Authorization header minted by the configured headersHelper` | [命令行错误](#server-rejected-the-authorization-header-minted-by-the-configured-headershelper) | | `Error: MCP tool (passed via --permission-prompt-tool) not found` | [命令行错误](#mcp-permission-prompt-tool-not-found) | -| `Marketplace "" is registered from an untrusted source` | [插件错误](#marketplace-is-registered-from-an-untrusted-source) | -| `references ${user_config.*} in a shell-form command` | [插件错误](#plugin-command-references-user-config) | -| `Monitor "" from plugin references ${user_config.*} in its command` | [插件错误](#plugin-command-references-user-config) | -| `headersHelper for MCP server '' references ${user_config.*}` | [插件错误](#plugin-command-references-user-config) | +| `OAuth callback port is already in use — another process may be holding it` | [命令行错误](#oauth-callback-port-is-already-in-use) | +| `No available ports for OAuth redirect` | [命令行错误](#no-available-ports-for-oauth-redirect) | +| `Shell command failed for pattern "..."`, from `/security-review` or any skill that injects dynamic context | [命令行错误](#security-review-fails-without-origin-head) | +| `Shell command permission check failed for pattern "..."`, from a skill that injects dynamic context | [命令行错误](#security-review-fails-without-origin-head) | +| ``Skill requires bash (`shell: bash` in frontmatter) but Git Bash was not found`` | [命令行错误](#security-review-fails-without-origin-head) | +| `Input must be provided either through stdin or as a prompt argument when using --print` | [命令行错误](#input-must-be-provided-when-using-print) | +| `Error: Input contained only whitespace` | [命令行错误](#input-contained-only-whitespace) | +| `Blank prompt — the message was only whitespace, so nothing was sent to the model.` | [命令行错误](#input-contained-only-whitespace) | +| `Error: stream-json input carried over 256M characters with no newline` | [命令行错误](#stream-json-input-carried-over-256m-characters-with-no-newline) | +| `Unknown command: /`, with or without a `Did you mean` suggestion | [命令行错误](#unknown-command) | +| `Diff is too large for ultrareview` / `PR # is too large for ultrareview` | [命令行错误](#diff-is-too-large-for-ultrareview) | +| `Could not find merge-base with ` | [命令行错误](#could-not-find-merge-base-with-the-base-branch) | +| `Your checkout has no branches (detached HEAD only)` | [命令行错误](#your-checkout-has-no-branches) | +| `Ultrareview clones / in the cloud with the GitHub account connected to your Claude account, and none is connected` | [命令行错误](#no-github-account-is-connected-to-your-claude-account) | +| `Your connected GitHub account can't see /` | [命令行错误](#your-connected-github-account-cant-see-the-repository) | +| `The GitHub App preflight failed transiently (network or service hiccup) — retry in a moment to start from GitHub instead` | [命令行错误](#the-github-app-preflight-failed-transiently) | +| `GitHub isn't connected to your Claude account, so this repository can't be cloned in the cloud` | [命令行错误](#github-isnt-connected-to-your-claude-account) | +| `Single sign-on authorization needed` | [命令行错误](#single-sign-on-authorization-needed) | +| `Failed to resume the conversation` | [命令行错误](#failed-to-resume-the-conversation) | +| `No conversation found with session ID: ` | [命令行错误](#no-conversation-found-with-the-session-id) | +| `Cannot switch renderers in this session` | [命令行错误](#cannot-switch-renderers-in-this-session) | +| `Cannot switch renderers while work is running in the background` | [命令行错误](#cannot-switch-renderers-in-this-session) | +| `Couldn't open Claude Desktop` | [命令行错误](#couldnt-open-claude-desktop) | +| `Failed to open Claude Desktop. Please try opening it manually.` | [命令行错误](#couldnt-open-claude-desktop) | +| `Couldn't read your Zed keymap` / `Couldn't back up your Zed keymap` / `Couldn't update your Zed keymap` | [命令行错误](#terminal-setup-left-your-zed-keymap-unchanged) | +| `Your Zed keymap isn't a readable list of keybindings` | [命令行错误](#terminal-setup-left-your-zed-keymap-unchanged) | +| `Skill usage reports are not available on this connection.` | [命令行错误](#skill-usage-reports-are-not-available-on-this-connection) | +| `Custom output styles can't be selected over Remote Control or from a relayed message` | [命令行错误](#custom-output-styles-cant-be-selected-over-remote-control) | +| `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) | +| `` `plugin eval` is currently in early access `` / `` `plugin eval` is currently unavailable `` | [Plugin 错误](#plugin-eval-is-currently-in-early-access) | +| `Marketplace "" is registered from an untrusted source` | [Plugin 错误](#marketplace-is-registered-from-an-untrusted-source) | +| `Marketplace "" is already added from a different source` | [Plugin 错误](#marketplace-is-already-added-from-a-different-source) | +| `"" is another spelling of "", a reserved marketplace name` | [Plugin 错误](#marketplace-name-is-another-spelling-of-a-reserved-name) | +| `references ${user_config.*} in a shell-form command` | [Plugin 错误](#plugin-command-references-user-config) | +| `Monitor "" from plugin references ${user_config.*} in its command` | [Plugin 错误](#plugin-command-references-user-config) | +| `headersHelper for MCP server '' references ${user_config.*}` | [Plugin 错误](#plugin-command-references-user-config) | +| `Plugin archive integrity check failed` | [Plugin 错误](#plugin-archive-integrity-check-failed) | +| `path escapes plugin directory` | [Plugin 错误](#path-escapes-plugin-directory) | +| `path could not be checked` | [Plugin 错误](#path-could-not-be-checked) | +| `its marketplace entry path does not stay inside the marketplace directory` | [Plugin 错误](#marketplace-entry-path-does-not-stay-inside-the-marketplace-directory) | +| `Plugin source path refused` | [Plugin 错误](#marketplace-entry-path-does-not-stay-inside-the-marketplace-directory) | +| `Failed to load marketplace configuration` | [Plugin 错误](#failed-to-load-marketplace-configuration) | +| `Marketplace configuration file is corrupted` | [Plugin 错误](#failed-to-load-marketplace-configuration) | +| `Plugin "@synced" is required by your organization and can't be disabled here` | [Plugin 错误](#plugin-is-required-by-your-organization) | | `would be spawned with zero tools — refusing` | [工具错误](#agent-would-be-spawned-with-zero-tools) | | `File is covered by a Read deny rule in your permission settings` | [工具错误](#file-is-covered-by-a-read-deny-rule) | +| `subagent_type is required: the general-purpose agent is not available in this session` | [工具错误](#subagent-type-is-required) | +| `Error: this write left the memory index at MEMORY.md at ..., over its ... read limit` | [工具错误](#memory-index-is-over-its-read-limit) | +| `pkill: refusing to run` | [工具错误](#pkill-pattern-matches-the-claude-code-process) | +| `Failed to write to 's inbox — nothing was sent` | [工具错误](#failed-to-write-to-a-teammate-inbox) | +| `Failed to write the plan approval request to the lead's inbox — plan not submitted` | [工具错误](#failed-to-write-to-a-teammate-inbox) | +| `Its agent definition was not restored: the folder its definition file came from is not trusted` | [工具错误](#teammate-agent-definition-not-restored) | +| `Message too large for cross-session delivery` | [工具错误](#message-too-large-for-cross-session-delivery) | +| `Too many messages to this session just now` | [工具错误](#too-many-messages-to-this-session-just-now) | +| `Refusing to send: reply target is a symlink` / `Refusing to send: cannot vet reply target` | [工具错误](#refusing-to-send-a-cross-session-message) | +| `Refusing to send: connected endpoint is not the expected process` / `Refusing to send: connected endpoint identity could not be read` | [工具错误](#refusing-to-send-a-cross-session-message) | +| `Refusing to send: connected endpoint is not owned by this user` / `Refusing to send: connected endpoint owner could not be read` | [工具错误](#refusing-to-send-a-cross-session-message) | +| `Refusing to send: connected endpoint is a different process with the expected pid` | [工具错误](#refusing-to-send-a-cross-session-message) | +| `Refusing to read : its symlink resolution changed after permission was checked ()` / `Refusing to search : its symlink resolution changed after permission was checked` | [工具错误](#refusing-after-a-symlink-changed) | +| `Refusing to write : its parent-directory symlink resolution changed after permission was checked` / `Refusing to write : it is a symbolic link. Write to the link's target path instead` | [工具错误](#refusing-after-a-symlink-changed) | +| `Refusing to write through symlink: ` / `Refusing to write into symlinked directory: ` | [工具错误](#refusing-after-a-symlink-changed) | +| `Refusing to search : a path one of its Read deny rules is written through changed while the search was being prepared` / `Refusing to search : it could not be opened` | [工具错误](#refusing-after-a-symlink-changed) | +| `its permission check expired before it ran (too many concurrent file operations)` / `ripgrep was found only by name on PATH` | [工具错误](#refusing-after-a-symlink-changed) | +| `task output swap refused (tasks dir moved or linked)` | [工具错误](#task-output-swap-refused) | +| `Command killed: its output file was replaced or could no longer be verified` | [工具错误](#task-output-swap-refused) | +| `the source file is not valid UTF-8 text` / `the source file is not valid UTF-16 text` | [工具错误](#the-source-file-is-not-valid-utf-8-text) | +| `the source file has the replacement character U+FFFD` | [工具错误](#the-source-file-is-not-valid-utf-8-text) | +| `Reading a local file from outside this session's connected folders, or through a link, needs the approval card` | [工具错误](#reading-a-local-file-from-outside-the-connected-folders) | +| `cannot read file_path (...) — the file could not be examined, and no one can answer the approval card` | [工具错误](#reading-a-local-file-from-outside-the-connected-folders) | +| `WebFetch cannot fetch localhost or other hostnames without a dot` | [工具错误](#webfetch-cannot-fetch-localhost) | +| `Can't open MCP settings while no terminal is attached to this background session` | [后台会话错误](#commands-refused-in-a-background-session) | | `Can't open MCP settings in a background session` | [后台会话错误](#commands-refused-in-a-background-session) | +| `blocked because the path is spelled in a form that cannot be safely resolved` | [后台会话错误](#write-or-command-blocked-because-the-path-cannot-be-safely-resolved) | +| `blocked because the path is network-shaped` | [后台会话错误](#write-or-command-blocked-because-the-path-names-a-network-location) | +| `is isolated in the worktree , but this command . Refusing to run it` | [后台会话错误](#command-blocked-by-the-worktree-isolation-checks) | +| `too complex to verify that it stays inside the worktree` | [后台会话错误](#command-blocked-by-the-worktree-isolation-checks) | +| `This session has no saved transcript` | [后台会话错误](#this-session-has-no-saved-transcript) | +| `Can't open — this session is running in another terminal` | [后台会话错误](#this-session-is-running-in-another-terminal) | +| `This conversation is already open in another running Claude session` | [后台会话错误](#this-session-is-running-in-another-terminal) | +| `This session's saved conversation is no longer on disk` | [后台会话错误](#this-sessions-saved-conversation-is-no-longer-on-disk) | +| `kept — its worktree is still at ` | [后台会话错误](#worktree-has-commits-that-are-not-pushed-anywhere) | +| `kept — unpushed commits on ` | [后台会话错误](#worktree-has-commits-that-are-not-pushed-anywhere) | +| `kept — worktree has commits that are not pushed anywhere` | [后台会话错误](#worktree-has-commits-that-are-not-pushed-anywhere) | +| `terminal host process died — press Enter to restart` / `This session's terminal host process died` | [后台会话错误](#terminal-host-process-died) | +| `Session isn't responding` / `Press enter again to restart this session — it isn't responding` | [后台会话错误](#session-isnt-responding) | +| `Session was stopped while the respawn was in flight` | [后台会话错误](#session-was-stopped-while-the-respawn-was-in-flight) | +| `This session was running agent '', which is no longer available` | [后台会话错误](#session-agent-no-longer-available) | | `CLAUDE_CODE_PROCESS_WRAPPER: launcher ...` | [后台会话错误](#claude_code_process_wrapper-launcher-errors) | +| `EUNKNOWN: unknown error, uv_spawn` | [后台会话错误](#eunknown-when-starting-a-background-session) | +| `EACCES: permission denied, posix_spawn` | [后台会话错误](#eacces-when-starting-a-background-session) | +| `exited before it became reachable` | [后台会话错误](#background-service-exited-before-it-became-reachable) | +| `Couldn't start a background session (working directory no longer exists or is not accessible: ...)` | [后台会话错误](#working-directory-no-longer-exists-when-starting-a-background-session) | +| `Claude Code is being updated by npm on this machine (still not runnable after 2 min, ...)` | [后台会话错误](#eacces-when-starting-a-background-session) | +| `Claude Code process exited with code N` | [包装器和 IDE 错误](#claude-code-process-exited-with-code-n) | +| `The connection to Claude Code ended before this message completed` | [包装器和 IDE 错误](#the-connection-to-claude-code-ended-before-this-message-completed) | +| `Could not locate the Claude CLI on PATH` | [包装器和 IDE 错误](#could-not-locate-the-claude-cli-on-path) | +| `Restored the code, but skipped N files` | [Rewind 警告和错误](#restored-the-code-but-skipped-files) | +| `No files were restored: N files failed (backup missing, or the file could not be updated)` | [Rewind 警告和错误](#no-files-were-restored) | +| `Transcript writes are failing (...)` | [会话保存警告](#transcript-writes-are-failing) | +| `Transcript saving is off — CLAUDE_CODE_SKIP_PROMPT_HISTORY is set` | [会话保存警告](#transcript-saving-is-off-skip-prompt-history) | +| `Transcript saving is off — inherited CLAUDE_CODE_CHILD_SESSION marker` | [会话保存警告](#transcript-saving-is-off-child-session-marker) | +| `Claude Code's fullscreen renderer didn't finish starting last time on this machine` / `Claude Code's fullscreen renderer has repeatedly failed to start on this machine` | [配置警告](#fullscreen-failed-start-notice) | +| `Claude Code exited after an unrecoverable interface error (...)` | [配置警告](#exited-after-an-unrecoverable-interface-error) | +| `Agent descriptions are over the 15.0k-token limit` | [配置警告](#agent-descriptions-are-over-the-15000-token-limit) | | `Ignoring N permissions.allow entries from ... this workspace has not been trusted` | [配置警告](#workspace-has-not-been-trusted) | -| 响应质量似乎低于平常 | [响应质量](#responses-seem-lower-quality-than-usual) | +| `is a network path, which cannot be added as a working directory` | [配置警告](#working-directory-is-a-network-path) | +| `Remote managed settings failed to load ()` | [配置警告](#remote-managed-settings-failed-to-load) | +| `Managed settings were not approved; exiting without applying them.` | [配置警告](#managed-settings-were-not-approved) | +| `MCP server is blocked by enterprise managed policy` | [配置警告](#mcp-server-is-blocked-by-enterprise-managed-policy) | +| `Managed settings document could not be parsed as a JSON object; none of its settings are in effect. Fix or remove it.` | [配置警告](#managed-settings-document-could-not-be-parsed) | +| `Managed settings drop-in directory could not be read` | [配置警告](#managed-settings-document-could-not-be-parsed) | +| `otelHeadersHelper failed; telemetry is not being exported. See /status: ...` | [配置警告](#otelheadershelper-failed) | +| `"crossSessionInbound" must be one of "accept", "hold", "refuse"` | [配置警告](#crosssessioninbound-must-be-one-of-accept-hold-refuse) | +| `headersHelper not run — this workspace has no persisted trust` | [配置警告](#headershelper-not-run) | +| `Invalid permission rule "..." was skipped: Malformed Tool(content) rule` | [配置警告](#malformed-tool-content-rule) | +| `... is not matched by file permission checks` | [配置警告](#is-not-matched-by-file-permission-checks) | +| `... has a wildcard before the rest of the command` | [配置警告](#has-a-wildcard-before-the-rest-of-the-command) | +| `CLAUDE_CODE_DISABLE_1M_CONTEXT is set, but the 200K limit isn't enforced` | [配置警告](#the-200k-limit-isnt-enforced) | +| `[claude-code:unrecognized_model]` | [配置警告](#unrecognized-model-id-on-a-request) | +| `Stale sandbox mask files left by a killed session` | [配置警告](#stale-sandbox-mask-files-left-by-a-killed-session) | +| 响应质量似乎比平时低 | [响应质量](#responses-seem-lower-quality-than-usual) |

自动重试

-Claude Code 在向您显示错误之前会重试瞬时故障。服务器错误、过载响应、请求超时、临时 429 限流和断开的连接都会以指数退避方式重试最多 10 次。从 v2.1.198 开始,这涵盖了在任何可见输出流出之前在响应中途断开的连接:Claude Code 使用相同的退避重新发出请求,轮次继续而不是停止并显示连接错误。从 v2.1.199 开始,不携带您计划配额标头的临时 429 限流在您使用 claude.ai 订阅登录时也会重试;早期版本仅对 API 密钥和企业登录重试它们。 +Claude Code 在显示错误之前,会以指数退避方式重试瞬时故障最多 10 次。它并不总是重试在 Claude 响应过程中途出现的故障。当您看到本页面上的错误之一时,Claude Code 已经对该故障进行了适用的重试;下面的列表说明哪些故障获得完整预算、哪些获得较小预算,以及哪些不获得预算。 -某些故障类别不会重试,因为重试无法成功: +Claude Code 重试这些故障: -* 从 v2.1.199 开始,TLS 证书验证失败(例如 TLS 检查代理、缺少 `NODE_EXTRA_CA_CERTS` 包或过期证书)在第一次尝试时失败,因此修复立即出现,而不是在完整重试预算之后。请参阅 [SSL 证书错误](#ssl-certificate-errors)。瞬时 TLS 条件(例如握手超时)仍然会重试。 -* 从 v2.1.199 开始,在 Claude 已经流出可见输出后到达的服务器错误会保留部分响应并附加[不完整响应通知](#the-response-above-may-be-incomplete),而不是重试,因为重新运行请求可能会执行相同的工具两次。早期版本丢弃了部分输出并将轮次报告为错误。 -* [Amazon Bedrock 流式响应具有意外的内容类型](#bedrock-streaming-response-has-an-unexpected-content-type)在第一次尝试时失败,因为网关或代理重写响应会以相同方式重写重试。需要 Claude Code v2.1.208 或更高版本。 +* 在 Claude 响应开始流式传输之前到达的服务器错误、过载响应和请求超时。 +* 连接断开。当连接在请求过程中途断开,且 Claude 尚未完成其响应的任何部分(包括其思考过程)时,Claude Code 会使用相同的退避重新发送请求,转换继续进行,即使某些文本已经开始流式传输。当连接在 Claude 完成思考之后但在开始任何文本或工具调用之前断开时,Claude Code 改为快速连续重新发送请求最多两次,如果连接在该点继续断开,则以 `Connection lost before a response was produced` 结束转换。 +* Claude Code 检测到的连接在您的计算机进入睡眠状态时在请求过程中途被破坏。Claude Code 将其计为上述规则下的断开连接;一旦重试标签命名了具体原因,它会读作 `Connection lost while your computer was asleep`,如果转换在 Claude 完成思考之后但在任何文本或工具调用之前结束,消息会读作 `Your computer went to sleep before a response was produced`。 +* 停滞的响应流,当响应头已到达但 Claude 响应的任何部分都未到达,或当 Claude 完成思考但尚未开始任何文本或工具调用时:Claude Code 中止停滞连接并最多重新发送一次请求,不在上述 10 次尝试预算之外。如果响应在 Claude 完成思考之后但在任何文本或工具调用之前第二次停滞,Claude Code 以 `The response stalled before a response was produced` 结束转换。 +* 流式请求 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` 时,一次重试上限不适用。 +* 临时 429 节流,但不是网关的支出限制 `429`,这不是节流;请参阅 [Spend limit reached](#spend-limit-reached)。 + * 当您使用 claude.ai 订阅登录时,这包括不携带您计划配额头的 429 节流。在 v2.1.199 之前,Claude Code 仅对 API 密钥和企业登录重试这些节流。 +* 因为输入加上 `max_tokens` 超过上下文限制而被拒绝的请求。以相同方式重新发送它会以相同方式失败,所以 Claude Code 使用减少的 `max_tokens` 重试,并在两种情况下停止重试并改为压缩: + * 当没有减少可以适应时,例如当对话本身几乎填满上下文窗口时。 + * 当重试无法进一步缩小 `max_tokens` 时。在 v2.1.218 之前,Claude Code 可以重新发送仍然不适应的减少请求,例如当扩展思考预算超过剩余上下文时,直到重试预算用尽。 +* [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 凭证,然后显示错误。 +* 来自 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)。 -重试时,微调器在错误标签后显示 `Retrying in Ns · attempt x/y` 倒计时。标签命名了第一次尝试中您可以立即采取行动的特定原因:网络已关闭、TLS 握手失败或您达到了速率限制。对于其他错误,它最初读作 `API error`。从 v2.1.198 开始,它切换到第三次尝试中的特定原因,或当 `CLAUDE_CODE_MAX_RETRIES` 允许少于三次时在最后一次尝试;早期版本仅在最后一次尝试时切换。 +在 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`。 -从 v2.1.198 开始,重试期间会抑制通常的微调器提示。一旦错误原因被揭示,如果故障是 529 过载,倒计时下方的行也会命名检查服务状态的位置:Anthropic API 上的 `status.claude.com`,或其他配置上的提供商或网关主机。 +Claude Code 不重试这些故障: -如果在请求仍然待处理时,响应流上 20 秒内没有数据到达,微调器会显示 `Waiting for API response · will retry in … · check your network`,然后再进行任何重试。请求尚未失败:倒计时运行到 Claude Code 中止停滞连接并重试的点,因此一旦数据恢复或重试成功,横幅就会自动清除。从 v2.1.185 开始,阈值为 20 秒;早期版本在 10 秒后显示横幅,措辞不同。如果它在每次尝试时都重新出现,请将其视为[网络问题](#unable-to-connect-to-api)。 +* TLS 证书验证失败,例如 TLS 检查代理、缺失的 `NODE_EXTRA_CA_CERTS` 包或过期的证书。Claude Code 在第一次尝试时报告错误,以便您可以立即修复证书设置;请参阅 [SSL certificate errors](#ssl-certificate-errors)。Claude Code 仍然重试瞬时 TLS 条件,例如握手超时。在 v2.1.199 之前,Claude Code 通过完整重试预算重试证书失败,然后显示错误。 +* 服务器错误、断开连接或停滞流在 Claude 完成文本块或工具调用之后到达,或在完成思考之后开始一个但在完成响应之前。Claude Code 不重新运行请求,因为这可能会执行相同的工具调用两次。它保留 Claude 完成的内容,运行 Claude 完成的任何工具调用,并从其结果继续转换。对于您在交互式会话和非交互式会话中看到的内容,请阅读 [The response above may be incomplete](#the-response-above-may-be-incomplete)。在 v2.1.199 之前,当服务器错误在流中途到达时,Claude Code 丢弃部分输出并将整个转换报告为错误。 +* 在 Claude 完成响应之后到达的故障:无需重试任何内容,所以 Claude Code 保留完整响应并正常结束转换。 +* [Amazon Bedrock 流式响应具有意外的 content-type](#bedrock-streaming-response-has-an-unexpected-content-type),因为重写响应的网关或代理会以相同方式重写重试。需要 Claude Code v2.1.208 或更高版本。 +* 失败的流式请求的非流式重试获得成功状态但 [body 中没有 Claude API 消息](#api-returned-an-empty-or-malformed-response)。Claude Code 以该错误结束转换。 +* 您的组织的策略检查拒绝的请求,其表现为携带拒绝消息的 `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 可以重新发送拒绝的请求,不流式传输或在配置的备用模型上,然后向您显示拒绝。 -当您看到本页上的错误之一时,这些重试已经用尽,除非它属于不会重试的类别,例如证书验证失败。您可以使用这些环境变量调整行为: +

+ Claude Code 重试或等待时您看到的内容 +

+ +重试时,微调器在错误标签后显示 `Retrying in Ns · attempt x/y` 倒计时。标签命名第一次尝试的具体原因,用于您可以立即采取行动的故障:网络已关闭、TLS 握手失败或您达到速率限制。对于其他错误,它最初读作 `API error`。从 v2.1.198 开始,它切换到第三次尝试的具体原因,或当 `CLAUDE_CODE_MAX_RETRIES` 允许少于三次时在最后一次尝试;较早版本仅在最后一次尝试时切换。 + +从 v2.1.198 开始,通常的微调器提示在重试期间被抑制。一旦错误原因被揭示,如果故障是 529 过载,倒计时下方的行也命名了检查服务状态的位置:Anthropic API 上的 `status.claude.com`,或其他配置上的提供商或网关主机。 + +如果在请求仍然待处理时响应流上 20 秒内没有数据到达,微调器显示 `Waiting for API response · will retry in … · check your network`,然后任何重试都尚未开始。请求尚未失败:倒计时运行到 Claude Code 中止停滞连接的点。中止后,您看到的内容取决于响应已进行的距离: + +* 在 Claude 完成文本块或工具调用之前,或在完成思考之后开始一个,Claude Code 重试请求或以错误结束转换。[Automatic retries](#automatic-retries) 说明它重试哪些停滞以及多少次。 +* 在 Claude 完成文本块或工具调用之后,或在完成思考之后开始一个,但在 Claude 完成响应之前,Claude Code 保留 Claude 完成的内容,从 Claude 完成的任何工具调用继续转换,并显示 [The response above may be incomplete](#the-response-above-may-be-incomplete)。在非交互式会话中,以及对于任何会话中的子代理响应,Claude Code 可能首先提示 Claude 继续响应;该条目说明何时执行以及何时您仍然在那里看到通知。 +* 在 Claude 完成响应之后,Claude Code 正常结束转换。 + +一旦数据恢复或重试成功,横幅会自动清除。如果它在每次尝试时重新出现,将其视为 [network issue](#unable-to-connect-to-api)。在 v2.1.185 之前,横幅在 10 秒后出现,措辞不同。 + +当 Claude 咨询 [advisor](/docs/zh-CN/advisor) 时,横幅在 90 秒无数据后出现,而不是 20 秒,因为长时间的顾问审查可以发送超过 20 秒的任何内容。在 v2.1.214 之前,20 秒阈值也适用于顾问调用,所以横幅在顾问审查期间出现,即使没有任何问题。 + +

+ 调整重试行为 +

+ +您可以使用这些环境变量调整重试行为: | 变量 | 默认值 | 效果 | -| :---------------------------------------------- | :----- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [`CLAUDE_CODE_MAX_RETRIES`](/docs/zh-CN/env-vars) | 10 | 重试次数。从 v2.1.186 开始上限为 15;从 v2.1.199 开始 `CLAUDE_CODE_RETRY_WATCHDOG` 提高默认值并移除上限。降低它以在脚本中更快地显示故障。 | -| [`CLAUDE_CODE_RETRY_WATCHDOG`](/docs/zh-CN/env-vars) | 未设置 | 在 CI 作业等无人值守会话中设置为 `1`,以无限期重试 `429` 和 `529` 容量错误,而不是在 `CLAUDE_CODE_MAX_RETRIES` 次尝试后失败。从 v2.1.199 开始,它也提高了其他瞬时错误(例如服务器错误、超时和断开的连接)的默认重试计数至 300,大约三小时的退避,如果您显式设置该变量,则移除 `CLAUDE_CODE_MAX_RETRIES` 的 15 上限。 | -| [`API_TIMEOUT_MS`](/docs/zh-CN/env-vars) | 600000 | 每个请求的超时时间(毫秒)。为慢速网络或代理提高它。 | +| :------------------------------------------------------- | :----- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| [`CLAUDE_CODE_MAX_RETRIES`](/docs/zh-CN/env-vars) | 10 | 重试尝试次数。从 v2.1.186 开始上限为 15;从 v2.1.199 开始 `CLAUDE_CODE_RETRY_WATCHDOG` 提高默认值并移除上限。降低它以在脚本中更快地显示故障。 | +| [`CLAUDE_CODE_RETRY_WATCHDOG`](/docs/zh-CN/env-vars) | 未设置 | 在 CI 作业等无人值守会话中设置为 `1`,以无限期重试 `429` 和 `529` 容量错误,而不是在 `CLAUDE_CODE_MAX_RETRIES` 尝试后失败。当标准速度请求获得报告支出限制或耗尽使用额度的 `429` 时,Claude Code 立即失败,即使来自 [gateway spend cap](#spend-limit-reached) 的也是如此,该上限按计划重置。在 v2.1.239 之前,看门狗无限期重试这些。对于快速模式请求,请参阅 [Handle rate limits](/docs/zh-CN/fast-mode#handle-rate-limits)。在 v2.1.199 或更高版本上,它还为其他瞬时错误(例如服务器错误、超时和断开连接)提高默认重试计数至 300,大约三小时的退避,如果您明确设置该变量,则移除 `CLAUDE_CODE_MAX_RETRIES` 的 15 上限。 | +| [`API_TIMEOUT_MS`](/docs/zh-CN/env-vars) | 600000 | 每个请求的超时(毫秒)。为慢速网络或代理提高它。它还限制 Claude Code 等待响应头的时间,在 [No response from API](#no-response-from-api) 中描述。 | +| [`CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS`](/docs/zh-CN/env-vars) | 未设置 | 流式请求的第一个响应字节的截止时间(毫秒)。需要 Claude Code v2.1.242 或更高版本。对于当此未设置时 Claude Code 如何选择截止时间,请参阅 [No response from API](#no-response-from-api)。 |

服务器错误

-这些错误来自推理提供商,而不是您的账户或请求。在 Anthropic API 上,这意味着 Anthropic 基础设施。在 Amazon Bedrock、Google Cloud 的 Agent Platform、Microsoft Foundry 或自定义网关上,这意味着该提供商的基础设施。 +这些错误中的大多数来自推理提供商: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 账户或达到使用限制的子代理。

- API 错误:500 内部服务器错误 + API Error: 500 Internal server error

-Claude Code 显示任何 5xx 响应的状态代码和 API 的错误消息。下面的示例显示了 Anthropic API 上的 500 响应: +Claude Code 显示任何 5xx 响应的状态代码和 API 的错误消息。下面的示例显示 Anthropic API 上的 500 响应: ```text theme={null} API Error: 500 Internal server error. This is a server-side issue, usually temporary — try again in a moment. If it persists, check https://status.claude.com. ``` -末尾的句子指出了检查服务健康状态的位置,因提供商而异。Amazon Bedrock、Google Cloud 的 Agent Platform 和 Microsoft Foundry 配置会指出该提供商的服务状态。自定义 `ANTHROPIC_BASE_URL` 会指出网关主机。 +尾部句子指出了检查服务健康状况的位置,因提供商而异。Amazon Bedrock、Google Cloud 的 Agent Platform 和 Microsoft Foundry 配置会指出该提供商的服务状态。自定义 `ANTHROPIC_BASE_URL` 会指出网关主机。 这表示 API 内部出现了意外故障。它不是由您的提示、设置或账户引起的。 **应该做什么:** -* 检查 [status.claude.com](https://status.claude.com) 或消息中指定的提供商状态页面,查看是否有活跃的事件 -* 等待一分钟,然后重新发送您的消息。您的原始消息仍在对话中,所以对于较长的提示,您可以输入 `try again` 而不是粘贴整个内容。 -* 如果错误持续存在且没有发布的事件,请运行 `/feedback`,以便 Anthropic 可以使用您的请求详情进行调查。如果 `/feedback` 在您的环境中不可用,请参阅[报告错误](#report-an-error)。 +* 检查 [status.claude.com](https://status.claude.com) 或消息中指出的提供商状态页面,查看是否有活跃事件 +* 等待一分钟,然后再次发送您的消息。您的原始消息仍在对话中,因此对于较长的提示,您可以输入 `try again` 而不是粘贴整个内容。 +* 如果错误持续存在且没有发布事件,请运行 `/feedback` 以便 Anthropic 可以使用您的请求详情进行调查。如果您的环境中 `/feedback` 不可用,请参阅[报告错误](#report-an-error)。

- API 错误:重复的 529 过载错误 + API Error: Repeated 529 Overloaded errors

API 在所有用户中暂时处于容量限制。Claude Code 在显示此消息之前已经重试了多次: @@ -155,18 +408,18 @@ API 在所有用户中暂时处于容量限制。Claude Code 在显示此消息 API Error: Repeated 529 Overloaded errors. The API is at capacity — this is usually temporary. Try again in a moment. If it persists, check https://status.claude.com. ``` -末尾的句子因提供商而异,方式与上面的 500 错误相同。 +尾部句子因提供商而异,方式与上面的 500 错误相同。 529 不是您的使用限制,也不会计入您的配额。 **应该做什么:** -* 检查 [status.claude.com](https://status.claude.com) 或消息中指定的提供商状态页面,查看容量通知 +* 检查 [status.claude.com](https://status.claude.com) 或消息中指出的提供商状态页面,查看容量通知 * 几分钟后重试 -* 运行 `/model` 并切换到不同的模型以继续工作,因为容量是按模型跟踪的。当某个模型处于特别高的负载下时,Claude Code 会提示您这样做,例如 `Opus is experiencing high load, please use /model to switch to Sonnet`。 +* 运行 `/model` 并切换到不同的模型以继续工作,因为容量是按模型跟踪的。当一个模型处于特别高的负载下时,Claude Code 会提示您这样做,例如 `Opus is experiencing high load, please use /model to switch to Sonnet`。

- 请求超时 + Request timed out

API 在连接截止时间之前没有响应。 @@ -175,56 +428,101 @@ API 在连接截止时间之前没有响应。 Request timed out ``` -这可能发生在高负载期间或模型生成非常大的响应时。默认请求超时为 10 分钟。 +这可能在高负载期间或模型生成非常大的响应时发生。默认请求超时为 10 分钟。 **应该做什么:** * 重试请求 * 对于长时间运行的任务,将工作分解为较小的提示 -* 如果是由于网络缓慢或代理引起的,请按照[自动重试](#automatic-retries)中的说明提高 `API_TIMEOUT_MS` +* 如果是缓慢的网络或代理导致,请按照[自动重试](#automatic-retries)中的说明提高 `API_TIMEOUT_MS` * 如果超时频繁且您的网络状况良好,请参阅下面的[网络和连接错误](#network-and-connection-errors) +

+ No response from API +

+ +Claude 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)中描述的预算下重试。 + +```text theme={null} +API 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. +``` + +Claude Code 分别为第一次尝试的等待响应头和重试的等待设置: + +* **第一次尝试**:当您将其设置为 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 添加一秒。 +* **重试**:比 `API_TIMEOUT_MS` 少一秒,默认略低于 10 分钟,以便重试可以超过保持响应直到生成完成的代理或网关。在 Amazon Bedrock 上,重试使用与第一次尝试相同的截止时间,消息显示一个持续时间而不是两个。 + +两个等待都不超过正 `API_TIMEOUT_MS` 少一秒,正 `API_TIMEOUT_MS` 低于 11 秒会关闭截止时间。字节级监视程序仅在响应头到达后才开始,因此在此之后停止发送字节的响应遵循[停滞流规则](#automatic-retries)而不是此截止时间。 + +**应该做什么:** + +* 再次发送您的消息。您的原始消息仍在对话中,因此对于较长的提示,您可以输入 `try again` 而不是粘贴整个内容。 +* 如果重复出现,将其视为[网络或代理问题](#unable-to-connect-to-api)。接受连接但从不转发请求的代理会在每次尝试时产生此错误。 +* 如果您网络上的代理或网关保持响应直到完成,请提高 `API_TIMEOUT_MS` 以便重试等待更长时间。在 Amazon Bedrock 上,也提高 `CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS`。 +* 如果第一次尝试持续超时,然后重试成功,请提高 `CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS` 以便第一次尝试也等待足够长的时间。 + +在 v2.1.242 之前,Claude Code 在未回复的流式请求失败之前等待完整的 `API_TIMEOUT_MS` 请求超时(默认为 10 分钟)。在 v2.1.261 之前,重试等待与第一次尝试相同的截止时间,消息没有显示持续时间。 +

- 上面的响应可能不完整 + The response above may be incomplete

-流式响应在 Claude 已经生成可见输出后失败。重新发送请求可能会运行相同的工具调用两次,因此 Claude Code 保留已经流式传输的内容,并附加此通知,而不是丢弃该轮次。您看到的变体指出了原因: +流式请求在响应仍在进行中时失败,在 Claude 完成了一个文本块或工具调用之后,或在完成思考后开始了一个。重新发送请求可能会运行相同的工具调用两次,因此 Claude Code 保留 Claude 完成的输出并附加此通知,而不是丢弃该轮次。您看到的变体指出了原因: ```text theme={null} API Error: Server error mid-response. The response above may be incomplete. -API Error: Connection closed mid-response. The response above may be incomplete. -API Error: Response stalled mid-stream. The response above may be incomplete. +API Error: Connection lost mid-response. The response above may be incomplete. +API Error: Your computer went to sleep mid-response. The response above may be incomplete. +API Error: The response stopped arriving. The response above may be incomplete. ``` -* }`Server error mid-response`:流中的过载或 5xx 服务器错误。此变体需要 Claude Code v2.1.199 或更高版本;在此之前,该情况会丢弃部分输出并将整个轮次报告为错误。 -* `Connection closed mid-response`:连接断开。 -* `Response stalled mid-stream`:流停止发送数据。 +* `Server error mid-response`:中流过载或 5xx 服务器错误。此变体需要 Claude Code v2.1.199 或更高版本;在此之前,该情况会丢弃部分输出并将整个轮次报告为错误。 +* `Connection lost mid-response`:连接断开。 +* `Your computer went to sleep mid-response`:Claude Code 检测到您的计算机在响应流式传输时进入睡眠状态。一旦您的计算机唤醒,Claude Code 会将连接视为断开并停止从中读取。 +* `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)。 + +在 v2.1.227 之前,`Connection lost mid-response` 读作 `Connection closed mid-response`,`The response stopped arriving` 读作 `Response stalled mid-stream`。 + +在四种情况下,Claude Code 处理故障而不立即显示此通知: + +* 在响应的早期,Claude Code 要么重试故障,要么以不同的错误结束轮次。请参阅[自动重试](#automatic-retries)。 +* 当这些故障之一在 Claude 完成响应后到达时,Claude Code 保留完整响应并正常结束轮次,没有此通知。在 v2.1.222 之前,当连接在响应完成后断开或停滞时,Claude Code 显示此通知,并将轮次报告为错误,即使响应是完整的。 +* 在[非交互式会话](/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 在第一次截断时以此通知结束非交互式轮次。 +* 在[子代理](/docs/zh-CN/sub-agents#api-errors-in-subagents)中,无论会话是否交互式:当其截断响应包含文本但没有工具调用时,Claude Code 提示子代理继续。通知仅在这些继续用完后才成为子代理的最后一条消息。在 v2.1.257 之前,子代理在第一次截断时显示此通知。 **应该做什么:** -* 阅读流式传输的响应。没有任何内容丢失,但最后的句子或工具调用可能缺失。 -* 回复 `continue` 让 Claude 从停止的地方继续 -* 如果在任何可见输出之前出现相同的错误,Claude Code 会重试请求而不是完成它。请参阅[自动重试](#automatic-retries)。 +* 在交互式会话中,阅读屏幕上剩余的响应:Claude Code 保留 Claude 在错误前完成的每个块,但当轮次结束时丢弃中断的最后块,因此最后的句子或工具调用可能会丢失。回复 `continue` 以让 Claude 从其最后完成的块继续。 +* 在[非交互式模式](/docs/zh-CN/headless)(`-p`)中: + * 使用默认文本输出,Claude Code 打印它仍然从轮次早期保留的最后完成的文本块,然后是此消息。当它不保留任何内容时,Claude Code 仅打印此消息,例如因为 Claude Code 在轮次中间压缩了对话并清除了该文本。在 v2.1.219 之前,Claude Code 仅在 `-p` 文本输出中打印此消息并丢弃它已经生成的响应。 + * 使用 `--output-format json` 或 `stream-json`,Claude Code 在 `result` 字段中报告此消息。 + * 一旦连接稳定,要继续该轮次,请恢复会话并按照[继续对话](/docs/zh-CN/headless#continue-conversations)中的说明发送 `continue`。

- 自动模式无法确定操作的安全性 + Auto mode cannot determine the safety of an action

-[自动模式](/docs/zh-CN/permission-modes#eliminate-prompts-with-auto-mode)用来分类操作的模型无法做出决定,因此自动模式没有自动批准该操作。您看到的消息取决于分类器失败的原因。 +[auto mode](/docs/zh-CN/permission-modes#eliminate-prompts-with-auto-mode) 使用的模型无法对操作进行分类,因此 auto mode 没有自动批准该操作。您看到的消息取决于分类器如何失败。 -在您的工作目录内的读取、搜索和编辑会跳过分类器,因此在所有这些情况下都能继续工作。 +对工作目录内的读取、搜索和编辑会跳过分类器,因此它们在所有这些情况下都继续工作。 -当分类器模型过载时: +当分类器模型不可用时: ```text theme={null} - is temporarily unavailable, so auto mode cannot determine the safety of right now. Wait briefly and then try this action again. + is temporarily unavailable, so auto mode cannot determine the safety of right now. Wait a moment and then try this action again. ``` +当 Claude Code 可以确定故障类别时,它在 `temporarily unavailable` 后的括号中指出该类别,例如 ` is temporarily unavailable (rate-limited), so auto mode cannot determine the safety of right now`。类别为 `(rate-limited)`、`(overloaded)`、`(server error)`、`(timed out)` 和 `(connection failed)`。速率限制、过载和服务器错误是暂时的,重试有效。如果 `(timed out)` 或 `(connection failed)` 重复出现,请检查您的连接;请参阅[无法连接到 API](#unable-to-connect-to-api)。在 v2.1.229 之前,消息从不指出类别,读作 `Wait briefly and then try this action again`。 + +当没有类别适用时,消息出现时括号中没有类别;多个故障会产生该形式。在 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 上,包括 [Mantle 端点](/docs/zh-CN/amazon-bedrock#use-the-mantle-endpoint),当您的 AWS 账户无法调用消息中指出的模型时,它也会出现,该故障在每次重试时重复,直到您的账户被授予访问该模型的权限。 + **应该做什么:** -* 几秒钟后重试;Claude 会看到相同的消息,通常会自动重试 -* 如果重试继续失败,继续执行只读任务,稍后再回到被阻止的操作 -* 这是暂时的,与[自动模式资格](/docs/zh-CN/permission-modes#eliminate-prompts-with-auto-mode)无关;您不需要更改设置 +* 几秒后重试;Claude 看到相同的消息,通常会自动重试。暂时故障与 [auto mode 资格](/docs/zh-CN/permission-modes#eliminate-prompts-with-auto-mode)无关;您不需要更改设置 +* 如果重试持续失败,继续进行只读任务,稍后回到被阻止的操作 +* 在 Amazon Bedrock 上,如果消息在每次重试时返回,请检查您的账户是否可以调用它指出的模型:对于标准 Amazon Bedrock 模型,确认您的 [IAM 策略](/docs/zh-CN/amazon-bedrock#iam-configuration)允许调用它;对于 Mantle 模型 ID,[联系您的 AWS 账户团队](/docs/zh-CN/amazon-bedrock#mantle-endpoint-errors) + +当分类器请求失败是因为您的 OAuth 令牌过期或被另一个会话轮换时,Claude Code 刷新令牌并重试请求一次,因此例行令牌过期不会显示为此消息。在 v2.1.216 之前,过期或轮换的令牌会导致每个分类器请求失败,auto mode 会拒绝每个检查的操作,直到令牌被刷新。 当分类器返回无法解析的响应时: @@ -237,36 +535,81 @@ Auto mode could not evaluate this action and is blocking it for safety — run w * 重试该操作;这通常在下一次尝试时成功 * 运行 `claude --debug` 并重复该操作以在调试日志中查看底层分类器响应 -当单独的 API 安全检查因早期对话内容而阻止了分类器请求时: +当单独的 API 安全检查因早期对话内容而阻止分类器请求时: ```text theme={null} Auto 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 ``` +Claude Code 拒绝该操作,但告诉 Claude 这不是对该操作不安全的判断,并继续进行其他任务而不是重试。这些拒绝不计入 [auto mode 的暂停阈值](/docs/zh-CN/permission-modes#when-auto-mode-falls-back)。在[非交互式](/docs/zh-CN/headless) `-p` 运行中,Claude Code 不会停止运行。Claude 接收的内容取决于它请求操作的位置: + +* 对于 `-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` 的错误结果 +* 在其他地方,包括交互式会话和 `-p` 运行的主对话,Claude Code 将该拒绝返回给 Claude + +在 v2.1.225 之前,Claude Code 将这些拒绝计入暂停阈值,并返回与真正分类器块相同的拒绝消息。 + **应该做什么:** -* 这不是关于您的操作的决定。您对话中已有的内容在自动模式将对话发送给分类器时触发了 API 上的安全过滤器 +* 这不是对您的操作的决定。您对话中已有的内容在 auto mode 将对话发送给分类器时触发了 API 上的安全过滤器 * 重试无法帮助;相同的对话内容将再次触发过滤器 -* 切换到不同的[权限模式](/docs/zh-CN/permission-modes),以便在提示时可以批准该操作,或开始一个没有触发内容的新对话 +* 在交互式会话中,切换到不同的[权限模式](/docs/zh-CN/permission-modes),以便您可以在提示时批准该操作 +* 开始一个新对话,不包含触发内容 -当对话大小超过分类器的上下文窗口时: +当对话增长到超过分类器的上下文窗口时: ```text theme={null} Auto mode classifier transcript exceeded context window — falling back to manual approval (try /compact to reduce conversation size) ``` -在交互式会话中,自动模式会为该操作回退到正常权限提示,以便您可以手动批准或拒绝它。在[非交互式模式](/docs/zh-CN/headless)中,运行会中止,因为记录只会增长,重试无法成功。 +操作发生的情况取决于 Claude 请求它的位置: + +* 在交互式会话中,auto mode 回退到该操作的正常权限提示,以便您可以手动批准或拒绝它 +* 对于[非交互式](/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` 的错误结果,运行继续 +* 在 `-p` 运行中的其他地方,没有 [`--permission-prompt-tool`](/docs/zh-CN/cli-reference#cli-flags),没有提示可以回退到,因此操作不运行,运行继续 + +**应该做什么:** + +* 在交互式会话中,在出现的提示中批准或拒绝该操作 +* 在交互式会话中,运行 `/compact` 以减少对话大小,以便后续操作再次适应分类器窗口 + +

+ The server returned no safety verdict +

+ +在[服务器端分类器审查](/docs/zh-CN/permission-modes#server-side-classifier-review)下,当服务器对操作没有给出判决时,auto mode 拒绝该操作。当 Claude Code 可以确定一个类别时,拒绝会在括号中指出一个类别,例如 `(timed out)`: + +```text theme={null} +The server-side auto mode classifier gave no verdict (timed out), so auto mode cannot determine the safety of . +``` + +消息的其余部分告诉 Claude 一次重试是否可以帮助。在某些这些拒绝之前,Claude Code 会等待,以便 Claude 的下一次尝试不会立即跟随。在交互式会话中等待期间,微调器显示 `Auto mode check unavailable` 和倒计时,按 `Esc` 会中断轮次。 + +在连续十个响应都没有判决后,auto mode 停止轮次: + +```text theme={null} +Auto 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. +``` + +停止消息在每种会话中出现在不同的位置: + +* 在交互式会话中,消息作为警告出现在记录中,轮次结束 +* 在[非交互式](/docs/zh-CN/headless) `-p` 运行中,运行结束并报告执行错误。使用默认文本输出,消息在 stderr 上打印。 +* 当[子代理](/docs/zh-CN/sub-agents)达到限制时,子代理在完成之前停止,Claude 接收它生成的任何内容,并附带 auto mode 停止它的说明 **应该做什么:** -* 在出现的提示中批准或拒绝该操作 -* 运行 `/compact` 以减少对话大小,以便后续操作再次适应分类器窗口 +* 发送另一条消息以让 Claude 重试。响应计数重新开始。 +* 如果停止重复且您的请求通过[LLM 网关或代理](/docs/zh-CN/llm-gateway),检查它是否截断流式响应或重写它们。[服务器端分类器审查](/docs/zh-CN/permission-modes#server-side-classifier-review)说明哪种网关行为会导致拒绝,[网关兼容性指南](/docs/zh-CN/llm-gateway-protocol#feature-pass-through)列出了要保持不变的内容。 +* 在启动 Claude Code 之前设置 `CLAUDE_CODE_AUTO_MODE_SERVER=0` 以改用其自己的分类器请求。在 v2.1.281 之前,Claude Code 在直接连接到 Anthropic API 时不读取该变量。 +* 要自己批准操作,请改为[切换出 auto mode](/docs/zh-CN/permission-modes#switch-permission-modes) + +在 v2.1.280 之前,Claude Code 立即拒绝来自没有判决的响应的每个操作,从不停止轮次。

- 代理因 API 错误而提前终止 + Agent terminated early due to an API error

-[子代理](/docs/zh-CN/sub-agents)的 API 请求终止失败,例如因为达到了使用限制或服务器错误的重试用尽,所以子代理在完成其任务之前停止。此消息需要 Claude Code v2.1.199 或更高版本;在此之前,API 错误文本被返回给 Claude,就像它是子代理的结果一样。 +[子代理](/docs/zh-CN/sub-agents)的 API 请求终止失败,例如因为达到了使用限制或服务器错误的重试用尽,因此子代理在完成其任务之前停止。此消息需要 Claude Code v2.1.199 或更高版本;在此之前,API 错误文本被返回给 Claude,就像它是子代理的结果一样。 ```text theme={null} Agent terminated early due to an API error: @@ -274,66 +617,95 @@ Agent terminated early due to an API error: **应该做什么:** -* 将冒号后的错误详情与此页面上的其自己的部分相匹配,例如[使用限制](#usage-limits)或[服务器错误](#server-errors),并按照该部分的步骤操作 +* 将冒号后的错误详情与此页面上的其自己的部分匹配,例如[使用限制](#usage-limits)或[服务器错误](#server-errors),并按照该部分的步骤操作 * 一旦底层错误清除,请要求 Claude 重试任务或[恢复子代理](/docs/zh-CN/sub-agents#resume-subagents) -当速率限制、过载或服务器错误中断已经生成文本输出的前台子代理时,Claude 会收到该部分输出标记为不完整,而不是此错误。仅输出为工具调用的子代理也会收到此错误;在 v2.1.199 中,该形状返回了空的部分结果。请参阅[子代理中的 API 错误](/docs/zh-CN/sub-agents#api-errors-in-subagents)。 +当速率限制、过载或服务器错误中断已经生成文本输出的前台子代理时,Claude 接收该部分输出标记为不完整,而不是此错误。仅输出为工具调用的子代理也会收到此错误;在 v2.1.199 中,该形状返回了空的部分结果。请参阅[子代理中的 API 错误](/docs/zh-CN/sub-agents#api-errors-in-subagents)。

使用限制

-这些错误表示与您的账户或计划相关的配额已达到。它们不同于[服务器错误](#server-errors),后者会影响所有人。 +本部分中的大多数错误意味着与您的账户或计划相关的配额已达到。其中三个的工作方式不同:[`Server is temporarily limiting requests`](#server-is-temporarily-limiting-requests) 是与您的计划配额无关的服务器端限流,[`Usage credits required for 1M context`](#usage-credits-required-for-1m-context) 是权限检查而非配额耗尽,[`The prompt to confirm went unanswered`](#the-prompt-to-confirm-went-unanswered) 表示使用额度同意提示未被回答而关闭,无论是否达到配额。

- 您已达到会话限制 + You've hit your session limit

-订阅计划包括滚动使用额度。当额度用尽时,您会看到以下消息之一: +订阅计划包括滚动使用额度。当额度用完时,您会看到以下消息之一: ```text theme={null} You've hit your session limit · resets 3:45pm You've hit your weekly limit · resets Mon 12:00am You've hit your Opus limit · resets 3:45pm +You've hit your Sonnet limit · resets 3:45pm ``` -Claude Code 会阻止进一步的请求,直到消息中显示的重置时间。会话和每周限制在所有模型中共享,因此切换模型不会恢复访问权限。Opus 限制仅适用于 Opus 请求,因此使用 `/model` 切换到另一个模型可以继续工作。 +Claude Code 会阻止进一步的请求,直到消息中显示的重置时间。会话和周限制在所有模型中共享,因此切换模型不会恢复访问权限。Opus 和 Sonnet 限制各自仅适用于对该模型系列的请求,因此使用 `/model` 切换到该系列之外的模型可以继续工作。 -使用量同时计入会话和每周额度。单次大量活动突发(例如大型工作流扇出)可能会在会话窗口重置之前耗尽每周额度。 +在使用 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 不提供此等待功能。 -**应该怎么做:** +使用量同时计入会话和周额度。单次大量活动突发(例如大型工作流扇出)可能会在会话窗口重置之前耗尽周额度。 + +**要做什么:** -* 等待错误消息中显示的重置时间 -* 对于 Opus 限制,运行 `/model` 并切换到另一个模型以继续工作 -* 运行 `/usage` 查看您的计划限制以及它们何时重置 -* 运行 `/usage-credits` 在 Pro 和 Max 上购买额外使用量,或在 Team 和 Enterprise 上向您的管理员请求。有关如何计费,请参阅[付费计划的使用额度](https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans)。 +* 等待错误中显示的重置时间 +* 在 [Desktop app](/docs/zh-CN/desktop) 的 Code 选项卡中,会话限制卡提供 **Auto-continue when limits reset** 复选框。周限制卡没有。选中后,Desktop app 会在重置后重试中断的轮次,并在卡上显示重试时间。Desktop 复选框和 CLI 中 `/config` 中的 **Continue automatically at usage limit** 设置是分开的,因此需要分别关闭每一个。 +* 对于 Opus 或 Sonnet 限制,运行 `/model` 并切换到该系列之外的模型以继续工作。每个模型都有自己的提示缓存,因此下一个请求会重新读取整个对话,没有缓存命中;请参阅 [Switching models](/docs/zh-CN/prompt-caching#switching-models) +* 运行 `/usage` 查看您的计划限制以及何时重置 +* 运行 `/usage-credits` 在 Pro 和 Max 上购买额外使用,或在 Team 和 Enterprise 上向您的管理员请求。有关如何计费的信息,请参阅 [usage credits for paid plans](https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans)。 * 要升级您的计划以获得更高的基础限制,请参阅 [claude.com/pricing](https://claude.com/pricing) -要在达到限制之前监控您的剩余额度,请将 `rate_limits` 字段添加到[自定义状态行](/docs/zh-CN/statusline#rate-limit-usage),或在桌面应用中单击模型选择器旁边的[使用量环](/docs/zh-CN/desktop#check-usage)。 +在窗口用完之前,Claude Code 可以警告您已使用了大部分额度,显示类似 `You've used 85% of your session limit · resets 3:45pm` 的消息。要持续监视您的剩余额度,请将 `rate_limits` 字段添加到 [custom status line](/docs/zh-CN/statusline#rate-limit-usage),或在 Desktop app 中单击模型选择器旁边的 [usage ring](/docs/zh-CN/desktop#check-usage)。

- 1M 上下文需要使用额度 + Usage credits required for 1M context

-所选模型使用 1M 令牌扩展上下文窗口,而您的计划仅通过使用额度包含它。 +所选模型使用 1M 令牌扩展上下文窗口,您的计划仅通过使用额度包含它。 ```text theme={null} -API Error: Usage credits required for 1M context · run /usage-credits to turn them on, or /model to switch to standard context +API Error: Usage credits required for 1M context · run /usage-credits to turn them on (they take effect after you restart Claude Code), or /model to switch to standard context ``` -这是一项权利检查,而不是配额耗尽。即使您的会话和每周额度仍有容量,它也会触发。有关哪些计划直接包含 1M 上下文以及哪些需要使用额度,请参阅[扩展上下文](/docs/zh-CN/model-config#extended-context)。 +这是权限检查,而非配额耗尽。即使您的会话和周额度有剩余容量,它也会触发。有关哪些计划直接包含 1M 上下文以及哪些需要使用额度的信息,请参阅 [Extended context](/docs/zh-CN/model-config#extended-context)。Claude Code 在您使用 `/model` 选择模型时运行此检查,仅在直接连接到 Anthropic API 时;如果您将 `ANTHROPIC_BASE_URL` 指向 [LLM gateway](/docs/zh-CN/llm-gateway),`/model` 允许 `[1m]` 选择,网关决定请求是否成功。 -当此错误在对话中期出现,因为上下文增长超过 200K 令牌时,Claude Code 会自动将对话压缩回标准上下文限制以下,并在之后将会话保持在该限制,因此无需采取任何操作。在 v2.1.172 之前的版本上,错误会在每个后续请求(包括 `/compact`)上重复出现;在这些版本上运行 `/clear` 以恢复。以下步骤适用于您明确选择 `[1m]` 模型的情况。 +当此错误在对话中期出现,因为上下文增长超过 200K 令牌时,Claude Code 会自动将对话压缩回标准上下文限制以下,并之后将会话保持在该限制,因此无需采取任何操作。在 v2.1.172 之前的版本中,错误会在每个后续请求(包括 `/compact`)上重复;在这些版本上运行 `/clear` 以恢复。以下步骤适用于您明确选择 `[1m]` 模型的情况。 -**应该怎么做:** +**要做什么:** * 运行 `/model` 并选择不带 `[1m]` 后缀的变体以回退到标准上下文窗口 -* 运行 `/usage-credits` 在 Pro 和 Max 上为 1M 变体启用按量计费,或在 Team 和 Enterprise 上向您的管理员请求 -* 如果 `/model` 后错误仍然存在,1M 模型 ID 可能在其他地方设置。有关要按优先级顺序检查的配置位置,请参阅[所选模型存在问题](#theres-an-issue-with-the-selected-model)。 +* 在消息命名 `/usage-credits` 的地方,运行它以在 Pro 和 Max 上为 1M 变体启用按量计费,或在 Team 和 Enterprise 上向您的管理员请求使用额度。启用使用额度后,重启 Claude Code 或启动新会话,按消息所说的进行。在此之前,会话保持在标准上下文限制。 +* 如果在 `/model` 后错误仍然存在,1M 模型 ID 可能在其他地方设置。有关要按优先级检查的配置位置,请参阅 [Setting your model](/docs/zh-CN/model-config#setting-your-model)。 * 要从模型选择器中完全删除 1M 变体,请设置 [`CLAUDE_CODE_DISABLE_1M_CONTEXT=1`](/docs/zh-CN/env-vars) +在 v2.1.268 之前,消息以 `run /usage-credits to turn them on, or /model to switch to standard context` 结尾,没有提及重启。 + +

+ The prompt to confirm went unanswered +

+ +如果您的账户需要 [Fable usage-credits consent](/docs/zh-CN/model-config#fable-and-usage-credits),Claude Code 会在 Fable 请求计费使用额度之前要求您确认。当在可能没有人在其终端的会话中没有人回答该同意提示时,Claude Code 会关闭提示并以以下消息之一结束轮次: + +```text theme={null} +Fable limit reached · continuing on Fable 5.1 uses usage credits, and the prompt to confirm went unanswered — nothing was sent · answer it where this session is running, or /model to change +Fable 5.1 now uses usage credits · the prompt to confirm went unanswered — nothing was sent · answer it where this session is running, or /model to change +``` + +消息命名会话的 Fable 模型,因此在 Fable 5 上它们读作 `continuing on Fable 5` 和 `Fable 5 now uses usage credits`。在 v2.1.257 之前,第一条消息以 `Fable 5 limit reached` 开头。 + +这发生在 [Remote Control](/docs/zh-CN/remote-control) 会话、[background sessions](/docs/zh-CN/agent-view) 和 [agent team](/docs/zh-CN/agent-teams) 队友会话中。Claude Code 仅在会话自己的交互式视图中显示同意提示:运行它的终端,或对于后台会话,一旦您附加,[agents view](/docs/zh-CN/agent-view)。Remote Control 客户端无法显示它。Claude Code 在 [`dialogExpiry`](/docs/zh-CN/settings-reference#dialogexpiry) 截止时间关闭提示,默认为五分钟,或一旦新提示到达而没有人在该终端输入时立即关闭,例如从 Remote Control 客户端发送的提示。在会话运行的终端输入会取消截止时间,Claude Code 等待您的答案。在附加的后台会话视图中,输入不会取消截止时间,新提示仍会关闭同意提示,因此在任何一个发生之前回答。Claude Code 不发送任何内容并保持您的模型,因此当您发送下一个提示时,Claude Code 会再次显示同意提示。 + +**要做什么:** + +* 在会话运行的终端,发送另一个提示并在它重新出现时回答同意提示。对于后台会话,首先从 [agents view](/docs/zh-CN/agent-view) 附加到它。从 Remote Control 客户端重新发送会再次显示此消息,因为客户端无法显示提示。 +* 运行 `/model` 切换到不计费使用额度的模型 +* 要给自己更多时间到达该终端,请将 [`dialogExpiry`](/docs/zh-CN/settings-reference#dialogexpiry) 设置为更长的值或 `"never"` + +在 v2.1.236 之前,此消息没有出现:当 Remote Control 客户端连接时,Claude Code 等待 60 秒以获得答案,然后在您的默认模型上继续轮次。 +

- 服务器暂时限制请求 + Server is temporarily limiting requests

API 应用了与您的计划配额无关的短期限流。 @@ -342,47 +714,114 @@ API 应用了与您的计划配额无关的短期限流。 API Error: Server is temporarily limiting requests (not your usage limit) ``` -Claude Code 通过真实限制响应所携带的统一配额标头的缺失来区分这些与您的计划限制。从 v2.1.199 开始,无论您如何进行身份验证,这都会[自动重试](#automatic-retries)并进行退避,然后才会显示。在早期版本上,使用 claude.ai 订阅登录的会话在第一次出现时失败;只有 API 密钥和 Enterprise 登录会重试。 +Claude Code 通过真实限制响应所携带的统一配额标头的缺失来区分这些。从 v2.1.199 开始,这是 [retried automatically](#automatic-retries) 带有退避,无论您如何进行身份验证。在早期版本中,使用 claude.ai 订阅登录的会话在第一次出现时失败轮次;只有 API 密钥和 Enterprise 登录重试了它。 -**应该怎么做:** +**要做什么:** * 稍等片刻后重试 * 如果问题仍然存在,请检查 [status.claude.com](https://status.claude.com)

- 请求被拒绝 (429) + Request rejected (429)

-您已达到为 API 密钥、Amazon Bedrock 项目或 Google Cloud 项目配置的速率限制。 +您已达到为您的 API 密钥、Amazon Bedrock 项目或 Google Cloud 项目配置的速率限制。 ```text theme={null} API Error: Request rejected (429) · this may be a temporary capacity issue. If it persists, check https://status.claude.com. ``` -尾部句子指出检查服务健康状况的位置,因提供商而异。Amazon Bedrock、Google Cloud 的 Agent Platform 和 Microsoft Foundry 配置会指出该提供商的服务状态,而不是 Anthropic 状态页面。自定义 `ANTHROPIC_BASE_URL` 会指出网关主机。 +尾部句子命名检查服务健康的位置,并因提供商而异。Amazon Bedrock、Google Cloud 的 Agent Platform 和 Microsoft Foundry 配置命名该提供商的服务状态,而不是 Anthropic 状态页面。自定义 `ANTHROPIC_BASE_URL` 命名网关主机。 -**应该怎么做:** +**要做什么:** + +* 运行 `/status` 并确认活跃凭证是您期望的。环境中的流浪 `ANTHROPIC_API_KEY` 可能会通过低层密钥而不是您的订阅路由请求。 +* 检查您的提供商控制台以了解活跃限制,如果需要请求更高的层级 +* 对于 Anthropic API 密钥,请参阅 [rate limits reference](https://platform.claude.com/docs/en/api/rate-limits) 了解层级如何工作以及如何设置每个工作区的上限 +* 降低并发:降低 [`CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY`](/docs/zh-CN/env-vars),避免运行许多并行子代理,或使用 `/model` 为高容量脚本运行切换到更小的模型 + +

+ You've hit your monthly spend limit +

+ +您的计划包含的使用量无法覆盖此请求,而本应为其付款的 [usage credits](https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans) 已达到支出限制。这发生在您的计划的使用窗口之一用完时,或当请求是仅由使用额度支付的请求时,例如对 [bills to usage credits](/docs/zh-CN/model-config#fable-and-usage-credits) 的模型的请求。消息命名其限制阻止了您。`·` 后的文本说明如何增加该限制,并因您的计划和您是否管理计费而异: + +```text theme={null} +You've hit your monthly spend limit · raise it at claude.ai/settings/usage +You've hit your individual spend limit · ask your admin for a higher limit +You've hit your org's monthly spend limit · visit claude.ai/admin-settings/usage to raise it +You've hit your team's shared budget · ask your admin to raise it at claude.ai/admin-settings/usage +You've hit your channel's monthly spend limit · an org owner or channel manager can raise it in the channel's Claude settings +``` + +`team's shared budget` 是管理员分配给您所属的组的汇总预算;消息不命名该组。`channel's monthly spend limit` 是会话运行的一个 Slack 频道的预算,因此您的组织可能在其外部仍有预算。 + +当您的计划的窗口之一用完时,消息也会说该窗口何时重置,例如 `· your session limit resets 3:45pm`,访问权限会在那时返回,无需任何人提高限制。在使用基于使用量的计费的组织中,消息说 `usage limit` 代替 `spend limit`,如 `You've hit your individual usage limit`。 + +在 v2.1.239 之前,消息没有命名计划窗口的重置时间。在 v2.1.268 之前,组的汇总预算产生 `individual spend limit` 消息而不是 `team's shared budget`。 + +如果您通过 Claude apps gateway 连接并看到小写 `spend limit reached`,那是您的网关操作员的上限;请参阅 [Spend limit reached](#spend-limit-reached)。 + +**要做什么:** + +* 在 Pro 和 Max 上,在 claude.ai 的 [**Settings > Usage**](https://claude.ai/settings/usage) 中增加您的月度支出限制,或运行 `/usage-credits` +* 在 Team 和 Enterprise 上,如果您管理计费,在 [**Admin settings > Usage**](https://claude.ai/admin-settings/usage) 中增加限制,或要求管理员这样做。`/usage-credits` 为您向您的管理员发送该请求 +* 对于频道的限制,要求组织所有者或频道的管理员在 claude.ai 上提高它。请参阅 Claude Tag 文档中的 [Per-channel limits](https://claude.com/docs/claude-tag/admins/set-spend-limit#per-channel-limits) +* 如果消息命名您的计划窗口的重置时间,您可以改为等待它 +* 运行 `/usage` 查看您的计划窗口以及每个何时重置 -* 运行 `/status` 并确认活跃凭证是您期望的凭证。环境中的杂散 `ANTHROPIC_API_KEY` 可能会通过低级密钥而不是您的订阅来路由请求。 -* 检查您的提供商控制台以了解活跃限制,如果需要,请请求更高的层级 -* 对于 Anthropic API 密钥,请参阅[速率限制参考](https://platform.claude.com/docs/en/api/rate-limits)了解层级如何工作以及如何设置每个工作区的上限 -* 降低并发:降低 [`CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY`](/docs/zh-CN/env-vars),避免运行许多并行子代理,或使用 `/model` 切换到较小的模型以进行大容量脚本运行 +

+ Spend limit reached +

+ +您通过 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway) 连接,并已超过您的网关操作员设置的 [spend cap](/docs/zh-CN/claude-apps-gateway-spend-limits)。网关阻止您的请求,直到命名的期间重置或操作员提高上限。它将每个被阻止的 `429` 响应标记为 `x-should-retry: false`,因此 Claude Code 显示此消息而不重试。 + +```text theme={null} +spend limit reached (daily; resets 2026-08-09 00:00 UTC) +``` + +消息命名上限的期间和重置时间,当操作员配置了 `blocked_message` 时,他们的说明跟在它后面。在 v2.1.225 之前,消息仅读作 `spend limit reached`;较旧版本上的网关仍然发送该较短的形式。 + +**要做什么:** + +* 等待消息命名的重置时间,或如果消息包含说明,请遵循操作员的说明 +* 如果您经常达到上限,要求您的网关操作员提高上限 + +一条相关消息 `spend limit unavailable` 意味着网关无法读取其支出记录,并作为预防措施而不是超过您的上限而阻止了请求。它通常会自行清除;如果它持续存在,请告诉您的网关操作员。

- 信用余额过低 + Credit balance is too low

-您的 Console 组织已用尽预付信用。 +您的 Console 组织已用完预付额度,或 Claude Code 使用 Console API 密钥发送您的请求,而您打算使用您的订阅。 ```text theme={null} Credit balance is too low ``` -**应该怎么做:** +**要做什么:** + +* 如果您有 Pro、Max、Team 或 Enterprise 计划并看到这个,运行 `/status` 并检查 `API key` 行。环境中已批准的 `ANTHROPIC_API_KEY` 通过该密钥而不是您的订阅路由请求。在当前 shell 中取消设置它并从您的 shell 配置文件中删除它,然后重新启动 `claude`。如果您还没有使用您的订阅登录,运行 `/login`。 +* 在 [platform.claude.com/settings/billing](https://platform.claude.com/settings/billing) 添加额度,并考虑在那里启用自动重新加载,以便余额在达到零之前重新填充 +* 在 Console 中设置每个工作区的支出上限,以防止单个项目耗尽组织余额。请参阅 [Manage costs effectively](/docs/zh-CN/costs)。 + +

+ Could not update your spend limit +

+ +服务器拒绝了您在达到支出限制时出现的提示中所做的支出限制更改。 + +```text theme={null} +Could not update your spend limit: +``` + +当服务器解释拒绝时,消息以该原因结尾,重试相同的值会再次失败。当失败没有服务器提供的原因时,例如连接断开,消息读作 `Could not update your spend limit. Press Enter to retry.` 并且重试可能成功。在 v2.1.216 之前,Claude Code 为每个失败显示通用形式。 -* 在 [platform.claude.com/settings/billing](https://platform.claude.com/settings/billing) 添加信用,并考虑在那里启用自动重新加载,以便在余额达到零之前进行补充 -* 如果您有 Pro、Max、Team 或 Enterprise 计划,请使用 `/login` 切换到订阅身份验证 -* 在 Console 中设置每个工作区的支出上限,以防止单个项目耗尽组织余额。请参阅[有效管理成本](/docs/zh-CN/costs)。 +**要做什么:** + +* 如果消息包含原因,选择满足它的限制,例如较低的金额 +* 如果消息仅显示通用形式,重试;失败可能是暂时的 +* 如果更改持续失败,改为从浏览器中的 [claude.ai billing settings](https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans) 进行

身份验证错误 @@ -402,95 +841,144 @@ Not logged in · Please run /login **应该做什么:** -* 运行 `/login` 使用您的 Claude 订阅或 Console 账户进行身份验证 +* 运行 `/login` 以使用您的 Claude 订阅或 Console 账户进行身份验证 * 如果您期望使用环境变量进行身份验证,请确认 `ANTHROPIC_API_KEY` 已在启动 `claude` 的 shell 中设置并导出 -* 对于无法进行交互式登录的 CI 或自动化环境,配置一个 [`apiKeyHelper`](/docs/zh-CN/settings#available-settings) 脚本,在启动时获取密钥 -* 查看 [身份验证优先级](/docs/zh-CN/authentication#authentication-precedence) 了解当存在多个凭证时 Claude Code 使用哪个凭证 +* 对于无法进行交互式登录的 CI 或自动化,配置一个 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 脚本,在启动时获取密钥 +* 查看 [身份验证优先级](/docs/zh-CN/authentication#authentication-precedence) 以了解当存在多个凭证时 Claude Code 使用哪个凭证 -如果您被反复提示登录,请参阅 [未登录或令牌过期](/docs/zh-CN/troubleshoot-install#not-logged-in-or-token-expired) 了解系统时钟和 macOS Keychain 修复。 +如果您被重复提示登录,请参阅 [未登录或令牌过期](/docs/zh-CN/troubleshoot-install#not-logged-in-or-token-expired) 了解系统时钟检查和 macOS 凭证存储恢复步骤。

无法解析身份验证方法

-会话到达 API 客户端时没有任何凭证。这出现在 [后台会话](/docs/zh-CN/agent-view)、云会话和 Agent SDK 上下文中,其中交互式登录检查在第一个请求之前不会运行。 +会话到达 API 客户端时没有任何凭证。[后台会话](/docs/zh-CN/agent-view) 和云会话在 worker 启动时没有凭证时显示此消息。交互式、`-p` 和 Agent SDK 运行报告与 [未登录](#not-logged-in) 相同的条件,并仅将此字符串写入其调试日志,因此如果您在那里找到它,请改为遵循该条目。 ```text theme={null} Could 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 ``` -在 v2.1.174 之前,分配给空闲预初始化工作进程的后台或云会话即使配置了有效凭证也可能以这种方式失败。升级以恢复。在当前版本中,该错误意味着工作进程没有可用的凭证。 +在当前版本上,该错误意味着 worker 进程没有可用的凭证。在 v2.1.174 之前,分配给空闲预初始化 worker 的后台会话即使配置了有效凭证也可能以这种方式失败。在 v2.1.176 之前,在被声明之前处于空闲状态的云会话也可能失败。升级以恢复。 **应该做什么:** -* 如果这出现在后台或云会话中且您的凭证已配置,请升级到 v2.1.174 或更高版本 -* 确认 `ANTHROPIC_API_KEY`、`CLAUDE_CODE_OAUTH_TOKEN` 或您的云提供商凭证已在启动工作进程的环境中设置,而不仅仅在您的交互式 shell 中 -* 对于 Agent SDK,请参阅 [身份验证设置](/docs/zh-CN/agent-sdk/overview#get-started) -* 在同一环境中的交互式会话中运行 `/status` 以确认哪个凭证源可以解析 +* 如果这出现在后台或云会话中且您的凭证已配置,请升级到 v2.1.176 或更高版本 +* 确认 `ANTHROPIC_API_KEY`、`CLAUDE_CODE_OAUTH_TOKEN` 或您的云提供商凭证已在启动 worker 的环境中设置,而不仅仅在您的交互式 shell 中 +* 对于 Agent SDK,请参阅 [快速入门中的身份验证设置](/docs/zh-CN/agent-sdk/quickstart#setup) +* 在同一环境中的交互式会话中运行 `/status` 以确认哪个凭证源可解析

无效的 API 密钥

-`ANTHROPIC_API_KEY` 环境变量或 `apiKeyHelper` 脚本返回的密钥被 API 拒绝。 +`ANTHROPIC_API_KEY` 环境变量或 `apiKeyHelper` 脚本返回了 API 拒绝的密钥,或 Claude Code 在发送前阻止了来自 `ANTHROPIC_API_KEY` 的密钥。 ```text theme={null} Invalid API key · Fix external API key ``` +当消息在 `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) 了解如何读取描述并修复该值。 + **应该做什么:** * 检查拼写错误并确认密钥未在 [Console](https://platform.claude.com/settings/keys) 中被撤销 -* 在同一 shell 中运行 `env | grep ANTHROPIC`。direnv、dotenv shell 插件和 IDE 终端等工具可以从项目中的 `.env` 文件加载过时的密钥,而无需您显式设置它 -* 取消设置 `ANTHROPIC_API_KEY` 并运行 `/login` 改用订阅身份验证 -* 如果密钥来自 [`apiKeyHelper`](/docs/zh-CN/settings#available-settings) 脚本,直接运行该脚本以确认它在 stdout 上打印有效密钥 -* 运行 `/status` 确认 Claude Code 实际使用的凭证源 +* 在同一 shell 中,运行 `env | grep ANTHROPIC`,或在 PowerShell 中运行 `Get-ChildItem Env:ANTHROPIC*`。direnv、dotenv shell 插件和 IDE 终端等工具可以从项目中的 `.env` 文件加载过时的密钥,而无需您显式设置它 +* 取消设置 `ANTHROPIC_API_KEY` 并运行 `/login` 以改用订阅身份验证 +* 如果密钥来自 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 脚本,请直接运行该脚本以确认它在 stdout 上打印有效密钥 +* 运行 `/status` 以确认 Claude Code 实际使用的凭证源

您的 apiKeyHelper 脚本失败

-在 [`apiKeyHelper`](/docs/zh-CN/settings#available-settings) 设置中配置的命令以错误退出、超时或未向 stdout 打印任何内容。没有来自脚本的密钥,请求到达 API 时带有占位符凭证,API 以 `401` 拒绝它。 +Claude Code 运行了您的 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 设置中的命令,但没有获得密钥。没有密钥,请求会到达 API,并带有占位符凭证,API 会以 `401` 拒绝它。终端中的 `Authentication` 面板显示发生了以下哪种情况: + +* 命令以错误退出或超时 +* 命令未向 stdout 打印任何内容 +* 命令打印了除密钥之外的内容,例如登录横幅或日志行。该面板显示 `returned output that cannot be used as an API key` 并说明了问题所在,而不重复输出。在 v2.1.227 之前,Claude Code 发送命令打印的任何内容,在修剪周围空格后。 ```text theme={null} Your apiKeyHelper script is failing · This usually means you need to re-authenticate with your provider · Run /status to see the script's error output ``` -Claude Code 重新运行脚本并在显示此消息之前最多重试请求两次,因此故障在三次尝试内浮出。在 v2.1.208 之前,Claude Code 花费完整的 [重试预算](#automatic-retries) 使用占位符凭证重新发送请求,然后报告通用的 `401` 身份验证错误而不是脚本故障。 +在 [非交互式模式](/docs/zh-CN/headless) 中,stderr 也带有具体原因,前缀为 `apiKeyHelper failed:`。 + +Claude Code 重新运行脚本并在显示此消息之前最多重试请求两次,因此故障在三次尝试内出现。在 v2.1.208 之前,Claude Code 花费完整的 [重试预算](#automatic-retries) 使用占位符凭证重新发送请求,然后报告通用 `401` 身份验证错误而不是脚本故障。 + +运行 `/login` 在这里没有帮助:只要设置存在,helper 的输出 [优先于](/docs/zh-CN/authentication#authentication-precedence) 保存的登录。 + +**应该做什么:** + +* 直接在您的 shell 中运行在 `apiKeyHelper` 中配置的命令以重现故障 +* 如果命令报告会话过期,请使用您的凭证提供商重新身份验证,例如再次登录您的 SSO 或密钥保管库 +* 修复命令,使其仅将密钥打印到 stdout,作为单个可打印 ASCII 令牌,最多 16,384 个字符,并以代码 0 退出。请参阅 [使用 apiKeyHelper 轮换凭证](/docs/zh-CN/llm-gateway-connect#rotate-credentials-with-apikeyhelper) 了解工作设置。 +* 运行 `/status` 查看故障并确认 `apiKeyHelper` 是活跃凭证源。`apiKeyHelper` 行显示 `Failing` 以及最后一次故障的详细信息,例如退出代码和命令的错误输出,并在下一次成功运行后消失。在 v2.1.274 之前,`/status` 仅显示凭证源,而不是故障。 +* 每次命令失败时,其退出代码和错误输出也会出现在终端中的 `Authentication` 面板中。在 v2.1.212 之前,该面板的标题为 `Cloud authentication`。 + +

+ 无效的请求标头值 +

+ +Claude Code 即将作为请求标头发送的值包含 HTTP 标头无法传输的字符:换行符、NUL 字节或 `U+00FF` 以上的字符,例如弯引号或零宽空格。Claude Code 在发送任何内容之前停止请求,并命名要修复的变量或设置。通常的原因是从文档或聊天粘贴的凭证,其中包含不可见字符或杂散换行符。 + +Claude Code 在直接向 Claude API 或通过 [LLM 网关](/docs/zh-CN/llm-gateway) 发送请求时运行此检查。在第三方云提供商(如 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock))上,Claude Code 在发送前不运行它。 + +```text theme={null} +Invalid auth token · Fix external auth token +Invalid ANTHROPIC_CUSTOM_HEADERS · Fix the environment variable +Invalid request header from the environment · Fix the environment variable +``` + +消息的第一部分取决于坏值来自何处: + +* `Invalid auth token`:来自 [`ANTHROPIC_AUTH_TOKEN`](/docs/zh-CN/env-vars) 或 [`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 的持有者令牌 +* `Invalid ANTHROPIC_CUSTOM_HEADERS`:您在 [`ANTHROPIC_CUSTOM_HEADERS`](/docs/zh-CN/env-vars) 中设置的标头名称或值。描述计算哪个 `Name: Value` 对有问题,例如 `distinct header 2 of 3 parsed from ANTHROPIC_CUSTOM_HEADERS`,而不重复名称或值,因为您选择了两者。 +* `Invalid request header from the environment`:Claude Code 从另一个环境变量(如 `CLAUDE_AGENT_SDK_CLIENT_APP`)复制到请求标头中的值。描述命名要修复的变量。 + +Claude 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)。 + +在第二个 `·` 之后,消息描述问题,如以下完整示例: + +```text theme={null} +Invalid 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). +``` -运行 `/login` 在这里无法帮助:只要设置存在,helper 的输出 [优先于](/docs/zh-CN/authentication#authentication-precedence) 保存的登录。 +位置从 1 开始计算字符。描述由固定短语和字符计数构建,因此它永远不包括值本身。它仅在字符是众所周知的不可见或排版字符(如字节顺序标记、零宽空格或弯引号)时命名该字符,并将其他任何内容报告为 `a non-ASCII character`。 **应该做什么:** -* 在您的 shell 中直接运行在 `apiKeyHelper` 中配置的命令以重现故障 -* 如果命令报告会话已过期,请使用您的凭证提供商重新身份验证,例如再次登录您的 SSO 或密钥保管库 -* 修复命令以便它将密钥打印到 stdout 并以代码 0 退出。有关工作设置,请参阅 [使用 apiKeyHelper 轮换凭证](/docs/zh-CN/llm-gateway-connect#rotate-credentials-with-apikeyhelper)。 -* 运行 `/status` 确认 `apiKeyHelper` 是活跃凭证源。每次命令失败时,其退出代码和错误输出都会出现在终端中的 `Cloud authentication` 面板中。 +* 重新设置消息命名的变量或设置,重新输入报告位置周围的字符,而不是从同一来源再次粘贴 +* 对于 `ANTHROPIC_CUSTOM_HEADERS`,每行保留一个 `Name: Value` 对,并重写消息计数的对 +* 运行 `/status` 以确认哪个凭证源处于活跃状态

此组织已被禁用

-来自已禁用 Console 组织的过时 `ANTHROPIC_API_KEY` 正在覆盖您的订阅登录。 +Claude Code 正在使用来自已禁用 Console 组织的过时 `ANTHROPIC_API_KEY`。当您有保存的订阅登录时,密钥会覆盖它。 ```text theme={null} -Your ANTHROPIC_API_KEY belongs to a disabled organization · Unset the environment variable to use your other credentials +Your ANTHROPIC_API_KEY belongs to a disabled organization · Unset the environment variable to use your subscription instead +Your ANTHROPIC_API_KEY belongs to a disabled organization · Update or unset the environment variable API Error: 400 ... This organization has been disabled. ``` -环境变量优先于 `/login`,因此即使您有有效的 Pro 或 Max 订阅,在 shell 配置文件中导出或从 `.env` 文件加载的密钥也会被使用。在非交互模式 (`-p`) 中,当密钥存在时始终使用该密钥。 +`·` 之后的提示取决于您保存的凭证:当存储的 `/login` 可以在您取消设置密钥后接管时出现第一种形式,当密钥是您唯一的凭证时出现第二种形式。 + +环境变量优先于 `/login`,因此在您的 shell 配置文件中导出或从 `.env` 文件加载的密钥即使您有有效的 Pro 或 Max 订阅也会被使用。在非交互式模式 (`-p`) 中,当存在密钥时始终使用该密钥。 **应该做什么:** -* 在当前 shell 中取消设置 `ANTHROPIC_API_KEY` 并从 shell 配置文件中删除它,然后重新启动 `claude` -* 之后运行 `/status` 确认活跃凭证是您的订阅 -* 如果未设置环境变量且错误仍然存在,则禁用的组织是与您的 `/login` 关联的组织。联系支持或使用不同的账户登录。 +* 在当前 shell 中取消设置 `ANTHROPIC_API_KEY` 并从您的 shell 配置文件中删除它,然后重新启动 `claude` +* 如果消息说 `Update or unset`,您没有保存的登录可以回退。取消设置密钥并运行 `/login`,或将密钥替换为来自活跃 Console 组织的密钥。 +* 之后运行 `/status` 以确认活跃凭证是您的订阅 +* 如果未设置环境变量且错误仍然存在,则禁用的组织是与您的 `/login` 关联的组织。联系支持或使用不同账户登录。

您的组织已禁用 API 密钥身份验证

-此消息需要 Claude Code v2.1.169 或更高版本。您的 Console 组织管理员已关闭 API 密钥身份验证,因此 API 拒绝 Claude Code 发送的密钥。`·` 之后的恢复提示因密钥来源而异: +此消息需要 Claude Code v2.1.169 或更高版本。您的 Console 组织的管理员已关闭 API 密钥身份验证,因此 API 拒绝 Claude Code 正在发送的密钥。`·` 之后的恢复提示因密钥来自何处而异: ```text theme={null} Your organization has disabled API key authentication · Run /login to sign in with your claude.ai account @@ -499,21 +987,21 @@ Your organization has disabled API key authentication · Unset ANTHROPIC_API_KEY Your organization has disabled API key authentication · Unset the apiKeyHelper setting and run /login to sign in with your claude.ai account ``` -环境变量和 `apiKeyHelper` 优先于 `/login`,因此仅运行 `/login` 在任一仍在提供密钥时无法帮助。请参阅 [身份验证优先级](/docs/zh-CN/authentication#authentication-precedence)。 +环境变量和 `apiKeyHelper` 优先于 `/login`,因此仅运行 `/login` 在任一仍在提供密钥时没有帮助。请参阅 [身份验证优先级](/docs/zh-CN/authentication#authentication-precedence)。 **应该做什么:** -* 如果消息提到 `ANTHROPIC_API_KEY`,在当前 shell 中取消设置它并从 shell 配置文件或 `.env` 文件中删除它,然后重新启动 `claude` -* 如果消息提到 `apiKeyHelper`,从您的 `settings.json` 中删除 [`apiKeyHelper`](/docs/zh-CN/settings#available-settings) 设置 -* 运行 `/login` 使用您的 claude.ai 账户登录 -* 之后运行 `/status` 确认活跃凭证是您的订阅而不是 API 密钥 +* 如果消息命名 `ANTHROPIC_API_KEY`,在当前 shell 中取消设置它并从您的 shell 配置文件或 `.env` 文件中删除它,然后重新启动 `claude` +* 如果消息命名 `apiKeyHelper`,从您的 `settings.json` 中删除 [`apiKeyHelper`](/docs/zh-CN/settings-reference#apikeyhelper) 设置 +* 运行 `/login` 以使用您的 claude.ai 账户登录 +* 之后运行 `/status` 以确认活跃凭证是您的订阅而不是 API 密钥 * 如果您需要 API 密钥身份验证用于自动化,请要求您的组织管理员在 Console 中重新启用它

您的组织已禁用 Claude 订阅访问

-您的 Claude 组织不允许使用订阅登录登录到 Claude Code。使用同一账户再次运行 `/login` 会返回相同的错误。 +您的 Claude 组织不允许使用订阅登录登录 Claude Code。使用同一账户再次运行 `/login` 会返回相同的错误。 ```text theme={null} Your organization has disabled Claude subscription access for Claude Code · Use an Anthropic API key instead, or ask your admin to enable access @@ -521,19 +1009,19 @@ Your organization has disabled Claude subscription access for Claude Code · Use 这是服务器端组织设置,因此无法从本地设置、环境变量或 CLI 标志覆盖。 -Agent SDK 和 `-p` 非交互模式将其显示为 `oauth_org_not_allowed` 错误代码。 +Agent SDK 和 `-p` 非交互式模式将此显示为 `oauth_org_not_allowed` 错误代码。 **应该做什么:** * 要求您的管理员为您的组织启用 Claude Code 访问 -* 使用 Console API 密钥而不是您的订阅进行身份验证。有关设置,请参阅 [Claude Console 身份验证](/docs/zh-CN/authentication#claude-console-authentication)。 +* 使用 Console API 密钥而不是您的订阅进行身份验证。请参阅 [Claude Console 身份验证](/docs/zh-CN/authentication#claude-console-authentication) 了解设置。 * 如果您是管理员且看不到启用访问的选项,请联系 [Anthropic 支持](https://support.claude.com)

例程被您的组织的策略禁用

-您的 Team 或 Enterprise 组织中的所有者已在组织级别关闭例程。当您尝试创建或运行例程时会出现该错误,包括从 `/schedule` 和 claude.ai/code 上的 [Routines](/docs/zh-CN/routines) UI。 +您的 Team 或 Enterprise 组织中的所有者已在组织级别关闭例程。当您尝试创建或运行例程时会出现错误,例如从 claude.ai/code 上的 [例程](/docs/zh-CN/routines) UI。在 Claude Code v2.1.227 或更高版本上,相同的设置也 [隐藏 CLI 中的 `/schedule`](/docs/zh-CN/routines#troubleshooting)。 ```text theme={null} Routines are disabled by your organization's policy. @@ -553,842 +1041,3883 @@ Routines are disabled by your organization's policy. 会话不是直接与 Anthropic API 通信,因此没有 claude.ai 后端供 [Remote Control](/docs/zh-CN/remote-control) 配对。 ```text theme={null} -Remote Control is only available when using Claude via api.anthropic.com. +Remote 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. ``` -这出现在 Amazon Bedrock、Google Cloud 的 Agent Platform 和 Microsoft Foundry 上。从 v2.1.196 开始,当 [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 指向 `api.anthropic.com` 以外的主机时,例如 [LLM 网关](/docs/zh-CN/llm-gateway) 或代理,即使您使用 claude.ai 登录,它也会出现。 +第二句解释了什么将会话路由离开 Anthropic API;在 v2.1.219 之前,消息仅为第一句。根据原因,消息命名: + +* `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` +* [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 指向 `api.anthropic.com` 以外的主机,例如 [LLM 网关](/docs/zh-CN/llm-gateway) 或代理,即使您使用 claude.ai 登录;在 v2.1.196 之前,自定义基础 URL 不会阻止 Remote Control +* `ANTHROPIC_UNIX_SOCKET` 已设置,因此会话通过本地套接字而不是 `api.anthropic.com` 发送其请求 +* 企业 [云网关](/docs/zh-CN/claude-apps-gateway) 通过 `/login` 登录,不支持 Remote Control,没有变量可取消设置 **应该做什么:** -* 取消设置 `ANTHROPIC_BASE_URL` 并重启会话,或从直接与 Anthropic API 通信的会话启动 Remote Control -* 对于此错误和其他 Remote Control 启动消息,请参阅 [Remote Control 故障排除](/docs/zh-CN/remote-control#troubleshooting) +* 取消设置消息命名的变量,例如 `CLAUDE_CODE_USE_BEDROCK` 或 `ANTHROPIC_BASE_URL`,并重新启动会话,或从直接与 Anthropic API 通信的会话启动 Remote Control +* 如果变量未在您的 shell 中设置,请检查您的 [设置文件](/docs/zh-CN/settings#where-settings-live) 中的 `env` 键,该键将环境变量应用于每个会话 +* 对于此和其他 Remote Control 启动消息,请参阅 [Remote Control 故障排除](/docs/zh-CN/remote-control#troubleshooting) -

- OAuth 令牌被撤销或过期 +

+ Remote Control 无法刷新您的登录

-您保存的登录不再有效。撤销的令牌意味着您在任何地方都已登出或管理员删除了访问权限;过期的令牌意味着自动刷新在会话中途失败。 +Claude Code 在短期凭证上运行实时 [Remote Control](/docs/zh-CN/remote-control) 连接,它使用您保存的 claude.ai 登录获取和更新这些凭证。当 claude.ai 停止接受该登录或 Claude Code 没有保存的登录时,Claude Code 停止 Remote Control 并需要您再次登录。任一故障都可能在 Claude Code 仍在连接时或稍后在更新凭证时发生。 -两条消息都报告 Claude Code 发送的请求 API 返回的拒绝。当保存的登录在失败的刷新后已被清除时,您会看到 [登录已过期](#login-expired) 代替。 +当 Claude Code 要求登录服务刷新您保存的登录并且没有得到答复时,它会保持 Remote Control 运行并在连接的当前凭证仍然有效时再次尝试刷新。当 Claude Code 无法到达登录服务、请求超时或服务在不拒绝您的登录的情况下失败时,刷新会得不到答复。如果当该凭证过期时登录服务仍然没有答复,Claude Code 会停止 Remote Control 并报告 `OAuth token refresh failed`。 + +当 Claude Code 停止 Remote Control 时,它在警告和以 `Remote Control disconnected` 开头的成绩单行中显示原因。您的本地会话继续运行而没有 Remote Control。本部分涵盖这些行: ```text theme={null} -OAuth token revoked · Please run /login -OAuth token has expired · Please run /login -API Error: 401 ... authentication_error +Remote Control disconnected — Claude.ai login expired — run /login to restore Remote Control +Remote Control disconnected — Claude.ai login expired — run /login, then /remote-control +Remote Control disconnected — Claude.ai login was rejected — run /login, then /remote-control +Remote Control disconnected — OAuth token unavailable — run /login to restore Remote Control +Remote Control disconnected — OAuth token refresh failed — run /login to re-authenticate +Remote Control disconnected — JWT refresh failed: no OAuth token — run /login +Remote Control disconnected — Signed out of Claude — run /login, then /remote-control ``` +Claude Code 在消息中间命名原因: + +* ` Claude.ai login expired` 和 `Claude.ai login was rejected`:claude.ai 不再接受您保存的登录令牌,因为它已过期或被撤销 +* ` OAuth token unavailable`:当连接的凭证到期需要更新时,Claude Code 没有保存的登录令牌 +* `OAuth token refresh failed`:claude.ai 在 Claude Code 重新连接时拒绝了您保存的登录令牌,刷新令牌没有产生新令牌 +* `JWT refresh failed: no OAuth token`:Claude Code 找不到保存的登录令牌来更新 +* ` Signed out of Claude`:您在此机器上登出,例如在另一个终端中运行 `/logout`,因此 Claude Code 没有保存的登录来更新连接 + **应该做什么:** -* 运行 `/login` 重新登录 -* 如果在同一会话中重新身份验证后错误返回,请先运行 `/logout` 完全清除存储的令牌,然后运行 `/login` -* 对于跨启动的重复登录提示,请参阅 [故障排除](/docs/zh-CN/troubleshoot-install#not-logged-in-or-token-expired) 中的系统时钟和 macOS Keychain 检查 -* 对于其他故障,包括 `403 Forbidden` 和 OAuth 浏览器问题,请参阅 [登录和身份验证](/docs/zh-CN/troubleshoot-install#login-and-authentication) +* 运行 `/login` 再次登录 +* 运行 `/remote-control` 重新连接会话。以 `run /login to restore Remote Control` 结尾的消息不需要此步骤:Claude Code 在您登录后自动重新连接。 -

- 登录已过期 -

+在 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 )`。` Claude.ai login expired`、`Claude.ai login was rejected` 和 `OAuth token unavailable` 消息在 v2.1.225 中添加。 -Claude Code 尝试更新您保存的 claude.ai 或 Claude Console 登录,OAuth 服务拒绝了存储的刷新令牌,因此 Claude Code 清除了保存的凭证。之后,每个请求在到达 API 之前都会在本地停止,因为只有 `/login` 可以创建新凭证。在 v2.1.206 之前,Claude Code 无论如何都会发送请求,使用环境中剩余的任何凭证,然后每个模型都会失败,显示 [所选模型有问题](#theres-an-issue-with-the-selected-model) 或 401 而不是登录提示。 +在 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`。 -```text theme={null} -Login expired · Please run /login -``` +

+ Remote Control 停止,因为登录账户已更改 +

+ +Claude Code 在 [Remote Control](/docs/zh-CN/remote-control) 会话期间显示此行,当您在此机器上登录到不同的 claude.ai 账户或组织时。您在 Claude Code 会话外进行了切换,例如在另一个终端中运行 `/login`。 -在 [非交互模式](/docs/zh-CN/headless) (`-p`) 和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,消息如下所示,结构化错误代码为 `authentication_failed`: +您在通过 `/login` 登录时启动的 Remote Control 会话属于当时登录的 claude.ai 账户和组织。 ```text theme={null} -Failed to authenticate: OAuth session expired and could not be refreshed +Remote 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 ``` -这与 [OAuth 令牌被撤销或过期](#oauth-token-revoked-or-expired) 的状态不同。这些消息报告 API 返回的 401。Claude Code 本身为已失败刷新的登录生成 `Login expired`,因此它不发送请求。 - -使用 API 密钥、[`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 或第三方提供商进行身份验证的会话不使用保存的登录,永远不会看到此消息。 +Claude Code 在 claude.ai 确认账户或组织已更改后立即停止 Remote Control 会话。您的本地会话继续运行而没有 Remote Control。 **应该做什么:** -* 运行 `/login` 重新登录。不登录重试会在每个请求上显示相同的消息。 -* 在非交互模式中,在同一环境中运行 `claude`,完成 `/login`,然后重新运行您的命令。对于无法交互式登录的自动化,使用 `ANTHROPIC_API_KEY` 进行身份验证或 [使用 `claude setup-token` 生成长期令牌](/docs/zh-CN/authentication#generate-a-long-lived-token)。 -* 如果登录持续失败,请参阅 [登录和身份验证](/docs/zh-CN/troubleshoot-install#login-and-authentication) +* 运行 `/remote-control` 在当前账户或组织下启动新的 Remote Control 会话 +* 要切换回去,运行 `/login` 并再次登录到之前的账户或组织。然后运行 `/remote-control`。 -

- OAuth 范围要求 +在 v2.1.234 之前,Claude Code 在您在 Claude Code 会话外切换到不同账户或组织时没有注意到。Claude Code 保持 Remote Control 会话连接,直到稍后对 Remote Control 服务器的请求失败,显示 `Remote Control server rejected the request (HTTP 404)`。该故障可能在切换后数小时发生。 + +

+ Remote Control 停止,因为运行会话的应用登出或切换了账户

-存储的令牌早于较新功能需要的权限范围。您最常从 `/usage` 和状态行使用情况指示器看到这一点: +当 Claude 桌面应用或 IDE 托管您的会话时,Claude Code 从该应用而不是从 `/login` 获取其登录令牌。当 claude.ai 拒绝该令牌时,Claude Code 要求应用提供新令牌。如果应用回答说它已登出或现在登录到不同的 Claude 账户,Claude Code 结束 [Remote Control](/docs/zh-CN/remote-control) 会话并向应用发送以下行之一: ```text theme={null} -OAuth token does not meet scope requirement: user:profile +Remote Control stopped — the app running this session is now signed in to a different Claude account +Remote Control stopped — the app running this session is signed out of Claude. Sign in there, then turn Remote Control back on ``` +您的本地会话继续运行而没有 Remote Control。 + **应该做什么:** -* 运行 `/login` 获取具有当前范围的新令牌。您不需要先登出。 +* 如果应用已登出,再次登录,然后在应用中重新打开 Remote Control +* 如果应用切换了账户,Claude Code 无法在新账户下继续已结束的会话。在该账户下启动新的 Remote Control 会话。 -

- AWS 凭证已过期或无效 +在 v2.1.238 之前,Claude Code 在两种情况下都向应用发送了 [Remote Control 无法刷新您的登录](#remote-control-couldnt-refresh-your-login) 下列出的 `run /login` 消息。 + +

+ OAuth 令牌被撤销或过期

-此消息需要 Claude Code v2.1.198 或更高版本,仅当在您的设置文件中设置了 [`awsAuthRefresh`](/docs/zh-CN/amazon-bedrock#advanced-credential-configuration) 时才会出现。您的 AWS 会话令牌已过期或被拒绝,Claude Code 已运行的自动刷新未产生 API 接受的凭证。它出现在来自 [Claude Platform on AWS](/docs/zh-CN/claude-platform-on-aws) 或 [Mantle 端点](/docs/zh-CN/amazon-bedrock#use-the-mantle-endpoint) 的 401 上,这是这些提供商报告过期安全令牌的方式。 +您保存的登录不再有效。被撤销的令牌意味着您在任何地方登出或管理员删除了访问权限;过期的令牌意味着自动刷新在会话中失败。 -中间的操作提示命名了您的设置中的 `awsAuthRefresh` 命令,因此它会有所不同。稳定的部分是前导的 `AWS credentials expired or invalid`: +两条消息都报告 API 为 Claude Code 发送的请求返回的拒绝。当保存的登录在失败的刷新后已被清除时,您会看到 [登录过期](#login-expired)。如果您使用 [`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 中的长期令牌进行身份验证,当该令牌过期或被撤销时,您会看到相同的消息。 ```text theme={null} -AWS 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 ... +OAuth token revoked · Please run /login +Please run /login · API Error: 401 OAuth token has expired ... ``` -如果未配置 `awsAuthRefresh`,相同的 401 会显示通用的 `Please run /login` 消息,该消息无法刷新 AWS 凭证。 - **应该做什么:** -* 在另一个终端中运行消息中命名的 `awsAuthRefresh` 命令,例如 `aws sso login --profile myprofile`,完成浏览器登录,然后重试 -* 在交互式会话中,运行 `/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) -* 如果刷新命令成功后错误重复出现,请在同一 shell 和配置文件中使用 `aws sts get-caller-identity` 确认身份在 Claude Code 外部有效 +* 运行 `/login` 再次登录 +* 如果重新身份验证后错误在同一会话中返回,首先运行 `/logout` 以完全清除存储的令牌,然后运行 `/login` +* 如果您使用 `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 错误。 +* 对于跨启动的重复登录提示,请参阅 [故障排除](/docs/zh-CN/troubleshoot-install#not-logged-in-or-token-expired) 中的系统时钟检查和 macOS 凭证存储恢复步骤 +* 对于其他故障,包括 `403 Forbidden` 和 OAuth 浏览器问题,请参阅 [登录和身份验证](/docs/zh-CN/troubleshoot-install#login-and-authentication) -

- AWS 身份验证失败 +

+ API 错误:401 无效的身份验证凭证

-此消息需要 Claude Code v2.1.198 或更高版本,仅当在您的设置文件中设置了 [`awsAuthRefresh`](/docs/zh-CN/amazon-bedrock#advanced-credential-configuration) 时才会出现。您的 AWS 提供商返回了 403,或 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 返回了 401。 - -Claude Code 无法判断您遇到了哪个原因。Amazon Bedrock 将过期的安全令牌报告为 403,但 403 也是它报告授权拒绝的方式,例如来自缺失 IAM 权限或未为您的账户启用的模型的 `AccessDeniedException`。 - -来自 Amazon Bedrock 的 401 也会落在这里而不是在 [AWS 凭证已过期或无效](#aws-credentials-expired-or-invalid) 下,因为 Amazon Bedrock 不会将过期令牌报告为 401。来自该端点的 401 通常来自请求路径中的其他内容,例如公司代理。 - -凭证刷新可以修复过期的令牌,无法修复其他原因,因此消息提供两者: +API 识别了您凭证的格式,但拒绝了其背后的账户或组织。当凭证最近被撤销、组织被禁用或删除了您的访问权限或账户本身被停用时,Anthropic 返回此消息,因此过期的令牌不是原因。凭证可以是您保存的登录或批准的 `ANTHROPIC_API_KEY`,修复方式不同,因此首先运行 `/status` 查看哪个处于活跃状态。 ```text theme={null} -AWS 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 ... +Please run /login · API Error: 401 Invalid authentication credentials ``` -中间的操作提示命名了您的设置中的 `awsAuthRefresh` 命令,因此它会有所不同。稳定的部分是前导的 `AWS authentication failed`。 - **应该做什么:** -* 运行消息中命名的 `awsAuthRefresh` 命令或 `aws sso login`,以防过期凭证是原因 -* 如果您的凭证是最新的,请确认 [IAM 配置](/docs/zh-CN/amazon-bedrock#iam-configuration) 中的 IAM 权限已附加到您使用的身份,并且所选模型已为您的账户和区域启用 -* 运行 `aws sts get-caller-identity` 确认您的请求使用哪个身份;过时的 `AWS_PROFILE` 或默认配置文件是权限不匹配的常见原因 +* 如果 `/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`。 +* 如果 `/status` 仅显示您的登录,运行 `/login` 一次。如果凭证被撤销,新登录会替换它。 +* 如果相同的消息对相同的登录账户返回,则该账户或组织不再活跃。检查 `/status` 报告的账户和组织,并要求您的组织管理员恢复访问。 +* 如果 [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 指向 [LLM 网关](/docs/zh-CN/llm-gateway),`401` 之后的文本是您网关的消息而不是 Anthropic 的,`/login` 不会改变它。改为修复您的网关期望的凭证。 -

- AWS 默认链凭证解析超时 +

+ 登录过期

-AWS 默认凭证提供商链在 60 秒内未产生凭证,因此 Claude Code 停止了解析并使请求失败。故障是本地凭证解析:请求从未到达 [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) 并重试,因此到您看到它时链已在重复尝试上停滞。 +Claude Code 尝试更新您保存的 claude.ai 或 Claude Console 登录,OAuth 服务拒绝了存储的刷新令牌,因此 Claude Code 清除了保存的凭证。之后,每个模型请求在到达 API 之前都会在本地停止,显示此消息,因为只有 `/login` 可以创建新凭证。 + +在 v2.1.206 之前,Claude Code 无论如何都会发送模型请求,使用环境中剩余的任何凭证,每个模型都会失败,显示 [所选模型有问题](#theres-an-issue-with-the-selected-model) 或 401,而不是登录提示。 ```text theme={null} -API Error: AWS default-chain credential resolve timed out +Login expired · Please run /login ``` -常见原因是 AWS 配置文件中的 `credential_process` 命令等待它无法接收的输入,以及容器或 VM 的实例元数据服务 (IMDS) 从不回答链的探测。在 v2.1.207 之前,停滞的链使请求无限期等待而不是以此消息失败。 +在 [非交互式模式](/docs/zh-CN/headless) (`-p`) 和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,消息如下所示,结构化错误代码为 `authentication_failed`: -**应该做什么:** +```text theme={null} +Failed to authenticate: OAuth session expired and could not be refreshed +``` -* 在同一 shell 中使用相同的 `AWS_PROFILE` 运行 `aws sts get-caller-identity`。如果它也挂起,请修复配置文件;提示交互式的 `credential_process` 命令是常见原因。 -* 在启动 Claude Code 之前完成登录步骤,例如 `aws sso login --profile myprofile`,以便链从本地 SSO 缓存解析而不是等待浏览器流 -* 如果您的链运行合法需要超过 60 秒的交互式登录,例如通过 `aws-vault` 等包装器的带 MFA 的 SSO,请使用 [`CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS`](/docs/zh-CN/env-vars) 以毫秒为单位提高限制 +这与 [OAuth 令牌被撤销或过期](#oauth-token-revoked-or-expired) 的状态不同。这些消息报告 API 返回的拒绝。Claude Code 本身为已失败更新的登录生成 `Login expired`,因此它不发送请求。当更新失败是因为账户本身被暂停而不是登录过时时,Claude Code 改为显示 [您的账户被冻结](#your-account-is-on-hold)。 -

- 网络和连接错误 -

+使用 API 密钥、[`CLAUDE_CODE_OAUTH_TOKEN`](/docs/zh-CN/env-vars) 或第三方提供商进行身份验证的会话不使用保存的登录,永远不会看到此消息。 -这些错误表示来自 Claude Code 的网络请求未能到达其目的地,或 Claude Code 和 API 之间的某些东西在返回途中改变了响应。它们通常源于您的本地网络、代理或防火墙,或云环境的网络策略。 +您可以在请求失败之前检查此状态:[`/status`](/docs/zh-CN/commands) 显示读取 `Expired — log in again` 的 `Login` 行,加上它为过期登录保存的组织和电子邮件。该行仅在保存的登录是您的活跃凭证且无法再刷新时出现。以其他方式进行身份验证的会话不显示该行,即使过期的登录仍然保存。在 v2.1.210 之前,`/status` 在此状态下没有指示登录曾经存在过,因为清除的凭证使其无法报告。 -

- 无法连接到 API +**应该做什么:** + +* 运行 `/login` 再次登录。在不登录的情况下重试会在每个请求上显示相同的消息。 +* 在非交互式模式中,在同一环境中运行 `claude`,完成 `/login`,然后重新运行您的命令。对于无法交互式登录的自动化,使用 `ANTHROPIC_API_KEY` 进行身份验证或 [使用 `claude setup-token` 生成长期令牌](/docs/zh-CN/authentication#generate-a-long-lived-token)。 +* 如果登录持续失败,请参阅 [登录和身份验证](/docs/zh-CN/troubleshoot-install#login-and-authentication) + +

+ Claude 登录未被接受

-与 API 的 TCP 连接失败或从未完成。 +您尝试启动 [云会话](/docs/zh-CN/claude-code-on-the-web),服务器拒绝使用 401 创建它:它不接受此机器发送的 Claude 登录,通常是因为登录过期或被撤销。 + +当服务器给出自己的原因时,行的第一部分是该原因。否则该行读作: ```text theme={null} -Unable to connect to API. Check your internet connection -Unable to connect to API (ECONNREFUSED) -Unable to connect to API (ECONNRESET) -Unable to connect to API (ETIMEDOUT) -fetch failed -Request timed out. Check your internet connection and proxy settings +Claude login not accepted · Run /login, then try again ``` -常见原因包括没有互联网访问、阻止 `api.anthropic.com` 的 VPN,或未配置的必需企业代理。 - **应该做什么:** -* 通过在同一 shell 中运行 `curl -I https://api.anthropic.com` 来确认您可以到达 API 主机。在 Windows PowerShell 上使用 `curl.exe -I https://api.anthropic.com`,以便不使用内置的 `Invoke-WebRequest` 别名。 -* 如果您在企业代理后面,请在启动 Claude Code 之前设置 `HTTPS_PROXY`,并参阅[网络配置](/docs/zh-CN/network-config) -* 如果您通过 LLM 网关或中继路由,请将 [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 设置为其地址。有关设置,请参阅[将 Claude Code 连接到 LLM 网关](/docs/zh-CN/llm-gateway-connect)。 -* 确保您的防火墙允许[网络访问要求](/docs/zh-CN/network-config#network-access-requirements)中列出的主机 -* 间歇性故障会[自动重试](#automatic-retries);持续故障指向本地网络问题 - -如果 `curl` 成功但 Claude Code 仍然失败,原因通常是运行时和网络之间的某些东西,而不是网络本身: - -* 在 Linux 和 WSL 上,检查 `/etc/resolv.conf` 是否有无法到达的名称服务器。特别是 WSL 可能会从主机继承损坏的解析器。 -* 在 macOS 上,已断开连接或卸载的 VPN 客户端可能会留下隧道接口或路由规则。检查 `ifconfig` 是否有过时的 `utun` 接口,并在系统设置中删除 VPN 的网络扩展。 -* Docker Desktop 和类似的容器运行时可能会拦截出站流量。退出它们并重试以排除这种可能性。 +* 运行 `/login`,完成登录,然后再次启动会话 -

- Bedrock 流式响应具有意外的内容类型 +

+ 工件需要 claude.ai 登录

-Claude Code 和 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 之间的网关或代理正在转换流式响应体或其 `Content-Type` 标头。Amazon Bedrock 将响应流式传输为 `application/vnd.amazon.eventstream`,Claude Code 拒绝报告不同内容类型的成功流式响应,而不是解码它无法读取的响应体。请求不会重试。 +Claude Code 拒绝了 [工件](/docs/zh-CN/artifacts) 发布或读取,因为会话没有可用于工件的 claude.ai 登录。 + +消息的每种形式都以相同的词开头,然后是取决于您的会话如何进行身份验证的补救措施。没有竞争凭证时,它读作: ```text theme={null} -Bedrock streaming response has content-type "text/event-stream"; expected "application/vnd.amazon.eventstream". A gateway or proxy between Claude Code and Bedrock is likely transforming the response body — Bedrock's binary event-stream format must be passed through unmodified. Set CLAUDE_CODE_DISABLE_BEDROCK_CONTENT_TYPE_GUARD=1 to suppress this check while the gateway is being fixed. +Artifacts 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. ``` -在 v2.1.208 之前,相同的配置错误表现为 `API Error: Truncated event message received`,在整个响应被缓冲后出现。 - **应该做什么:** -* 配置网关以不修改地传递 `InvokeModelWithResponseStream` 响应体及其 `Content-Type` 标头。将流重新发出为服务器发送事件的中介是常见原因。 -* 如果网关仅重写标头并完整传递二进制体,请设置 [`CLAUDE_CODE_DISABLE_BEDROCK_CONTENT_TYPE_GUARD=1`](/docs/zh-CN/env-vars) 以跳过检查,直到网关被修复。请参阅[网关或代理后的流式错误](/docs/zh-CN/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy)。 +* 运行 `/login` 并选择 **Claude account with subscription**。**Anthropic Console account** 选项不提供 claude.ai 凭证。 +* 当消息命名优先的凭证(如 `ANTHROPIC_API_KEY`、`apiKeyHelper` 设置或之前 `/login` 保存的 Console 密钥)时,按消息说的方式删除它,然后运行 `/login` +* 当消息说此远程会话通过启动它的机器进行身份验证时,在该机器上登录到 claude.ai,然后重新连接会话 +* 当消息说凭证由会话的主机环境注入时,您无法在该会话中更改它;启动登录到 claude.ai 的会话 +* 请参阅 [可用性](/docs/zh-CN/artifacts#availability) 了解工件具有的其他要求,例如计划、模型提供商和组织策略 -

- SSL 证书错误 +

+ 管理员策略需要 Cloud gateway 登录

-您网络上的代理或安全设备正在用其自己的证书拦截 TLS 流量,而 Claude Code 不信任它。 +管理员在此机器上的 [托管设置](/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) 登录。您会看到两条消息之一: ```text theme={null} -Unable to connect to API: SSL certificate verification failed. Check your proxy or corporate SSL certificates -Unable to connect to API: Self-signed certificate detected +Not signed in to the Cloud gateway — run /login. ``` -从 v2.1.199 开始,证书验证失败不会重试,因此此错误在第一次尝试时出现,而不是在完整[重试预算](#automatic-retries)之后。早期版本在显示它之前花费几分钟重试。瞬时 TLS 条件(例如握手超时)仍然会重试。 +当会话没有网关登录时,模型请求失败,显示此消息,例如因为您自策略到达机器后未运行 `/login`。 -在 `/login` 和启动连接检查期间,使用 OpenSSL 代码和内联修复报告相同的失败: +如果您还配置了 `ANTHROPIC_API_KEY`、`ANTHROPIC_AUTH_TOKEN` 或 `apiKeyHelper` 凭证,且托管设置设置了 `forceLoginMethod`,Claude Code 在启动时改为以以下消息退出: ```text theme={null} -SSL certificate error (UNABLE_TO_GET_ISSUER_CERT_LOCALLY). If you are behind a corporate proxy or TLS-intercepting firewall, set NODE_EXTRA_CA_CERTS to your CA bundle path, or ask IT to allowlist *.anthropic.com. Run `claude doctor` for details. +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. ``` **应该做什么:** -* 导出您组织的 CA 包,并使用 `NODE_EXTRA_CA_CERTS=/path/to/ca-bundle.pem` 将 Claude Code 指向它 -* 有关完整设置说明,请参阅[网络配置](/docs/zh-CN/network-config#custom-ca-certificates) -* 不要设置 `NODE_TLS_REJECT_UNAUTHORIZED=0`,这会完全禁用证书验证 +* 运行 `/login` 并在 **Cloud gateway** 屏幕上完成登录 +* 对于启动消息,删除您配置的 `ANTHROPIC_API_KEY`、`ANTHROPIC_AUTH_TOKEN` 或 `apiKeyHelper` 设置,然后启动 `claude` 并运行 `/login` +* 如果您认为机器不应该需要网关,请要求管理该机器的管理员从其托管设置中删除 `forceLoginMethod` 和 `forceLoginGatewayUrl` -

- 云会话中不允许的主机 +在 v2.1.265 上,回归也在某些 LLM 网关和代理配置中显示第一条消息,这些配置使用 API 密钥、`apiKeyHelper` 或自定义标头进行身份验证,即使机器上没有管理员要求。更新到 v2.1.266 或更高版本。您不需要更改您的配置。 + +在 v2.1.261 之前,在将 `forceLoginMethod` 设置为 `"gateway"` 的机器上,Claude Code 使用剩余的保存登录而不是失败模型请求,并使用 `This machine's managed settings require a first-party login` 而不是启动消息报告配置的环境凭证。在 v2.1.265 之前,其托管设置仅设置 `forceLoginGatewayUrl` 的机器不需要网关登录,Claude Code 在那里使用剩余凭证。 + +

+ 您的账户被冻结

-来自云会话或例程的出站 HTTP 请求被环境的网络策略阻止。 +您的 Claude 账户背后的登录已被暂停。Claude Code 在尝试更新您保存的登录并了解冻结时显示第一条消息,在您在浏览器中完成的登录报告时显示第二条消息: ```text theme={null} -HTTP 403 -x-deny-reason: host_not_allowed +Your account is on hold and can't use Claude Code. View details or appeal: https://claude.ai/restricted +Your account is on hold and can't sign in to Claude Code. View details or appeal: https://claude.ai/restricted ``` -您也可能看到与目的地真实证书不匹配的 TLS 证书。云环境通过代理路由出站流量以强制执行网络策略,因此证书不匹配意味着代理终止了连接,而不是目的地。 - -这不是客户端网络问题。云会话和[例程](/docs/zh-CN/routines)在沙箱环境内运行,其出站流量被过滤到环境的允许列表。**默认**环境使用**受信任**访问,允许[默认允许列表](/docs/zh-CN/claude-code-on-the-web#default-allowed-domains)中的包注册表、云提供商 API、容器注册表和常见开发域,但阻止其他所有内容。 +使用同一账户再次登录不会清除消息,因为冻结是在账户上而不是登录上。在 [非交互式模式](/docs/zh-CN/headless) (`-p`) 和 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,结构化错误代码为 `account_on_hold`。在 v2.1.235 之前,Claude Code 将被冻结的账户报告为 [登录过期 · 请运行 /login](#login-expired),其恢复步骤无法清除冻结。 **应该做什么:** -* 打开例程进行编辑,或启动云会话。选择显示您的环境名称(例如**默认**)的云图标以打开选择器。将鼠标悬停在您的环境上,然后单击设置图标。 -* 在**更新云环境**对话框中,将**网络访问**从**受信任**更改为**自定义**,然后将被阻止的域添加到**允许的域**。每行输入一个域。选中**也包括常见包管理器的默认列表**以在自定义域旁边保留[默认允许列表](/docs/zh-CN/claude-code-on-the-web#default-allowed-domains)。如果您想要不受限制的访问,请改为选择**完全**。 -* 单击**保存更改**。下一次运行使用更新的允许列表。 - -有关访问级别和默认允许列表,请参阅[网络访问](/docs/zh-CN/claude-code-on-the-web#network-access)。本地 CLI 会话不受此策略影响。 +* 打开消息中的链接以查看冻结的详细信息或对其提出上诉 +* 如果您有另一个 Claude 账户或不受冻结影响的 API 密钥,您可以在冻结解决期间继续工作:使用该账户运行 `/login`,或使用 `ANTHROPIC_API_KEY` 设置密钥 -

- 无法重新连接到您的 Remote Control 会话 +

+ Anthropic 配置文件登录过期

+Claude Code 通过 Anthropic 凭证配置文件进行身份验证,其保存的登录凭证已过期,且配置文件不包含 Claude Code 可用于更新它的刷新凭证。Claude Code 在本地停止每个请求而不重试,因为重试会读取相同的过期凭证。 + ```text theme={null} -Couldn't reconnect to your Remote Control session. Retry, or start a fresh session without --resume. +Anthropic profile login expired · Re-authenticate your Anthropic profile +Anthropic profile login expired · Run /login to use your claude.ai account instead, or re-authenticate the profile ``` -使用 `claude --resume` 或 `claude --continue` 恢复会重新连接到该对话中记录的 [Remote Control](/docs/zh-CN/remote-control) 会话。此消息意味着重新连接因可能是临时的原因(例如网络中断或服务器错误)而失败,因此 Claude Code 无法确认远程会话是否仍然存在。您的本地会话继续运行而不使用 Remote Control。 - -**应该做什么:** +这仅在活跃凭证来自 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`)或第三方提供商进行身份验证的会话永远不会看到此消息。 -* 运行 `/remote-control` 以重试连接 -* 启动 Claude Code 而不使用 `--resume` 以创建新的 Remote Control 会话 -* 有关其他 Remote Control 启动消息,请参阅[排查 Remote Control 故障](/docs/zh-CN/remote-control#troubleshooting) +在 [提供无密钥登录](/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 发现了它: -当服务器确认前一个会话不再存在时,您不会看到此消息;Claude Code 在这种情况下会创建一个新的会话。在 v2.1.200 之前,任何重新连接失败都会创建一个新的 Remote Control 会话,这在 claude.ai/code 的会话列表中留下了额外的会话。 +* 当您显式设置 `ANTHROPIC_PROFILE` 时,消息以 `Re-authenticate your Anthropic profile` 结尾。 +* 当 Claude Code 从您的配置目录发现配置文件时,消息提供 `/login`,因为 Claude Code 给予工作的 `/login` 优先于发现的配置文件,然后改为使用您的 claude.ai 或 Console 账户进行身份验证。在 v2.1.234 之前,Claude Code 在这种情况下也显示 `Re-authenticate your Anthropic profile` 形式。 -

- 请求错误 -

+**应该做什么:** -这些错误与您的请求内容有关。大多数来自 API 在拒绝请求后的返回;少数是由 Claude Code 在发送任何请求之前在本地生成的。 +* 再次登录到配置文件,然后重试:在 [提供无密钥登录](/docs/zh-CN/authentication#sign-in-without-an-api-key) 的机器上,运行 `/login` 并为无密钥 Console 登录或 Claude Platform CLI 的 `ant auth login` 写入的配置文件选择 Anthropic Console 账户;对于其他配置文件,使用创建它们的工具 +* 如果管理员配置了配置文件的凭证,请要求他们颁发新凭证 +* 运行 `/status` 以确认活跃凭证源和配置文件名称 +* 要停止使用配置文件,如果您设置了 `ANTHROPIC_PROFILE`,则取消设置它,然后以其他方式进行身份验证,例如 `/login` 或 `ANTHROPIC_API_KEY` -

- Prompt is too long +

+ OAuth 范围要求

-对话加上附加文件超过了模型的上下文窗口。 +存储的令牌早于较新功能需要的权限范围。您最常从 `/usage` 和状态行使用指示器看到这种情况: ```text theme={null} -Prompt is too long +OAuth token does not meet scope requirement: user:profile ``` **应该做什么:** -* 运行 `/compact` 来总结早期的回合并释放空间,或运行 `/clear` 来重新开始 -* 运行 `/context` 来查看消耗窗口的内容分解:系统提示、工具、内存文件和消息 -* 使用 `/mcp disable ` 禁用您未使用的 MCP 服务器,以从上下文中移除其工具定义 -* 修剪大型 `CLAUDE.md` 内存文件,或将说明移到[路径范围规则](/docs/zh-CN/memory#path-specific-rules)中,这些规则仅在相关时加载 -* 子代理从父会话继承每个 MCP 工具定义,这可能会在第一个回合之前填满它们的上下文窗口。在生成子代理之前禁用您未使用的 MCP 服务器。 -* 自动压缩默认启用,通常可以防止此错误。如果您设置了 [`DISABLE_AUTO_COMPACT`](/docs/zh-CN/env-vars),请重新启用它或在窗口填满之前手动运行 `/compact`。 +* 运行 `/login` 以获取具有当前范围的新令牌。您不需要先登出。 -请参阅[探索上下文窗口](/docs/zh-CN/context-window)以获得上下文如何填充的交互式视图。 - -

- Error during compaction: Conversation too long +

+ claude.ai 拒绝了会话令牌

-`/compact` 本身失败,因为没有足够的可用上下文来容纳它生成的摘要。 +[claude.ai 连接器](/docs/zh-CN/mcp#use-mcp-servers-from-claude-ai) 请求失败,因为 claude.ai 拒绝了您的 Claude Code 登录中的令牌,通常是已过期且无法刷新的登录。被拒绝的令牌是您的登录,而不是连接器在 claude.ai 中的自己的授权,因此再次授权连接器不会解决它。在 `/mcp` 中,连接器显示为 `connected · session token rejected`,其详细视图读作: ```text theme={null} -Error during compaction: Conversation too long. Press esc twice to go up a few messages and try again. +claude.ai rejected the session token. Run /login, then reconnect. ``` -当窗口在自动压缩触发时已经满了,或者在看到 `Prompt is too long` 后运行 `/compact` 时,可能会发生这种情况。 - **应该做什么:** -* 按 Esc 两次打开消息列表并回退几个回合。这会从上下文中删除最近的消息。然后再次运行 `/compact`。 -* 如果回退没有释放足够的空间,运行 `/clear` 来启动新的会话。您之前的对话会被保留,可以使用 `/resume` 重新打开。 +* 运行 `/login` 再次登录 +* 从 `/mcp` 重新连接连接器,或运行 `/mcp reconnect `。在您再次登录之前重新连接会使连接器处于相同状态。`/mcp` 面板的 **Reconnect** 选项报告 `your claude.ai session token was rejected`;输入的 `/mcp reconnect ` 形式报告成功重新连接,即使令牌仍然被拒绝。 -

- Request too large +在 v2.1.222 之前,Claude Code 改为将连接器标记为需要身份验证,这指向您连接器的授权流程,即使完成它也不会解决状态。 + +

+ MCP 服务器需要您再次登录

-原始请求体在标记化之前超过了 API 的字节限制,通常是因为粘贴的大文件或附件。 +远程 [MCP 服务器](/docs/zh-CN/mcp) 在会话中期拒绝了工具调用上的凭证,通常是因为登录或令牌过期或令牌缺少工具需要的权限。工具调用失败,`/mcp` 将服务器标记为 [需要身份验证](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers)。 + +对于您从 Claude Code 登录的服务器,包括 claude.ai 连接器,登录已过期或被撤销: ```text theme={null} -Request too large (max 30 MB). Double press esc to go back and remove or shrink the attached content. +MCP server "" needs you to sign in again (run /mcp to re-authenticate) ``` -这是 HTTP 请求的大小限制,与[上下文窗口限制](#prompt-is-too-long)分开。 +运行 `/mcp`,选择服务器,并从其菜单再次登录。 -**应该做什么:** +对于使用 [`headersHelper`](/docs/zh-CN/mcp#use-dynamic-headers-for-custom-authentication) 脚本配置的服务器,Claude Code 已在显示此之前重新运行 helper 并重试调用一次: -* 按 Esc 两次并回退到添加超大内容的回合之前 -* 通过路径引用大文件而不是粘贴其内容,以便 Claude 可以分块读取它们 -* 对于图像,请参阅下面的[图像太大](#image-was-too-large) +```text theme={null} +MCP server "" rejected the credential from its headersHelper (check the helper and run /mcp to reconnect, or to authenticate if the server also uses OAuth) +``` -

- Image was too large -

+检查 helper 返回服务器接受的凭证,然后从 `/mcp` 重新连接,这会再次运行 helper。 -粘贴或附加的图像超过了 API 的大小或尺寸限制。 +对于在其配置中具有静态 `Authorization` 标头的服务器: ```text theme={null} -Image was too large. Double press esc to go back and try again with a smaller image. -API Error: 400 ... image dimensions exceed max allowed size +MCP server "" rejected the Authorization header in its config (update it, then run /mcp to reconnect) ``` -Claude Code 将无法处理的图像替换为文本占位符并重试,因此后续消息成功。在 2.1.142 之前的版本中,粘贴的图像可能会保留在对话中,并在后续的每条消息上重复相同的错误。要在这些版本上恢复,请按 Esc 两次并回退到添加图像的回合之前。 - -**应该做什么:** - -* 在粘贴之前调整图像大小。API 接受单个图像最长边最多 8000 像素的图像,或当许多图像在上下文中时为 2000 像素。 -* 拍摄相关区域的更紧密屏幕截图,而不是整个屏幕 +在配置服务器的位置更新标头值,然后从 `/mcp` 重新连接。 -

- Unable to resize image -

+在 v2.1.273 之前,过期的登录、`headersHelper` 和 `Authorization` 标头情况都显示 `MCP server "" requires re-authorization (token expired)`。 -Claude Code 无法在将附加图像发送到 API 之前对其进行缩小。 +服务器也可以使用 HTTP 403 `insufficient_scope` 拒绝工具调用,以要求您授权范围,有时是您的令牌已列出的范围。消息命名该范围: ```text theme={null} -Unable to resize image — image processing is unavailable and dimensions could not be read from the file header. Please convert the image to PNG, JPEG, GIF, or WebP. -Unable to resize image — dimensions exceed the 2000x2000px limit and image processing failed. Please resize the image to reduce its pixel dimensions. -Unable to resize image (… raw, … base64). The image exceeds the … API limit and compression failed. Please resize the image manually or use a smaller image. -Unable to resize image — could not verify image dimensions are within the 2000x2000px API limit. +MCP server "" needs additional permissions (scope: "") — run /mcp to re-authenticate ``` -Claude Code 通常会自动调整大型图像的大小。这些错误意味着本机图像处理器无法加载或返回错误,因此无法调整图像大小以适应 API 限制。 +运行 `/mcp`,选择服务器,并从其菜单再次进行身份验证。 -**应该做什么:** +当服务器的配置既不设置 [`oauth.scopes`](/docs/zh-CN/mcp#restrict-oauth-scopes) 也不设置 [`authServerMetadataUrl`](/docs/zh-CN/mcp#override-oauth-metadata-discovery) 时,Claude Code 请求服务器命名的范围。使用任一设置,Claude Code 改为请求该设置的范围。如果您固定了 `oauth.scopes`,在再次进行身份验证之前将缺失的范围添加到该列表。 -* 如果消息要求您转换图像,请将其转换为 PNG、JPEG、GIF 或 WebP,然后再次附加。Claude Code 可以在不使用图像处理器的情况下验证这些格式的尺寸。 -* 如果消息报告尺寸或大小限制,请在附加之前将图像调整大小或重新压缩到该限制以下。 +在 v2.1.274 之前,这种情况显示 `needs you to sign in again` 消息,在 v2.1.273 之前它显示 `requires re-authorization (token expired)`,如其他情况。 -

- PDF errors +

+ 授权响应中的发行者不匹配

-您附加的 PDF 无法处理。 +在 [MCP OAuth 登录](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers) 期间,授权服务器重定向回 Claude Code,其中 `iss` 参数不命名 Claude Code 从服务器的 OAuth 元数据期望的发行者。此步骤中的错误发行者是授权服务器混合攻击的样子,因此 Claude Code 失败登录而不是交换授权代码。Claude Code 在浏览器登录后在 `/mcp` 服务器菜单中显示错误: ```text theme={null} -PDF too large (max 100 pages, 32 MB). Try splitting it or extracting text first. -PDF is password protected. Try removing protection or extracting text first. -The PDF file was not valid. Try converting to a different format first. +Issuer mismatch in authorization response (RFC 9207): expected "https://auth.example.com", received "https://other.example.com" ``` +`expected` 是来自服务器的 OAuth 元数据的发行者,`received` 是重定向携带的 `iss` 值。其重定向不携带 `iss` 参数的登录通过检查,除非服务器的元数据设置 `authorization_response_iss_parameter_supported`,在这种情况下 Claude Code 失败登录。 + **应该做什么:** -* 对于超大 PDF,要求 Claude 使用 Read 工具读取页面范围而不是附加整个文件,或使用 `pdftotext` 之类的工具提取文本并通过路径引用输出文件 -* 对于受保护或无效的 PDF,删除密码或从其源应用程序重新导出文件,然后重试 +* 从 `/mcp` 再次尝试登录 +* 如果错误重复,将其报告给服务器操作员。修复是服务器端的:授权服务器必须在 `iss` 参数中返回与在其元数据中宣传的相同发行者 +* 要在修复服务器时连接,使用 [`MCP_SDK_GENERATION=v1`](/docs/zh-CN/env-vars) 启动 Claude Code,其 [运行时](/docs/zh-CN/mcp#mcp-client-runtimes) 不运行此检查。这消除了对混合攻击的保护,因此更喜欢服务器端修复 -

- Extra inputs are not permitted +在 v2.1.232 之前,Claude Code 仅在逐步推出中或当您设置 `MCP_SDK_GENERATION=v2` 时使用 v2 运行时。 + +

+ AWS 凭证已过期或无效

-Claude Code 和 API 之间的代理或 LLM 网关删除了 `anthropic-beta` 请求头,因此 API 拒绝了依赖它的字段。 +您的 AWS 会话令牌已过期或被拒绝。此消息出现在来自 [Claude Platform on AWS](/docs/zh-CN/claude-platform-on-aws) 或 [Mantle 端点](/docs/zh-CN/amazon-bedrock#use-the-mantle-endpoint) 的 401,这是这些提供商报告过期安全令牌的方式。 + +中间的操作提示因您的设置而异。稳定部分是前导 `AWS credentials expired or invalid`: ```text theme={null} -API Error: 400 ... Extra inputs are not permitted ... context_management -API Error: 400 ... Extra inputs are not permitted ... tools.0.custom.input_examples -API Error: 400 ... Unexpected value(s) for the `anthropic-beta` header +AWS 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 ... ``` -Claude Code 发送仅限测试版的字段,如 `context_management`、`effort` 和工具 `input_examples`,以及启用它们的 `anthropic-beta` 头。当网关转发正文但删除头时,API 会看到它不识别的字段。 +在 v2.1.273 之前,仅当配置了 `awsAuthRefresh` 时才出现此消息。 **应该做什么:** -* 配置您的网关以转发 `anthropic-beta` 头。请参阅[功能传递](/docs/zh-CN/llm-gateway-protocol#feature-pass-through)了解网关必须转发的内容。 -* 作为备选方案,在启动前设置 [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](/docs/zh-CN/env-vars)。这会禁用需要测试版头的功能,以便请求通过无法转发它的网关成功。 +* 如果提示说凭证由此环境管理,启动 Claude Code 的应用拥有凭证,此处的其他步骤不适用:重试或联系您的管理员 +* 如果设置了 [`awsAuthRefresh`](/docs/zh-CN/amazon-bedrock#advanced-credential-configuration),在另一个终端中运行消息中命名的命令,例如 `aws sso login --profile myprofile`,并完成浏览器登录,然后重试。否则自己刷新您使用的 AWS 凭证:您的 SSO 登录、访问密钥、API 密钥或代理令牌 +* 在交互式会话中设置 `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) +* 如果刷新命令成功后错误重复,通过在同一 shell 和配置文件中使用 `aws sts get-caller-identity` 在 Claude Code 外确认身份有效 -

- There's an issue with the selected model +

+ AWS 身份验证失败

-配置的模型名称未被识别,或您的账户无权访问它。从 v2.1.160 开始,尾部提示(此处以其交互形式显示)因表面而异。 +您的 AWS 提供商返回了 403,或 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 返回了 401。 + +Amazon Bedrock 将过期的安全令牌报告为 403,但 403 也是它报告授权拒绝的方式,例如来自缺失 IAM 权限的 `AccessDeniedException`。Claude Code 无法区分这两个原因。 + +来自 Amazon Bedrock 的 401 也在这里而不是在 [AWS 凭证已过期或无效](#aws-credentials-expired-or-invalid) 下,因为 Amazon Bedrock 不将过期令牌报告为 401。来自该端点的 401 通常来自请求路径中的其他内容,例如公司代理。 + +凭证刷新修复过期令牌,无法修复其他原因,因此消息提供两者: ```text theme={null} -There's an issue with the selected model (claude-...). It may not exist or you may not have access to it. Run /model to pick a different model. +AWS 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 ... ``` +中间的操作提示因您的设置而异。稳定部分是前导 `AWS authentication failed`。 + +当 403 是 Amazon Bedrock 的答案,说您无权访问具有指定模型 ID 的模型时,提示改为告诉您在 Amazon Bedrock 控制台中为您的账户和区域启用模型。 + +在 v2.1.273 之前,仅当配置了 `awsAuthRefresh` 时才出现此消息。 + **应该做什么:** -* **交互式 CLI**:运行 `/model` 从您账户可用的模型中选择。 -* **非交互模式 (`-p`)**:使用有效的别名或 ID 传递 `--model`,或设置 [`ANTHROPIC_MODEL`](/docs/zh-CN/env-vars)。错误文本在此表面上显示 `Run --model`。 -* **Agent SDK**:错误文本省略提示,因为模型是以编程方式设置的。在 TypeScript 中设置 [`Options` 上的 `model`](/docs/zh-CN/agent-sdk/typescript#options) 或在 Python 中设置 [`ClaudeAgentOptions(model=...)`](/docs/zh-CN/agent-sdk/python#claudeagentoptions),并处理结构化的 `model_not_found` 错误以显示您自己的重试或模型选择器。 -* 使用别名(如 `sonnet` 或 `opus`)而不是完整的版本化 ID。别名解析为维护的默认值,因此不会过时。请参阅[模型配置](/docs/zh-CN/model-config)。 -* 如果 CLI 中一直返回错误的模型,则某处设置了过时的 ID。按[优先级顺序](/docs/zh-CN/model-config#setting-your-model)检查:`--model` 标志、`ANTHROPIC_MODEL` 环境变量,然后是 `.claude/settings.local.json` 中的 `model` 字段、您项目的 `.claude/settings.json` 和 `~/.claude/settings.json`。删除过时的值,Claude Code 会回退到您的账户默认值。 -* Claude Code 将过期的 claude.ai 登录报告为[登录已过期](#login-expired),而不是此错误。在 v2.1.206 之前,无法再刷新的过期登录在每个模型上都失败,出现此错误;如果您在较旧版本上看到这个,请运行 `/login`。 -* 对于 Google Cloud 的 Agent Platform 部署,请参阅 [Google Cloud 的 Agent Platform 故障排除](/docs/zh-CN/google-vertex-ai#troubleshooting)。 +* 如果提示说凭证由此环境管理,启动 Claude Code 的应用拥有凭证,此处的其他步骤不适用:重试或联系您的管理员 +* 刷新您的 AWS 凭证以防过期凭证是原因:运行消息中命名的 [`awsAuthRefresh`](/docs/zh-CN/amazon-bedrock#advanced-credential-configuration) 命令(当设置时),或自己刷新您的 SSO 登录、访问密钥、API 密钥或代理令牌 +* 如果您的凭证是最新的,确认 [IAM 配置](/docs/zh-CN/amazon-bedrock#iam-configuration) 中的 IAM 权限已附加到您使用的身份,并且所选模型已为您的账户和区域启用 +* 运行 `aws sts get-caller-identity` 以确认您的请求使用哪个身份;过时的 `AWS_PROFILE` 或默认配置文件是权限不匹配的常见原因 -

- Model is not a recognized model id +

+ Google Cloud 凭证已过期或无效

-您传递给模型切换的模型字符串不是模型别名、此 Claude Code 版本知道的模型 ID,也不是以 `claude-` 开头的 ID。常见原因是 ID 中的拼写错误、显示名称(如 `Sonnet 5`,其中需要 ID `claude-sonnet-5`)或仅较新 Claude Code 版本识别的别名。Claude Code 立即拒绝切换。在 v2.1.200 之前,Claude Code 保存字符串并在下一个请求时失败,出现[所选模型有问题](#theres-an-issue-with-the-selected-model)。 +您的 [Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) Google Cloud 凭证已过期或被拒绝:请求返回了 401,这是 Agent Platform 报告凭证过期的方式。 + +中间的操作提示因您的设置而异。稳定部分是前导 `Google Cloud credentials expired or invalid`: ```text theme={null} -Model "claud-sonnet-5" is not a recognized model id. Did you mean 'claude-sonnet-5'? +Google 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 ... ``` -尾部提示命名最接近的匹配别名或模型 ID。当没有足够接近的内容时,它读作 `Run /model to see available models.`。 - -Claude Code 在请求切换时在本地生成此错误,在发出任何 API 请求之前。它适用于通过 [Agent SDK](/docs/zh-CN/agent-sdk/typescript) `setModel()` 方法或为您运行 Claude Code CLI 的应用程序(如 [Desktop app](/docs/zh-CN/desktop))设置模型的情况。 - **应该做什么:** -* 运行不带参数的 `/model` 来打开选择器并从您账户可用的模型中选择,然后传递那里显示的别名或 ID -* 如果您使用了较新 Claude Code 版本支持的别名,运行 `claude update`。以 `claude-` 开头的完整 ID 即使模型比您的 Claude Code 版本更新,也会通过此检查,因此不需要升级。 -* v2.1.200 之前保存的模型不会被此检查修复。如果过时的值一直出现,请从[所选模型有问题](#theres-an-issue-with-the-selected-model)下列出的位置中删除它。 -* 检查仅在 Anthropic API 上运行。在 Amazon Bedrock、Google Cloud 的 Agent Platform、Microsoft Foundry、[Claude Platform on AWS](/docs/zh-CN/claude-platform-on-aws) 和 [LLM 网关](/docs/zh-CN/llm-gateway)后面或自定义 `ANTHROPIC_BASE_URL`,您的提供商或网关定义模型名称,因此 Claude Code 接受任何字符串并将其传递。 +* 如果提示说凭证由此环境管理,启动 Claude Code 的应用拥有凭证,此处的其他步骤不适用:重试或联系您的管理员 +* 如果您使用应用默认凭证进行身份验证,运行消息中命名的 [`gcpAuthRefresh`](/docs/zh-CN/google-vertex-ai#advanced-credential-configuration) 命令或 `gcloud auth application-default login`,并完成登录,然后重试 +* 如果您通过设置了 `CLAUDE_CODE_SKIP_VERTEX_AUTH` 的 [LLM 网关](/docs/zh-CN/llm-gateway) 路由,刷新 `ANTHROPIC_AUTH_TOKEN` 或 `ANTHROPIC_CUSTOM_HEADERS` 中的网关令牌,然后重试 +* 如果您使用服务账户密钥文件进行身份验证,确认 `GOOGLE_APPLICATION_CREDENTIALS` 指向有效密钥。请参阅 [配置 GCP 凭证](/docs/zh-CN/google-vertex-ai#3-configure-gcp-credentials) +* 如果刷新后错误重复,通过在同一 shell 中使用 `gcloud auth application-default print-access-token` 在 Claude Code 外确认身份有效 -

- Claude Opus is not available with the Claude Pro plan +在 v2.1.273 之前,来自 Agent Platform 的 401 显示通用 `Please run /login` 或 `Failed to authenticate` 消息,无法刷新 Google Cloud 凭证。 + +

+ Google Cloud 身份验证失败

-您的活跃订阅计划不包括您选择的模型。 +[Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) 返回了 403,它用于授权拒绝而不是过期凭证。通常您进行身份验证的身份缺少 IAM 权限,或模型未为您的项目启用。 + +中间的操作提示因您的设置而异。稳定部分是前导 `Google Cloud authentication failed`: ```text theme={null} -Claude Opus is not available with the Claude Pro plan · Select a different model in /model +Google 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 ... ``` **应该做什么:** -* 运行 `/model` 并选择您的计划包含的模型 -* 如果您最近升级了计划但仍然看到这个,运行 `/logout` 然后 `/login`。存储的令牌反映您登录时的计划,因此在现有会话中在网络上升级不会生效,直到您重新进行身份验证。 -* 请参阅 [claude.com/pricing](https://claude.com/pricing) 了解每个计划包含哪些模型 +* 如果提示说凭证由此环境管理,启动 Claude Code 的应用拥有凭证,此处的其他步骤不适用:重试或联系您的管理员 +* 确认 [IAM 配置](/docs/zh-CN/google-vertex-ai#iam-configuration) 中的角色已授予您进行身份验证的身份 +* 确认模型已为您的项目启用。请参阅 [请求模型访问](/docs/zh-CN/google-vertex-ai#2-request-model-access) -

- Model is restricted by your organization's settings +在 v2.1.273 之前,来自 Agent Platform 的 403 显示通用 `Please run /login` 或 `Failed to authenticate` 消息,无法刷新 Google Cloud 凭证。 + +

+ Microsoft Foundry 身份验证失败

-您的组织管理员在 claude.ai 管理控制台中禁用了此模型,或者它被托管设置中的 [`availableModels`](/docs/zh-CN/model-config#restrict-model-selection) 允许列表排除。当受限模型使用 `--model`、`ANTHROPIC_MODEL` 或 `model` 设置设置时,Claude Code 替换允许的模型并继续。为受限模型键入 `/model ` 会被拒绝,显示 `Run /model to choose a different model.`,会话保持其当前模型。 +[Microsoft Foundry](/docs/zh-CN/microsoft-foundry) 返回了 401 或 403:请求上的 Azure 凭证被拒绝,或其背后的身份无权访问 Foundry 资源。`/login` 无法铸造 Azure 凭证。中间的操作提示因您的设置而异。稳定部分是前导 `Microsoft Foundry authentication failed`: ```text theme={null} -Model "claude-opus-4-8" is restricted by your organization's settings. Using claude-sonnet-4-6 instead. +Microsoft 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 ... ``` -Claude Code 将模型族别名(`opus`、`sonnet`、`haiku` 或 `fable` 之一)视为对该族的请求,而不是对其最新版本的请求。在 Anthropic API 和 [Claude Platform on AWS](/docs/zh-CN/claude-platform-on-aws) 上,受限的族别名解析为您的组织和 `availableModels` 允许列表允许的族的最新版本,替换通知命名该版本。Claude Code 仅当族的每个版本都受限时才拒绝 `/model `。在 v2.1.205 之前,族别名基于其最新版本单独替换或拒绝,即使同一族的较旧版本被允许。 - **应该做什么:** -* 运行 `/model` 从您的组织允许的模型中选择。受限模型从选择器中隐藏。 -* 如果受限模型在 `--model`、`ANTHROPIC_MODEL` 或设置文件的 `model` 字段中设置,删除或更新该值,以便通知不会在每次启动时重复出现 -* 如果您需要访问受限模型,请要求您的组织管理员启用它。请参阅[组织模型限制](/docs/zh-CN/model-config#organization-model-restrictions)。 +* 如果提示说凭证由此环境管理,启动 Claude Code 的应用拥有凭证,此处的其他步骤不适用:重试或联系您的管理员 +* 刷新您在 [配置 Azure 凭证](/docs/zh-CN/microsoft-foundry#2-configure-azure-credentials) 中配置的凭证:轮换 `ANTHROPIC_FOUNDRY_API_KEY`、铸造新的 `ANTHROPIC_FOUNDRY_AUTH_TOKEN` 或运行 `az login` 以便默认 Microsoft Entra 凭证链可以再次登录 +* 如果凭证是最新的,确认身份有权访问 Foundry 资源。请参阅 [Azure RBAC 配置](/docs/zh-CN/microsoft-foundry#azure-rbac-configuration) -

- thinking.type.enabled is not supported for this model +在 v2.1.273 之前,来自 Microsoft Foundry 的 401 或 403 显示通用 `Please run /login` 或 `Failed to authenticate` 消息,无法刷新 Azure 凭证。 + +

+ 无法加载 AWS 或 Google Cloud 凭证

-您的 Claude Code 版本比 Sonnet 5、Opus 4.8 或 Opus 4.7 的最低版本更旧。CLI 发送了模型不再接受的思考配置。 +Claude Code 无法从 AWS 凭证提供商链或从它运行的机器上的 Google 应用默认凭证获取可用凭证,因此没有请求到达您的云提供商。Claude Code 清除其缓存凭证并在显示此消息之前重试两次。`·` 之后的详细信息命名具体原因,例如过期的 SSO 会话、缺失的应用默认凭证报告为 `Could not load the default credentials` 或被撤销的登录报告为 `invalid_grant`: ```text theme={null} -API Error: 400 ... "thinking.type.enabled" is not supported for this model. Use "thinking.type.adaptive" and "output_config.effort" to control thinking behavior. +API Error: Could not load AWS credentials · Could not load credentials from any providers. Check or refresh your AWS credentials and try again. +API Error: Could not load Google Cloud credentials · invalid_grant. Check or refresh your Google Cloud credentials and try again. ``` +在 [非交互式模式](/docs/zh-CN/headless) 中使用 `-p` 和在 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中,结构化错误代码为 `cloud_credential_error`。在 v2.1.267 之前,消息仅显示 `API Error:` 之后的详细信息文本,结构化代码为 `server_error` 或 `unknown`。 + **应该做什么:** -* 运行 `claude update` 并重启 Claude Code。Opus 4.7 需要 v2.1.111 或更高版本。Opus 4.8 需要 v2.1.154 或更高版本。Sonnet 5 需要 v2.1.197 或更高版本 -* 如果您无法升级,运行 `/model` 并改为选择 Opus 4.6 或 Sonnet 4.6 -* 如果您在 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中遇到这个问题,请升级 SDK 包。Opus 4.8 需要 TypeScript SDK v0.3.154 或更高版本和 Python SDK v0.2.88 或更高版本。Sonnet 5 需要 TypeScript SDK v0.3.197 或更高版本 +* 运行您的提供商的登录命令,例如 `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 外确认凭证 +* 如果详细信息读作 `AWS default-chain credential resolve timed out`,链挂起而不是失败,因此改为遵循 [AWS default-chain credential resolve timed out](#aws-default-chain-credential-resolve-timed-out) -

- Thinking budget exceeds output limit +

+ AWS default-chain credential resolve 超时

-配置的扩展思考预算超过了最大响应长度,因此没有空间留给实际答案。 +AWS 默认凭证提供商链在 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) 并重试,因此当您看到它时链已在重复尝试中停滞。 ```text theme={null} -API Error: 400 ... max_tokens must be greater than thinking.budget_tokens +API Error: Could not load AWS credentials · AWS default-chain credential resolve timed out. Check or refresh your AWS credentials and try again. ``` -Claude Code 在 Anthropic API 上自动调整这些值。您通常在 Amazon Bedrock 或 Google Cloud 的 Agent Platform 上看到此错误,当 [`MAX_THINKING_TOKENS`](/docs/zh-CN/env-vars) 设置高于提供商的输出限制时,或当计划模式提高思考预算时。 +常见原因是您的 AWS 配置文件中的 `credential_process` 命令等待它无法接收的输入,以及其实例元数据服务 (IMDS) 从不回答链探针的容器或 VM。 + +在 v2.1.267 之前,消息读作 `API Error: AWS default-chain credential resolve timed out`。 +在 v2.1.207 之前,停滞的链使请求无限期等待而不是失败。 **应该做什么:** -* 降低 `MAX_THINKING_TOKENS`,或将 [`CLAUDE_CODE_MAX_OUTPUT_TOKENS`](/docs/zh-CN/env-vars) 提高到思考预算之上 -* 请参阅[扩展思考](/docs/zh-CN/model-config#extended-thinking)了解预算如何与输出长度相互作用 +* 在同一 shell 中使用相同的 `AWS_PROFILE` 运行 `aws sts get-caller-identity`。如果它也挂起,修复配置文件;提示交互式的 `credential_process` 命令是常见原因。 +* 在启动 Claude Code 之前完成登录步骤,例如 `aws sso login --profile myprofile`,以便链从本地 SSO 缓存而不是等待浏览器流解析 +* 如果您的链运行合法需要超过 60 秒的交互式登录,例如通过 `aws-vault` 等包装器的 SSO 与 MFA,使用 [`CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS`](/docs/zh-CN/env-vars) 以毫秒为单位提高限制 -

- Tool use or thinking block mismatch +

+ Bedrock 设置验证超时等待 AWS

-对话历史以不一致的状态到达 API,通常是在工具调用被中断或回合在流中途被编辑后。 +在 [Bedrock 设置向导](/docs/zh-CN/amazon-bedrock#sign-in-with-bedrock) 的凭证验证期间对 AWS 的调用,例如凭证查找或身份检查,未在 60 秒限制内完成。向导停止等待并失败验证步骤: ```text theme={null} -API Error: 400 due to tool use concurrency issues. Run /rewind to recover the conversation. -API Error: 400 ... unexpected `tool_use_id` found in `tool_result` blocks -API Error: 400 ... thinking blocks ... cannot be modified +Timed 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. +``` + +该数字反映您的限制:默认 60 秒,或您在 [`CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS`](/docs/zh-CN/env-vars) 中设置的值。 + +常见原因是停滞对 AWS 的请求的网络或代理,包括 SSO 令牌刷新,以及仍在等待您看不到的输入的凭证 helper。仅当 helper 合法需要更多时间时才提高限制。 + +对 AWS 的单个停滞请求也可能在其自己的每请求超时上失败,这在同一步骤上显示较短的消息: + +```text theme={null} +A request to AWS timed out. Check your network and proxy settings, then try again. ``` -所有三个变体都意味着同一件事:历史中 `tool_use`、`tool_result` 和 `thinking` 块的序列不再与 API 期望的相匹配。 +当相同的超时在模型固定步骤上发生时,向导将模型标记为 `unreachable` 而不是显示任一消息。 **应该做什么:** -* 如果您使用的是 Opus 4.7 或 Opus 4.8,请先运行 `claude update`。v2.1.156 之前的版本可能在正常工具使用期间触发此错误,`/rewind` 不会清除它。 -* 运行 `/rewind` 或按 Esc 两次,回退到损坏回合之前的检查点并从那里继续。请参阅[检查点](/docs/zh-CN/checkpointing)了解如何创建和恢复检查点。 +* 在同一 shell 中运行 `aws sts get-caller-identity`。如果它也挂起,停滞在 Claude Code 外,在您的网络、您的代理或您的 AWS 配置文件中的凭证 helper 中;首先修复它。 +* 在打开向导之前完成任何交互式登录,例如 `aws sso login --profile myprofile` +* 如果您的 AWS 配置文件中的凭证 helper 合法需要超过 60 秒来提示您,使用 [`CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS`](/docs/zh-CN/env-vars) 以毫秒为单位提高限制 -

- Usage Policy refusal +

+ Cloud gateway 会话已过期

-API 拒绝响应,因为对话中的内容触发了[使用政策](https://www.anthropic.com/legal/aup)检查。消息包含一个请求 ID,如果您认为拒绝不正确,可以向支持部门引用。 +您通过 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway) 登录,此机器上保存的网关会话已过期且无法更新,或网关不再接受它,例如在网关的 [JWT 密钥被替换](/docs/zh-CN/claude-apps-gateway-deploy#jwt-secret-rotation) 后。如果您在交互式启动 `claude` 时看到此行,会话已打开且未登录网关: ```text theme={null} -API Error: Claude Code is unable to respond to this request, which appears to violate our Usage Policy (https://www.anthropic.com/legal/aup). Please double press esc to edit your last message or start a new session for Claude Code to assist with a different task. +Cloud gateway session expired — run /login to reconnect. ``` -检查评估完整对话,而不仅仅是您的最新提示,因此在同一会话中发送新消息通常会重新触发相同的拒绝。在使用 `--continue` 或 `--resume` 退出并重新打开会话后也是如此,因为磁盘上的记录仍然包含触发内容。在 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock)、[Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) 和 [Microsoft Foundry](/docs/zh-CN/microsoft-foundry) 上,此消息也涵盖模型的安全措施标记为网络安全主题的请求。请参阅[安全措施标记了网络安全主题](#safety-measures-flagged-a-cybersecurity-topic)。 +相同的行可能在会话中期出现,当网关凭证过期且 Claude Code 无法更新它时。 + +在 [非交互式](/docs/zh-CN/headless) 运行、后台或其他无人值守会话或 `claude` 子命令(除 `claude auth` 外)中,Claude Code 改为在网关不再接受会话时以此消息退出: + +```text theme={null} +Cloud gateway no longer accepts this session. Start `claude` and sign in again with /login. +``` **应该做什么:** -* 按 Esc 两次或运行 `/rewind` 回退到触发拒绝的回合之前的检查点,然后重新表述或采取不同的方法。请参阅[检查点](/docs/zh-CN/checkpointing)。 -* 如果您无法识别哪个回合导致了它,运行 `/clear` 在同一项目中启动新对话。您之前的对话保留在磁盘上,在 `/resume` 中仍然可用。 -* 在[非交互模式](/docs/zh-CN/headless)(`-p`) 中,其中 rewind 不可用,在没有 `--continue` 的新会话中使用重新表述的提示重试。政策检查因模型而异,因此使用 `--model` 切换到不同的模型也可能在某些情况下解决拒绝。 +* 在会话中运行 `/login` 并完成浏览器登录 +* 对于非交互式启动,在同一环境中启动 `claude`,运行 `/login`,然后重新运行您的命令 -

- Safety measures flagged a cybersecurity topic +

+ 登录超时,等待您继续

-模型的安全措施将对话中的内容标记为网络安全主题。消息命名标记请求的模型: +在 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway) 登录期间,网关命名了登录的账户,Claude Code 要求您在保存凭证之前确认它。您将确认保持打开状态超过登录自己的过期,网关未颁发可更新它的刷新令牌,因此当您继续时 Claude Code 未存储任何内容: ```text theme={null} -API Error: Opus 4.8 has safety measures that flagged this message for a cybersecurity topic. To learn about the Cyber Verification Program and apply for access, visit our help center: https://support.claude.com/en/articles/14604842-real-time-cyber-safeguards-on-claude. - -If you were not engaging in a cybersecurity topic, please send feedback via /feedback. +Sign-in timed out while waiting for you to continue. Try again. ``` -消息链接到[网络验证计划](https://support.claude.com/en/articles/14604842-real-time-cyber-safeguards-on-claude),该计划为合法网络安全工作授予访问权限。保护措施本身是服务器端的,早于 v2.1.203;此版本仅更改了消息的措辞和它链接到的页面。 +**应该做什么:** + +* 再次运行 `/login` 并在登录过期之前确认账户 -您看到的内容取决于您的提供商和模式: +

+ Gateway 拒绝了请求 +

-* 在 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock)、[Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) 和 [Microsoft Foundry](/docs/zh-CN/microsoft-foundry) 上,网络安全标志会产生[使用政策拒绝](#usage-policy-refusal)消息。 -* [非交互模式](/docs/zh-CN/headless)省略 `/feedback` 句子。 +您通过 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway) 登录,请求返回了 403:网关或其背后的上游拒绝了它。再次登录不会改变拒绝,因此消息指向您的网关管理员: -在 v2.1.203 之前,消息读作 `'s safeguards flagged this message for a cybersecurity topic. If your work requires this access, you can apply for an exemption:` 后跟豁免表单链接。 +```text theme={null} +Gateway refused the request · signing in again won't change this — check with your gateway administrator · API Error: 403 ... +``` **应该做什么:** -* 如果您的工作需要此内容,请通过[网络验证计划](https://support.claude.com/en/articles/14604842-real-time-cyber-safeguards-on-claude)申请访问权限 -* 如果您的请求不是关于网络安全主题,运行 `/feedback` 来报告误报 -* 要在同一会话中继续工作,按 Esc 两次或运行 `/rewind` 回退到触发标志的回合之前的检查点,然后采取不同的方法。请参阅[检查点](/docs/zh-CN/checkpointing)。 +* 要求您的网关管理员查找请求。`API Error:` 尾部携带网关返回的拒绝 +* 对于管理员:网关上的 [访问控制规则](/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) 传递 -

- 安装错误 +在 v2.1.273 之前,网关会话上的 403 显示通用 `Please run /login` 或 `Failed to authenticate` 消息,再次登录不会清除拒绝。 + +

+ 网络和连接错误

-这些错误在安装或更新 Claude Code 时出现,来自[安装脚本](/docs/zh-CN/setup#install-claude-code)、`claude install` 或 `claude update`。对于设置期间的 `command not found`、PATH、权限和 TLS 问题,请参阅[排查安装和登录问题](/docs/zh-CN/troubleshoot-install)。 +大多数这些错误意味着来自 Claude Code 的网络请求未能到达其目的地,或者 Claude Code 和 API 之间的某些东西在返回时改变了响应;如果条目还有本地原因(例如存档写入失败),其正文会说明这一点。它们通常源于您的本地网络、代理或防火墙,或云环境的网络策略。 -

- 安装在完成前被中止 +

+ 无法连接到 API

-安装脚本会报告 `claude install` 步骤何时被信号终止。在 Linux 上,退出代码 137 表示进程收到了 SIGKILL,在低内存主机上通常是内核内存不足 (OOM) 杀手。脚本打印此说明并以代码 137 退出: +到 API 的 TCP 连接失败或从未完成。对于常见的连接错误代码,消息名称指出失败的类型并在括号中保留代码: ```text theme={null} -Installation was killed before it could finish (exit code 137). This usually means the system ran out of memory. -Claude Code needs roughly 512MB of free memory to install. Free up memory, then run this script again. +Unable to connect to API. Check your internet connection +Connection refused — a firewall or proxy may be blocking it (ConnectionRefused) +Can't reach the API server — check your internet or DNS (ENOTFOUND) +No internet route — check your connection or VPN (EHOSTUNREACH) +Couldn't connect through your proxy (ERR_PROXY_TUNNEL) — the proxy refused the tunnel: check its credentials and that it allows this host +Connection dropped (ECONNRESET) +fetch failed +Request timed out. Check your internet connection and proxy settings ``` -对于任何其他致命信号,以及 macOS 上的退出代码 137,脚本打印 `Installation was killed before it could finish (exit code )`,其中包含实际退出代码,并省略内存不足的说明。该消息来自 macOS 和 Linux 使用的安装脚本,该脚本也涵盖 WSL 内的安装;本机 Windows 安装脚本永远不会打印它。在 v2.1.200 之前,脚本仅以 shell 的裸 `Killed` 行退出。 +Claude Code 不识别的代码显示为 `Unable to connect to API` 后跟括号中的代码。某些这些消息可以显示多个代码:`Connection refused` 可以显示 `ConnectionRefused` 或 `ECONNREFUSED`,例如,`Can't reach the API server` 可以显示 `ENOTFOUND` 或 `FailedToOpenSocket`。 -**应该做什么:** +在 v2.1.227 之前,这些编码消息中的每一个都读作 `Unable to connect to API` 后跟代码,例如 `Unable to connect to API (ECONNREFUSED)`。 -* 停止其他进程以释放内存,然后重新运行安装程序 -* 添加交换空间或移至更大的实例。有关交换文件命令,请参阅[在低内存 Linux 服务器上安装被中止](/docs/zh-CN/troubleshoot-install#install-killed-on-low-memory-linux-servers)。 +常见原因包括没有互联网访问、阻止 `api.anthropic.com` 的 VPN,或未配置的必需企业代理。 -

- 下载更新时连接断开 +**要做什么:** + +* 通过从同一 shell 运行 `curl -I https://api.anthropic.com` 来确认您可以到达 API 主机。在 Windows PowerShell 上使用 `curl.exe -I https://api.anthropic.com` 以便不使用内置的 `Invoke-WebRequest` 别名。 +* 如果您在企业代理后面,在启动 Claude Code 之前设置 `HTTPS_PROXY` 并查看[网络配置](/docs/zh-CN/network-config) +* 如果您通过 LLM 网关或中继路由,将 [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 设置为其地址。有关设置,请参阅[将 Claude Code 连接到 LLM 网关](/docs/zh-CN/llm-gateway-connect)。 +* 确保您的防火墙允许[网络访问要求](/docs/zh-CN/network-config#network-access-requirements)中列出的主机 +* 间歇性故障会[自动重试](#automatic-retries);持续故障指向本地网络问题 + +如果 `curl` 成功但 Claude Code 仍然失败,原因通常是运行时和网络之间的某些东西,而不是网络本身: + +* 在 Linux 和 WSL 上,检查 `/etc/resolv.conf` 是否有无法到达的名称服务器。WSL 特别可以从主机继承损坏的解析器。 +* 在 macOS 上,已断开连接或卸载的 VPN 客户端可能会留下隧道接口或路由规则。检查 `ifconfig` 是否有陈旧的 `utun` 接口,并在系统设置中删除 VPN 的网络扩展。 +* Docker Desktop 和类似的容器运行时可以拦截出站流量。退出它们并重试以排除这种可能性。 + +

+ 无法连接到 Anthropic 服务

-在 `claude install`、`claude update` 或[自动更新程序](/docs/zh-CN/setup#auto-updates)获取 Claude Code 二进制文件时,与下载服务器的连接关闭,重试未能恢复。当连接断开、传输停滞或下载的文件未通过校验和时,Claude Code 会重试下载,总共最多尝试三次。已完成的 HTTP 错误(例如 404)不会重试,因为服务器已经响应。在 v2.1.202 之前,单个断开的连接会立即导致下载失败,显示裸错误 `aborted`,而不是重试。 +在首次运行设置期间,Claude Code 检查它是否可以到达 `api.anthropic.com` 和 `platform.claude.com`,然后再显示登录步骤。当任一检查失败时,Claude Code 打印原因并退出。 ```text theme={null} -The connection dropped while downloading the update (attempt 3/3: aborted). Check your network — proxies sometimes cut off large downloads. +Unable to connect to Anthropic services +Failed to connect to api.anthropic.com: ECONNREFUSED +Connection to api.anthropic.com timed out after 10 seconds +A proxy is configured via HTTPS_PROXY. Check that it allows connections to the host above. ``` -括号中的文本命名失败的尝试和底层网络错误。`claude update` 在 stderr 上以 `Error: Failed to install native update` 开头的消息。 +Claude Code 通过与 API 请求相同的[代理配置](/docs/zh-CN/network-config)发送检查,并给每个探针 10 秒。当失败的探针通过代理时,消息名称配置它的环境变量,例如 `HTTPS_PROXY`。在 v2.1.222 之前,检查使用不同的代理传输,没有超时:在具有 `https://` 方案的代理 URL 后面,它可能会在 `Checking connectivity...` 上无限期停滞,然后即使通过同一代理的 API 请求成功也会失败。 -保持连接但在 10 分钟内未完成的下载失败,显示 `Download timed out: exceeded the total deadline`。Claude Code 不会重试超时的下载,因为连接速度太慢而无法在截止时间内完成,在立即重试时也不会完成。以下步骤适用于两条消息。在 v2.1.205 之前,相同的 10 分钟截止时间被报告为 HTTP 客户端的通用 `timeout of 600000ms exceeded`。 +当[托管设置文件、MDM 策略或策略助手](/docs/zh-CN/managed-settings)将 [`forceLoginMethod`](/docs/zh-CN/settings-reference#forceloginmethod) 设置为 `"gateway"` 或设置 [`forceLoginGatewayUrl`](/docs/zh-CN/settings-reference#forcelogingatewayurl) 而不设置 `forceLoginMethod` 时,Claude Code 会跳过此检查。使用任一配置,Claude Code 在**云网关**屏幕上打开登录步骤,而不是 Anthropic 登录方法。当机器上存在托管设置源但无法读取时,Claude Code 也会跳过检查,因为该源可能包含网关配置。在 v2.1.247 之前,Claude Code 在此配置下也运行检查,当 Anthropic 的端点无法到达时以此错误退出。 -通常的原因是代理或网关在长传输完成前关闭它。Claude Code 二进制文件是一个大型下载,因此永远不会影响正常 API 流量的代理连接限制仍然可能中断它。 +**要做什么:** -**应该做什么:** +* 如果消息名称代理变量,检查其值是否指向正确的代理,并要求您的网络团队允许通过它进行 HTTPS 连接到消息中的主机。请参阅[网络配置](/docs/zh-CN/network-config)。 +* 完成[无法连接到 API](#unable-to-connect-to-api) 中的检查。那里的 `curl` 测试和防火墙指导也适用于此检查。 +* 如果您的组织通过[云网关](/docs/zh-CN/claude-apps-gateway)登录,并且此错误出现在首次运行时,请更新到 Claude Code v2.1.247 或更高版本。 +* 如果您的网络是开放的,故障仍然存在,Claude Code 可能在您的国家[不可用](https://www.anthropic.com/supported-countries) -* 再次运行 `claude update`。在网络状况良好的情况下,下载通常在下次运行时成功。对于超时消息,从更快或限制较少的网络再次运行它。 -* 如果您的网络需要代理,请在运行安装程序或 `claude update` 之前设置 `HTTPS_PROXY`。请参阅[检查网络连接](/docs/zh-CN/troubleshoot-install#check-network-connectivity)。 -* 如果公司代理持续关闭传输,请要求您的网络团队允许从 `downloads.claude.ai` 进行完整下载。请参阅[网络访问要求](/docs/zh-CN/network-config#network-access-requirements)。 -* 从您的 shell 运行 `claude doctor` 以进行安装诊断 +

+ Socket 已关闭 +

-

- 命令行错误 -

+`Socket is closed` 意味着承载流式响应的连接在响应仍在到达时被关闭。最常见的原因是 Windows 上的企业代理在响应中途丢弃已建立的隧道。 -这些错误来自 `claude` 命令行及其子命令。Claude Code 在运行您的提示或发送任何 API 请求之前会打印这些错误。 +根据响应的进度,Claude Code 重试请求、保留 Claude 生成的内容或结束轮次。请参阅[自动重试](#automatic-retries)。 -

- \--bg 和 --print 之间的冲突 +在 v2.1.214 之前,Claude Code 不会重试此故障,轮次停止并显示包含 `Socket is closed` 的错误。 + +**要做什么:** + +* 如果您看到此错误,使用 `claude update` 更新到 v2.1.214 或更高版本,然后再次发送您的消息 +* 如果在更新后轮次在同一代理后面继续失败,请完成[无法连接到 API](#unable-to-connect-to-api) 并检查[网络配置](/docs/zh-CN/network-config)中的代理设置 + +

+ API 返回了空的或格式错误的响应

-此消息需要 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 之前,此组合会静默创建一个永远无法附加的后台作业。 +Claude Code 在失败的流式请求的非流式重试获得 HTTP 成功状态但正文不是 Claude API 消息时显示此错误:通常是 HTML 错误或登录页面、空正文或其他格式的 JSON。代理、网关或网络登录页面代替 API 回答是常见的来源。Claude Code 不会重试请求,轮次以此错误结束。 ```text theme={null} ---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 ''`. +API returned an empty or malformed response (HTTP 200) — check for a proxy or gateway intercepting the request. ``` -**应该怎么做:** +在该开头之后,消息报告返回的内容和哪个请求失败: -* 删除 `-p` 或 `--print`。`--bg` 将提示作为其位置参数,所以 `claude --bg ""` 是完整的命令。请参阅[从您的 shell 分派新代理](/docs/zh-CN/agent-view#from-your-shell)。 -* 要以非交互方式运行提示并打印结果而不是创建后台会话,请删除 `--bg` 并运行 `claude -p ""` +* 一个 `Response:` 子句,包含内容类型、正文类型(例如 `body is an HTML page` 或 `empty body`)、其大小(以字节为单位)以及响应是否携带 Anthropic 请求 id。当响应名称可识别的服务器(例如 `nginx` 或 `cloudflare`)或携带中介标头(例如 `cf-ray` 或 `via`)时,子句也会列出这些。 +* 一个句子,名称失败的流式请求的 id 和触发重试的故障。当流在故障之前打开时,它也报告有多少流事件到达,如果有的话,当尝试失败时流已沉默多长时间。 -

- \--json-schema 值不是有效的 JSON Schema +在 v2.1.234 之前,消息在 `intercepting the request` 之后结束。 + +在 v2.1.271 之前,在非 JSON 内容类型(例如 `text/plain`)下携带有效 API 消息的回复也以此错误结束轮次。某些 LLM 网关对非流式回复使用该内容类型。 + +**要做什么:** + +* 阅读 `Response:` 子句以查看哪个系统回答。HTML 正文、没有 Anthropic 请求 id 或名称服务器(例如 `nginx` 或 `cloudflare`)意味着 Claude Code 和 API 之间的某些东西代替回答 +* 如果您通过[LLM 网关](/docs/zh-CN/llm-gateway-connect#troubleshoot-gateway-errors)路由,使用直接请求测试路由,并修复返回非 API 响应的跳跃 +* 在具有登录页面的网络上(例如访客 Wi-Fi),在浏览器中完成登录,然后重试 +* 如果只有通过您的网关的非流式路由被破坏,设置 [`CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK=1`](/docs/zh-CN/env-vars#variables) 以便在流中失败的请求转到正常重试路径而不是此回退,除非流式端点本身返回 `404`,Claude Code 仍然会回退 + +

+ 流式响应在接收任何完整数据之前结束

-您在[非交互模式](/docs/zh-CN/headless#get-structured-output)中传递给 [`--json-schema`](/docs/zh-CN/cli-reference#cli-flags) 的架构未能通过 JSON Schema 编译,因此 `claude` 以代码 1 退出,而不是运行提示。在 v2.1.205 之前,无效的架构会产生无结构的输出且没有错误,任何使用 `format` 关键字的架构都被视为无效。 +来自您的模型提供商的流式响应完成而没有传递任何可用数据,因此 Claude Code 重新发送了没有流式的请求以完成轮次。Claude Code 在交互式会话中每个会话显示一次警告。在 v2.1.239 之前,Claude Code 无声地重试而不流式。 ```text theme={null} -Error: --json-schema is not a valid JSON Schema: data/type must be equal to one of the allowed values +Streaming response ended before any complete data was received. Retrying without streaming. If this keeps happening, check any proxy or gateway between Claude Code and your model provider. ``` -第二个冒号后面的文本是验证器的诊断,并命名了失败的关键字或位置。使用 `format` 关键字的架构(例如 `"format": "email"`)是有效的:Claude Code 接受 `format` 作为注释,不强制执行它。 - -Claude Code 在架构编译之前运行两项检查:它拒绝不可解析的 JSON 值,并显示 `Error: --json-schema is not valid JSON`,以及拒绝不是对象的有效 JSON,并显示 `Error: --json-schema must be a JSON object`。 +Claude Code 发送每个受影响的请求两次:空流式尝试和重试。常见原因是在返回时消耗或转换流式响应正文的代理或网关。 -**应该怎么做:** +**要做什么:** -* 修复诊断命名的架构部分,然后重新运行命令 -* 如果诊断是 `schema too large`,请减少架构的嵌套和 `$ref` 重用 -* 请参阅[获取结构化输出](/docs/zh-CN/headless#get-structured-output)以获取有效的架构和命令 +* 配置 Claude Code 和您的模型提供商之间的任何代理或网关,以通过未修改的流式响应正文和其标头 +* 在[Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 上,请参阅[网关或代理后面的流式错误](/docs/zh-CN/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy)了解标头和正文要求 -

- 无法从 Claude Desktop 导入服务器 +

+ Bedrock 流式响应具有意外的 content-type

-Claude Code 无法添加您在 `claude mcp add-from-claude-desktop` 中选择的其中一个服务器。该命令仍然导入其他选定的服务器,并为每个无法添加的服务器打印一行。在 v2.1.205 之前,第一个失败的服务器会停止导入,并且不会添加任何选定的服务器。 +Claude Code 和[Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 之间的网关或代理正在转换流式响应正文或其 `Content-Type` 标头。Amazon Bedrock 将响应流式传输为 `application/vnd.amazon.eventstream`。Claude Code 不会解码它无法读取的正文,而是拒绝报告不同 content-type 的成功流式响应。Claude Code 不会重试请求。 ```text theme={null} -Could not import my server: Invalid name my server. Names can only contain letters, numbers, hyphens, and underscores. +Bedrock streaming response has content-type "text/event-stream"; expected "application/vnd.amazon.eventstream". A gateway or proxy between Claude Code and Bedrock is likely transforming the response body — Bedrock's binary event-stream format must be passed through unmodified. Set CLAUDE_CODE_DISABLE_BEDROCK_CONTENT_TYPE_GUARD=1 to suppress this check while the gateway is being fixed. ``` -服务器名称后面的文本是原因。最常见的是名称检查:Claude Desktop 允许服务器名称中的字符(例如空格和句号),而 `claude mcp` 仅限于字母、数字、连字符和下划线。其他原因包括未通过验证的服务器配置和被您组织的 [MCP 策略](/docs/zh-CN/managed-mcp)阻止的服务器。 +在 v2.1.208 之前,相同的配置错误显示为 `API Error: Truncated event message received`,在整个响应被缓冲后。 -**应该怎么做:** +**要做什么:** -* 在 `claude_desktop_config.json` 中重命名服务器,仅使用字母、数字、连字符和下划线,然后再次运行 `claude mcp add-from-claude-desktop` -* 使用 `claude mcp add` 或 `claude mcp add-json` 在有效名称下直接添加该服务器。请参阅[从 Claude Desktop 导入 MCP 服务器](/docs/zh-CN/mcp#import-mcp-servers-from-claude-desktop)。 +* 配置网关以通过未修改的 `InvokeModelWithResponseStream` 响应正文及其 `Content-Type` 标头。将流重新发出为服务器发送事件的中介是常见原因。 +* 设置 [`CLAUDE_CODE_DISABLE_BEDROCK_CONTENT_TYPE_GUARD=1`](/docs/zh-CN/env-vars) 隐藏此错误,但 Claude Code 不会在重写的标头下解码二进制正文,因此这些请求回退到较慢的非流式路径。请参阅[网关或代理后面的流式错误](/docs/zh-CN/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy)。 -

- 找不到 MCP 权限提示工具 +

+ SSL 证书错误

-您传递给 [`--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 之前,启动不会等待服务器完成连接,因此启动缓慢但健康的服务器也会产生此错误。 +您网络上的代理或安全设备正在用其自己的证书拦截 TLS 流量,Claude Code 不信任它。 ```text theme={null} -Error: MCP tool mcp__permissions__approve (passed via --permission-prompt-tool) not found. Available MCP tools: none +Unable to connect to API: SSL certificate verification failed (UNABLE_TO_GET_ISSUER_CERT_LOCALLY). The certificate comes from an authority Claude Code doesn't trust, usually a TLS-inspecting corporate proxy or a gateway signed by a private CA: set NODE_EXTRA_CA_CERTS to that CA bundle, or add it to the system certificate store · see https://code.claude.com/docs/en/network-config +Unable to connect to API: Self-signed certificate detected (SELF_SIGNED_CERT_IN_CHAIN). The certificate comes from an authority Claude Code doesn't trust, usually a TLS-inspecting corporate proxy or a gateway signed by a private CA: set NODE_EXTRA_CA_CERTS to that CA bundle, or add it to the system certificate store · see https://code.claude.com/docs/en/network-config ``` -`Available MCP tools:` 后面的列表命名了在等待结束时连接的 MCP 工具。 +在 v2.1.273 之前,两条消息都在 `Check your proxy or corporate SSL certificates` 处结束,没有 OpenSSL 代码或 `NODE_EXTRA_CA_CERTS` 提示。 -**应该怎么做:** +从 v2.1.199 开始,证书验证失败不会重试,因此此错误出现在第一次尝试而不是完整[重试预算](#automatic-retries)之后。早期版本在显示它之前花费几分钟重试。瞬时 TLS 条件(例如握手超时)仍然重试。 -* 检查服务器是否启动并保持连接:在同一目录中运行 `claude mcp list`,并确认服务器列为已连接 -* 确认工具名称与服务器公开的 `mcp____` 名称匹配 -* 如果服务器需要超过 30 秒才能启动,请提高 [`MCP_TIMEOUT`](/docs/zh-CN/env-vars) +在 `/login` 和启动连接检查期间,相同的故障产生不同的消息: -

- 插件错误 -

+```text theme={null} +SSL certificate error (UNABLE_TO_GET_ISSUER_CERT_LOCALLY). If you are behind a corporate proxy or TLS-intercepting firewall, set NODE_EXTRA_CA_CERTS to your CA bundle path, or ask IT to allowlist *.anthropic.com. Run `claude doctor` for details. +``` -这些错误来自[插件](/docs/zh-CN/plugins)和[marketplace](/docs/zh-CN/plugin-marketplaces)配置。对于不会产生本页面上的消息之一的插件问题,例如无法加载的 marketplace URL 或已安装但不显示的插件,请参阅[插件故障排除](/docs/zh-CN/discover-plugins#troubleshooting)。 +在[Amazon Bedrock](/docs/zh-CN/amazon-bedrock) 上,Claude Code 本身发送给 AWS 的请求,例如 STS 和 SSO 角色凭证调用、模型发现和设置向导的检查,取决于相同的证书配置。请参阅[TLS 检查代理后面的证书错误](/docs/zh-CN/amazon-bedrock#certificate-errors-behind-a-tls-inspecting-proxy)。 -

- Marketplace 从不受信任的源注册 +**要做什么:** + +* 导出您组织的 CA 包并使用 `NODE_EXTRA_CA_CERTS=/path/to/ca-bundle.pem` 指向 Claude Code +* 有关完整设置说明,请参阅[网络配置](/docs/zh-CN/network-config#custom-ca-certificates) +* 不要设置 `NODE_TLS_REJECT_UNAUTHORIZED=0`,这会完全禁用证书验证 + +

+ 云会话中不允许的主机

-marketplace 以[为官方 Anthropic marketplace 保留的名称](/docs/zh-CN/plugin-marketplaces#marketplace-schema)注册,但其注册源不是 `anthropics` GitHub 存储库。Claude Code 每次加载或刷新 marketplace 时都会重新检查保留的名称,因此 marketplace 和从中安装的插件停止加载。在 v2.1.205 之前,仅在添加 marketplace 时检查名称,因此在其名称被保留之前注册的条目继续加载。 +来自云会话或例程的出站 HTTP 请求被环境的网络策略阻止。 ```text theme={null} -Marketplace "claude-community" is registered from an untrusted source: The name 'claude-community' is reserved for official Anthropic marketplaces. Only repositories from 'github.com/anthropics/' can use this name. To fix it, remove the marketplace and re-add it from the official source. +HTTP 403 +x-deny-reason: host_not_allowed ``` -**应该怎么做:** +您也可能看到与目标的真实证书不匹配的 TLS 证书。云会话通过代理路由出站流量以强制执行网络策略,因此不匹配的证书意味着代理终止了连接,而不是目标。 -* 运行 `claude plugin marketplace remove `,然后从官方 `github.com/anthropics` 存储库重新添加 marketplace -* 如果您发布了在名称被保留之前使用该名称的第三方 marketplace,请重命名它并要求用户从您的源重新添加它 -* 请参阅[Marketplace schema](/docs/zh-CN/plugin-marketplaces#marketplace-schema)下的保留名称列表 +这不是客户端网络问题。云会话和[例程](/docs/zh-CN/routines)在沙箱 VM 内运行,其通过会话网络的出站流量被过滤到[云环境的](/docs/zh-CN/cloud-environments)允许列表;[GitHub 操作](/docs/zh-CN/cloud-environments#github-proxy)和 MCP 连接器流量使用单独的通道,这就是为什么当其他主机被阻止时它们可以继续工作。**默认**环境使用**受信任**访问,允许[默认允许列表](/docs/zh-CN/cloud-environments#default-allowed-domains)的包注册表、云提供商 API、容器注册表和常见开发域,并阻止该路径上的其他域。 -

- 插件命令在 shell 命令中引用 user\_config -

+**要做什么:** -插件 hook、[monitor](/docs/zh-CN/plugins-reference#monitors)或 MCP [`headersHelper`](/docs/zh-CN/mcp#use-dynamic-headers-for-custom-authentication)命令引用 `${user_config.KEY}` [插件选项](/docs/zh-CN/plugins-reference#user-configuration),替换后的字符串将被传递到 shell。配置的值包含 `$(...)` 、反引号或 `;` 会在那里作为代码运行,因此 Claude Code 拒绝启动该组件而不是替换该值。检查在命令模板上运行,因此即使尚未配置任何值,错误也会出现。在 v2.1.207 之前,该值被替换到 shell 命令中。 +这些步骤更改您自己的环境之一。[组织共享环境](/docs/zh-CN/cloud-environments#organization-shared-environments)在选择器中以只读方式打开,因此请要求所有者从[管理设置](https://claude.ai/admin-settings)中的**云环境**页面更改其网络访问。 -措辞取决于哪个表面引用了该选项。shell 形式的 hook 报告: +* 打开例程进行编辑,或启动云会话。选择显示您的环境名称(例如**默认**)的云图标以打开选择器。将鼠标悬停在您的环境上,然后单击设置图标。 +* 在**更新云环境**对话框中,将**网络访问**从**受信任**更改为**自定义**,然后将被阻止的域添加到**允许的域**。每行输入一个域。检查**也包括常见包管理器的默认列表**以将[默认允许列表](/docs/zh-CN/cloud-environments#default-allowed-domains)与您的自定义域保持在一起。如果您想要不受限制的访问,请改为选择**完全**。 +* 单击**保存更改**。下一次运行使用更新的允许列表。 + +有关访问级别和默认允许列表,请参阅[网络访问](/docs/zh-CN/cloud-environments#network-access)。本地 CLI 会话不受此策略影响。 + +

+ 代理拒绝了连接 +

+ +当 Claude 通过您在 `HTTPS_PROXY` 中设置的代理或相关[代理变量](/docs/zh-CN/network-config#environment-variables)读取[工件](/docs/zh-CN/artifacts)时,您会看到此消息。工件内容来自 `*.frame.claudeusercontent.com`,因此 Claude Code 首先向代理发送 `CONNECT` 请求,要求它打开到该主机的隧道。当代理拒绝时,没有任何东西到达主机,消息携带代理的 HTTP 状态: ```text theme={null} -Hook from plugin formatter@acme-tools references ${user_config.*} in a shell-form command. The substituted value would be re-parsed by the shell. Use exec form instead — {"command": "", "args": ["${user_config.KEY}", ...]} — or read $CLAUDE_PLUGIN_OPTION_ from the hook's environment. Command: ./scripts/notify.sh ${user_config.webhook_url} +artifact content fetch failed (proxy refused the connection: HTTP 407) +artifact content fetch failed (proxy refused the connection: HTTP 403) +the proxy refused the connection to the artifact's content host (HTTP 502) ``` -monitor 报告: +状态是代理对 `CONNECT` 的答案。主机从未回答,因此每个状态指向不同的修复: + +* `HTTP 407`:代理需要它没有获得的凭证。将它们放在代理 URL 中,如[基本身份验证](/docs/zh-CN/network-config#basic-authentication)所示。 +* `HTTP 403`:代理拒绝隧道到 `*.frame.claudeusercontent.com`。要求运行代理的人允许该主机,[网络访问要求](/docs/zh-CN/network-config#network-access-requirements)列出了该主机。 +* 任何其他状态,例如 `HTTP 502`:代理由于其自己的原因没有打开隧道,例如无法到达主机。在代理的日志中查找状态。 +* `unreadable reply` 代替状态:代理地址处的任何东西都没有用 HTTP 状态行回答。检查地址是否是 HTTP 代理。 + +**要做什么:** + +* 检查代理变量中的地址和凭证,如[代理配置](/docs/zh-CN/network-config#proxy-configuration)所述,然后从启动 Claude Code 的 shell 运行 `curl -x http://proxy.example.com:8080 -I https://api.anthropic.com`,使用您自己的代理 URL。在 Windows PowerShell 上,运行 `curl.exe`。如果此探针以相同方式失败,首先修复代理设置。如果成功,拒绝特定于工件主机。 +* 如果您的网络让 Claude Code 直接到达工件主机,将 `.frame.claudeusercontent.com` 添加到 [`NO_PROXY`](/docs/zh-CN/network-config#environment-variables)。保持条目狭窄:更广泛的 `.claudeusercontent.com` 条目也会绕过 `bridge.claudeusercontent.com` 的代理,具有[IP 允许列表](/docs/zh-CN/network-config#organization-ip-allowlists-and-proxy-egress)的组织需要将其保留在代理上。 + +在 v2.1.238 之前,Claude Code 将拒绝的隧道报告为通用网络错误。 + +

+ 云环境服务返回了空的或意外的响应 +

+ +Claude Code 在多个点请求您的[云环境](/docs/zh-CN/cloud-environments)列表,例如当您从 CLI 创建云会话或运行 [`/remote-env`](/docs/zh-CN/cloud-environments#select-an-environment-from-the-cli) 时。当它无法读取服务器的答案时,它显示以下消息之一: ```text theme={null} -Monitor "deploy-status" from plugin deploy-tools references ${user_config.*} in its command. The substituted value would be passed to a shell. Monitor commands cannot safely reference ${user_config.*}; have the monitor script read the value from a config file or prompt instead. +The cloud environments service returned an empty response (HTTP 200 with no body). This is usually temporary — try again in a moment. +The cloud environments service returned a response in an unexpected format (HTTP 200 with a non-JSON body). This is usually temporary — try again in a moment. +The cloud environments service returned a response in an unexpected format (HTTP 200 without a usable environments list). This is usually temporary — try again in a moment. ``` -MCP `headersHelper` 报告: +服务器接受了请求但用不是环境列表的正文回答:空、不是 JSON 或没有列表的 JSON。这通常伴随服务端中断,并自行清除。根据请求列表的表面,Claude Code 可能会添加前缀,例如 `/remote-env` 对话框中的 `couldn't list environments:`。 + +**要做什么:** + +* 重试操作。Claude Code 每次都再次请求列表 +* 如果消息继续出现,检查 [status.claude.com](https://status.claude.com) 是否有活跃事件 + +在 v2.1.236 之前,Claude Code 显示原始 JavaScript TypeError 而不是这些消息。 + +

+ 无法重新连接到您的 Remote Control 会话 +

```text theme={null} -headersHelper for MCP server 'internal-api' references ${user_config.*}. The substituted value would be passed to a shell; read the value inside the helper script instead (e.g. from an env var set in the server's "env" block). +Couldn't reconnect to your Remote Control session. Retry, or start a fresh session without --resume. ``` -**应该怎么做:** +使用 `claude --resume` 或 `claude --continue` 恢复会重新连接到该对话中记录的[Remote Control](/docs/zh-CN/remote-control) 会话。此消息意味着重新连接因可能是临时的原因(例如网络中断或服务器错误)而失败,因此 Claude Code 无法确认远程会话是否仍然存在。您的本地会话继续运行而不使用 Remote Control。 -* 对于 hook,添加 `args` 数组以便它在[exec 形式](/docs/zh-CN/hooks#exec-form-and-shell-form)中运行,其中每个 `${user_config.KEY}` 成为一个参数,中间没有 shell。或删除引用并在脚本内读取 `$CLAUDE_PLUGIN_OPTION_` 环境变量 -* 对于 monitor,删除引用并让 monitor 脚本从配置文件读取该值 -* 对于 `headersHelper`,将 `${user_config.KEY}` 移到服务器的 `headers` 字段中,该字段不会被 shell 解析,或在 helper 脚本内读取该值 +**要做什么:** -

- 工具错误 -

+* 运行 `/remote-control` 重试连接 +* 使用 `claude --remote-control` 启动新会话以创建新的 Remote Control 会话 +* 对于其他 Remote Control 启动消息,请参阅[Remote Control 故障排除](/docs/zh-CN/remote-control#troubleshooting) -这些错误来自 Claude 的内置工具拒绝输入。Claude 会自动纠正大多数工具错误;下面两个错误需要你进行更改,因为它们来自你控制的子代理定义或权限规则。 +如果服务器报告之前的会话已消失,您不会看到此消息。Claude Code 在其位置启动新会话或显示 [`Previous session is unavailable — run /remote-control to start a new one`](/docs/zh-CN/remote-control#previous-session-is-unavailable),取决于[对话的重新连接记录](/docs/zh-CN/remote-control#resume-outcomes)。从 v2.1.227 到 v2.1.231,Claude Code 显示了以 `Remote Control could not resume the previous session under the current login` 开头的消息,[早期版本的行为也不同](/docs/zh-CN/remote-control#reconnect-history)。 -

- Agent would be spawned with zero tools +

+ 此机器离线时会话已结束

-[子代理的 `tools` 列表](/docs/zh-CN/sub-agents#supported-frontmatter-fields)中没有任何内容解析为工具,因此 Claude Code 拒绝启动子代理,而不是启动一个无法执行操作的代理。该消息按它们未解析的原因对条目进行分组:不是公认的工具、子代理不可用的工具,或已识别但与当前会话中的任何工具都不匹配。省略 `tools` 字段永远不会触发此拒绝。MCP 服务器模式(如 `mcp__github__*`)不例外:当没有来自该服务器的连接工具时,启动会被拒绝,该模式在匹配失败组中。在 v2.1.208 之前,子代理启动时没有工具,并返回空结果或令人困惑的结果。 +Claude Code 在运行 [`claude remote-control`](/docs/zh-CN/remote-control#start-a-remote-control-session) 的终端中显示此消息,在您的机器离线足够长的时间后,服务器清理了您的机器正在服务的 Remote Control 环境。该环境中的会话已结束,您无法恢复它们。计数是已结束的会话数。 ```text theme={null} -Agent 'code-reviewer' would be spawned with zero tools — refusing. Its tools list resolved to nothing: unrecognized [Grpe]. Fix the agent's tools frontmatter or pass a different subagent_type. +2 sessions ended while this machine was offline — the environment was cleaned up on the server and can't be resumed. ``` -**应该做什么:** +**要做什么:** -* 针对[子代理可用的工具](/docs/zh-CN/sub-agents#available-tools)纠正错误命名的每个条目 -* 删除会话没有的工具条目,例如来自未连接的服务器的 MCP 工具 -* 要给子代理提供父代理拥有的每个工具,请删除 `tools` 字段而不是列出工具 +* 当 Claude Code 在此消息下列出保留的 worktrees 时,从它们中拾取任何未提交的工作 +* 运行 `claude remote-control` 启动新环境 -

- File is covered by a Read deny rule +

+ 无法共享成绩单

-Edit 工具在与 [`Read` 拒绝规则](/docs/zh-CN/permissions#read-and-edit)匹配的路径上被调用,包括在该路径创建新文件。编辑会重写 Claude 必须能够读回的内容,因此在任何文件访问之前调用被拒绝。该规则仅阻止 Edit 工具:Write 和 NotebookEdit 不受 `Read` 拒绝规则的覆盖。在 v2.1.208 之前,只有 `Edit` 拒绝规则阻止编辑,而 `Read` 拒绝规则单独不会。 +在您同意从调查提示(例如[会话质量调查](/docs/zh-CN/data-usage#session-quality-surveys))共享您的会话成绩单后,Claude Code 将其上传到 Anthropic,或在第三方提供商上、[Claude apps gateway](/docs/zh-CN/claude-apps-gateway) 会话上以及当没有 Anthropic 凭证可用时保存本地存档。此消息意味着共享未完成。 ```text theme={null} -File is covered by a Read deny rule in your permission settings and cannot be edited. +Couldn't share the transcript. ``` -**应该做什么:** +上传必须符合 8 MiB 限制。在长会话上,Claude Code 逐步删除共享的部分,最后一个请求的模型设置首先,然后是结构化对话和子代理成绩单,仅当没有减少的版本可以发送或网络或服务器错误停止上传时才显示此消息。当 Claude Code 保存本地存档时,消息意味着它无法写入存档。 -* 如果 Claude 应该能够编辑该文件,请在 `/permissions` 或[设置](/docs/zh-CN/settings#permission-settings)中删除或缩小 `Read` 拒绝规则 -* 如果文件必须保持不变,请保留该规则并为相同路径添加 `Edit` 拒绝规则,以便 Write 和 NotebookEdit 工具也被阻止 +**要做什么:** -

- 后台会话错误 +* 运行 `/feedback` 发送成绩单并描述发生了什么。如果 `/feedback` 在您的环境中不可用,请参阅[报告错误](#report-an-error) +* 如果其他请求也失败,检查您的网络连接并查看[无法连接到 API](#unable-to-connect-to-api) + +

+ 请求错误

-[后台会话](/docs/zh-CN/agent-view)在没有交互式终端的情况下运行,因此需要终端的命令在那里的行为会有所不同。这些消息出现在后台会话的记录中,在代理视图中或附加后。 +这些错误与您的请求内容有关。大多数来自 API 拒绝请求后的返回;少数是由 Claude Code 在发送任何请求之前在本地生成的。 -

- 后台会话中被拒绝的命令 +

+ 提示词过长

-打开交互式对话框的命令在后台会话中被拒绝,并显示一条消息,该消息要么命名一个在那里有效的表单,要么告诉您从常规终端运行该命令。`/install-github-app`、`/mcp` 设置列表和 MCP 服务器菜单中的身份验证操作都以这种方式被拒绝。在 v2.1.208 之前,它们在后台会话内打开其对话框。 -在 v2.1.208 中,`/model` 选择器也在后台会话中被拒绝,`/upgrade` 打印升级 URL 而不是打开浏览器。 +对话加上附加文件超过了模型的上下文窗口。 + +```text theme={null} +Prompt is too long +``` -措辞会命名被拒绝的命令。`/mcp` 设置列表报告: +在交互式会话中,Claude Code 将此错误显示为: ```text theme={null} -Can't open MCP settings in a background session — use `/mcp enable|disable|reconnect ` to steer, or run /mcp from an interactive terminal to authenticate. +Context limit reached · /compact or /clear to continue ``` -**应该怎么做:** +当设置了 [`DISABLE_COMPACT`](/docs/zh-CN/env-vars) 时,该行仅显示 `/clear`。较长形式的错误,例如下面的压缩失败形式,保留 `Prompt is too long ·` 的措辞。在 `-p` 输出和记录中,文本保持为 `Prompt is too long`。 -* 使用消息命名的表单,例如 `/mcp reconnect `、`/mcp enable` 或 `/mcp disable` -* 对于登录和授权流程,从终端中的常规 `claude` 会话运行该命令 +当您在[用户设置](/docs/zh-CN/settings-reference#autocompactenabled)中关闭自动压缩时,该行也会显示: -

- CLAUDE\_CODE\_PROCESS\_WRAPPER 启动器错误 +```text theme={null} +Context limit reached · /compact or /clear to continue · auto-compact is off · /config to turn it on +``` + +`/config` 中的**自动压缩**切换将 `autoCompactEnabled` 写入用户设置。该提示仅在 `/config` 更改会生效时出现。例如,当 [`DISABLE_AUTO_COMPACT`](/docs/zh-CN/env-vars) 或 [`DISABLE_COMPACT`](/docs/zh-CN/env-vars) 关闭自动压缩时,它不会出现。当更高优先级的范围(如项目或托管设置)将 `autoCompactEnabled` 设置为 `false` 时,它也不会出现。在 v2.1.235 之前,该行没有自动压缩提示。 + +Amazon Bedrock 将此条件报告为 `Input is too long for requested model.`,Claude Code 以相同方式处理。在 v2.1.217 之前,Claude Code 不识别 Bedrock 的措辞,因此自动压缩从不在其上触发,`/compact` 失败并显示相同错误。 + +[Claude apps gateway](/docs/zh-CN/claude-apps-gateway-config#upstream-error-messages) 在云上游以提供商自己的错误形状拒绝请求时,将此条件报告为 `capability_rejected: prompt_too_long`。Claude Code 将该令牌视为与 `Prompt is too long` 相同。在 v2.1.228 之前,Claude Code 不识别该令牌,因此自动压缩不会在其上触发。 + +当自动压缩在此轮上运行并因底层错误(如不可用的模型或身份验证失败)而失败时,该消息在分隔符后命名该错误: + +```text theme={null} +Prompt is too long · automatic compaction failed: +``` + +首先解决命名的错误;在您这样做之前,`/compact` 会因相同错误而失败。在 v2.1.229 之前,失败的自动压缩显示 `Prompt is too long` 而不显示原因。 + +当自动压缩在此错误上运行时,它通常会总结您最早的交换并保留最新的。作为最后的手段,Claude Code 会以不同的方式总结: + +* 当它无法总结任何完整交换时,Claude Code 会逐字保留您最新的提示,并总结其前面的所有内容。 +* 在这种情况下,当对话不以您的提示结尾时,Claude Code 会改为总结整个对话。 + +当它将转发的内容不包含模型回复且您自己的文本少于约 1,000 个令牌(如在超大粘贴后发送的短重试)时,Claude Code 会跳过此恢复。运行 `/clear` 以重新开始。在 v2.1.269 之前,每当压缩无法总结完整交换时就会失败,因此处于该状态的会话在每一轮都会再次遇到此错误。 + +单交换对话没有更早的轮次可总结。当自动压缩会在其上运行时,Claude Code 会跳过尝试并解释请求中填充的内容。当 API 在其错误中不报告令牌计数时,消息读取: + +```text theme={null} +Prompt is too long · this conversation is a single exchange and cannot be compacted — the request size comes mostly from system prompt, tool definitions, or attachments. +``` + +当 API 在其错误中报告令牌计数时,Claude Code 将其与对话大小的自己估计进行比较,以判断请求的大部分是什么:对话自己的内容,还是 Claude Code 与其一起发送的系统提示、工具定义和附件内容。当对话自己的内容是请求的大部分时,消息读取: + +```text theme={null} +Prompt is too long · the request is ~ tokens (limit ) and this conversation's own content is most of it. A single-exchange conversation cannot be compacted; start with less content (smaller files or pasted text). +``` + +当请求的大部分在对话之外时,消息读取: + +```text theme={null} +Prompt is too long · the request is ~ tokens (limit ) but this conversation is only ~ tokens — the rest is system prompt, tool definitions, and attachment content. A single-exchange conversation cannot be compacted; reduce attached files/tools or start with less context. +``` + +在 v2.1.162 之前,Claude Code 尝试了压缩,并在失败时显示裸露的 `Prompt is too long`。 + +**要做什么:** + +* 运行 `/compact` 以总结较早的轮次并释放空间,或运行 `/clear` 以重新开始。如果 `/compact` 回答 `Not enough messages to compact.`,则对话是单个交换,没有更早的内容可总结,因此空间由该单个提示和 Claude Code 与每个请求一起发送的内容占用:运行 `/clear` 并使用较少的粘贴文本或较小的附件重新发送,或使用下面的步骤减少工具定义和内存文件 +* 运行 `/context` 以查看窗口消耗内容的分解:系统提示、工具、内存文件和消息 +* 使用 `/mcp disable ` 禁用您未使用的 MCP 服务器,以从上下文中删除其工具定义 +* 修剪大型 `CLAUDE.md` 内存文件,或将说明移到仅在相关时加载的[路径范围规则](/docs/zh-CN/memory#path-specific-rules)中 +* 子代理从父会话继承每个 MCP 工具定义,这可能在第一轮之前填满其上下文窗口。在生成子代理之前,禁用您未使用的 MCP 服务器。 +* 自动压缩默认开启,通常可防止此错误。如果您在 `/config` 中或使用 [`DISABLE_AUTO_COMPACT`](/docs/zh-CN/env-vars) 关闭了它,请将其重新打开。如果您保持关闭,请在窗口填满之前自己运行 `/compact`。 + +有关上下文如何填满的交互式视图,请参阅[探索上下文窗口](/docs/zh-CN/context-window)。 + +

+ 上下文超过令牌限制

-[`CLAUDE_CODE_PROCESS_WRAPPER`](/docs/zh-CN/corporate-launcher) 已设置,其值无法使用,因此 Claude Code 拒绝启动受影响的进程,而不是在没有启动器的情况下运行它。配置问题会报告一条以变量名开头并说明原因的消息,例如: +当对话超过模型的上下文窗口时,`/context` 在其输出顶部显示此警告。请求失败,显示 [`Prompt is too long`](#prompt-is-too-long),直到您释放空间。交互式会话将该错误显示为 `Context limit reached` 行。 ```text theme={null} -CLAUDE_CODE_PROCESS_WRAPPER: launcher `/opt/corp/launcher` is not an executable regular file +Context exceeds the 200k-token limit by 94k tokens — run /compact or /clear to continue. ``` -启动但退出而不用 Claude Code 替换自身的启动器会导致它启动的会话失败,该会话在代理视图中的行报告启动器 `must exec, not daemonize`,后跟启动器打印的任何内容。由于启动器而无法启动或到达后台服务的会话会将启动器问题报告为 `Couldn't reach the background service (...)` 内的原因。 +当您超过的限制是压缩窗口(如 1M 上下文模型上的 200K 边界)时,警告的读取方式不同。压缩窗口可以位于模型的上下文窗口下方,因此超过它的请求仍然可以成功。 -**应该怎么做:** +```text theme={null} +Context is 94k tokens past the 200k-token compaction window — run /compact to reduce usage. +``` -* 将变量设置为可执行文件的绝对路径,该文件以调用 `exec "$@"` 结尾。有关完整合同,请参阅[启动器合同](/docs/zh-CN/corporate-launcher#the-launcher-contract) -* 检查 `/status`,它在其 Self-exec 条目中显示已解析的启动命令,并在运行的后台服务与其不匹配时发出警告,或从 shell 运行 `claude daemon status` -* 在[设置](/docs/zh-CN/corporate-launcher#set-up-the-launcher)的 `env` 块中修复值后,使用 `claude daemon stop --any` 重启后台服务,以便下一次调度启动一个包装的服务 +当您设置了 [`DISABLE_COMPACT`](/docs/zh-CN/env-vars) 时,两种形式都命名 `/clear` 而不是 `/compact`。 -

- 配置警告 -

+**要做什么:** -Claude Code 在启动时将这些消息写入 stderr,而不是在对话中显示错误。它们报告 Claude Code 读取但未应用的配置。 +* 在多轮对话中,运行 `/compact` 以总结较早的轮次并释放空间。要重新开始,请运行 `/clear` +* 有关减少使用的更多方法,请参阅 [Prompt is too long](#prompt-is-too-long) -

- 工作区尚未被信任 +在 v2.1.216 之前,`/context` 显示超过 100% 的使用情况,没有警告行解释这意味着什么或如何恢复。 + +

+ 压缩期间出错:对话过长

-Claude Code 在项目的 `.claude/settings.json` 或 `.claude/settings.local.json` 中找到了 `permissions.allow` 规则或 `permissions.additionalDirectories` 条目,但未应用它们,因为[项目设置中的允许规则需要工作区信任](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust)。消息中的计数、设置名称和文件名会根据您的配置而变化。`deny` 和 `ask` 规则不受影响。 +`/compact` 本身失败,因为没有足够的可用上下文来保存它生成的摘要。 ```text theme={null} -Ignoring 2 permissions.allow entries from .claude/settings.local.json: this workspace has not been trusted. Run Claude Code interactively here once and accept the trust dialog, or set projects["/Users/you/project"].hasTrustDialogAccepted: true in /Users/you/.claude.json. +Error during compaction: Conversation too long. Press esc twice to go up a few messages and try again. ``` -**应该做什么:** +当窗口在自动压缩触发时已满,或当您在看到 [`Prompt is too long`](#prompt-is-too-long) 后运行 `/compact` 时,可能会发生这种情况。在交互式会话中,该错误是 `Context limit reached` 行。 + +**要做什么:** + +* 按 Esc 两次打开消息列表并回退几轮。这会从上下文中删除最近的消息。然后再次运行 `/compact`。 +* 如果回退没有释放足够的空间,运行 `/clear` 以启动新的会话。您之前的对话被保留,可以使用 `/resume` 重新打开。 + +此消息和其他 `/compact` 失败以错误样式显示。在 v2.1.216 之前,它们以与成功命令输出相同的暗淡样式呈现,因此您可能会将失败的压缩读取为成功。 + +

+ 请求过大 +

+ +原始请求体在令牌化之前超过了 API 的 32MB 限制,通常是由于大型粘贴内容、工具结果或附件。此限制与[上下文窗口](#prompt-is-too-long)分开。 + +```text theme={null} +Request too large (max 32MB). Accumulated images and attachments in the conversation pushed the request over the limit. Run /compact, or double press esc to go back and remove attachments. +``` + +当请求直接进入 Claude API 且 API 本身拒绝了它时,Claude Code 会测量对话并根据恢复是否可行来表述消息。通过代理、网关或云提供商,您会获得一般消息。测量的形式: + +* `Request too large (max 32MB; 20.1MB of about 33.4MB is images or documents).`:图像或文档将请求推过了限制。Claude Code 会在去除它们后重试。 +* `Request too large for the API's 32MB request limit`:消息本身超过了限制,因此消息说 `compacting cannot make it fit`,Claude Code 不会重试。在[非交互模式](/docs/zh-CN/headless)中,消息告诉您减少输入或启动新会话。 + +在 v2.1.212 之前,具有足够累积图像的对话在每一轮都失败,显示 `Request too large (max 32MB). Double press esc to go back and try with a smaller file.` 在 v2.1.229 之前,Claude Code 为每次拒绝显示附件建议,即使压缩无法帮助。 + +**要做什么:** + +* 如果消息说 `compacting cannot make it fit`,按 Esc 两次回退到添加大型内容的轮次之前,或运行 `/clear` 以重新开始 +* 否则,运行 `/compact`,它会删除累积的图像和附件 +* 按路径引用大型文件而不是粘贴其内容,以便 Claude 可以分块读取它们 +* 对于图像,请参阅下面的[图像过大](#image-was-too-large) + +

+ 图像过大 +

+ +粘贴或附加的图像超过了 API 的大小或尺寸限制。 + +```text theme={null} +Image was too large. Double press esc to go back and try again with a smaller image. +API Error: 400 ... image dimensions exceed max allowed size +``` + +Claude Code 用文本占位符替换无法处理的图像并重试,因此后续消息成功。在 2.1.142 之前的版本上,粘贴的图像可能保留在对话中,并在每个后续消息上重复相同的错误。要在这些版本上恢复,按 Esc 两次并回退到添加图像的轮次之前。 + +**要做什么:** + +* 在粘贴之前调整图像大小。API 接受单个图像最长边最多 8000 像素的图像,或当许多图像在上下文中时最多 2000 像素。 +* 拍摄相关区域的更紧密屏幕截图,而不是整个屏幕 + +

+ 无法调整图像大小 +

+ +Claude Code 无法在将附加图像发送到 API 之前对其进行缩小。 + +```text theme={null} +Unable to resize image — image processing is unavailable and dimensions could not be read from the file header. Please convert the image to PNG, JPEG, GIF, or WebP. +Unable to resize image — dimensions exceed the 2000x2000px limit and image processing failed. Please resize the image to reduce its pixel dimensions. +Unable to resize image (… raw, … base64). The image exceeds the … API limit and compression failed. Please resize the image manually or use a smaller image. +Unable to resize image — could not verify image dimensions are within the 2000x2000px API limit. +Unable to resize image — it is a CMYK JPEG, which Claude Code cannot decode, and at …px it is over the 2000x2000px limit, so it cannot be sent. Re-save it as an RGB PNG or JPEG and try again. +Unable to resize image — it is an animated WebP whose first frame Claude Code cannot decode, and at …px it is over the 2000x2000px limit, so it cannot be sent. Save its first frame as a PNG or JPEG and try again. +Unable to resize image — its pixels could not be decoded (the file may be damaged, or use an encoding Claude Code cannot read), and it is over the … API limit (… raw, … base64), so it cannot be sent. Re-save it as a PNG or JPEG and try again. +``` + +Claude Code 通常会自动调整大型图像的大小。这些错误意味着无法解码或调整图像大小以适应 API 限制。 + +**要做什么:** + +* 如果消息要求您转换图像,请将其转换为 PNG、JPEG、GIF 或 WebP,然后再次附加。Claude Code 可以从文件头为这些格式验证尺寸,而无需解码图像。 +* 如果消息报告尺寸或大小限制,请在附加之前将图像调整或重新压缩到该限制以下。 +* 如果消息命名原因,例如 CMYK JPEG、动画 WebP 或可能损坏的文件,请以消息建议的格式重新保存图像并再次附加。 + +

+ PDF 错误 +

+ +您附加的 PDF 无法处理。消息在此处以非交互形式显示;在交互式会话中,它们会提示您按 Esc 两次并重试。 + +```text theme={null} +PDF too large (max 100 pages, 20MB). Try reading the file a different way (e.g., extract text with pdftotext). +PDF is password protected. Try using a CLI tool to extract or convert the PDF. +The PDF file was not valid. Try converting it to text first (e.g., pdftotext). +``` + +**要做什么:** + +* 对于超大 PDF,要求 Claude 使用 Read 工具读取页面范围,而不是附加整个文件,或使用 `pdftotext` 等工具提取文本并按路径引用输出文件 +* 对于受保护或无效的 PDF,删除密码或从其源应用程序重新导出文件,然后重试 + +

+ 不允许额外输入 +

+ +Claude Code 和 API 之间的代理或 LLM 网关删除了 `anthropic-beta` 请求头,因此 API 拒绝了依赖它的字段。 + +```text theme={null} +API Error: 400 ... Extra inputs are not permitted ... context_management +API Error: 400 ... Unexpected value(s) for the `anthropic-beta` header +``` + +Claude Code 发送 `context_management` 和 `effort` 等仅限测试版的字段,以及启用它们的 `anthropic-beta` 头。当网关转发正文但删除头时,API 会看到它不识别的字段。 + +**要做什么:** + +* 配置您的网关以转发 `anthropic-beta` 头。有关网关必须转发的内容,请参阅[功能传递](/docs/zh-CN/llm-gateway-protocol#feature-pass-through)。 +* 作为后备,在启动前设置 [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](/docs/zh-CN/env-vars)。[禁用预发布功能](/docs/zh-CN/llm-gateway-protocol#disable-pre-release-capabilities)涵盖确切范围。 + +

+ 工具输入架构无效 +

+ +请求中的工具声明了 `input_schema`,该架构未通过 API 的 JSON Schema 验证,因此 API 拒绝了整个请求。`tools.` 后的数字是失败工具在请求的工具列表中的位置,而不是您可以查找的名称。 + +```text theme={null} +API Error: 400 ... tools.N.custom.input_schema: JSON schema is invalid +API Error: 400 ... tools.N.custom.input_schema.properties: Property keys should match pattern '^[a-zA-Z0-9_.-]{1,64}$' +``` + +第一种形式意味着架构不是有效的 JSON Schema draft 2020-12。第二种意味着顶级属性名称与消息引用的模式不匹配。 + +Claude Code [在加载服务器的工具时排除其输入架构会失败此验证的 MCP 工具](/docs/zh-CN/mcp#tools-with-invalid-input-schemas),因此请求通常永远不会包含一个。 + +在[禁用标志获取的部署](/docs/zh-CN/env-vars#features-that-need-feature-flag-fetching)上,或在标志从未到达的机器上,Claude Code 在服务器的日志中记录哪个工具会被拒绝,但仍然发送它,因此此错误仍然可能发生。 + +该错误也可能发生在其架构在 `$schema` 中声明 JSON Schema 方言(而不是 draft 2020-12)的工具上。Claude Code 不会根据 JSON Schema 元架构检查这些架构,尽管顶级属性名称检查仍然适用。 + +在 v2.1.216 之前,没有部署运行排除检查。 + +**要做什么:** + +* 如果您的 Claude Code 版本早于 v2.1.216,运行 `claude update`。 +* 删除或[禁用](/docs/zh-CN/mcp#disable-a-server-without-removing-it)声明无效架构的 MCP 服务器。该错误仅按位置命名工具。在 v2.1.216 或更高版本上,检查每个服务器的日志,查找命名其输入架构会被拒绝的工具的行。如果没有日志命名一个,一次禁用一个服务器。 +* 如果您维护服务器,请修复工具的 `input_schema`。架构必须是有效的 JSON Schema,顶级属性名称必须为 1 到 64 个字符长,并仅使用 ASCII 字母和数字、`_`、`.` 和 `-`。请参阅[具有无效输入架构的工具](/docs/zh-CN/mcp#tools-with-invalid-input-schemas)。 + +

+ 所选模型存在问题 +

+ +配置的模型名称未被识别,或您的帐户无权访问它。从 v2.1.160 开始,尾部提示(此处以其交互形式显示)因表面而异。 + +```text theme={null} +There's an issue with the selected model (claude-...). It may not exist or you may not have access to it. Run /model to pick a different model. +``` + +**要做什么:** + +* **交互式 CLI**:运行 `/model` 从您帐户可用的模型中选择。 +* **非交互模式 (`-p`)**:使用有效的别名或 ID 传递 `--model`,或设置 [`ANTHROPIC_MODEL`](/docs/zh-CN/env-vars)。错误文本在此表面上显示 `Run --model`。 +* **Agent SDK**:错误文本省略提示,因为模型是以编程方式设置的。在 TypeScript 中的 [`Options` 上设置 `model`](/docs/zh-CN/agent-sdk/typescript#options),或在 Python 中设置 [`ClaudeAgentOptions(model=...)`](/docs/zh-CN/agent-sdk/python#claudeagentoptions),并处理结构化的 `model_not_found` 错误以显示您自己的重试或模型选择器。 +* 使用别名(如 `sonnet` 或 `opus`)而不是完整的版本化 ID。别名解析为维护的默认值,因此它们不会过时。请参阅[模型配置](/docs/zh-CN/model-config)。 +* 如果错误的模型在 CLI 中不断返回,则某处设置了过时的 ID。按[优先级顺序](/docs/zh-CN/model-config#setting-your-model)检查您可以设置模型的位置,并删除过时的值。 +* 新推出的模型可能在 Anthropic API 上可用,但在 Amazon Bedrock、Google Cloud 的 Agent Platform 或 Microsoft Foundry 上可用之前。如果您在这些提供商之一上固定了新模型 ID 并看到此错误,请检查您提供商的模型目录以了解您所在地区的可用性,并保持固定前一个版本,直到新版本出现。 +* Claude Code 将过期的 claude.ai 登录报告为[登录过期](#login-expired),而不是此错误。在 v2.1.206 之前,无法再刷新的过期登录对每个模型都失败,显示此错误;如果您在较旧版本上看到这种情况,请运行 `/login`。 +* 对于 Google Cloud 的 Agent Platform 部署,请参阅 [Google Cloud 的 Agent Platform 故障排除](/docs/zh-CN/google-vertex-ai#troubleshooting)。 + +

+ 模型不是公认的模型 ID +

+ +您传递给模型切换的模型字符串不是模型别名、此 Claude Code 版本知道的模型 ID,也不是以 `claude-` 开头的 ID。常见原因是 ID 中的拼写错误、显示名称(如 `Sonnet 5`,其中需要 ID `claude-sonnet-5`)或仅较新 Claude Code 版本识别的别名。Claude Code 立即拒绝切换。在 v2.1.200 之前,Claude Code 保存字符串并在下一个请求时失败,显示[所选模型存在问题](#theres-an-issue-with-the-selected-model)。 + +```text theme={null} +Model "claud-sonnet-5" is not a recognized model id. Did you mean 'claude-sonnet-5'? +``` + +尾部提示命名最接近的匹配别名或模型 ID。当没有足够接近的内容时,它读取 `Run /model to see available models.`。 + +Claude Code 在请求切换时在本地生成此错误,在发送任何 API 请求之前。它适用于通过 [Agent SDK](/docs/zh-CN/agent-sdk/typescript) `setModel()` 方法设置模型的情况,通过运行 Claude Code CLI 的应用程序(如 [Desktop app](/docs/zh-CN/desktop)),或当您从通过 [Remote Control](/docs/zh-CN/remote-control) 连接的设备选择模型时。在 v2.1.260 之前,检查不涵盖 Remote Control 选择,因此 Claude Code 应用了选择,下一个请求失败,显示[所选模型存在问题](#theres-an-issue-with-the-selected-model)。 + +**要做什么:** + +* 运行 `/model` 不带参数以打开选择器并从您帐户可用的模型中选择,然后传递那里显示的别名或 ID +* 如果您使用了较新 Claude Code 版本支持的别名,运行 `claude update`。以 `claude-` 开头的完整 ID 通过此本地检查,即使模型比您的 Claude Code 版本更新。服务器仍然可能需要该模型的最低版本;请参阅 [Claude Code 不支持此模型](#claude-code-does-not-support-this-model)。 +* v2.1.200 之前保存的模型不会被此检查修复。如果过时的值不断返回,请从[设置您的模型](/docs/zh-CN/model-config#setting-your-model)下列出的位置删除它。 +* 检查仅在 Anthropic API 上运行。在任何其他提供商或网关上,包括自定义 `ANTHROPIC_BASE_URL`,提供商定义模型名称,因此 Claude Code 接受任何字符串并将其传递。Claude Code 仍然可以在请求时写入[无法识别的模型诊断行](#unrecognized-model-id-on-a-request),在每个提供商上。 + +

+ 模型未找到 +

+ +您使用 `/model ` 选择了模型,Claude Code 无法确认存在具有该名称的模型。当名称不是 [model alias](/docs/zh-CN/model-config#model-aliases) 或 Claude Code 在本地接受的另一种拼写时,`/model` 使用最小 API 请求验证它,此错误通常是您的 API 端点的答案。无法成为模型 ID 的名称(如包含空格的名称)会获得相同的消息。 + +```text theme={null} +Model 'claude-opus-9' not found +``` + +在具有提供商特定模型 ID 的提供商上,消息可能会添加 `Try '...' instead` 建议,该建议命名您提供商的后备模型 ID。 + +**要做什么:** + +* 运行 `/model` 不带参数并从您帐户可用的模型中选择,或使用 [model alias](/docs/zh-CN/model-config#model-aliases)(如 `sonnet`),它解析为维护的默认值 +* 如果您输入了完整 ID,请根据您提供商的模型目录检查它。新推出的模型可能在 Anthropic API 上可用,但您的提供商或地区尚未提供。 +* 在 v2.1.265 之前,`/model` 也以此错误拒绝了 `opusplan[1m]` 别名拼写。在这些版本上,更新 Claude Code,或在[设置](/docs/zh-CN/model-config#setting-your-model)中或使用 `--model` 设置模型。 + +

+ Claude Opus 在 Claude Pro 计划中不可用 +

+ +您的活跃订阅计划不包括您选择的模型。 + +```text theme={null} +Claude Opus is not available with the Claude Pro plan. If you have updated your subscription plan recently, run /logout and /login for the plan to take effect. +``` + +**要做什么:** + +* 运行 `/model` 并选择您的计划包括的模型 +* 如果您最近升级了计划但仍然看到这个,运行 `/logout` 然后 `/login`。存储的令牌反映您登录时的计划,因此在现有会话中升级 claude.ai 不会生效,直到您重新进行身份验证。 +* 有关每个计划包括哪些模型,请参阅 [claude.com/pricing](https://claude.com/pricing) + +

+ Claude Code 不支持此模型 +

+ +API 因您的 Claude Code 版本低于所需最低版本而拒绝了请求,返回 400。要么您选择的模型需要较新版本(服务器按模型检查),要么您的组织政策需要一个。400 携带错误代码 `claude_code_version_too_old`,消息说明适用的最低版本。 + +```text theme={null} +API Error: 400 Claude Code 2.1.219 does not support this model; version 2.1.255 or newer is required. Run 'claude update', or update the Claude desktop app, then try again. +``` + +组织政策措辞读取: + +```text theme={null} +API Error: 400 Claude Code 2.1.240 is older than the minimum version required by your organization's policy. Run 'claude update', or update the Claude desktop app, to continue. +``` + +**要做什么:** + +* 运行 `claude update`,或更新 Claude 桌面应用,然后启动新会话 +* 对于按模型措辞,您可以通过使用 `/model` 切换到另一个模型来继续在当前会话中工作 +* 对于组织政策措辞,在继续之前更新 + +

+ 模型受您的组织设置限制 +

+ +您的组织管理员在 claude.ai 管理控制台中禁用了此模型,或它被托管设置中的 [`availableModels`](/docs/zh-CN/model-config#restrict-model-selection) 允许列表排除。当受限制的模型使用 `--model`、`ANTHROPIC_MODEL` 或 `model` 设置设置时,Claude Code 替换允许的模型并继续。为受限制的模型键入 `/model ` 被拒绝,显示 `Run /model to choose a different model.`,会话保持其当前模型。替换通知也可能在会话中期出现,在组织管理员在 claude.ai 管理控制台中禁用会话正在运行的模型之后。 + +```text theme={null} +Model "claude-opus-4-8" is restricted by your organization's settings. Using claude-sonnet-4-6 instead. +``` + +以代理、技能或命令名称为前缀的通知意味着限制适用于该[子代理的请求模型](/docs/zh-CN/sub-agents#choose-a-model):子代理在替换模型上运行,您的会话模型保持不变。在 v2.1.223 之前,Claude Code 仅为使用 Agent 工具启动的子代理显示通知。 + +Claude Code 将模型族别名(`opus`、`sonnet`、`haiku` 或 `fable` 之一)视为对该族的请求,而不是对其最新版本的请求。在 Anthropic API 和 [Claude Platform on AWS](/docs/zh-CN/claude-platform-on-aws) 上,受限制的族别名解析为您的组织和 `availableModels` 允许列表允许的族的最新版本,替换通知命名该版本。Claude Code 仅当族的每个版本都受限制时才拒绝 `/model `。在 v2.1.205 之前,族别名基于其最新版本单独被替换或拒绝,即使同一族的较旧版本被允许。 + +**要做什么:** + +* 运行 `/model` 从您的组织允许的模型中选择。受限制的模型从选择器中隐藏。 +* 如果受限制的模型在 `--model`、`ANTHROPIC_MODEL`、设置文件的 `model` 字段或[子代理](/docs/zh-CN/sub-agents#choose-a-model)、技能或命令的 `model` frontmatter 中设置,删除或更新该值,以便通知不会再次出现 +* 如果您需要访问受限制的模型,请要求您的组织管理员启用它。请参阅[组织模型限制](/docs/zh-CN/model-config#organization-model-restrictions)。 + +

+ 模型切换被 PreModelSwitch hook 阻止 +

+ +[PreModelSwitch hook](/docs/zh-CN/hooks#premodelswitch) 没有批准您或客户端请求的模型切换,因此会话保持其当前模型。当切换来自 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 主机或 [Remote Control](/docs/zh-CN/remote-control) 而不是您键入的命令时,消息读取 `Model switch blocked by a PreModelSwitch hook` 而不命名目标模型。 + +```text theme={null} +Model switch to Opus 4.6 was blocked by a PreModelSwitch hook: Opus 4.6 is retired for this project. Use a newer model. +``` + +冒号后的原因说明拒绝切换的原因: + +* **hook 写入的原因**:PreModelSwitch hook 在[拒绝切换或要求确认](/docs/zh-CN/hooks#premodelswitch-decision-control)时提供了该原因。解决它要求的内容,或选择您的 hook 允许的模型。 +* **`PreModelSwitch hook did not respond before its timeout`**:在其[超时](/docs/zh-CN/hooks#timeouts)之前不回答的 hook 阻止切换。修复挂起的命令或提高该 hook 的 `timeout`,然后再次切换。 +* **`confirmation required, and this session cannot ask`**:hook 回答 `ask` 而没有原因,控制请求无法显示确认提示。[`-p` 运行](/docs/zh-CN/headless)中的 `/model` 命令以原因后的 `(run /model interactively to confirm)` 报告相同条件。从交互式会话进行切换,或更改 hook 对此模型的决定。 +* **`so organization-managed PreModelSwitch hooks could not be checked`**:Claude Code 无法判断您的组织的[托管插件](/docs/zh-CN/settings-reference#enabledplugins)提供哪些 PreModelSwitch hook,例如因为托管插件加载失败。这些 hook 之一可能阻止切换,因此 Claude Code 拒绝而不是应用未检查的切换。原因的开始命名失败的内容。Claude Code 在每次切换尝试时重新检查,因此已清除的失败停止阻止;如果它继续失败,运行 `claude --debug` 并再次切换以捕获详细信息,然后修复插件或要求您的管理员修复它。 +* **`a PreModelSwitch hook failed before answering`** 或 **`PreModelSwitch hooks were cancelled (the control stream closed) before answering`**:hook 运行在没有判决的情况下结束,Claude Code 不将其视为批准。运行 `claude --debug` 以查看失败的内容,然后再次切换。 + +在 v2.1.260 之前,托管插件拒绝读取 `plugin hooks could not be loaded, so PreModelSwitch hooks could not be checked; see the debug log`。Claude Code 重试了一次插件加载,然后在会话中拒绝了后来的切换,即使您的组织没有管理任何插件。在这些版本上重启会话以再次运行插件加载。 + +

+ 无法将其保存为您的默认值 +

+ +您选择了一个模型以保存为您的默认值,例如使用 `/model ` 或 `/model` 选择器中的 Enter,Claude Code 无法将选择写入您的用户设置文件 `~/.claude/settings.json`。切换本身已应用,因此当前会话在您选择的模型上运行,但您的默认值保持不变,下一个会话在旧值上启动。 + +```text theme={null} +Set model to Fable 5.1 for this session only · couldn't save it as your default: ~/.claude/settings.json can't be written (EROFS) +``` + +文件路径后的原因说明失败的内容: + +* **`can't be written ()`**:写入失败,显示括号中的操作系统错误代码,如 `EROFS`(当文件或其链接到的文件位于拒绝写入的文件系统上时)。使文件可写并再次切换。如果另一个工具生成文件,请在该工具中设置 `model` 键;请参阅[您在 Claude Code 中所做的更改在新会话中丢失](/docs/zh-CN/settings#a-change-you-made-in-claude-code-is-lost-in-new-sessions)。 +* **`isn't valid JSON`**:磁盘上的文件不解析,Claude Code 保持不动而不是覆盖它无法读回的内容。修复语法错误,然后再次切换;请参阅[修复损坏的设置文件](/docs/zh-CN/settings#fix-a-broken-settings-file)。 + +以 `couldn't confirm it was saved as your default (~/.claude/settings.json is still being written)` 结尾的通知意味着写入在三秒后未完成。它在后台继续,因此默认值可能仍然被保存;检查您的下一个会话启动的模型,或再次运行 `/model `。 + +在 v2.1.265 之前,通知说模型被`保存为您的新会话默认值`,即使写入失败。 + +

+ thinking.type.enabled 此模型不支持 +

+ +您的 Claude Code 版本早于所选模型的最低版本。CLI 发送了模型不再接受的思考配置。 + +```text theme={null} +API Error: 400 ... "thinking.type.enabled" is not supported for this model. Use "thinking.type.adaptive" and "output_config.effort" to control thinking behavior. +``` + +**要做什么:** + +* 运行 `claude update` 并重启 Claude Code。Opus 4.7 需要 v2.1.111 或更高版本。Opus 4.8 需要 v2.1.154 或更高版本。Sonnet 5 需要 v2.1.197 或更高版本。Opus 5 需要 v2.1.219 或更高版本。Opus 5.5 需要 v2.1.280 或更高版本 +* 如果您无法升级,运行 `/model` 并选择 Opus 4.6 或 Sonnet 4.6 +* 如果您在 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 中遇到这个,升级 SDK 包。Opus 4.8 需要 TypeScript SDK v0.3.154 或更高版本和 Python SDK v0.2.88 或更高版本。Sonnet 5 需要 TypeScript SDK v0.3.197 或更高版本。Opus 5 需要 TypeScript SDK v0.3.219 或更高版本。Opus 5.5 需要 TypeScript SDK v0.3.280 或更高版本 + +

+ 关闭思考时努力不可用 +

+ +您关闭了[扩展思考](/docs/zh-CN/model-config#extended-thinking)并以[努力级别](/docs/zh-CN/model-config#adjust-effort-level)高于 `high` 运行。模型不接受该组合,因此 API 拒绝了请求。 + +```text theme={null} +API Error: Effort 'xhigh' isn't available with thinking turned off on this model · run /effort high to continue, or turn thinking back on (unset MAX_THINKING_TOKENS=0) +``` + +**要做什么:** + +* [降低努力级别](/docs/zh-CN/model-config#set-the-effort-level)到 `high` 或以下。 +* 打开思考,例如通过取消设置 [`MAX_THINKING_TOKENS`](/docs/zh-CN/env-vars) 或从您的设置中删除 [`"alwaysThinkingEnabled": false`](/docs/zh-CN/settings-reference#alwaysthinkingenabled)。 + +在 v2.1.242 之前,Claude Code 显示了 API 自己的消息:`API Error: 400 output_config.effort 'xhigh' is not supported when thinking is disabled on this model. Use effort 'high' or below, or enable thinking.` 在 v2.1.251 之前,Claude Code 以您设置的努力级别发送请求,因此 Opus 5 拒绝了关闭思考时高于 `high` 的每个请求。Claude Code 现在向它知道拒绝该组合的模型(如 Opus 5)发送努力 `high`,因此在 v2.1.251 或更高版本上,此错误仅从 Claude Code 不知道拒绝它的模型到达您。 + +

+ 思考预算超过输出限制 +

+ +配置的扩展思考预算超过最大响应长度,因此实际答案没有剩余空间。 + +```text theme={null} +API Error: 400 ... max_tokens must be greater than thinking.budget_tokens +``` + +Claude Code 在 Anthropic API 上自动调整这些值。当 [`MAX_THINKING_TOKENS`](/docs/zh-CN/env-vars) 设置高于提供商的输出限制时,或当计划模式提高思考预算时,您通常在 Amazon Bedrock 或 Google Cloud 的 Agent Platform 上看到此错误。 + +**要做什么:** + +* 降低 `MAX_THINKING_TOKENS`,或提高 [`CLAUDE_CODE_MAX_OUTPUT_TOKENS`](/docs/zh-CN/env-vars) 高于思考预算 +* 请参阅[扩展思考](/docs/zh-CN/model-config#extended-thinking)以了解预算如何与输出长度交互 + +

+ 工具使用或思考块不匹配 +

+ +对话历史以不一致的状态到达 API,通常在工具调用被中断或轮次在流中期被编辑后。 + +```text theme={null} +API Error: 400 due to tool use concurrency issues. Run /rewind to recover the conversation. +API Error: 400 orphaned tool_result in conversation history. Run /rewind to recover the conversation. +API Error: 400 duplicate tool_use ID in conversation history. Run /rewind to recover the conversation. +API Error: 400 ... unexpected `tool_use_id` found in `tool_result` blocks +API Error: 400 ... thinking blocks ... cannot be modified +``` + +所有变体意味着相同的事情:历史中 `tool_use`、`tool_result` 和 `thinking` 块的序列不再与 API 期望的匹配。 + +**要做什么:** + +* 如果您使用 Opus 4.7 或 Opus 4.8,首先运行 `claude update`。v2.1.156 之前的版本可以在正常工具使用期间触发此错误,`/rewind` 不会清除它。 +* 运行 `/rewind`,或按 Esc 两次,回退到损坏轮次之前的检查点并从那里继续。请参阅[检查点](/docs/zh-CN/checkpointing)以了解如何创建和恢复检查点。 + +

+ 删除了不支持的工具内容 +

+ +当 Claude Code 直接连接到 Anthropic API 并加载或预览保存的会话时,它删除 Anthropic API 不接受的工具内容,并在两个思考块之间删除的内容所在的位置留下此行: + +```text theme={null} +[Unsupported tool content removed] +``` + +当 Anthropic API 以外的东西以 API 的格式回答时,这样的内容到达会话文件,通常是通过 [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 设置的第三方代理,它转换另一个提供商的工具调用。Claude Code 仅在会话直接连接到 Anthropic API 时删除它,并在会话通过代理或在另一个提供商上运行时按原样加载保存的历史。在 v2.1.246 之前,Claude Code 将工具使用及其结果发送回 API,恢复会话的每一轮都失败,显示 400 错误,如 `messages.1.content.0.server_tool_use.name: Input should be 'web_search', 'web_fetch', ...`。 + +**要做什么:** + +* 当您看到占位符行时,无需任何操作。会话继续而不删除的内容。 +* 如果恢复会话的每一轮都失败,显示 400 错误,运行 `claude update` 并再次恢复会话。v2.1.246 之前的版本不删除内容。 + +

+ role 'system' 必须在 'assistant' 消息之前 +

+ +API 拒绝了请求,返回 400,因为系统消息位于对话中它不接受的位置: + +```text theme={null} +API Error: 400 messages.6: role 'system' must precede an 'assistant' message or end the array; ... +``` + +Claude Code 将其一些提醒和附件文本作为系统消息发送到对话中。当 API 拒绝一个的位置时,Claude Code 重试请求一次,将该文本作为普通用户消息发送。API 的兄弟位置措辞,如 `use the top-level 'system' parameter for the initial system prompt`,获得相同的恢复。 + +当错误确实出现时,被拒绝的系统消息不是 Claude Code 可以删除的。这通常意味着 Claude Code 和 API 之间的代理或 [LLM gateway](/docs/zh-CN/llm-gateway) 添加了自己的系统消息或重新排序了对话。 + +**要做什么:** + +* 运行 `/clear` 以启动新对话。如果错误也在那里返回,原因在请求路径上,而不在保存的对话中。 +* 如果错误在通过 [`ANTHROPIC_BASE_URL`](/docs/zh-CN/env-vars) 配置的代理或网关后的每一轮上重复,连接而不使用代理以确认源,并向操作它的人报告错误 + +在 v2.1.280 之前,Claude Code 不识别此措辞,因此当被拒绝的系统消息是 Claude Code 本身发送的时,错误也出现,对话的每个后来轮次都以相同方式失败。 + +

+ search\_result 块中的 encrypted\_content 无效 +

+ +API 拒绝了请求,返回 400,因为对话历史包含它无法解密的托管网络搜索内容。措辞命名它无法读取的字段: + +```text theme={null} +API Error: 400 messages.21.content.0: Invalid `encrypted_content` in `search_result` block +API Error: 400 messages.21.content.3.citations.0: Invalid `encrypted_index` in `text` block +API Error: 400 Failed to decrypt web search result content +``` + +来自 API 的托管[网络搜索工具](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool)的结果携带只有 API 可以读取的加密字段。API 拒绝重放它无法解密的内容的请求,如为不同组织生成的内容。 + +Claude Code 自己的 [WebSearch 工具](/docs/zh-CN/tools-reference#websearch-tool-behavior)将搜索结果记录为纯文本,因此这些块通常通过代理或 [LLM gateway](/docs/zh-CN/llm-gateway) 到达对话,该网关自己运行了托管网络搜索。 + +被拒绝的块保留在对话历史中,因此每个后来的轮次和 `/compact` 都以相同方式失败。 + +**要做什么:** + +* 运行 `/clear` 或启动新会话;新对话不携带被拒绝的块 +* 如果您在代理或网关后运行 Claude Code,向操作它的人报告错误 + +

+ 使用政策拒绝 +

+ +API 拒绝了响应,因为对话中的内容触发了[使用政策](https://www.anthropic.com/legal/aup)检查。消息包括您可以引用给支持的请求 ID,如果您认为拒绝不正确。 + +```text theme={null} +API Error: Opus 4.6 can't help with this. Start a new session to continue. + +Send feedback with /feedback or learn more: https://www.anthropic.com/legal/aup +``` + +消息命名拒绝的模型,或当没有记录模型时命名 `Claude`。 + +检查评估完整对话,而不仅仅是您的最新提示,因此在同一会话中发送新消息通常会重新触发相同的拒绝。使用 `--continue` 或 `--resume` 退出并重新打开会话后也是如此,因为磁盘上的记录仍然包含触发内容。在 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock)、[Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) 和 [Microsoft Foundry](/docs/zh-CN/microsoft-foundry) 上,此消息也涵盖模型的安全措施标记为网络安全主题的请求。请参阅[安全措施标记了网络安全主题](#safety-measures-flagged-a-cybersecurity-topic)。 + +在 v2.1.219 之前,消息读取 `Claude Code is unable to respond to this request, which appears to violate our Usage Policy (https://www.anthropic.com/legal/aup). Please double press esc to edit your last message or start a new session for Claude Code to assist with a different task.` + +**要做什么:** + +* 按 Esc 两次或运行 `/rewind` 回退到触发拒绝的轮次之前的检查点,然后重新表述或采取不同的方法。请参阅[检查点](/docs/zh-CN/checkpointing)。 +* 如果您无法识别哪个轮次导致了它,运行 `/clear` 在同一项目中启动新对话。您之前的对话保留在磁盘上,并在 `/resume` 中保持可用。 +* 在[非交互模式](/docs/zh-CN/headless)(`-p`) 中,其中回退不可用,在没有 `--continue` 的新会话中使用重新表述的提示重试。政策检查因模型而异,因此使用 `--model` 切换到不同的模型也可能在某些情况下解决拒绝。 + +

+ 安全措施标记了网络安全主题 +

+ +模型的安全措施将对话中的内容标记为网络安全主题。消息命名标记请求的模型: + +```text theme={null} +API Error: Opus 4.8's safeguards flagged this message. Our intentionally broad safeguards allow us to deliver more capabilities faster, but can sometimes flag legitimate cybersecurity work. Apply to the Cyber Verification Program to reduce these interruptions. Send feedback with /feedback or learn more: https://support.claude.com/en/articles/14604842-real-time-cyber-safeguards-on-claude +``` + +消息链接到[网络安全验证计划](https://support.claude.com/en/articles/14604842-real-time-cyber-safeguards-on-claude),该计划为合法网络安全工作授予访问权限。在 Opus 5.5 上(需要 v2.1.280 或更高版本),消息以 `Opus 5.5's safeguards flagged this session` 开头。当标记的类别有可用的后备模型时,Claude Code [切换模型](/docs/zh-CN/model-config#automatic-model-fallback) 而不是显示此错误。 + +在 [Amazon Bedrock](/docs/zh-CN/amazon-bedrock)、[Google Cloud 的 Agent Platform](/docs/zh-CN/google-vertex-ai) 和 [Microsoft Foundry](/docs/zh-CN/microsoft-foundry) 上,网络安全标记会产生[使用政策拒绝](#usage-policy-refusal)消息。 + +保护措施本身是服务器端的,早于 v2.1.203;自那以后的客户端版本仅更改了消息的措辞。 +从 v2.1.203 到 v2.1.218,消息读取 ` has safety measures that flagged this message for a cybersecurity topic. To learn about the Cyber Verification Program and apply for access, visit our help center:` 后跟相同的帮助中心链接,交互式会话附加 `If you were not engaging in a cybersecurity topic, please send feedback via /feedback.` +在 v2.1.203 之前,它读取 `'s safeguards flagged this message for a cybersecurity topic. If your work requires this access, you can apply for an exemption:` 后跟豁免表单链接。 + +**要做什么:** + +* 如果您的工作需要此内容,通过[网络安全验证计划](https://support.claude.com/en/articles/14604842-real-time-cyber-safeguards-on-claude)申请访问权限 +* 如果您的请求不是关于网络安全主题,运行 `/feedback` 报告误报 +* 要继续在同一会话中工作,按 Esc 两次或运行 `/rewind` 回退到触发标记的轮次之前的检查点,然后采取不同的方法。请参阅[检查点](/docs/zh-CN/checkpointing)。 + +

+ 安装错误 +

+ +这些错误在安装或更新 Claude Code 时出现,来自 [安装脚本](/docs/zh-CN/setup#install-claude-code)、`claude install` 或 `claude update`。对于安装过程中的 `command not found`、PATH、权限和 TLS 问题,请参阅 [排查安装和登录问题](/docs/zh-CN/troubleshoot-install)。 + +

+ 安装在完成前被中止 +

+ +当 `claude install` 步骤被信号终止时,安装脚本会报告。在 Linux 上,退出代码 137 表示进程收到了 SIGKILL,在低内存主机上通常是内核内存不足 (OOM) 杀手。脚本打印此说明并以代码 137 退出: + +```text theme={null} +Installation was killed before it could finish (exit code 137). This usually means the system ran out of memory. +Claude Code needs roughly 512MB of free memory to install. Free up memory, then run this script again. +``` + +对于任何其他致命信号,以及 macOS 上的退出代码 137,脚本打印 `Installation was killed before it could finish (exit code )`,其中包含实际的退出代码,并省略内存不足的说明。该消息来自 macOS 和 Linux 使用的安装脚本,该脚本也涵盖 WSL 内的安装;本机 Windows 安装脚本永远不会打印它。在 v2.1.200 之前,脚本仅以 shell 的裸 `Killed` 行退出。 + +**应该做什么:** + +* 停止其他进程以释放内存,然后重新运行安装程序 +* 添加交换空间或移至更大的实例。有关交换文件命令,请参阅 [在低内存 Linux 服务器上安装被中止](/docs/zh-CN/troubleshoot-install#install-killed-on-low-memory-linux-servers)。 + +

+ 下载更新时连接断开 +

+ +在 `claude install`、`claude update` 或 [自动更新程序](/docs/zh-CN/setup#auto-updates) 获取 Claude Code 二进制文件时,与下载服务器的连接关闭,重试也没有恢复。当连接断开、传输停滞或下载的文件校验和失败时,Claude Code 会重试下载,总共最多尝试三次。已完成的 HTTP 错误(例如 404)不会重试,因为服务器已经响应。在 v2.1.202 之前,单个断开的连接会立即导致下载失败,并显示裸错误 `aborted`,而不是重试。 + +```text theme={null} +The connection dropped while downloading the update (attempt 3/3: aborted). Check your network — proxies sometimes cut off large downloads. +``` + +括号中的文本命名失败的尝试和底层网络错误。`claude update` 在 stderr 上以 `Error: Failed to install native update` 开头的消息。 + +保持连接但在 10 分钟内未完成的下载失败,显示 `Download timed out: exceeded the total deadline`。Claude Code 不会重试超时的下载,因为连接速度太慢而无法在截止时间内完成,在立即重试时也不会完成。以下步骤适用于两条消息。 + +通常的原因是代理或网关在长传输完成前关闭它。Claude Code 二进制文件是一个大型下载,因此永远不会影响正常 API 流量的代理连接限制仍然可能中断它。 + +**应该做什么:** + +* 再次运行 `claude update`。在网络状况良好的情况下,下载通常在下一次运行时成功。对于超时消息,从更快或限制较少的网络再次运行它。 +* 如果您的网络需要代理,请在运行安装程序或 `claude update` 之前设置 `HTTPS_PROXY`。请参阅 [检查网络连接](/docs/zh-CN/troubleshoot-install#check-network-connectivity)。 +* 如果公司代理持续关闭传输,请要求您的网络团队允许从 `downloads.claude.ai` 进行完整下载。请参阅 [网络访问要求](/docs/zh-CN/network-config#network-access-requirements)。 +* 从您的 shell 运行 `claude doctor` 以进行安装诊断 + +

+ 命令行错误 +

+ +这些错误来自 `claude` 命令行及其子命令、您在提示符处提交的命令名称,以及诸如 `/security-review` 之类的命令,这些命令通过运行 shell 命令来收集上下文,然后再运行其提示。它们也来自 `/tui`,它会重新启动 CLI。 + +

+ \--bg 和 --print 之间的冲突 +

+ +此消息需要 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 之前,此组合会以静默方式创建一个永远无法附加的后台作业。 + +```text theme={null} +--bg 和 --print 冲突:--print 永远不会启动 `claude agents` 附加到的交互会话,因此该作业将无法附加。提示是位置参数 — 删除 --print:`claude --bg ''`。 +``` + +**要做什么:** + +* 删除 `-p` 或 `--print`。`--bg` 将提示作为其位置参数,因此 `claude --bg ""` 是完整命令。请参阅[从您的 shell 分派新代理](/docs/zh-CN/agent-view#from-your-shell)。 +* 要以非交互方式运行提示并打印结果而不是创建后台会话,请删除 `--bg` 并运行 `claude -p ""` + +

+ 无效的 --agents 配置 +

+ +您传递给 `--agents` 的值无效,因此 `claude` 以代码 1 退出,而不是启动会话。当您传递 `--safe-mode`、`--resume` 或 `--continue`,或设置 [`CLAUDE_CODE_SAFE_MODE`](/docs/zh-CN/env-vars#variables) 时,Claude Code 不会检查该值并启动会话。在 v2.1.242 之前,Claude Code 无论如何都会启动会话,并遗漏它无法加载的定义。 + +```text theme={null} +Error: Invalid --agents configuration: + +``` + +第一行之后的内容取决于值如何失败。Claude Code 按顺序运行这些检查,并在第一个失败的检查处停止。如果您的值有两种问题,您只有在修复第一个问题后才会看到第二个问题: + +1. 当值不能解析为 JSON 时,Claude Code 打印一行 `invalid JSON:` 行,其中包含 JSON 解析器自己的消息 +2. 当它解析但代理定义与 [CLI 定义的子代理](/docs/zh-CN/sub-agents#choose-the-subagent-scope) 的架构不匹配时,Claude Code 为每个问题打印一行 +3. 当代理名称以 `-` 开头时,Claude Code 打印 `: agent names must not start with '-'` + +当有超过 20 个问题行时,Claude Code 打印前 20 个,并用 `…and N more` 替换其余的。 + +**要做什么:** + +* 修复消息列出的每个问题,然后再次运行命令。请参阅 [CLI 定义的子代理采用的字段](/docs/zh-CN/sub-agents#choose-the-subagent-scope)。 + +

+ 无法从 --restricted 会话创建云会话 +

+ +当您使用 [`--restricted`](/docs/zh-CN/cli-reference#cli-flags) 启动会话时,Claude Code 拒绝从它创建[云会话](/docs/zh-CN/claude-code-on-the-web#from-terminal-to-cloud),因为新会话将在受限进程之外运行,不会强制执行受限模式。Claude Code 在客户端拒绝,在联系服务器之前,因此不会创建云会话: + +```text theme={null} +Cloud sessions cannot be created from a --restricted session: they would not enforce it. +``` + +**要做什么:** + +* 在受限会话中本地运行任务 +* 如果您控制会话的启动方式,请启动一个没有 `--restricted` 的新 `claude` 会话,并从那里创建云会话 + +在 v2.1.248 之前,Claude Code 没有 `--restricted` 标志;较早的版本会以未知选项错误拒绝该标志本身。 + +

+ 云会话被您的组织的策略禁用 +

+ +您的组织的 `allow_remote_sessions` 策略已关闭,因此[云会话](/docs/zh-CN/claude-code-on-the-web)和使用它们的命令不可用: + +```text theme={null} +Cloud sessions are disabled by your organization's policy. Contact your organization admin to enable them. +``` + +当您[从终端创建云会话](/docs/zh-CN/claude-code-on-the-web#from-terminal-to-cloud)时,消息会出现,当您提交需要云会话的命令时,例如 `/teleport`、`/remote-env` 或 `/web-setup`。在 v2.1.268 之前,提交其中一个命令会返回 [`Unknown command`](#unknown-command)。 + +这是一个服务器端组织策略,因此无法从本地设置、环境变量或 CLI 标志覆盖。 + +如果 Claude Code 尚未加载您的组织的策略或无法获取它,这些命令会回答 `Couldn't verify your organization's policy for cloud sessions. Check your network connection, then restart Claude Code and try again.`。 + +**要做什么:** + +* 要求您的组织中的[所有者](/docs/zh-CN/server-managed-settings#access-control)在 [claude.ai/admin-settings/claude-code](https://claude.ai/admin-settings/claude-code) 的 Claude Code 管理员设置中启用云会话 +* 如果消息说它无法验证策略,请检查您的网络连接,然后重新启动 Claude Code 并重试 + +

+ \--json-schema 值不是有效的 JSON Schema +

+ +您传递给 [`--json-schema`](/docs/zh-CN/cli-reference#cli-flags) 的架构在[非交互模式](/docs/zh-CN/headless#get-structured-output)中未能通过 JSON Schema 编译,因此 `claude` 以代码 1 退出,而不是运行提示。在 v2.1.205 之前,无效的架构会产生无结构的输出,没有错误,任何使用 `format` 关键字的架构都被视为无效。 + +```text theme={null} +Error: --json-schema is not a valid JSON Schema: data/type must be equal to one of the allowed values +``` + +第二个冒号后的文本是验证器的诊断,并命名失败的关键字或位置。使用 `format` 关键字的架构,例如 `"format": "email"`,是有效的:Claude Code 接受 `format` 作为注释,不强制执行它。 + +Claude Code 在架构编译之前运行两个检查:它拒绝不可解析的 JSON 值,错误为 `Error: --json-schema is not valid JSON`,以及有效的 JSON 但不是对象的值,错误为 `Error: --json-schema must be a JSON object`。 + +**要做什么:** + +* 修复诊断命名的架构部分,然后重新运行命令 +* 如果诊断是 `schema too large`,请减少架构的嵌套和 `$ref` 重用 +* 请参阅[获取结构化输出](/docs/zh-CN/headless#get-structured-output)以获取工作架构和命令 + +

+ 设置文件超过 2MiB 限制 +

+ +您传递给 [`--settings`](/docs/zh-CN/cli-reference#cli-flags) 的文件大于 2 MiB,因此 `claude` 在启动时以代码 1 退出,而不是加载它。设置文件是一个小的 JSON 文档,所以这么大的文件通常意味着路径指向错误的文件。在 v2.1.214 之前,Claude Code 读取文件时没有大小检查,多 GB 的文件或诸如 `/dev/zero` 之类的设备文件会无限增长内存。 + +```text theme={null} +Error: Settings file exceeds the 2MiB limit: /path/to/settings.json +``` + +Claude Code 以相同的方式拒绝不是常规文件的 `--settings` 路径:设备、FIFO 或套接字报告 `Error: Cannot use settings file (Not a regular file (device, FIFO, or socket))`,后跟路径,目录报告 `EISDIR` 原因。 + +**要做什么:** + +* 将 `--settings` 指向 2 MiB 以下的常规 JSON 设置文件。请参阅[设置](/docs/zh-CN/settings)以了解格式。 + +

+ 当前目录不再存在 +

+ +您从一个在您的 shell 进入后被删除或移动的目录启动了 `claude`,例如 worktree 或另一个 shell 删除的临时目录。Claude Code 无法读取其工作目录,因此它在启动会话之前以代码 1 退出,在交互和[非交互](/docs/zh-CN/headless)模式中都是如此。在 v2.1.239 之前,Claude Code 会因缩小的捆绑源和原始 `ENOENT ... uv_cwd` 堆栈在 stderr 上崩溃,而不是显示此消息。 + +```text theme={null} +The current directory no longer exists (it was deleted or moved). Start Claude Code from an existing directory. +error: The current working directory was deleted, so that command didn't work. Please cd into a different directory and try again. +``` + +原因和修复对两种形式都是相同的。 + +当 Claude Code 因其他原因(例如权限更改)无法读取工作目录时,消息会命名错误代码:`Can't read the current directory (EACCES). Start Claude Code from a different directory.` + +在 macOS 上,`~/Desktop`、`~/Documents`、`~/Downloads` 或 iCloud Drive 中目录的 `EPERM` 通常意味着 macOS 阻止您的终端应用访问该文件夹。读取该文件夹的其他命令也会以相同的方式失败:即使使用 `sudo`,`ls` 也会报告 `Operation not permitted`。 + +**要做什么:** + +* 更改为存在的目录,例如您的主目录或项目目录,然后再次运行 `claude` +* 如果目录在同一路径处被重新创建,您的 shell 仍然持有已删除的目录。运行 `cd "$PWD"` 或离开并重新进入目录,然后再次运行 `claude` +* 对于 macOS 上的 `EPERM`,使用 Cmd+Q 退出您的终端应用,重新打开它,返回该文件夹,然后运行 `claude`。如果该文件夹中的 `ls` 仍然失败,请打开**系统设置 > 隐私和安全 > 文件和文件夹**,为您的终端应用打开该文件夹,然后重新打开终端 + +

+ 临时目录被拒绝或无法创建 +

+ +在 macOS 和 Linux 上,Claude Code 在启动时创建一个私有临时目录 `claude-`,位于系统临时目录或 [`CLAUDE_CODE_TMPDIR`](/docs/zh-CN/env-vars) 覆盖下。当无法创建目录或该路径处的现有条目未通过安全检查时,Claude Code 将失败打印到 stderr 并以代码 1 退出,而不是启动会话: + +```text wrap theme={null} +ENOSPC: no space left on device, mkdir '/tmp/claude-501' + +Temp directory /tmp/claude-501 is not a directory (may be an attacker-planted symlink). Refusing to use it. Set CLAUDE_CODE_TMPDIR to a directory you control, or ask an administrator to remove it. + +Temp directory /tmp/claude-501 is owned by uid 502, expected 501. Refusing to use it — another user may have pre-created it. Set CLAUDE_CODE_TMPDIR to a directory you control, or ask an administrator to remove it. + +Temp 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. +``` + +**要做什么:** + +* 对于 `ENOSPC`,释放保存临时目录的卷上的磁盘空间 +* 对于 `Refusing to use it` 形式,删除命名的条目本身,而不是链接指向的内容,然后再次启动 Claude Code;对于 `owned by uid` 形式,只有管理员或该用户可以删除它 +* 对于 `is not readable`,在命名目录上运行 `chmod 0700`,或删除它并重新启动 +* 在任何这些情况下,将 [`CLAUDE_CODE_TMPDIR`](/docs/zh-CN/env-vars) 设置为您控制的目录并启动 Claude Code,保持拒绝的路径不变 + +

+ 目录无法解析为真实位置 +

+ +您为工作目录的子目录运行了 `/add-dir`,Claude Code 无法将目录解析为其真实位置。 + +您已经有对工作目录的子目录的文件访问权限,因此 `/add-dir` 仅加载其 skills、命令和代理。在加载它们之前,Claude Code 检查目录的真实位置(解析任何符号链接)是否在工作目录内。当 Claude Code 无法解析该位置时,它不加载任何内容并显示此消息: + +```text theme={null} +packages/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. +``` + +**要做什么:** + +* 检查路径是否命名工作目录内的真实目录,然后再次运行 `/add-dir` +* 消息不会改变您的文件访问;它仅报告目录的 `.claude/` 内容未被加载 + +在 v2.1.261 之前,当工作目录在 `/net/` 自动挂载上时,此消息也会为每个 `/add-dir ` 出现,Claude Code 根据设计拒绝解析路径;目录很好,重试无法帮助。 + +

+ 启动远程控制时工作区不受信任 +

+ +您在未信任的目录中使用 `claude remote-control` 或其 `claude rc` 别名启动了[远程控制](/docs/zh-CN/remote-control)服务器模式。该命令本身不显示工作区信任对话框,因此它以代码 1 退出并命名修复: + +```text theme={null} +Error: Workspace not trusted. Please run `claude` in /Users/you/project first to review and accept the workspace trust dialog. +``` + +在您的主目录中,消息是不同的,因为工作区信任对话框永远不会保存主目录的信任,因此在那里接受它无法满足此检查。在 v2.1.214 之前,主目录显示上述消息,其建议无法在那里成功。 + +```text theme={null} +Error: 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). +``` + +**要做什么:** + +* 在目录中运行 `claude`,接受[工作区信任对话框](/docs/zh-CN/permissions#project-allow-rules-and-workspace-trust),然后再次运行 `claude remote-control` +* 在您的主目录中,更改为项目目录并在那里启动远程控制 + +

+ 未被远程控制启动的会话继承 +

+ +您使用全局 `claude` 标志在 `remote-control` 动词之前启动了[远程控制](/docs/zh-CN/remote-control),该标志会限制或配置远程控制启动的会话,例如 `--settings`、`--setting-sources`、`--permission-mode`、`--disallowed-tools` 或 `--mcp-config`。放在动词之前的标志永远不会到达这些会话。Claude Code 拒绝启动,而是命名标志: + +```text theme={null} +Error: `--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`). +``` + +Claude Code 不拒绝无害的全局标志,例如 `--verbose`、`--model` 或包装器注入的 `--session-id` 或 `--plugin-dir`:它忽略它们,远程控制启动。 + +Claude Code 也拒绝启动一个它尚未识别为无害的全局标志,因此在较新版本中添加的标志可能会出现在此消息中,直到稍后的版本将其标记为无害。 + +**要做什么:** + +* 从动词之前删除标志,并在其后传递[远程控制自己的选项](/docs/zh-CN/remote-control#start-a-remote-control-session);`claude remote-control --help` 列出它们 +* 当拒绝的标志是 `--permission-mode` 时,运行 `claude remote-control --permission-mode ` 为远程控制启动的会话设置权限模式 + +在 v2.1.248 之前,当全局标志首先出现时,`claude remote-control` 不接受自己的标志,命令失败并出现 `unknown option` 错误。 + +

+ claude import 在此构建中尚不可用 +

+ +您运行了 [`claude import`](/docs/zh-CN/cli-reference#cli-commands),Claude Code 发现导入流已关闭,因此命令以代码 1 退出,而不是启动导入。在 v2.1.222 之前,导入流关闭的构建将 `import` 视为提示并启动交互会话,而不是打印此消息。 + +```text theme={null} +`claude import` is not yet available in this build. Run `claude` and use /mcp or edit ~/.claude/settings.json directly. +``` + +Claude Code 通过从 Anthropic 获取的功能标志打开 `claude import`,并在磁盘上缓存。此消息意味着缓存的值已关闭。原因通常是以下之一: + +* 您自安装以来尚未启动会话,因此 Claude Code 尚未获取标志。第一个 `claude import` 即使在功能对您可用时也可能打印此消息。 +* 您通过 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` 保持不可用。 +* 您设置了 `DISABLE_TELEMETRY`、`DO_NOT_TRACK`、`DISABLE_GROWTHBOOK` 或 [`CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`](/docs/zh-CN/env-vars),这会关闭功能标志获取,因此 `claude import` 保持不可用。 + +**要做什么:** + +* 在全新安装上,启动 `claude`,等待会话加载,退出,然后再次运行 `claude import` +* 在功能标志获取保持关闭的地方,自己设置配置:使用 [`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 服务器。 + +

+ 无法读取 Claude Code 配置 +

+ +您运行了 [`claude import`](/docs/zh-CN/cli-reference#cli-commands),而 Claude Code 无法解析 `~/.claude.json`,这是它存储您的登录和每个项目状态的文件。子命令读取该文件以检查可用性,但不显示交互会话显示的恢复对话框,因此它以代码 1 退出。在 v2.1.222 之前,带有不可读配置文件的 `claude import` 启动了交互会话,其恢复对话框处理了该文件。 + +```text theme={null} +Could not read Claude Code config — run `claude` with no arguments to recover it. +``` + +**要做什么:** + +* 运行 `claude` 不带参数。Claude Code 检测无效文件并提供重置它。然后再次运行 `claude import`。 +* 要保留您所做的手动编辑,请在编辑器中修复 `~/.claude.json` 中的 JSON 语法,然后重新运行 `claude import` + +

+ 无法从 Claude Desktop 导入服务器 +

+ +Claude Code 无法添加您在 `claude mcp add-from-claude-desktop` 中选择的其中一个服务器。该命令仍然导入其他选定的服务器,并为每个无法添加的服务器打印一行。在 v2.1.205 之前,第一个失败的服务器会停止导入,所有选定的服务器都不会被添加。 + +```text theme={null} +Could not import my server: Invalid name my server. Names can only contain letters, numbers, hyphens, and underscores. +``` + +服务器名称后的文本是原因。最常见的是名称检查:Claude Desktop 允许服务器名称中的字符,例如空格和句号,而 `claude mcp` 限制为字母、数字、连字符和下划线。其他原因包括未通过验证的服务器配置和被您的组织的 [MCP 策略](/docs/zh-CN/managed-mcp)阻止的服务器。 + +**要做什么:** + +* 在 `claude_desktop_config.json` 中重命名服务器以仅使用字母、数字、连字符和下划线,然后再次运行 `claude mcp add-from-claude-desktop` +* 使用有效名称直接使用 `claude mcp add` 或 `claude mcp add-json` 添加该服务器。请参阅[从 Claude Desktop 导入 MCP 服务器](/docs/zh-CN/mcp#import-mcp-servers-from-claude-desktop)。 + +

+ 无法将 MCP 服务器添加到托管范围 +

+ +您使用 `--scope managed` 运行了 `claude mcp add` 或 `claude mcp add-json`。该范围保存您的组织通过 [`managedMcpServers`](/docs/zh-CN/settings-reference#managedmcpservers) 托管设置提供的服务器。Claude Code 仅从托管设置读取它们,因此命令无法向该范围写入服务器。 + +```text theme={null} +Cannot add MCP server to scope: managed +``` + +**要做什么:** + +* 将服务器添加到您可以写入的范围:`local`、`user` 或 `project`。不带 `--scope`,命令使用 `local`。请参阅 [MCP 安装范围](/docs/zh-CN/mcp#mcp-installation-scopes) +* 要为您的组织中的每个用户提供服务器,请将其添加到您部署的托管设置中的 [`managedMcpServers`](/docs/zh-CN/settings-reference#managedmcpservers) + +

+ 无法读取 .mcp.json +

+ +读取项目的 [`.mcp.json`](/docs/zh-CN/mcp#project-scope) 的命令,例如 `claude mcp add` 或 `claude mcp add-json` 带 `--scope project`,或 `claude mcp remove`,发现您当前目录中的文件不是常规文件或大于 2 MiB,因此它以此错误退出,而不是读取文件。 + +```text theme={null} +Can'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. +``` + +在 v2.1.257 之前,`.mcp.json` 处的 FIFO 会使命令无限期等待,没有输出,到设备文件(如 `/dev/zero`)的符号链接会增长内存,直到进程被杀死。 + +**要做什么:** + +* 检查您当前目录中 `.mcp.json` 处的内容。将其替换为[项目范围格式](/docs/zh-CN/mcp#project-scope)中的普通 JSON 文件,或删除它,然后再次运行命令。 + +

+ 服务器是 Anthropic 托管的,不支持本地 OAuth +

+ +您为 URL 指向通过第三方身份提供商进行身份验证的 Anthropic 托管连接器主机的 MCP 服务器启动了登录。这些主机包括 `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)。 + +```text theme={null} +"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. +``` + +Claude Code 按 URL 匹配这些主机,因此当您使用 `claude mcp add` 或在 `.mcp.json` 中添加的服务器指向其中之一时,消息会出现。 + +**要做什么:** + +* 使用 `claude mcp remove ` 删除您的条目,以便它无法隐藏同一 URL 处的 claude.ai 连接器 +* 删除后,在 [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) + +

+ 服务器拒绝了由配置的 headersHelper 生成的 Authorization 标头 +

+ +其 [`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) 对于服务器: + +```text theme={null} +Server 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. +``` + +Claude Code 在每次连接尝试时重新运行助手,因此在暂时拒绝后重试(例如令牌轮换竞争)可以使用新凭证成功。 + +**要做什么:** + +* 按照 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` 值是否被服务器的端点接受 +* 修复助手或其凭证源后,在 `/mcp` 中选择服务器并选择**重新连接** + +在 v2.1.248 之前,Claude Code 为其助手提供 `Authorization` 标头的服务器运行 OAuth 发现。该发现可能失败,错误为 `Incompatible auth server: does not support dynamic client registration`,而不是报告被拒绝的凭证。 + +

+ 找不到 MCP 权限提示工具 +

+ +您传递给 [`--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 之前,启动不等待服务器完成连接,因此启动缓慢但健康的服务器也会产生此错误。 + +```text theme={null} +Error: MCP tool mcp__permissions__approve (passed via --permission-prompt-tool) not found. Available MCP tools: none +``` + +等待结束时连接的 MCP 工具之后的列表命名了 MCP 工具。 + +**要做什么:** + +* 检查服务器启动并保持连接:在同一目录中运行 `claude mcp list` 并确认服务器列为已连接 +* 确认工具名称与服务器公开的 `mcp____` 名称匹配 +* 如果服务器需要超过 30 秒才能启动,请提高 [`MCP_TIMEOUT`](/docs/zh-CN/env-vars) + +

+ OAuth 回调端口已在使用中 +

+ +当您使用 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 会选择可用端口。 + +```text theme={null} +OAuth callback port is already in use — another process may be holding it. Run `lsof -ti: -sTCP:LISTEN` to find it. +``` + +在 Windows 上,建议的命令是 `netstat -ano | findstr :`。 + +**要做什么:** + +* 运行消息中的命令以找到持有端口的进程,并停止它或等待它完成 +* 如果另一个程序永久需要该端口,请向服务器注册不同的重定向 URI,并使用 `MCP_OAUTH_CALLBACK_PORT` 或 `--callback-port` 设置其端口,以及您使用的任何一个 +* 然后再次启动登录,例如通过在 `/mcp` 中选择服务器 + +

+ 没有可用的 OAuth 重定向端口 +

+ +当您使用[OAuth](/docs/zh-CN/mcp#authenticate-with-remote-mcp-servers) 登录远程 MCP 服务器时,Claude Code 启动本地侦听器以接收登录回调。当 Claude Code 无法为其绑定本地端口时,登录会失败并显示此消息。机器上的某些内容阻止它在 `127.0.0.1` 上侦听,例如安全软件或拒绝本地侦听器的沙箱策略。 + +```text theme={null} +No available ports for OAuth redirect +``` + +在 v2.1.268 之前,Claude Code 没有回退到操作系统分配的端口,因此消息也出现在只有其自选端口无法绑定时。这可能发生在 Hyper-V 保留覆盖 Claude Code 选择的端口的端口范围的 Windows 主机上。 + +**要做什么:** + +* 检查安全软件或沙箱策略是否阻止进程在 `127.0.0.1` 上侦听,并允许 Claude Code 绑定本地端口 +* 然后再次启动登录,例如通过在 `/mcp` 中选择服务器 + +

+ /security-review 在没有 origin/HEAD 的情况下失败 +

+ +[`/security-review`](/docs/zh-CN/commands#all-commands) 通过将您的分支与 `origin/HEAD` 进行比较来构建其审查上下文,这是记录您的 `origin` 远程上哪个分支是默认分支的本地 ref。当该 ref 不存在时,收集差异的 git 命令会失败,审查在启动前停止。 + +```text theme={null} +Error: Shell command failed for pattern "!`git diff --name-only origin/HEAD...`": [stderr] +fatal: ambiguous argument 'origin/HEAD...': unknown revision or path not in the working tree. +Use '--' to separate paths from revisions, like this: +'git [...] -- [...]' +``` + +消息可能引用 `git log` 或不同的 `git diff`。Git 仅在远程通告默认分支且您的获取 refspec 覆盖它时创建 `origin/HEAD`,这是完整 `git clone` 的远程提交所做的。该 ref 在这些设置中缺失: + +* 单分支或 CI 检出,它获取太窄的 refspec +* 远程的服务器端 HEAD 指向没有人推送的分支 +* 没有 `origin` 远程的存储库,或您从未获取的存储库 + +Claude Code 为任何[注入动态上下文](/docs/zh-CN/skills#when-an-injected-command-fails)的 skill 显示相同的错误,失败的注入命令会中止该 skill 的调用。两个同级字符串在命令运行之前就会触发: + +* `Shell command permission check failed for pattern "..."`:命令的权限检查不允许它。[注入命令的权限检查](/docs/zh-CN/skills#permission-checks-on-injected-commands)涵盖在每个权限模式中哪些结果中止以及如何使用 `allowed-tools` 预批准命令 +* ``Skill 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) + +**要做什么:** + +* 通过命名您的远程的默认分支创建 ref:`git remote set-head origin `。只要本地跟踪 ref `origin/` 存在,这就有效。如果不存在,如在单分支克隆中,首先获取分支:运行 `git remote set-branches --add origin `,然后 `git fetch origin`,然后重新运行 set-head 命令。重新运行 `/security-review`。 +* 如果您不想命名分支,运行 `git fetch origin` 然后 `git remote set-head origin --auto`,它询问远程哪个分支是其默认分支。当远程不通告默认分支时它失败,错误为 `error: Cannot determine remote HEAD`,因为它是空的或其 HEAD 指向没有人推送的分支;改为显式命名分支。当您的克隆不获取该分支时它失败,错误为 `error: Not a valid ref`;首先按上述方式扩大 refspec。 +* 如果存储库没有远程,使用 `git remote add origin ` 添加一个并在创建 ref 之前获取。如果远程是空的,首先使用 `git push -u origin HEAD` 推送您的分支,并在 set-head 命令中命名该分支;`origin/HEAD` 然后指向您刚推送的分支,因此 `/security-review` 看到空差异,直到分支与它分歧。 + +

+ 使用 --print 时必须提供输入 +

+ +裸 `claude` 需要 stdout 是终端才能启动交互 UI。当 stdout 被重定向或控制台不是真实终端时,例如 PowerShell ISE 和某些 IDE 输出窗格,`claude` 改为以[非交互](/docs/zh-CN/headless)方式运行。这与 `claude -p` 相同,它需要提示,因此消息命名 `--print`,即使您没有传递标志。在任何地方传递 `-p`/`--print` 不带提示且 stdin 上没有任何内容会产生相同的错误。 + +```text theme={null} +Error: Input must be provided either through stdin or as a prompt argument when using --print +``` + +**要做什么:** + +* 对于交互使用,在真实终端中运行 `claude`:Windows Terminal 或 PowerShell 控制台而不是 ISE,以及您的 IDE 的集成终端而不是输出窗格 +* 对于一次性使用,传递提示:`claude -p "your question"`,或使用 `echo "your question" | claude -p` 管道它 + +

+ 输入仅包含空格 +

+ +在[非交互模式](/docs/zh-CN/headless)中,Claude Code 拒绝完全由空格、制表符或换行符组成的提示,而不是发送它,因为 API 拒绝没有可见文本的消息。您看到的消息取决于空白提示来自何处: + +* **`claude -p` 的提示参数或管道 stdin**:`claude` 以 `Error: Input contained only whitespace. Provide a prompt with text through stdin or as a prompt argument when using --print` 退出 +* **提交给运行的 `--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.` + +在 v2.1.229 之前,Claude Code 将仅空格的消息发送到 API,API 以 400 错误拒绝请求。 + +**要做什么:** + +* 在提示中包含可见文本。如果脚本从变量或文件构建提示,请在调用 Claude Code 之前检查源是否不为空。 + +

+ stream-json 输入在没有换行符的情况下超过 256M 个字符 +

+ +您的程序在 stdin 上发送了超过 268,435,456 个字符,没有换行符到 `claude -p --input-format stream-json` 运行,因此 Claude Code 将此错误打印到 stderr 并以代码 1 退出,而不是缓冲更多输入。消息将该预算表示为 `256M`。在 v2.1.257 之前,Claude Code 无限制地缓冲此类输入,增长内存直到进程崩溃或被杀死。 + +```text theme={null} +Error: 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. +``` + +这么长的输入没有换行符通常意味着生产者根本不是 stream-json 生产者,例如二进制文件或意外管道的纯日志输出。超过预算的单个消息会失败相同的检查。 + +**要做什么:** + +* 检查什么被管道到 stdin。使用 [`--input-format stream-json`](/docs/zh-CN/cli-reference#cli-flags),每条消息必须是一个换行符终止的 JSON 行 +* 要改为发送纯文本,请删除 `--input-format stream-json`;`claude -p` 默认从 stdin 读取纯文本提示 + +

+ 未知命令 +

+ +在交互式终端会话中,您提交了一个 `/` 名称,它与此会话中的任何命令都不匹配,因此 Claude Code 报告该名称而不是运行任何内容: + +```text theme={null} +Unknown command: /hepl. Did you mean /help? +``` + +Claude Code 建议此会话中菜单列出的最接近的命令名称或别名。当没有接近的时候,消息在名称后结束。原因通常是以下之一: + +* 打字错误,例如 `/hepl` 代替 `/help`。[命令菜单如何匹配您键入的内容](/docs/zh-CN/commands#how-the-command-menu-matches-what-you-type)涵盖在提交前选择接近匹配 +* 存在但在此会话中不可用的命令,因为不满足要求,例如您的平台、计划或身份验证方法。[`/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) +* 来自此会话中未安装或未连接的[插件](/docs/zh-CN/plugins/overview)或 [MCP 服务器](/docs/zh-CN/mcp#use-mcp-prompts-as-commands)的命令 + +Claude Code 仅在交互式终端会话中以这种方式回答不匹配的 `/` 名称。在所有其他会话中,它将提示作为普通消息发送给 Claude,并注意命令未运行以及 Claude 可以在会话中运行的命令列表。这些会话包括: + +* `-p` 运行 +* [Agent SDK](/docs/zh-CN/agent-sdk/overview) 应用程序 +* [Desktop 应用](/docs/zh-CN/desktop)的代码选项卡 +* [VS Code 扩展](/docs/zh-CN/vs-code)的聊天面板 +* [云会话](/docs/zh-CN/claude-code-on-the-web)和[例程](/docs/zh-CN/routines) + +对于无法在这些会话之一中运行的内置命令,Claude Code 仍然回答该命令不可用,而不是将其发送给 Claude。在 v2.1.274 之前,只有云会话和例程将不匹配的名称发送给 Claude。在 v2.1.273 之前,他们也回答 `Unknown command`。 + +Claude Code 不将每个以 `/` 开头的提示视为命令。当 `/` 后的第一个单词以标点符号开头时,它将提示作为普通消息发送给 Claude,例如打开 Lean 文档注释的 `/--`,或是路径,例如 `/var/log/syslog`。 + +在 v2.1.236 之前,如果您在命令菜单列出您键入的名称的接近匹配时按 `Enter`,Claude Code 会运行该匹配,因此 `/hepl` 之类的打字错误会运行 `/help` 而不是产生此消息。 + +**要做什么:** + +* 运行建议的名称,或键入 `/` 后跟名称的一部分以查看此会话中可用的内容 +* 如果 Claude Code 将记录的命令报告为未知,请检查[命令参考](/docs/zh-CN/commands)中其行以了解它命名的要求 + +

+ Diff 对于 ultrareview 来说太大 +

+ +您的分支与基础分支之间的差异,包括未提交和暂存的更改,超过了 [ultrareview](/docs/zh-CN/ultrareview) 的大小限制,因此 `/code-review ultra` 和 `claude ultrareview` 子命令在云会话启动前拒绝审查。被拒绝的审查不使用免费运行,也不计费使用信用。消息命名生效的限制、您的差异大小以及贡献最多更改行的文件。在 v2.1.216 之前,消息仅显示原始差异统计。 + +```text theme={null} +Diff 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 `) to narrow the scope, or split the change. +``` + +审查拉取请求应用相同的限制;该形式的消息以 `PR # is too large for ultrareview` 开头,并命名 PR 的文件和行数。 + +**要做什么:** + +* 传递更接近您的工作的基础分支,例如 `/code-review ultra develop`,以便审查仅涵盖与该分支的差异 +* 将更改分成较小的分支并审查每一个。消息命名的文件贡献最多更改行,因此首先将这些移到它们自己的分支。 + +

+ 无法找到与基础分支的合并基础 +

+ +`/code-review ultra` 和 `claude ultrareview` 子命令审查您的分支与基础分支之间的差异,这需要两者共享的提交。当 `git merge-base` 找不到时,Claude Code 在云会话启动前拒绝审查。在 Claude Code 可以验证完整的克隆上,至少有一个分支,它改为回退到[审查每个跟踪文件](/docs/zh-CN/ultrareview#diff-limits-and-fallbacks)而不是拒绝。您在基础分支根本找不到、Claude Code 无法验证您的克隆完整或在罕见的存储库中看到此拒绝,其中整个树差异不可能,例如 SHA-256 对象格式。 + +```text theme={null} +Could 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. +``` + +第一句后的提示取决于 Claude Code 观察到的内容: + +* **您没有传递基础分支**:Claude Code 与存储库的默认分支进行了比较,并建议显式传递您的基础,如上例所示 +* **您传递了已在克隆中的基础分支**:提示读取 ``Make sure exists locally or on origin (try `git fetch origin `)`` +* **您传递了不在克隆中的基础分支**:Claude Code 在比较前从 origin 获取了它。提示读取 `` was fetched from origin but shares no history with HEAD. If another branch is your real base, pass it explicitly (`/code-review ultra `)``;当 Claude Code 无法判断您的克隆是否浅时,它改为建议 `git fetch --unshallow origin`。在 v2.1.221 之前,提示为每个获取的基础分支建议 `git fetch --unshallow origin`,在完整克隆上该命令失败,错误为 `fatal: --unshallow on a complete repository does not make sense`。 + +**要做什么:** + +* 如果另一个分支是您的真实基础,显式传递它:`/code-review ultra ` +* 如果您的克隆可能没有完整历史,运行 `git fetch --unshallow origin` 并重新运行审查 + +

+ 您的检出没有分支 +

+ +检出可以有提交但没有分支:如果您运行 `git init` 后跟 `git fetch ` 和 `git checkout FETCH_HEAD`,您会得到一个分离的 HEAD,没有 refs。Claude Code 将您的存储库打包为 git 包以上传以进行 [ultrareview](/docs/zh-CN/ultrareview),它无法打包没有分支或其他 refs 的存储库,因此 `/code-review ultra` 和 `claude ultrareview` 子命令在云会话启动前拒绝审查。 + +```text theme={null} +Your checkout has no branches (detached HEAD only), which cloud review can't bundle. Create one first — `git checkout -b ` — then rerun /code-review ultra. +``` + +在 v2.1.221 之前,Claude Code 尝试审查此检出中的每个跟踪文件,上传失败。 + +**要做什么:** + +* 使用 `git checkout -b ` 在您当前的提交处创建分支,然后重新运行审查 + +

+ 没有 GitHub 帐户连接到您的 Claude 帐户 +

+ +您运行了 `/code-review ultra ` 或 `claude ultrareview `,在创建云会话之前,Claude Code 询问服务器[连接到您的 Claude 帐户的 GitHub 帐户](/docs/zh-CN/ultrareview#review-a-pull-request)是否可以到达 PR 的存储库。没有帐户连接,或连接已过期,因此云克隆会失败,Claude Code 拒绝启动。Claude Code 不为被拒绝的启动花费免费运行或计费使用信用。 + +```text theme={null} +Ultrareview clones / 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). +``` + +当 [`/web-setup`](/docs/zh-CN/web-quickstart#connect-from-your-terminal) 在您的会话中不可用时,消息仅命名 claude.ai 链接。 + +**要做什么:** + +* 运行 `/web-setup` 将您的 GitHub CLI 登录连接到您的 Claude 帐户,或在 [claude.ai/connect-github](https://claude.ai/connect-github) 连接帐户 +* 连接后一分钟重新运行审查 + +在 v2.1.248 之前,Claude Code 在启动前不检查这个。 + +

+ 您连接的 GitHub 帐户看不到存储库 +

+ +您运行了 `/code-review ultra ` 或 `claude ultrareview `,[连接到您的 Claude 帐户的 GitHub 帐户](/docs/zh-CN/ultrareview#review-a-pull-request)无法读取 PR 的存储库,因此云克隆会失败,Claude Code 拒绝启动。Claude Code 不为被拒绝的启动花费免费运行或计费使用信用。 + +```text theme={null} +Your connected GitHub account can't see / — usually the Claude GitHub app isn't installed on 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. +``` + +当 [`/web-setup`](/docs/zh-CN/web-quickstart#connect-from-your-terminal) 在您的会话中不可用时,消息仅命名应用安装。 + +**要做什么:** + +* 如果您的本地 `gh` CLI 可以读取存储库,运行 `/web-setup` 将该登录连接到您的 Claude 帐户 +* 更改后重新运行审查 + +在 v2.1.248 之前,Claude Code 在启动前不检查这个。 + +

+ GitHub 应用预检失败暂时 +

+ +您从本地存储库启动了[云会话](/docs/zh-CN/claude-code-on-the-web),两个步骤一起失败。Claude Code 无法构建或上传您的存储库包。在上传之前,它检查了云服务是否可以从 GitHub 克隆存储库,而不是明确的答案,该检查以重试可能清除的错误结束,例如网络错误、超时或临时服务器错误。完整消息以停止包的内容开头,例如 `Could not upload repo bundle ()`,并以预检句子结尾: + +```text theme={null} +Could not upload repo bundle (). The GitHub App preflight failed transiently (network or service hiccup) — retry in a moment to start from GitHub instead +``` + +**要做什么:** + +* 片刻后重新运行命令。当 GitHub 检查通过时,Claude Code 可以从 GitHub 克隆启动会话,因此失败的上传不再阻止启动 +* 如果重试继续失败,消息的开头命名了停止上传的内容。当该原因是您可以修复的内容时,修复它以便会话可以从您的本地存储库启动。 + +在 v2.1.251 之前,Claude Code 以 `Please set up GitHub on https://claude.ai/code` 结束消息,即使 GitHub 检查仅暂时失败,设置建议也无法清除暂时失败。 + +

+ GitHub 未连接到您的 Claude 帐户 +

+ +您从本地存储库启动了[云会话](/docs/zh-CN/claude-code-on-the-web),例如使用 `/autofix-pr`。没有 GitHub 帐户连接到您的 Claude 帐户,或连接已过期,因此 Claude Code 拒绝启动: + +```text theme={null} +GitHub 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 +``` + +当您使用 [`/schedule`](/docs/zh-CN/routines) 创建例程时,相同的消息作为命名存储库的设置注释出现;注释不会阻止创建例程。 + +**要做什么:** + +* 运行 `/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)以了解两者的区别。 +* 连接后一分钟重新运行命令 + +在 v2.1.268 之前,Claude Code 将此报告为 Claude GitHub 应用检查的临时失败,并建议重试或安装应用;两者都不连接 GitHub 帐户。 + +

+ 需要单点登录授权 +

+ +您运行了 [`/install-github-app`](/docs/zh-CN/github-actions#quick-setup) 并选择了其组织强制执行 SAML 单点登录的存储库。在设置之前,Claude Code 使用 GitHub CLI 检查您对存储库的访问权限,GitHub 拒绝了该检查,因为您的 `gh` 令牌尚未为组织授权。向导显示警告和授权步骤: + +```text theme={null} +Single sign-on authorization needed +/ belongs to an organization that enforces SAML single sign-on, and your GitHub CLI token isn't authorized for it yet. +``` + +**要做什么:** + +* 通过运行 `gh auth refresh -h github.com -s repo,workflow` 使用 `repo` 和 `workflow` 范围重新授权您的 GitHub CLI 登录,并在 GitHub 提示单点登录时授权组织 +* 如果您在 `GH_TOKEN` 中使用个人访问令牌进行身份验证,请打开 [github.com/settings/tokens](https://github.com/settings/tokens),在令牌上选择**配置 SSO**,并授权组织 +* 再次运行 `/install-github-app` + +在 v2.1.273 之前,Claude Code 为此条件显示 `Admin permissions required` 警告。 + +

+ 无法恢复对话 +

+ +Claude Code 无法读取或处理您从 [`claude --resume` 选择器](/docs/zh-CN/sessions#use-the-session-picker)选择的会话的保存成绩单,因此它结束进程而不是在部分加载状态下继续。消息包括重试的命令: + +```text theme={null} +Failed to resume the conversation. +Run claude --resume to retry, or claude to start a new session. +``` + +Claude Code 在显示消息后以代码 1 退出。运行会话内的 `/resume` 选择器报告对话中的 `Failed to resume conversation`,您当前的会话保持运行。在 v2.1.216 之前,来自 `claude --resume` 选择器的失败恢复在 `Resuming conversation…` 微调器上无限期停留,而不是显示此消息。 + +**要做什么:** + +* 运行 `claude --resume `,其中 session-id 来自消息以重试 +* 如果每次重试都以相同的方式失败,运行 `claude update` 并再次恢复。v2.1.275 之前的版本在保存的成绩单包含它们无法读取的条目时恢复失败。 +* 如果重试再次失败,运行 `claude` 启动新会话 + +

+ 找不到具有会话 ID 的对话 +

+ +您将会话 ID 传递给 `claude --resume `,没有保存的成绩单与之匹配: + +```text theme={null} +No conversation found with session ID: +``` + +Claude Code 在显示消息后以代码 1 退出。Claude Code [首先搜索当前项目,然后搜索此机器上的所有其他项目](/docs/zh-CN/sessions#resume-a-session)以查找 ID。在 v2.1.223 之前,查找在当前项目目录及其 git worktrees 处停止,因此从会话最后工作的目录恢复。 + +常见原因: + +* **打字错误的 ID**:对于非交互式运行,ID 是 [`--output-format json` 输出](/docs/zh-CN/headless#get-structured-output)的 `session_id` 字段 +* **删除的成绩单**:Claude Code 在[保留期](/docs/zh-CN/sessions#where-transcripts-are-stored)后删除成绩单,默认 30 天,遵循[保留扫描规则](/docs/zh-CN/claude-directory#cleaned-up-automatically) +* **不同的机器**:Claude Code 在本地存储成绩单,因此在运行会话的机器上恢复会话 +* **重复副本**:如果您在 `~/.claude/projects` 下复制了项目目录,以便两个成绩单携带相同的 ID,Claude Code 报告此消息而不是任意恢复一个副本 + +**要做什么:** + +* 对于交互式会话,使用 `claude --resume` 打开[会话选择器](/docs/zh-CN/sessions#use-the-session-picker),按 `Ctrl+A` 将其扩展到此机器上的每个项目,然后选择会话 +* 使用 `claude -p` 或 [Agent SDK](/docs/zh-CN/agent-sdk/overview) 创建的会话不会出现在选择器中,因此重新检查 ID 与您的原始运行打印的 `session_id` + +

+ 无法在此会话中切换渲染器 +

+ +当您切换渲染器时,Claude Code 重新启动其进程。您在 Claude Code 拒绝重新启动的会话中运行了 [`/tui`](/docs/zh-CN/fullscreen#enable-fullscreen-rendering),因此它不切换并保存任何内容。您看到的消息告诉您原因: + +* `Cannot switch renderers while work is running in the background`:您有在后台运行的工作,重新启动会放弃,例如后台 shell 或子代理。等待工作完成或使用 [`/tasks`](/docs/zh-CN/commands) 停止它,然后再次运行 `/tui fullscreen` 或 `/tui default` +* `Cannot switch renderers in this session`:会话有 Claude Code 无法传递给重新启动的进程的限制。在 v2.1.234 之前,Claude Code 无论如何都会重新启动,重新启动的会话运行时没有它们 + +在限制消息中,括号中的部分命名 Claude Code 找到的限制: + +```text theme={null} +Cannot 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. +``` + +消息可以在括号中显示的每个原因: + +* `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) +* `permission rules set for this session only`:来自钩子或 SDK 调用者的[权限更新](/docs/zh-CN/hooks#permission-update-entries)添加了带有 `session` 目标的拒绝或询问规则。会话范围的允许规则不会触发拒绝。重新启动会删除它们,Claude Code 改为再次提示 +* `ask-before-running rules with no command-line form`:来自钩子或 SDK 调用者的权限更新添加了询问规则以及 Claude Code 作为 `--allowed-tools` 和 `--disallowed-tools` 传递回的规则。不存在询问规则的标志 +* `permission rules a command line cannot carry intact` 和 `added directories a command line cannot carry intact`:权限更新在会话中期添加了规则或目录路径。重新启动的进程的命令行无法将其文本作为相同值继承 + +**要做什么:** + +* 在没有这些限制的会话中,运行 `/tui fullscreen` 或 `/tui default` 切换回。Claude Code 在那里保存 [`tui` 设置](/docs/zh-CN/settings-reference#tui) + +

+ 无法打开 Claude Desktop +

+ +您运行了 [`/desktop`](/docs/zh-CN/desktop#coming-from-the-cli) 或其别名 `/app`,Claude Code 用来打开 Claude Desktop 的系统命令失败。会话保持在终端中。 + +```text theme={null} +Error: Couldn't open Claude Desktop (`open` exited 1: LSOpenURLsWithRole() failed for the URL claude://resume?session= with error -10814). Open Claude Desktop and run /desktop again. +``` + +**要做什么:** + +* 自己打开 Claude Desktop,然后再次运行 `/desktop` +* 要读取该命令的完整错误输出,使用 `/debug` 打开调试日志,再次运行 `/desktop`,并检查调试日志 + +在 v2.1.275 之前,消息是 `Failed to open Claude Desktop. Please try opening it manually.`,没有说什么失败。 + +

+ /terminal-setup 保持您的 Zed 快捷键不变 +

+ +您在 Zed 中运行了 [`/terminal-setup`](/docs/zh-CN/terminal-config#enter-multiline-prompts),Claude Code 无法完成对您的 Zed `keymap.json` 的更新,因此它保持文件不变。 + +每条消息命名您的快捷键的路径,并以您自己添加的快捷键块结尾: + +```text theme={null} +Couldn't update your Zed keymap, so it was left unchanged. +To add the binding yourself, add this block to the keymap array in : +{ "context": "Terminal", "bindings": { "shift-enter": ["terminal::SendText", "\u001b\r"] } } +``` + +消息的第一行命名原因: + +* `Couldn't read your Zed keymap, so it was left unchanged.`:Claude Code 无法读取文件,例如由于文件权限 +* `Your Zed keymap isn't a readable list of keybindings, so it was left unchanged.`:文件读取良好,但不解析为快捷键块数组,即使允许 `//` 注释和尾随逗号 +* `Couldn't back up your Zed keymap; not modifying it.`:Claude Code 无法将文件复制到其旁边的 `.bak` 备份,因此它没有更改任何内容 +* `Couldn't update your Zed keymap, so it was left unchanged.`:合并的结果未验证为有效的快捷键,携带绑定,因此 Claude Code 丢弃它而不是写入。具有重复键的快捷键块可能导致这种情况 + +**要做什么:** + +* 将消息中的块复制到您的 `keymap.json` 中消息命名的路径处的顶级数组中 +* 对于 `isn't a readable list of keybindings`,修复语法错误,或使文件的顶级值成为数组,然后再次运行 `/terminal-setup` + +在 v2.1.247 之前,`/terminal-setup` 无法解析使用 `//` 注释或尾随逗号的 Zed 快捷键,它用仅自己的绑定替换整个文件,同时报告绑定已安装。要恢复较早版本替换的快捷键,请使用[输入多行提示](/docs/zh-CN/terminal-config#enter-multiline-prompts)下描述的 `.bak` 备份文件。 + +

+ 此连接上不提供 Skill 使用报告 +

+ +您在[远程控制](/docs/zh-CN/remote-control)上运行了 [`/skill-doctor`](/docs/zh-CN/skills#find-unused-skills),从您的手机或浏览器。Claude Code 不通过远程控制发送 skill 使用报告,而是用此消息回复: + +```text theme={null} +Skill usage reports are not available on this connection. +``` + +**要做什么:** + +* 在会话运行的机器上的终端中运行 `/skill-doctor`,或在那里运行 `claude -p "/skill-doctor"` + +

+ 无法通过远程控制选择自定义输出样式 +

+ +您从移动应用或网络通过[远程控制](/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)名称获得与不存在的名称相同的回复: + +```text theme={null} +Custom 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. +``` + +**要做什么:** + +* 选择内置样式,例如 `/output-style concise` +* 要使用自定义样式,在项目的 `.claude/settings.local.json` 中设置 [`outputStyle`](/docs/zh-CN/settings-reference#outputstyle),或在会话自己的终端中运行 `/output-style