Skip to content

Troubleshooting Claude Code, Codex and Cursor starts with finding which layer failed before retrying: the installation, login and billing, usage limits, configuration (instructions, permissions, MCP servers), the conversation’s context, or the output itself. Each tool ships a health check for the first layers, and a fix counts only when the repository’s own checks pass again.

This page is for developers who use one or more of these agents every day, and for the tech lead who fields “it stopped working” messages from a team. The agent stopped halfway through a refactor with an error you have never seen. Or it keeps ignoring the rule that is plainly in AGENTS.md, or a teammate’s session bills an old API key instead of the team plan. Retrying the same prompt harder fixes none of these, and it burns your allowance.

Tool-specific depth lives elsewhere: troubleshooting a Claude Code session, Codex error recovery, Cursor error handling, and MCP connection issues. This page is the cross-tool triage that tells you which of them you need.

  • A six-layer triage table that names the failing layer in under two minutes
  • The health-check commands for each tool, checked against Claude Code 2.1.283 (the latest channel) and codex-cli 0.157.1 on 2026-09-26
  • Fixes for the failures that generate most support questions: command not found, the wrong credential, usage limits, ignored instructions, context drift, and lost work
  • Three copy-paste prompts: triage before retrying, a clean hand-off to a fresh session, and proof that the recovery is sound
  • A checklist for a bug report that maintainers can act on

Which layer broke? Triage before you retry

Section titled “Which layer broke? Triage before you retry”

Match the symptom to a layer, run the first check, and stop at the first check that fails. Most wasted hours come from fixing a prompt when the problem was a credential, or reinstalling when the problem was context.

LayerTypical symptomFirst check
Installationcommand not found, an old version, a feature from the changelog missingclaude --version / codex --version, then the health check below
Login and billingLogin loop, 401, usage billed to the wrong account/status or claude auth status; codex login status
Limits and capacity“usage limit reached”, 429, “overloaded”/usage in Claude Code or Codex
ConfigurationRules in CLAUDE.md or AGENTS.md ignored, a permission rule that “doesn’t work”, MCP tools missing/memory and /permissions (Claude Code); /debug-config (Codex); the Rules and MCP settings (Cursor)
ContextRepeats work, reopens decisions, forgets a constraint from an hour ago/context (Claude Code); /status (Codex)
OutputA diff that is too big, off-task, or breaks the buildgit diff --stat, then your test and type-check commands

Each CLI has a read-only health check. Run it before you edit a setting, and again after the fix.

Terminal window
# Terminal
claude --version # latest and stable channels differ by about a week
claude doctor # installation health and problems in the settings files
claude auth status # which account and method are active

Inside a session, /doctor runs a fuller checkup that can also fix what it finds, and /status shows version, model, account, API connectivity, and tool status. To test whether your own customizations cause the problem, start once with claude --safe-mode, which disables CLAUDE.md, skills, plugins, hooks and MCP servers for that session.

Fix “command not found” after installing

Section titled “Fix “command not found” after installing”

A new install that the shell cannot find is almost always a PATH problem or two competing binaries.

  1. Open a new terminal. The terminal you installed from still has the old PATH.
  2. Check for duplicates: which -a claude must print exactly one path. Two paths usually mean an old npm install alongside the native one.
  3. If ~/.local/bin/claude exists but is not found, add the directory to PATH in your shell profile:
    Terminal window
    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
  4. Reinstall with the native installer, curl -fsSL https://claude.ai/install.sh | bash, and confirm with claude doctor.

Never use sudo npm install -g. On native Windows, Claude Code uses Git Bash when Git for Windows is installed and the PowerShell tool otherwise, so a missing Git no longer blocks the install. The Claude Code installation guide covers every install method and release channel.

Fix login loops and usage billed to the wrong account

Section titled “Fix login loops and usage billed to the wrong account”

