You ran claude and got:
Error: EACCES: permission denied, open '/path/to/file'
Or Claude Code cannot access your git repository. Here are the fixes.
Fix 1: File permissions
Claude Code needs read/write access to your project files:
# Check permissions
ls -la /path/to/project
# Fix ownership (replace with your username)
sudo chown -R $USER:$USER /path/to/project
# Fix permissions recursively
chmod -R 755 /path/to/project
If you are on macOS and see this after cloning a repo:
# Git sometimes creates files with wrong permissions
git config --global core.fileMode false
Fix 2: Git repository ownership
Claude Code requires git repository access. If git has ownership issues:
# Check git ownership
git status
# If you see "dubious ownership" error
git config --global --add safe.directory /path/to/project
# Or add all directories in current folder
git config --global --add safe.directory *
Fix 3: API key not set
Claude Code needs an Anthropic API key:
# Check if key is set
echo $ANTHROPIC_API_KEY
# Set it
export ANTHROPIC_API_KEY="sk-ant-..."
# Or add to your shell profile
echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.zshrc
source ~/.zshrc
If using Claude Max subscription, authenticate with:
claude auth login
Fix 4: Directory not accessible
Claude Code may not access directories outside your project:
# Run Claude Code from your project directory
cd /path/to/project
claude
# Or specify the project directory
claude --project-dir /path/to/project
If you need access to parent directories:
# Add to Claude Code config
claude config set allowedDirectories /path/to/parent
Fix 5: Node.js/npm permission issues
If Claude Code installation has permission issues:
# Fix npm global permissions
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
# Reinstall Claude Code
npm install -g @anthropic-ai/claude-code
On macOS, avoid using sudo npm install -g. Use a version manager like nvm instead:
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Install Node.js
nvm install 20
# Install Claude Code
npm install -g @anthropic-ai/claude-code
Fix 6: Docker volume permissions
If Claude Code runs in Docker:
# Add to Dockerfile
RUN chown -R node:node /app
USER node
Or mount with correct permissions:
services:
claude:
image: node:20
volumes:
- ./project:/app
- /app/node_modules
user: "1000:1000" # Match your host user
Fix 7: SELinux (Linux)
On systems with SELinux enabled (RHEL, CentOS, Fedora):
# Check SELinux status
getenforce
# Temporarily set to permissive
sudo setenforce 0
# Or add proper context
sudo chcon -t home_repo_t /path/to/project -R
Still not working?
- Run as root temporarily β
sudo claude(not recommended for production) - Check Claude Code logs β
~/.claude/logs/ - Reinstall Claude Code β
npm uninstall -g @anthropic-ai/claude-code && npm install -g @anthropic-ai/claude-code - Use a fresh directory β Create a new folder and copy your project there
FAQ
Why does Claude Code need permission to access my files?
Claude Code reads and writes files in your project to generate code. It needs read access to understand your codebase and write access to make changes. The permission denied error usually means file ownership or permissions are misconfigured.
Can I use Claude Code with sudo?
You can, but it is not recommended. Running as root can create security issues and permission problems for files created by Claude Code. Fix the underlying permission issue instead.
How do I fix permissions on macOS?
On macOS, use sudo chown -R $USER:$USER /path/to/project to fix ownership. Also check System Preferences > Security & Privacy > Firewall if network access is blocked.
Related: Claude Code Complete Guide Β· Claude Code vs Aider vs Continue Β· How to Use Claude Code Β· Claude Code API Rate Limit Fix Β· Claude Code Context Overflow Fix