Claude repeatedly commits and pushes directly to main despite explicit instructions
Description
Claude Code commits and pushes directly to main despite:
- An explicit
CLAUDE.mdrule: "Never commit directly to main. All changes must go through a feature branch and a pull request." - A persistent memory entry (
feedback_never_commit_to_main.md) created after a previous identical incident (DEV-522) - The memory entry being updated and re-read within the same session
What happened (DEV-551 session, 2026-04-15)
- After a PR was merged, Claude found itself on
mainbut did not check the branch before committing an infrastructure fix. The commit was pushed tomain, triggering a full CI build and deployment. - Immediately after, Claude committed and pushed a plan documentation file directly to
main— a pure docs change with zero justification for bypassing a PR. This triggered another full CI build and deployment pipeline.
Both incidents happened in the same session, after the memory entry from a prior identical incident (DEV-522) was already loaded into context.
Root cause
Claude does not reliably run git branch --show-current before committing, even when the project's CLAUDE.md and persistent memory files explicitly require it. The instruction is followed inconsistently — present in memory but not enforced as a hard gate before every git commit.
Impact
- Triggered multiple unintended CI builds and deployments on the production branch
- Bypassed branch protection and required code review
- Wasted engineering time
Expected behaviour
Claude should run git branch --show-current before every git commit call. If the result is main (or master), it must stop, create a feature branch, and only then commit. This should be a hard gate, not a guideline.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