Fix GitHub Auth Errors in Claude Code: SSH, HTTPS, and Token Troubleshooting
Fix GitHub authentication errors in Claude Code — including SSH key issues, personal access tokens, HTTPS credential problems, and permission denied errors.
The Problem
You ask Claude Code to commit, push, or pull from GitHub, and you get:
Error: Git: Authentication failed
Error: Permission denied (publickey)
remote: Invalid username or password.
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Claude Code executes git commands through the shell, so it inherits your system's git authentication — or lack thereof. When git auth fails inside Claude Code, it usually means one of three things:
1. SSH keys aren't loaded in the agent's shell environment 2. HTTPS credentials need to be cached 3. Personal Access Token is missing or expired
This guide covers all three scenarios and more.
---
Step 1: Check Your Current Git Auth Status
First, see what's happening:
# Check if git can communicate with GitHub
ssh -T [email protected]
# Expected: "Hi username! You've successfully authenticated..."# Check your remote URL
git remote -v
# Shows either:
# origin [email protected]:user/repo.git (SSH)
# origin https://github.com/user/repo.git (HTTPS)
If You See SSH ([email protected]:...)
Good news — you're using SSH, which is the most reliable method for agents.
If You See HTTPS (https://github.com/...)
You'll need credential caching (see Step 3).
---
Step 2: Fix SSH Authentication (Recommended)
Problem: SSH Key Not Loaded
ssh -T [email protected]
# Permission denied (publickey).
Fix: Check and Load SSH Keys
# List loaded keys
ssh-add -l
# If you see "The agent has no identities", keys aren't loaded# Load your SSH key
ssh-add ~/.ssh/id_ed25519
# Or for RSA: ssh-add ~/.ssh/id_rsa
# Test again
ssh -T [email protected]
# Should say: Hi username! You've successfully authenticated...
Fix: Make SSH Keys Persistent
Add this to your shell profile (~/.zshrc or ~/.bashrc):
# Start ssh-agent and load keys automatically
if [ -z "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519 2>/dev/null
fi
Fix: Create SSH Key If You Don't Have One
ssh-keygen -t ed25519 -C "[email protected]"
# Press Enter for defaults, or set a passphrase# Start the agent and add key
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Add the public key to GitHub
cat ~/.ssh/id_ed25519.pub
# Copy this output
Then add it at GitHub SSH Keys Settings → New SSH Key.
External Links: - GitHub SSH Key Documentation - GitHub SSH Keys Settings - Generating a New SSH Key
---
Step 3: Fix HTTPS Authentication
If you're using HTTPS remotes, you need to cache your credentials:
Fix: Use Git Credential Manager
# Store credentials (macOS uses Keychain)
git config --global credential.helper osxkeychain# Linux
git config --global credential.helper cache
# Cache for 1 hour (3600 seconds)
git config --global credential.helper 'cache --timeout=3600'
# Windows
git config --global credential.helper manager-core
Fix: Use Personal Access Token (PAT) for HTTPS
GitHub no longer accepts passwords for HTTPS — you need a Personal Access Token:
1. Go to GitHub Tokens Settings
2. Click Generate new token (classic)
3. Select scopes:
- repo (full control of private repos)
- workflow (if you need GitHub Actions)
- read:org (for organization repos)
4. Copy the token
Then use it as your password:
git push
# Username: your-github-username
# Password: ghp_xxxxxxxxxxxxxxxxxxxx (paste the token)
Or include it in the URL:
# Not recommended (token visible in git log), but works:
git remote set-url origin https://USERNAME:[email protected]/user/repo.git
External Links: - GitHub Personal Access Tokens - GitHub Tokens Settings - Git Credential Manager
---
Step 4: Fix Claude Code-Specific Git Issues
Problem: Claude Code Can't Use Your Shell Profile
Claude Code starts in a non-interactive shell that might not source your .zshrc or .bashrc.
# Test: Does Claude Code see your SSH keys?
claude --print "Run: ssh-add -l"
# If empty, your keys aren't loaded in Claude's environment
Fix: Set up git config globally (works in any shell):
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global core.editor "nano"
Problem: "Terminal prompts disabled" Error
Claude Code can't show interactive password prompts:
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Fix: Use SSH instead of HTTPS:
# Switch your remote from HTTPS to SSH
git remote set-url origin [email protected]:user/repo.git
Or cache credentials (see Step 3).
Problem: Git Hooks Blocking Commits
If you have pre-commit hooks or lint-staged:
# Skip hooks temporarily (in Claude Code)
git commit --no-verify -m "commit message"
Or add to .claude/CLAUDE.md:
Git Commands
Always use --no-verify for commits in this project
---
Step 5: Fix Permission Issues Across Platforms
Linux/WSL
# Fix SSH directory permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
chmod 644 ~/.ssh/known_hosts
Windows
# Check if Git for Windows is installed and in PATH
where git# If using WSL, check permissions on Windows filesystem
# Files on /mnt/c/ or /mnt/d/ may have wrong permissions
macOS
# Add SSH key to Keychain
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
External Links: - WSL Git Configuration - Git for Windows
---
Step 6: Diagnose with Verbose SSH
For stubborn problems:
# Higher verbosity shows you exactly where auth fails
ssh -vT [email protected]# Look for these lines:
# debug1: Offering public key: ~/.ssh/id_ed25519
# debug1: Authentication succeeded (publickey).
# OR
# debug1: No more authentication methods to try.
# Permission denied (publickey).
Common SSH verbose output patterns:
| Output | Problem | Fix |
|--------|---------|-----|
| Offering public key... + succeeded | ✅ Works | — |
| Offering public key... + Permission denied | Key not added to GitHub | Add key at github.com/settings/keys |
| No authentication methods available | No SSH keys exist | Generate one (ssh-keygen) |
| Connection closed by remote host | Network/firewall blocking SSH | Check port 22, or use HTTPS |
---
Step 7: 2FA and SAML Issues
2FA Enabled
If you have two-factor authentication enabled:
# ❌ Password won't work even with correct password
# Instead, use a personal access token (see Step 3)
SAML Single Sign-On
If your organization uses SAML SSO:
# You need to authorize your PAT for SSO:
# 1. Go to https://github.com/settings/tokens
# 2. Click "Configure SSO" next to your token
# 3. Authorize your organization
---
Quick Reference Table
| Error Message | Likely Cause | Fix |
|---------------|-------------|-----|
| Permission denied (publickey) | SSH key not added to agent/account | ssh-add or add key to GitHub |
| Invalid username or password | Using password instead of token | Generate PAT or switch to SSH |
| Terminal prompts disabled | No cached credentials | git config --global credential.helper cache |
| Could not read from remote | Network/firewall | Check ssh -vT [email protected] |
| Repository not found | Wrong URL or permissions | Check URL and token scopes |
| Failed to push | Branch protection | Push to feature branch, not main |
| pre-commit hook failed | Linting/formatting hook | git commit --no-verify |
---
Prevention: Git Auth Setup Checklist
Run this checklist once to ensure Claude Code can always push/pull:
# 1. SSH key exists
ls -la ~/.ssh/id_ed25519# 2. SSH key is loaded
ssh-add -l
# 3. Git remote uses SSH
git remote -v
# 4. Test auth
ssh -T [email protected]
# 5. Git user config set
git config --global user.name && git config --global user.email
Related Articles: - Fix: Claude Code Not Working with Your Project — broader project setup - Setting Up Claude Code + OpenClaw — complete environment setup - How to Install Claude Code in 5 Minutes — fresh installation
Related Articles
Claude Code 'Context Window Full' — What to Do When You Run Out of Space
Fix the 'context window full' error in Claude Code. Learn practical strategies to free up space, avoid hitting limits, and keep working without losing progress.
Fix: Claude Code 'API Key Not Found' Error — Complete Troubleshooting Guide
Step-by-step guide to fixing the 'API key not found' error in Claude Code for Windows, macOS, and Linux. Covers .env setup, environment variables, CLI config, and common pitfalls.
Fix: Claude Code Not Working with Your Project — 12 Common Issues & Solutions
Troubleshooting guide for when Claude Code fails to work with your project — including file system issues, permission errors, unsupported frameworks, and config problems.