Shallow Clone Missing History for Blame — Fix (2026)

The Error

fatal: git blame --porcelain: no such path 'src/api/handler.ts' in HEAD
warning: unable to access beyond shallow boundary
  This repository is a shallow clone (depth=1). History is incomplete.
  git log and git blame show only the grafted commit.

This appears when Claude Code tries to use git blame, git log, or git bisect on a shallow clone that lacks full commit history.

The Fix

git fetch --unshallow
  1. Convert the shallow clone into a full clone by fetching all missing history.
  2. Verify full history is available: git log --oneline | wc -l should show all commits.
  3. Claude Code can now use blame, log, and bisect normally.

Why This Happens

CI/CD systems and quick setups often clone repositories with --depth=1 to save time and bandwidth. This creates a “shallow” clone containing only the latest commit. Claude Code’s git operations that require history (blame for understanding code authorship, log for reviewing changes, bisect for finding bugs) fail because the required commits do not exist locally.

If That Doesn’t Work

If unshallow takes too long on a massive repo, fetch only partial history:

git fetch --depth=100

Fetch history for a specific file:

git fetch origin main --deepen=50
git blame src/api/handler.ts

If the remote does not support unshallow (rare):

git clone --no-single-branch <repo-url> full-clone
cd full-clone

Prevention

# CLAUDE.md rule
This project requires full git history. Clone with 'git clone' (no --depth flag). In CI/CD, use 'fetch-depth: 0' in GitHub Actions checkout. Never use shallow clones for development.

See Also

This fix also applies if you see these related error messages:

  • fatal: not a git repository
  • error: failed to push some refs
  • fatal: refusing to merge unrelated histories
  • Error: ENOENT: no such file or directory
  • Cannot resolve path outside workspace

Frequently Asked Questions

Why does Claude Code require git?

Claude Code uses git for several core operations: tracking file changes, creating commits, reading blame information, searching history with git log, and managing branches. Without git, these operations fail and Claude Code falls back to less efficient alternatives.

Can Claude Code work in a non-git directory?

Yes, but with reduced functionality. File search and editing work normally, but version control operations (commit, diff, blame) are unavailable. Claude Code displays a warning when opened in a directory without git initialization.

How do I prevent Claude Code from making unwanted git operations?

Add rules to your CLAUDE.md: Do not create commits automatically. Do not run git push. Always ask before any git operation that modifies history. Claude Code respects these constraints and asks for confirmation before proceeding.

Why does Claude Code reject paths outside the workspace?

Claude Code sandboxes file operations to the current workspace directory for security. Writing to paths outside the project root (like /etc/ or ~/) is blocked by default. This prevents accidental modification of system files or other projects.

Configure permissions → Build your settings with our Permission Configurator.

Try it: Paste your error into our Error Diagnostic for an instant fix.

Git Operations in Claude Code: Safety Checklist

Claude Code can execute git commands, which makes safety guardrails important:

Before any destructive operation: Always check git status and git stash list to confirm there are no uncommitted changes that could be lost.

Branch management: Claude Code should create feature branches for non-trivial changes rather than committing directly to main. Use the pattern git checkout -b claude/feature-name to clearly identify AI-generated branches.

Commit message conventions: Configure your preferred commit format in CLAUDE.md. Claude Code follows the format you specify. Common formats: Conventional Commits (feat: add user search), Angular style, or simple descriptive messages.

Common Git Mistakes Claude Code Makes

  1. Amending the wrong commit. If a pre-commit hook fails, Claude Code sometimes uses --amend on the next attempt, which modifies the previous (successful) commit instead of creating a new one. Configure CLAUDE.md with: “Never use git commit –amend. Always create new commits.”

  2. Force pushing to shared branches. Claude Code may suggest git push --force to resolve push rejections. Add Bash(git push --force*) to your deny list in settings.json.

  3. Committing generated files. Without guidance, Claude Code may commit dist/, node_modules/, or .env files. Ensure your .gitignore is complete and add a pre-commit hook that checks for these.