Most login problems are two credentials competing, not a broken login.

  • Claude Code bills an API key instead of your plan. An exported ANTHROPIC_API_KEY can win over the subscription login. Run /status or claude auth status --text to see the active method, remove the variable from your shell profile, and run claude auth login. The Claude Code authentication guide lists the full precedence order.
  • Codex uses a key you did not expect. codex login status reads the stored login in ~/.codex/auth.json; the auth row of codex doctor also names keys that come from the environment. Unset stale OPENAI_API_KEY or CODEX_API_KEY values before you sign in again.
  • No browser on the machine (SSH, a container). Use codex login --device-auth for Codex. For Claude Code, see the SSH and CI sections of its authentication guide.
  • A CI job fails at a login prompt. CI never uses a person’s session. Give the job an API key from the CI secret store, as the Codex authentication guide shows for codex exec.

Never paste a key into a command line or a prompt; read it from an environment variable or a secret manager.

Why did I hit a usage limit or an “overloaded” error?

Section titled “Why did I hit a usage limit or an “overloaded” error?”

Three different things produce “limit” messages, and each has a different fix.

MessageWhat it meansWhat to do
Plan usage limit reachedClaude Code and Codex subscriptions meter usage in rolling five-hour and weekly windowsRun /usage in either tool: Claude Code shows what is contributing to your limits, Codex shows account usage and any usage-limit reset you can apply
429 or rate limit on an API keyThe API account’s own rate limit, separate from subscription windowsSlow parallel jobs down, or raise the tier in the provider console
“Overloaded” or 529The provider is at capacity; nothing is wrong with your setupWait and retry once. In Claude Code, --fallback-model names a model to fall back to when the default is overloaded

The biggest self-inflicted drain is a retry loop: each retry re-sends the whole conversation. Before retrying a long session, run /compact or start fresh with the hand-off prompt below. Model choice and effort are covered on the models hub, and spending controls on Claude Code cost control and Codex cost management.

Why is the agent ignoring my instructions or permissions?

Section titled “Why is the agent ignoring my instructions or permissions?”

When the agent ignores a rule, first prove the rule loaded, then prove it applies to this action.

  • /memory lists the CLAUDE.md files in play. Claude Code reads AGENTS.md only when a project has no CLAUDE.md (v2.1.277 and later, both release channels on 2026-10-12).
  • /permissions shows each rule and the settings file it comes from. A deny rule in a file that is not loaded does nothing.
  • If claude --safe-mode makes the problem disappear, the cause is one of your customizations; bisect them. The Claude Code troubleshooting page walks through the permission-rule traps.

A rule that must never be broken belongs in a hook, a permission rule or a CI gate, not only in prose. Permissions and sandboxing shows how to move a rule from “please” to “cannot”.

Why does the agent forget earlier decisions?

Section titled “Why does the agent forget earlier decisions?”

Long sessions degrade quietly. When the context fills, the tool compacts older turns into a summary, and a decision made an hour ago can drop out of it. The symptoms are repeated work, reopened decisions and ignored constraints.

ToolSee the usageSummarizeStart clean
Claude Code/context/compact/clear
Codex/status/compact/new

In Cursor, start a new chat. In every tool, starting clean works better than compacting when the task changed, provided you carry the decisions across with the hand-off note below. Read context windows for how to keep sessions small from the start.

Start the new session with “Read HANDOFF.md and continue from the next step.”

The three checks below find most causes. Run them in order.

  1. Print the entry the client actually uses: claude mcp get <name>, codex mcp get <name> --json, or the block in .cursor/mcp.json.
  2. Run the entry’s command and args in a terminal. If it exits with an error, the client fails the same way.
  3. Check that every variable the server needs is set in the entry’s env, and that remote OAuth is complete (/mcp in Claude Code, codex mcp login <name> in Codex).

Timeouts, spawn ENOENT, 401s on remote servers, and the CLI flags that save a broken entry are covered in MCP connection issues.

Stop the agent first, so it does not keep “fixing” the damage. Then pick the smallest undo that covers it.

  1. Press Esc to stop the current turn, and run git status and git diff --stat to see what changed.
  2. Undo inside the tool when the damage is recent:
    • Claude Code: /rewind, or Esc twice, restores code, conversation or both to an earlier checkpoint.
    • Cursor: restore the checkpoint from before the response that broke things. Checkpoints cover one chat’s file edits (Cursor’s checkpoint page could not be re-checked on 2026-09-26).
    • Codex: 0.157.1 has no undo slash command, so git is the undo. /diff shows the working-tree changes, including untracked files.
  3. Undo with git when the tool cannot: git restore <path> for one file, git stash to park everything, or git reset --hard <commit> to return to a known commit.
  4. Recover a lost commit with git reflog. It records where HEAD pointed, so it rescues commits, not edits you never committed.
  5. Undo side effects by hand. No checkpoint covers what the agent did through the terminal: an applied migration, an installed package, a pushed branch.

