The /doctor command
Run /doctor inside a Claude Code session to automatically diagnose your environment. The command checks your installation, authentication status, network connectivity, MCP server connections, and configuration files, then reports any problems it finds with suggested fixes.
Common issues
Authentication failures
Authentication failures
Symptoms: Claude Code prompts you to log in repeatedly, or API calls fail with
authentication_failed.Fixes:-
Re-run the login flow:
-
Check that your API key or OAuth token is set correctly. If you use an API key, verify the environment variable:
-
If you are behind a corporate proxy or VPN, ensure that
api.anthropic.comis reachable: -
On macOS, if the keychain lookup is failing, try logging out and back in:
-
For third-party providers (Bedrock, Vertex, Foundry), check that the respective credentials are configured in your environment — Claude Code uses AWS credentials,
gcloudADC, or Foundry tokens depending on the provider.
Tool permission denied
Tool permission denied
Symptoms: Claude Code asks for permission repeatedly, or a tool call fails with a permission error.Fixes:
-
Check the current permission mode with
/config. Set it toacceptEditsto auto-approve file operations, orbypassPermissionsin a trusted sandbox. -
Review your
allowedToolsanddeniedToolssettings in~/.claude/settings.jsonor.claude/settings.json. -
If running in headless mode (
-p), use--allowedToolsto explicitly allow the tools Claude needs: -
Use
--permission-mode bypassPermissionsonly in sandboxed environments with no internet access:
Context window full
Context window full
Symptoms: Claude Code reports the context window is full, responses become truncated, or you see a “context limit” error.Fixes:
-
Run
/compactto compress the conversation context. Claude summarises the conversation so far and continues with the summary in the context window. -
Start a fresh session with
/clearif the current conversation is no longer needed. -
Use
/costto monitor your context window utilisation: -
For very large codebases, use
--allowedToolsin headless mode to restrict tools and reduce tool-call verbosity in the transcript. - Consider enabling fast mode from settings — it uses a smaller, faster model for sub-tasks, which consumes fewer tokens.
MCP server not connecting
MCP server not connecting
Symptoms: MCP tools are missing, or Claude Code reports an MCP server as
failed or pending.Fixes:-
Run
/doctor— it checks all configured MCP servers and reports connection errors. -
Run
/mcpto see the connection status of each server. -
Check your MCP configuration file for syntax errors:
-
Enable debug output to see MCP server stderr:
-
Test the MCP server command directly in your terminal to confirm it starts without errors:
-
If the server requires environment variables, add them to the
envfield in the server config: -
In headless mode, use
--mcp-configto load a config file explicitly, and--strict-mcp-configto ignore all other MCP configuration:
High token usage and cost
High token usage and cost
Symptoms: API costs are higher than expected, or rate limits are hit frequently.Fixes:
-
Use
/costto see a breakdown of token usage for the current session: - Enable fast mode in settings. Fast mode uses a smaller model for routine sub-tasks and significantly reduces cost per session.
-
Use
/compactregularly to compress the context window rather than letting it fill up. -
In headless mode, use
--max-budget-usdto cap spending per run: -
Use
--max-turnsto limit agentic turns in scripts: -
Restrict available tools with
--allowedTools— fewer tools means fewer tool-call round-trips:
CLI not found after install
CLI not found after install
Symptoms: Running
claude in the terminal gives command not found.Fixes:-
Check that npm’s global bin directory is in your
PATH: -
Reload your shell profile:
-
If you used
npxto install, try a global install instead: -
On macOS with Homebrew-managed Node, the global bin path may differ. Find it with:
-
Verify the binary exists after install:
Log locations
Claude Code writes logs to the following locations:| Log | Location |
|---|---|
| Session transcripts | ~/.claude/projects/<project-hash>/<session-id>.jsonl |
| Debug logs | Written to stderr when --debug is passed, or to a file with --debug-file <path> |
| MCP server output | Shown in stderr when --debug is passed |
Resetting configuration
If your Claude Code configuration becomes corrupted or you want a clean slate, you can reset it by clearing the~/.claude/ directory:
Checking token usage with /cost
The /cost command displays token usage and estimated cost for the current session:
- Input tokens used (including cache reads and cache creations)
- Output tokens generated
- Total estimated cost in USD
- Context window utilisation
Reporting issues
If you encounter a bug or unexpected behaviour, report it on GitHub: github.com/instructkr/claude-code When filing an issue, include:- The
claude --versionoutput - Your operating system and Node.js version
- The command you ran (redact any secrets)
- The full error output (use
--debug-fileto capture it) - Whether the issue is reproducible in a fresh directory