Claude Code "permission denied": 4 causes in diagnostic order
Claude Code produces "permission denied" errors in two different situations: filesystem-level permission problems (the OS won't let Claude Code read or write a file) and tool-use permission problems (Claude Code's own safety layer is blocking an action). They look similar but have completely different fixes. This page covers both, in the order you should check them.
The 30-second answer
- Filesystem permission: Claude Code runs as your user. If it can't access a file, launch it from the correct directory and check that the file isn't owned by root or another user.
- Tool use blocked: Claude Code asks before taking actions. If you see a permission prompt and declined it, that's not an error — re-run and approve the action.
- Working directory matters: Claude Code scopes its file access to the directory it was launched from. Files outside that directory will appear inaccessible.
- .claudeignore: if a file is excluded via
.claudeignoreor.gitignore, Claude Code will refuse to read it.
Two different "permission denied" errors — which one do you have?
Before diving into causes, identify which kind of error you have:
| What you see | Type |
|---|---|
Error: EACCES: permission denied, open '/path/to/file' | Filesystem — OS won't allow access |
Permission denied: /path/to/file is outside the working directory | Scope — file is outside Claude Code's allowed path |
| Claude Code asks for confirmation with a permission prompt and stops when you decline | Tool use — Claude Code's own safety layer |
This file is excluded from Claude Code's context | .claudeignore / .gitignore exclusion |
Cause 1: File outside Claude Code's working directory
Claude Code scopes all file operations to the directory you launched it from. If you launch it from ~/projects/my-app, it won't read or write files in ~/other-project or /etc. This is a safety feature, not a bug — it prevents Claude Code from accidentally modifying files outside your project.
Fix:
- Close Claude Code.
- In your terminal,
cdto the root of the project containing the files you want Claude Code to access. - Run
claudefrom that directory.
If you need Claude Code to work across multiple project directories at once, launch it from their common parent directory.
Cause 2: Actual filesystem permission error (EACCES)
If the error includes EACCES or mentions a specific file path with "permission denied," the OS is blocking access. This happens when:
- The file is owned by
rootor another user (common if the file was created by a process run withsudo) - The directory has restrictive permissions (
chmod 700or similar) - You're on a shared system where certain paths are locked down
Fix:
# Check who owns the file
ls -la /path/to/file
# If owned by root and you need to edit it:
sudo chown $(whoami) /path/to/file
# Or fix the directory permissions:
chmod 755 /path/to/directory
Do not run Claude Code with sudo. Running sudo claude gives it root-level access to your entire filesystem, which is a significant security risk. Fix the file ownership instead.
Cause 3: Tool use permission blocked
Claude Code asks for your permission before taking actions like running bash commands, writing files, or using external tools. If you declined a permission prompt, Claude Code stops and won't retry — this is intentional behavior, not an error.
How permission prompts work:
- Claude Code will display what it wants to do and ask yes/no
- Responding "no" or pressing Ctrl+C cancels the action and Claude Code can't complete the task
- Responding "yes" allows the action once
- Some actions offer an "always allow" option that persists for the session
Fix: re-run your request. When the permission prompt appears, respond yes (or y). If you want to avoid repeated prompts for bash commands you trust, you can configure allowed tools in ~/.claude/settings.json:
{
"allowedTools": ["Bash(git status)", "Bash(npm run test)", "Bash(npm run build)"]
}
This allows specific bash commands without prompting. Be deliberate about what you allow — broad bash permissions let Claude Code run arbitrary shell commands.
Cause 4: File excluded by .claudeignore or .gitignore
Claude Code respects .gitignore by default and also checks for a .claudeignore file in the project root. Files matched by either are excluded from Claude Code's context — it won't read them, and attempting to ask Claude Code to modify them produces a permission-style refusal.
Fix — if the file should be accessible:
- Check
.claudeignorein your project root for patterns that match the file. - Check
.gitignore— if the file is gitignored, Claude Code treats it as excluded by default. - To override for a specific file, add a negation pattern to
.claudeignore:
# .claudeignore
# Allow this specific file even though it's in .gitignore
!src/generated/important-file.ts
Note: secrets files (.env, *.pem, *.key) are excluded by Claude Code's default ignore patterns as a security measure. This is intentional — don't add them to your context.
How to check exactly what Claude Code can access
Run this in Claude Code to see its working directory and understand scope:
# Ask Claude Code directly:
"What directory are you working from? List the files in the current directory."
# Or check from your terminal before launching:
pwd # This is what Claude Code will use as its root
FAQ
Can I give Claude Code access to my entire home directory? You can — launch it from ~. But this is not recommended. Claude Code's file access is broad when given a large working directory, and mistakes (accidental file deletion, overwriting config files) are harder to reverse. Scope it to the project you're working on.
Claude Code edited the wrong file. How do I undo it? Claude Code works inside your git repository. Run git diff to see what changed and git checkout -- filename to revert individual files. This is another reason to always have Claude Code working inside a git repo.
I get permission denied on node_modules. Why is Claude Code trying to read it? node_modules should be in your .gitignore and Claude Code should skip it automatically. If it's not gitignored, add it to .claudeignore. You almost never want Claude Code reading dependency source files.
Related
- Claude API 401 authentication_error: 5 causes & fixes
- Cursor authentication failed: 5 causes & fixes
- How to use Anthropic prompt caching to cut API costs
Last updated June 2026. Verified against Claude Code CLI current release. Behavior may vary with future Claude Code versions.