afterbuild/ops
ERR-146/stack trace
ERR-146
Claude Code Making Messy Git Commits? Cleanup Playbook (2026)

Claude Code Making Messy Git Commits? Cleanup Playbook (2026)

Last updated 15 April 2026 · 8 min read · By Hyder Shah
Direct answer

Claude Code writes giant catch-all commits by default, sometimes commits .env files, and writes vague messages like “update files”. Fix in four steps: clean current history with interactive rebase, install pre-commit hooks that reject bad commits, enforce commit-message style with commitlint, and write a CLAUDE.md that tells Claude to commit atomically. The Anthropic docs endorse exactly this pattern.

Quick fix for Claude Code Making Messy Git Commits

Start here

Fix 1 — Clean existing history with interactive rebase

Pick your current feature branch. Count back to the branch point: git log --oneline origin/main..HEAD. Start an interactive rebase:

git rebase -i origin/main

# In the editor, use:
# pick = keep commit as-is
# squash = merge into previous
# reword = change message
# edit = pause to split

Group related edits into atomic commits. Aim for “one logical change per commit”. Use edit + git reset HEAD^ + git add -p to split giant commits into surgically scoped ones.

Deeper fixes when the quick fix fails

  1. 02

    Fix 2 — Install a pre-commit hook that blocks secrets

    Install pre-commit (pip or brew) and wire up three hooks: no committed secrets, no giant files, run tsc.

    # .pre-commit-config.yaml
    repos:
      - repo: https://github.com/Yelp/detect-secrets
        rev: v1.5.0
        hooks: [{id: detect-secrets}]
      - repo: https://github.com/pre-commit/pre-commit-hooks
        rev: v5.0.0
        hooks:
          - id: check-added-large-files
          - id: check-merge-conflict
          - id: no-commit-to-branch
            args: [--branch, main]

    Add .env, *.pem, and credentials.json to .gitignore. Run pre-commit installso the hook fires on every commit — including Claude’s.

  2. 03

    Fix 3 — Enforce commit-message style with commitlint

    Install commitlint with conventional-commits config:

    npm i -D @commitlint/cli @commitlint/config-conventional husky
    
    # commitlint.config.js
    module.exports = { extends: ["@commitlint/config-conventional"] };
    
    # hook
    npx husky add .husky/commit-msg 'npx commitlint --edit "$1"'

    From now on, every commit must match type(scope): subject (e.g. feat(auth): add magic link login). Claude Code reads the rejected message and regenerates it correctly.

  3. 04

    Fix 4 — Write a CLAUDE.md that encodes your git conventions

    The CLAUDE.md file at your repo root is the single most effective lever on Claude Code behaviour. Spell out the git rules explicitly:

    # Git conventions (applies to every commit)
    - One logical change per commit.
    - Commit message format: type(scope): subject
    - Never commit .env, credentials.json, or any *.pem file.
    - Never stage files the user didn't ask about — review git status first.
    - Run tsc --noEmit and npm test before every commit.
    - For refactors, make the change in small PR-sized commits.

    Claude Code reads this on every session and follows it. Combined with the pre-commit + commitlint hooks, the probability of a bad commit slipping through drops to near zero.

If secrets have already leaked

A secret committed anywhere in history is a leaked secret. Rotate it immediately— Stripe, OAuth client, database password, whatever it is. Remove from history with git-filter-repo, force-push to every remote, and notify collaborators to re-clone. Removing the commit is not a substitute for rotation.

Why AI-built apps hit Claude Code Making Messy Git Commits

Claude Code does what you ask. If you ask for a feature and approve, it commits the whole turn as one commit with whatever message it generates. Left to its defaults, you end up with 2,000-line commits titled “Add checkout flow” that bundle schema migrations, UI, API, and refactors together.git bisect on that history is useless and code review is impossible.

The second failure class: Claude occasionally stages files you didn’t want — .env, secrets in test fixtures, or entire node_modules dumps. Without a pre-commit hook, those reach the remote. The Claude Code documentation explicitly recommends using a CLAUDE.md to lay down git conventions and secrets rules.

GitHub Copilot CVE-2025-53773, CVSS 9.6.
The Register, on AI coding tools committing unsafe artifacts

Diagnose Claude Code Making Messy Git Commits by failure mode

Run git log --oneline -n 20 and read the messages. If fewer than half describe a single logical change, you have a history problem. Run git secrets --scan-history and git ls-files | grep .env to check for committed secrets.

SymptomRoot causeFix
Single commit with 1000+ lines across 20 filesNo atomic commit disciplineFix #1
.env or secret in git historyNo pre-commit hook filteringFix #2
Commit messages say 'update files'No message convention enforcedFix #3
Claude repeats the same bad habits on every branchNo CLAUDE.md telling it the conventionsFix #4

Related errors we fix

Still stuck with Claude Code Making Messy Git Commits?

Emergency triage · $299 · 48h turnaround
We restore service and write the root-cause report.

If Claude Code has left you with a git mess:

  • Secrets may have leaked to the remote
  • Commits are too big to review or bisect
  • Your team can't read the history
  • You want CI and hooks set up properly
start the triage →

Claude Code Making Messy Git Commits questions

Why does Claude Code make such messy git commits?+
Claude Code commits once per turn by default, and each turn can touch many files. Without explicit conventions, you get 1,000-line commits with vague messages. The fix is four parts: clean existing history with interactive rebase, install pre-commit hooks that block secrets, enforce commit-message style with commitlint, and write a CLAUDE.md spelling out the conventions.
How do I stop Claude Code from committing secrets?+
Three layers. First, .gitignore any file that might contain secrets (.env, *.pem, credentials.json). Second, install a pre-commit hook with detect-secrets that scans every diff before allowing a commit. Third, write into CLAUDE.md that Claude must never stage .env or credential files. If a secret has already leaked, rotate it immediately — removing the commit is not enough.
Can I clean up Claude Code's bad git history after the fact?+
Yes, with git rebase -i. Start from the branch point (git rebase -i origin/main) and mark commits as squash, reword, or edit to split them. The goal is one logical change per commit so git bisect and code review actually work. For very tangled history, combine with git add -p to restage changes into atomic commits.
What should go in CLAUDE.md for git hygiene?+
At minimum: commit-message format (type(scope): subject), the rule 'one logical change per commit', explicit banned files (.env, *.pem, credentials.json), instruction to review git status before staging, instruction to run tsc --noEmit and tests before every commit, and a rule that refactors must be split into PR-sized commits. Claude Code reads this at session start and respects it.
What does it cost to clean up a Claude Code git repo?+
Integration Fix at $799 covers a full git-hygiene pass — rebase existing history, install pre-commit and commitlint hooks, write a CLAUDE.md, rotate any leaked secrets and force-push a clean history. Emergency Triage at $299 handles a single committed secret you need out of history now. Break-the-Fix-Loop at $3,999 includes git hygiene as part of a broader stabilisation.
Should I use git amend with Claude Code?+
Avoid it. If a hook rejects a commit, create a new commit rather than amending. Amending the previous commit after a hook failure can destroy work or lose earlier changes. The same applies to git push --force on shared branches — safe on your own feature branch, dangerous on main. Let the hooks do their job, make clean new commits, and rebase at the end of the branch if needed.
Next step

Ship the fix. Keep the fix.

Emergency Triage restores service in 48 hours. Break the Fix Loop rebuilds CI so this error cannot ship again.

About the author

Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.

Claude Code Making Messy Git Commits experts

If this problem keeps coming back, you probably need ongoing expertise in the underlying stack.

Sources