[BUG] The `doctor` command suggested `sudo chown -R $USER:$(id -gn) $(npm -g config get prefix)`, but this doesn't resolve anything.
Status Fixed / completed
Maintainer reply ✓ Yes — ant-kurt
Workaround ✓ Mentioned in thread ↓
Activity 6 comments · opened Jul 19, 2025 · closed Sep 10, 2025
💡 Likely answer: A maintainer (ant-kurt, collaborator)
responded on this thread — see the highlighted reply below.
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 1.0.56 (Claude Code)
- Operating System: WSL2 Ubuntu 22.04 on Windows 11
- Terminal: Windows Terminal with WSL2
Bug Description
The doctor command in Claude Code suggests commands to resolve permission-related issues, but these commands don't actually fix the problem. Alternatively, this may not be a permission issue at all - the process for determining permissions might be malfunctioning.
Steps to Reproduce
- Install Claude Code in WSL2 environment (Ubuntu distribution):
npm install -g @anthropic-ai/claude-code@1.0.56 - Run
claude doctorcommand
Expected Behavior
claude doctorshould display diagnostic information about installation status, permissions, and configuration- The auto-update functionality should become available by executing the permission configuration commands provided by Claude Code
Actual Behavior
ubuntu@roku-pc:~$ npm install -g @anthropic-ai/claude-code@1.0.56
changed 3 packages in 2s
2 packages are looking for funding
run `npm fund` for details
ubuntu@roku-pc:~$ claude doctor
Claude CLI Diagnostic
Currently running: npm-global (1.0.56)
Path: /home/ubuntu/.nvm/versions/node/v22.17.0/bin/node
Invoked: /home/ubuntu/.nvm/versions/node/v22.17.0/bin/claude
Config install method: global
Auto-updates enabled: true
Update permissions: No (requires sudo)
Warning: Insufficient permissions for auto-updates
Fix: Run: sudo chown -R $USER:$(id -gn) $(npm -g config get prefix)or use `claude migrate-installer` to migrate to local installation
Press Enter to continue…
ubuntu@roku-pc:~$ sudo chown -R $USER:$(id -gn) $(npm -g config get prefix)
ubuntu@roku-pc:~$ claude doctor
Claude CLI Diagnostic
Currently running: npm-global (1.0.56)
Path: /home/ubuntu/.nvm/versions/node/v22.17.0/bin/node
Invoked: /home/ubuntu/.nvm/versions/node/v22.17.0/bin/claude
Config install method: global
Auto-updates enabled: true
Update permissions: No (requires sudo)
Warning: Insufficient permissions for auto-updates
Fix: Run: sudo chown -R $USER:$(id -gn) $(npm -g config get prefix)or use `claude migrate-installer` to migrate to local installation
Press Enter to continue…
ubuntu@roku-pc:~$
The specific criteria used to determine "Insufficient permissions for auto-updates" remains unclear at present.
6 Comments
Root Cause Analysis and Solution
Hi @Rokurolize,
I've been investigating this exact issue and can confirm the root cause. This is not actually a permission problem - it's a bug in the runtime detection logic that causes permission checks to be bypassed entirely.
Root Cause
The issue occurs when Bun is installed in your environment (common in WSL2 setups). Here's what happens:
claude doctordetects Bun is available and attempts to runbun pm bin -gnullinstead of falling back to npmfs.accessSync) to be skipped entirelyThis explains why
sudo chown -R $USER:$(id -gn) $(npm -g config get prefix)doesn't help - your npm permissions were never actually being checked.Reproduction
I've created a minimal reproduction case that demonstrates both the broken and working behavior:
Usage:
Expected vs Actual Output
With Bun installed (broken):
With Bun disabled (working):
Proposed Fix
The fix requires adding a fallback to npm when the Bun command fails. The logic should be:
bun pm bin -gnpm -g config get prefixfs.accessSynccheck failsWorkaround
Until this is fixed, users can work around it by:
claude migrate-installerto switch to local installationnpm uninstall -g bunBUN_INSTALL=to disable Bun detection when runningclaude doctorTechnical Impact
This affects any Claude Code installation where:
npm install -gThis is particularly common in WSL2 and development environments where Bun might be installed for other projects.
The misleading "requires sudo" message has likely caused users to unnecessarily modify their npm permissions or assume permission issues when the actual problem is the runtime detection logic.
Hope this helps clarify the issue! The reproduction script above should help the team verify the fix once implemented.
Update: Root Cause Confirmed and Working Workaround
I've done additional testing and can confirm the exact mechanism behind this issue, plus provide a reliable workaround.
Root Cause Verification
The issue occurs because:
process.env.BUN_INSTALLorprocess.versions.bunbun pm bin -gfails with "No package.json was found" when no global packages are installed via Bunfs.accessSync) is never executedThis explains why
sudo chown -R $USER:$(id -gn) $(npm -g config get prefix)doesn't help - your npm permissions are never actually being checked.Verified Workaround
Immediate solution (works every time):
This disables Bun detection, forcing Claude Code to use npm permission checking, which works correctly.
Test Results
I created a reproduction script that demonstrates the exact behavior:
With Bun detected (broken):
With Bun detection disabled (working):
Why Standard Bun Removal Doesn't Work
Many users have Bun installed via the official installer (not npm), so:
npm uninstall -g bunhas no effectBUN_INSTALLenvironment variable remains setEnvironment-Specific Notes
Some development environments (including VS Code and certain shell configurations) may automatically set
BUN_INSTALLeven after manual removal. Theenv -u BUN_INSTALLworkaround works regardless of where the variable is defined.Recommendation for Users
Immediate fix: Use
env -u BUN_INSTALL claude doctorto get accurate diagnostic information.For auto-updates: If you want auto-updates to work properly, you'll need to either:
Technical Fix Needed
The fix requires modifying the permission checking logic to fall back to npm when the Bun command fails:
This would allow npm-global installations to work correctly even when Bun is present but not configured for global packages.
Hope this helps clarify the issue and provides a reliable workaround until the fix is implemented!
Add detailed reproduction steps.
As a starting point, you should have Claude Code installed through standard procedures, the
claude doctorcommand should have configured permissions, and bun should not be installed.When Claude Code is installed via
npm install -g @anthropic-ai/claude-code, installingbunresults in an incorrect determination that permissions are not sufficient for automatic updates, even though automatic updates are actually possibleThis issue remains unresolved as of Claude CLI version: 1.0.59 (Claude Code).
Brilliant! I have Bun installed and the workaround fixed the issue for me.
Thank you for the analysis and for sharing a fix. I've been staring at that red error message for weeks and no other suggestions have worked.
This should be working better in the next release (handling BUN_INSTALL being present).
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.