smart-commit
Generates clear, conventional commit messages from staged changes. Analyzes diffs to produce focused commit messages that explain WHY, not just WHAT. Supports conventional commits, multi-file changes, and interactive refinement. Use when committing code or when the user says /smart-commit.
Smart Commit Message Generator
Generate clear, well-structured commit messages by analyzing your staged changes.
When to Activate
- User asks to commit with a good message
- User says
/smart-commitor "commit this" or "write a commit message" - User has staged changes and wants help describing them
Instructions
Step 1: Check Staged Changes
# What's staged?
git diff --cached --stat
# Detailed diff of staged changes
git diff --cached
# Any unstaged changes the user might want to include?
git diff --stat
If nothing is staged:
- Show unstaged changes with
git diff --stat - Ask the user what to stage, or suggest
git add -pfor selective staging - Stop until changes are staged
Step 2: Analyze the Diff
Read the staged diff and determine:
-
Type: What kind of change is this?
feat— New functionalityfix— Bug repairrefactor— Restructuring without behavior changeperf— Performance improvementtest— Adding or fixing testsdocs— Documentation onlychore— Build, CI, dependencies, configstyle— Formatting, whitespace (no logic change)
-
Scope (optional): What area of the codebase?
- Module name, component, feature area
- Only include if the project uses scoped commits
-
Subject: One line summarizing the change
- Imperative mood: "Add feature" not "Added feature"
- Under 50 characters (hard limit: 72)
- Lowercase first word (after type prefix)
- No period at the end
-
Body (if needed): Explain WHY, not WHAT
- The diff shows WHAT changed — the message should explain WHY
- Include motivation, context, or trade-offs
- Wrap at 72 characters
- Separate from subject with blank line
-
Footer (if applicable):
BREAKING CHANGE:for breaking changesCloses #123for issue referencesCo-authored-by:for pair programming
Step 3: Check Recent History
# Match the project's commit style
git log --oneline -10
Adapt your message format to match the project's existing conventions:
- Does the project use conventional commits (
feat:,fix:)? - Does it use scopes (
feat(auth):)? - Does it use ticket numbers (
[PROJ-123])? - What tense and style do recent messages use?
Step 4: Generate Message
For simple, single-purpose changes:
feat: add rate limiting to auth endpoints
For changes that need context:
fix: prevent duplicate webhook deliveries
The retry logic was not checking if a webhook had already been
successfully delivered before retrying. This caused duplicate
notifications when the initial response was slow but successful.
Adds a delivery receipt check before each retry attempt.
Closes #847
For multi-file changes with a single theme:
refactor: extract email validation into shared utility
Three endpoints were each implementing their own email regex.
Consolidates into a single validateEmail() function with
proper RFC 5322 compliance and unit tests.
Step 5: Present and Execute
- Show the proposed commit message
- Ask if the user wants to adjust it
- Execute the commit:
git commit -m "$(cat <<'EOF'
<commit message here>
EOF
)"
Commit Quality Rules
Good Commits
- Atomic: One logical change per commit
- Complete: The codebase works after this commit
- Explained: The message tells you WHY without reading the diff
- Findable:
git log --grepcan find it by keyword
Signs of a Bad Commit
- "Fix stuff" / "WIP" / "misc changes" — too vague
- "Update auth.ts, user.ts, config.ts, test.ts" — describes files, not purpose
- 500+ lines touching 3 unrelated features — should be split
- "Add feature and also fix that bug and update deps" — multiple purposes
When to Suggest Splitting
If the staged changes contain multiple unrelated changes, suggest splitting:
I see two separate concerns in these changes:
1. Rate limiting logic (auth.ts, middleware.ts)
2. Typo fix in README
Want me to help split these into two commits? I'd suggest:
- `git reset HEAD README.md` to unstage the README
- Commit the rate limiting changes first
- Then stage and commit the README fix separately
Edge Cases
- Empty commit message request: Never create an empty message. Analyze the diff.
- Merge commits: Use the default merge message unless the user asks otherwise.
- Amend requests: Use
git commit --amendbut warn about rewriting published history. - Fixup commits: Support
git commit --fixup=<hash>for changes that will be squashed. - Co-authored work: Include
Co-authored-by:footer when the user mentions pair programming.