Prevention costs one command. Commit before any large agent task, or run the agent in its own worktree (claude --worktree, codex --worktree), so the undo is always git reset to that commit. The per-tool recovery pages go further: Claude Code error recovery, Codex error recovery, and Cursor error handling.

A fix is done when the evidence says so, not when the agent says so. You should not need to read every changed line to know.

  1. Re-run the thing that failed. The same command, the same health check, the same MCP tool call. Green output replaces “it should work now”.
  2. Run the repository’s gates. Tests, type check and lint, the same ones CI runs. A recovery that skips them has only moved the failure.
  3. Check the scope. git diff --stat against the last good commit should show only the files the fix needed. Unexpected files are the next incident.
  4. Record it. A one-line note in the pull request or the team channel: symptom, layer, fix, evidence. The developer who ran the fix signs off; the tech lead owns any change to shared settings files.

When the same failure keeps recurring, it is a harness problem, not a bad day. The failure taxonomy shows how to classify it and pick the control that catches it earlier.

What goes wrong while troubleshooting agents?

Section titled “What goes wrong while troubleshooting agents?”

The fix can do more damage than the fault. These are the traps that show up most often.

TrapWhy it hurtsDo this instead
Retrying the same prompt in a loopEach retry re-sends the whole context and drains the usage windowTriage first; compact or hand off before retrying
Silencing permission prompts with --dangerously-skip-permissions or --dangerously-bypass-approvals-and-sandboxRemoves the only guard between the agent and your machineAdd a specific allow rule; use full bypass only in a disposable, network-restricted sandbox
Deleting ~/.claude, ~/.codex or .cursor/ to “reset”Loses settings, credentials, session history and MCP entries (for .cursor/: project rules and MCP config)Use claude --safe-mode or codex doctor to isolate the cause; back up before deleting anything
Reinstalling with a second methodLeaves two binaries on PATH; the old one keeps winningwhich -a, remove the extra one, keep one install method
Attaching raw debug logs to a public issueLogs can contain paths, prompts and tokensUse codex doctor --json (redacted) and read any log before you share it
Stale worktrees after a crashed parallel runBranches stay locked and disk fills upgit worktree list, then git worktree prune

How do I report a bug maintainers can act on?

Section titled “How do I report a bug maintainers can act on?”

When the health check is green, the config is minimal, and the failure still reproduces, report it.

  • Claude Code: /feedback or /bug sends a report from inside the session, or open an issue at anthropics/claude-code.
  • Codex: /feedback sends logs to the maintainers, or open an issue at openai/codex.
  • Cursor: report through the app or the Cursor forum.

Include the version, the operating system, the exact error text, the minimal steps to reproduce it (ideally with claude --safe-mode or a bare config.toml), and what you already ruled out with the triage table.

Did this guide help you?

One tap, no sign-in.

not at all a lot

Frequently asked questions

What should I do first when an AI coding agent misbehaves?

Stop retrying and find the failing layer: install, login and billing, limits and capacity, configuration (instructions, permissions, MCP), context, or the output itself. Run the tool's health check first: claude doctor or /doctor in Claude Code, codex doctor in Codex.

Why is Claude Code billing an API key instead of my subscription?

An ANTHROPIC_API_KEY exported in your shell can take precedence over the subscription login. Run /status in a session or claude auth status in a terminal to see the active method, then unset the variable and log in again.

How do I recover code an agent overwrote?

Stop the agent, run git status and git diff to see the damage, then restore: /rewind (Esc Esc) in Claude Code, Cursor's checkpoints inside one chat, or git for everything else. Codex 0.157.1 has no undo slash command, so git is its undo. git reflog recovers commits, not uncommitted edits.

Why did I hit a usage limit so quickly?

Claude Code and Codex subscriptions meter usage in rolling five-hour and weekly windows. Run /usage in either tool to see what is consuming the allowance, clear or compact long sessions, and stop retry loops that re-send the same large context.