Claude Code Terminal Permission Denied Fix

To fix “permission denied” errors in Claude Code, run chmod +x on the failing command, verify your project directory has 755 permissions, and reset ownership of Claude’s data directory with sudo chown -R $(whoami). If the error persists, check your shell profile for broken sourced scripts and remove any macOS quarantine attributes with xattr -rd com.apple.quarantine. The detailed fixes below cover every common cause.

Understanding the Error

When Claude Code throws a permission denied error, it usually happens in one of three contexts: when executing shell commands through Claude Code, when accessing specific files or directories, or when Claude Code attempts to run its own internal processes. Identifying which context triggers your error determines the right fix.

The error message itself often includes the specific path or command that failed. Pay attention to this detail—it points directly to the source of the problem.

Fix 1: Verify Shell Command Execution Permissions

The most common cause involves Claude Code’s ability to execute shell commands. If your shell cannot run certain commands due to permission issues, Claude Code cannot use them either.

First, check if the command itself has executable permissions:

ls -la /usr/local/bin/your-command

If you see a dash (-) instead of an x in the permissions string, the file is not executable. Fix this with:

chmod +x /path/to/command

For commands installed via Homebrew on macOS, you may need to reinstall them:

brew reinstall package-name

Fix 2: Check Directory and File Access

Claude Code needs read access to your project files and write access to create or modify files. Permission errors occur when the user running Claude Code lacks these permissions.

For Project Files

Verify your project directory permissions:

ls -la /path/to/your/project

If you see permissions like drwx------ or drwxr-x---, only the owner can access the directory. Fix this for your user:

chmod 755 /path/to/your/project

For files within the project:

chmod 644 /path/to/your/project/file

For Sensitive Files

If you are working with files in protected directories (like ~/.ssh or /etc), Claude Code needs explicit permission. Add your user to the appropriate group or adjust permissions carefully:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa

Fix 3: Fix Claude Code’s Internal Permissions

Claude Code stores configuration and cache data in specific directories. If these become corrupted or have incorrect permissions, you may see permission denied errors when Claude Code tries to access its own files.

macOS

Check Claude Code’s data directory:

ls -la ~/Library/Application\ Support/Claude/

If permissions look wrong, reset them:

sudo chown -R $(whoami) ~/Library/Application\ Support/Claude/

Linux

Similarly, check the config directory:

ls -la ~/.config/Claude/

Reset permissions with:

sudo chown -R $USER ~/.config/Claude/

Fix 4: Resolve Shell Profile Issues

Sometimes the issue stems from your shell profile (.bashrc, .zshrc, .bash_profile) having commands that fail due to permission errors. When Claude Code spawns a new shell, it may encounter these failures.

Diagnostic Steps

Run your shell profile in verbose mode to identify problematic lines:

bash -x ~/.bashrc

or for Zsh:

zsh -x ~/.zshrc

Look for errors in the output—particularly anything marked “permission denied” or “command not found.”

Common Culprits

Comment out or fix any problematic lines, then restart your terminal session.

Fix 5: Handle macOS Gatekeeper and Quarantine

On macOS, security features can prevent Claude Code or its components from running. If you recently installed Claude Code or updated it, Gatekeeper may have flagged it.

Remove Quarantine Attribute

Check if the Claude Code binary is quarantined:

xattr -l $(which claude)

If you see com.apple.quarantine in the output, remove it:

sudo xattr -rd com.apple.quarantine /Applications/Claude.app

Or for the CLI:

sudo xattr -rd com.apple.quarantine $(which claude)

Allow Claude Code in Security Preferences

If Gatekeeper is blocking Claude Code, open System Preferences → Security & Privacy → General and click “Allow Anyway” next to the blocked software.

Fix 6: Check Sudo and Root Access Issues

If Claude Code attempts to run commands with elevated privileges, your user may lack sudo permissions. Verify your sudo access:

sudo -v

Enter your password when prompted. If this fails, contact your system administrator to add your user to the sudoers file.

For Claude Code itself, avoid running with sudo unless absolutely necessary. Running as root can cause permission issues with files in your home directory.

Diagnostic Tips

When troubleshooting permission errors, gather as much information as possible. Note the full error message text including any file paths or command names, and record what you were asking Claude Code to do when the error occurred. Check whether you recently updated your OS, installed new tools, or modified permissions. Review Claude Code’s log files for more detailed error information.

You can often find logs in:

Preventing Future Issues

Once you have resolved the permission error, take steps to prevent recurrence:

Permission denied errors in Claude Code usually stem from executable permissions on commands, file and directory access, or Claude Code’s own internal data. Start with chmod +x and directory permissions before moving to shell profile debugging or Gatekeeper quarantine removal.

Built by theluckystrike — More at zovo.one