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

Two different "permission denied" errors — which one do you have?

Before diving into causes, identify which kind of error you have:

What you seeType
Error: EACCES: permission denied, open '/path/to/file'Filesystem — OS won't allow access
Permission denied: /path/to/file is outside the working directoryScope — file is outside Claude Code's allowed path
Claude Code asks for confirmation with a permission prompt and stops when you declineTool 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:

  1. Close Claude Code.
  2. In your terminal, cd to the root of the project containing the files you want Claude Code to access.
  3. Run claude from 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:

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:

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:

  1. Check .claudeignore in your project root for patterns that match the file.
  2. Check .gitignore — if the file is gitignored, Claude Code treats it as excluded by default.
  3. 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

Last updated June 2026. Verified against Claude Code CLI current release. Behavior may vary with future Claude Code versions.