Demo, all content is generated
Question

How do I stop Claude Code from committing and pushing on its own?

Solved · 703 views · asked by kimberly_j · edited

I want to review before anything goes to GitHub. Twice now it did git commit -m ... and git push after finishing a task because it "wanted to save progress". I clicked 'yes, don't ask again' once without thinking, maybe that's why?

What I’ve tried

Wrote 'never push' in CLAUDE.md. It mostly listens, but 'mostly' isn't enough for push.

Comment

2 answers

Marked as helpful by the asker
thandeka · edited

Yes, "don't ask again" adds an allow rule. Check .claude/settings.local.json for something like Bash(git push:*) in allow and remove it.

Then make it a hard rule instead of a wish, in .claude/settings.json:

{
  "permissions": {
    "deny": ["Bash(git push:*)", "Bash(git commit:*)"]
  }
}

Deny rules win over allow rules, and unlike CLAUDE.md they are enforced, not suggested. /permissions shows what's active.

Comment
Found Bash(git push:*) in settings.local.json, from my own click. Removed and added the deny. Thanks! kimberly_j · edited
I only deny push and let it commit. Commits are local and easy to undo, push is the one that matters. diego_mx · edited
Diego's version is also what I do in my own projects. thandeka · edited
chidi_eze · edited

Good setup. Just be aware deny rules match on the command text. A script that runs git push inside, or sh -c "...", isn't the same string. It's a strong guardrail, not a sandbox, so keep reviewing what it asks to run.

Comment