feat(git): auto-create feature branch when committing on mainline - #12
Conversation
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
git/skills/commit/SKILL.md (1)
10-10:⚠️ Potential issue | 🟡 MinorUpdate Quick Reference to reflect conditional branching logic.
Line 10 states "Check if on mainline (if yes, create branch first)" but the actual workflow (lines 47-49) now includes conditional logic to check for opt-out language before deciding whether to create a branch.
📝 Proposed fix to align Quick Reference with workflow
-1. Check if on mainline (if yes, create branch first) +1. Check if on mainline (if yes, create branch unless explicitly allowed)
🤖 Fix all issues with AI agents
In `@git/skills/commit/SKILL.md`:
- Line 47: Update the mainline opt-out detection to read the project CLAUDE.md
"## Git Workflow" section (consistent with the pre-commit verification logic)
and only treat mainline as allowed if that section contains explicit phrases
such as "commit to main", "mainline", or "allow direct commits"; if the section
is missing or the wording is ambiguous, fall back to creating a feature branch.
Modify the existing "mainline opt-out detection" logic so it parses the "## Git
Workflow" heading, searches only within that section for the keywords above, and
defaults to branch creation when unclear, keeping the pre-commit verification
behavior as the authoritative source.
In `@git/skills/pr/SKILL.md`:
- Around line 31-39: The uncommitted-changes branch is missing handling for when
the user declines to commit: after prompting "You have uncommitted changes.
Would you like to commit them first?" if the user answers "no" you must
immediately check the current branch against the mainline and abort with an
error if it's the mainline; update the flow that invokes the commit skill (the
"commit" skill invocation block) to include an explicit "decline" branch which
queries the current branch name and raises an error suggesting creating a
feature branch (or instructs the user to commit later) when on mainline,
otherwise continue the PR process with an explicit warning about uncommitted
changes.
🧹 Nitpick comments (1)
git/skills/pr/SKILL.md (1)
39-39: Minor clarity: rephrase "changes to PR" for readability.The phrase "with the changes to PR" at the end of line 39 could be clearer. Consider: "error and suggest creating a feature branch first for the changes you want to include in the PR."
| **If uncommitted changes exist:** | ||
|
|
||
| 1. Ask user: "You have uncommitted changes. Would you like to commit them first?" | ||
| 2. If yes, invoke the `commit` skill using the Skill tool | ||
| 3. After commit succeeds, continue with PR process | ||
|
|
||
| **Verify branch is not mainline:** | ||
|
|
||
| If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first with the changes to PR. |
There was a problem hiding this comment.
Incomplete conditional: handle user declining to commit.
The uncommitted changes flow (lines 31-35) asks if the user wants to commit, but doesn't specify what happens if the user says "no". If the user declines, the mainline check at line 39 won't trigger (since uncommitted changes still exist), allowing the PR flow to continue with uncommitted changes on the mainline branch.
Expected behavior: If the user declines to commit and is on the mainline branch with uncommitted changes, the skill should error out rather than proceeding.
📋 Proposed fix to handle the "no" case
**If uncommitted changes exist:**
1. Ask user: "You have uncommitted changes. Would you like to commit them first?"
2. If yes, invoke the `commit` skill using the Skill tool
3. After commit succeeds, continue with PR process
+4. If no, stop and inform user they must commit or stash changes before creating a PR
**Verify branch is not mainline:**
If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first with the changes to PR.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| **If uncommitted changes exist:** | |
| 1. Ask user: "You have uncommitted changes. Would you like to commit them first?" | |
| 2. If yes, invoke the `commit` skill using the Skill tool | |
| 3. After commit succeeds, continue with PR process | |
| **Verify branch is not mainline:** | |
| If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first with the changes to PR. | |
| **If uncommitted changes exist:** | |
| 1. Ask user: "You have uncommitted changes. Would you like to commit them first?" | |
| 2. If yes, invoke the `commit` skill using the Skill tool | |
| 3. After commit succeeds, continue with PR process | |
| 4. If no, stop and inform user they must commit or stash changes before creating a PR | |
| **Verify branch is not mainline:** | |
| If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first with the changes to PR. |
🤖 Prompt for AI Agents
In `@git/skills/pr/SKILL.md` around lines 31 - 39, The uncommitted-changes branch
is missing handling for when the user declines to commit: after prompting "You
have uncommitted changes. Would you like to commit them first?" if the user
answers "no" you must immediately check the current branch against the mainline
and abort with an error if it's the mainline; update the flow that invokes the
commit skill (the "commit" skill invocation block) to include an explicit
"decline" branch which queries the current branch name and raises an error
suggesting creating a feature branch (or instructs the user to commit later)
when on mainline, otherwise continue the PR process with an explicit warning
about uncommitted changes.
b7558ab to
45adfb9
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@git/skills/pr/SKILL.md`:
- Around line 31-40: After the doc's "yes → commit" flow, add an explicit step
to refresh git state and re-run the branch checks (the uncommitted-changes and
"not on mainline" prerequisite) after the `commit` skill finishes; specifically,
invoke the same branch-detection/validation logic used in the pre-commit path to
re-evaluate the current branch (to catch auto-branching or opts-out) and if the
branch equals the mainline branch halt PR creation and instruct the user to
create a feature branch before proceeding.
| **If uncommitted changes exist:** | ||
|
|
||
| 1. Ask user: "You have uncommitted changes. Would you like to commit them first?" | ||
| 2. If yes, invoke the `commit` skill using the Skill tool | ||
| 3. After commit succeeds, continue with PR process | ||
| 4. If no, stop and inform user they must commit or stash changes before creating a PR | ||
|
|
||
| **Verify branch is not mainline:** | ||
|
|
||
| If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first for the changes you want to include in the PR. |
There was a problem hiding this comment.
Re-check branch (and refresh git state) after commit skill runs.
After committing, the branch may have changed (auto-branching or an explicit mainline opt‑out). The flow currently skips the “not on mainline” prerequisite in the “yes → commit” path, which can let PR creation proceed from mainline. Re-run the git state checks and enforce the mainline rule after the commit completes.
🔧 Suggested doc tweak
2. If yes, invoke the `commit` skill using the Skill tool
-3. After commit succeeds, continue with PR process
+3. After commit succeeds, re-fetch git state (current branch, uncommitted changes)
+4. If current branch equals mainline, stop and instruct creating a feature branch
+5. Continue with PR process
-4. If no, stop and inform user they must commit or stash changes before creating a PR
+6. If no, stop and inform user they must commit or stash changes before creating a PRBased on learnings: “All skills should check prerequisites (uncommitted changes, base branch, not on mainline) before doing detection work.”
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| **If uncommitted changes exist:** | |
| 1. Ask user: "You have uncommitted changes. Would you like to commit them first?" | |
| 2. If yes, invoke the `commit` skill using the Skill tool | |
| 3. After commit succeeds, continue with PR process | |
| 4. If no, stop and inform user they must commit or stash changes before creating a PR | |
| **Verify branch is not mainline:** | |
| If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first for the changes you want to include in the PR. | |
| **If uncommitted changes exist:** | |
| 1. Ask user: "You have uncommitted changes. Would you like to commit them first?" | |
| 2. If yes, invoke the `commit` skill using the Skill tool | |
| 3. After commit succeeds, re-fetch git state (current branch, uncommitted changes) | |
| 4. If current branch equals mainline, stop and instruct creating a feature branch | |
| 5. Continue with PR process | |
| 6. If no, stop and inform user they must commit or stash changes before creating a PR | |
| **Verify branch is not mainline:** | |
| If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first for the changes you want to include in the PR. |
🤖 Prompt for AI Agents
In `@git/skills/pr/SKILL.md` around lines 31 - 40, After the doc's "yes → commit"
flow, add an explicit step to refresh git state and re-run the branch checks
(the uncommitted-changes and "not on mainline" prerequisite) after the `commit`
skill finishes; specifically, invoke the same branch-detection/validation logic
used in the pre-commit path to re-evaluate the current branch (to catch
auto-branching or opts-out) and if the branch equals the mainline branch halt PR
creation and instruct the user to create a feature branch before proceeding.
Update commit skill to automatically create a feature branch when user is on mainline, instead of just recommending it. Skill now checks for explicit opt-out language in user prompt or CLAUDE.md before auto-branching. Update PR skill pre-flight check order to check uncommitted changes first, since commit skill will handle branch creation automatically. Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
45adfb9 to
95e69a7
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
git/skills/commit/SKILL.md (1)
47-57:⚠️ Potential issue | 🟡 MinorAvoid auto‑creating a branch when there are no changes to commit.
Right now the mainline check runs before verifying changes, so a feature branch is created even when the working tree is clean. Consider checking for changes first and exiting early if none exist.
Proposed doc tweak
-**If on mainline branch:** - -Check if the user's prompt or project CLAUDE.md explicitly allows committing directly to mainline (e.g., "commit to main", "no feature branch", "allow mainline commits"). If so, skip branch creation and proceed with the commit. - -Otherwise, automatically create a feature branch: - -1. Inform user: "You're on the `{mainline}` branch. Creating a feature branch." -2. Invoke the `branch` skill using the Skill tool -3. After branch created, continue with commit process - -**Verify there are changes to commit:** +**Verify there are changes to commit:** Check the "Status" and "Staged changes" to see if there are any changes to commit. If no changes exist, inform the user there's nothing to commit and exit early. + +**If on mainline branch:** + +Check if the user's prompt or project CLAUDE.md explicitly allows committing directly to mainline (e.g., "commit to main", "no feature branch", "allow mainline commits"). If so, skip branch creation and proceed with the commit. + +Otherwise, automatically create a feature branch: + +1. Inform user: "You're on the `{mainline}` branch. Creating a feature branch." +2. Invoke the `branch` skill using the Skill tool +3. After branch created, continue with commit processAs per coding guidelines, “All skills should check prerequisites (uncommitted changes, base branch, not on mainline) before doing detection work.”
Add explicit NEVER rule to the Git Safety Protocol prohibiting direct commits to the mainline branch unless the user explicitly requests it. This protection was present in the old skill-based architecture (PR #12) but was lost during the SessionStart rewrite. Assisted-by: Claude:claude-opus-4-6
Summary
This PR implements automatic feature branch creation when using the
git:commitskill while on the mainline branch, replacing the previous soft "recommended" approach that often prompted for user confirmation.Changes
git/skills/commit/SKILL.md: Updated mainline branch protection to:
git/skills/pr/SKILL.md: Reordered pre-flight checks to:
Testing
git:commitwhile on mainline → should auto-create branch without askinggit:commitwith "commit directly to main" → should skip branch creationRelated
Implements the plan from previous session to make auto-branching the default behavior with explicit opt-out support.
🤖 Generated with Claude Code
Summary by CodeRabbit
Enhancements
Bug Fixes / UX