Skip to content
Go back

Claude Code committed directly to main

| Last edited: Today

I was working on a side project this morning and asked Claude Code to commit the latest changes and submit a PR. It spun up as usual, but then something strange happened.

Claude code session with unexpected git commands

It started suggesting commands like:

git reset --hard HEAD~2
git cherry-pick ea2ea65 513d8a1

That’s when I realized what had happened. Calude Code had committed directly to main.

Claude even narrated it helpfully:

 Wait, I need to cherry-pick the commits to the feature branch since I committed directly to main. Let me fix this:

To be fair, it wasn’t entirely Claude’s fault. My Claude project includes a CLAUDE.md file that outlines expectations, but I hadn’t updated it with some of the newer workflow rules I’ve come to rely on, especially the one that says never commit directly to main.

Here’s what that file currently looks like:

## Workflow Expectations

- If a feature or function already exists, review it before creating new code.
- Use test-driven prompts when possible: write tests first, then the implementation.
- When stuck, expand the reasoning and ask questions before retrying.
- All features must respect the current architecture and file structure.

In newer projects, I’ve added stricter instructions that explicitly prohibit committing to main and enforce branch discipline.

Lesson learned: even if your velocity increases dramatically with an AI assistant like Claude Code (and mine definitely has), you still have to encode your working agreements clearly. AI follows the path of least resistance, and if your instructions leave a gap, it will fall right into it.

Anyway, just passing this along, and wondering how many tokens were burned cleaning up that little mess. Or I guess I should say, how many tokens Claude burned on my behalf.


Share this post on:

Previous Post
How I debugged Let's Encrypt TLS cert renewals with ChatGPT
Next Post
Why Caddy proxy sometimes causes a zero-byte file to download