Smart commit - auto-groups changed files by relationship, pick a group to commit
Analyze changed files and group them by relationship (directory, imports, naming). Let user pick which group to commit, then auto-generate a smart commit message. Use `--dry-run` to preview groups without committing.
/plugin marketplace add vanman2024/dev-lifecycle-marketplace/plugin install versioning@dev-lifecycle-marketplace[--dry-run]EXECUTION NOTICE FOR CLAUDE
When you invoke this command via SlashCommand, the system returns THESE INSTRUCTIONS below.
YOU are the executor. This is NOT an autonomous subprocess.
Arguments: $ARGUMENTS
Goal: Intelligently analyze all changed files, cluster them into related groups, and let user pick which group to commit. Perfect for multi-terminal workflows where different features accumulate uncommitted changes.
Core Principles:
Validate git state:
git rev-parse --git-dirgit status --porcelainGet all changed files with their status:
# Get all changed files (modified, added, deleted, untracked)
git status --porcelain
Parse into a list of files with their paths.
Clustering Algorithm - Group files by these signals (in priority order):
Group files by their parent directories:
# Extract directory patterns
for file in changed_files:
dir = dirname(file)
# Group by top 2 levels: src/auth/*, src/blog/*, components/ui/*
Find common naming patterns:
blog-*.ts, auth-*.tsx*-service.ts, *-utils.ts*Blog*, *Auth*, *Payment*For TypeScript/JavaScript files, check if files import each other:
# For each file, extract imports
grep -E "^import.*from ['\"]" <file> | extract imported paths
# If file A imports file B, they belong to same group
Analyze git diff content for common keywords:
git diff <file> | extract significant words
# Files with overlapping keywords ā same group
Files that don't fit elsewhere:
package.json, tsconfig.json, .env*Output: Create named groups like:
blog (5 files) - files in blog/, BlogCard.tsx, blog-api.tsauth (3 files) - auth/, middleware/auth.tsconfig (2 files) - package.json, tsconfig.jsonDisplay the detected groups:
š¦ Detected change groups:
[1] blog (5 files)
- src/pages/blog/index.tsx
- src/pages/blog/[slug].tsx
- src/components/BlogCard.tsx
- src/lib/blog-api.ts
- src/types/blog.ts
[2] auth (3 files)
- src/lib/auth.ts
- src/middleware/auth.ts
- src/pages/api/auth/login.ts
[3] config (2 files)
- package.json
- tsconfig.json
Which group to commit?
Use AskUserQuestion with options:
If --dry-run flag is set:
Get selected group's files.
Stage only those files:
git add <file1> <file2> <file3> ...
Determine commit type from files:
test/, *.test.*, *.spec.*) ā testdocs/, *.md) ā docs*.css, *.scss) ā stylefixfeatGenerate commit message using group name as scope:
<type>(<group-name>): update <group-name> files
Files:
- file1.ts
- file2.tsx
- file3.ts
š¤ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Create the commit:
git commit -m "<commit_message>"
Show commit result:
ā
Committed: <commit_hash>
<type>(<group-name>): update <group-name> files
Files committed (N):
- file1.ts
- file2.tsx
š Remaining uncommitted groups:
- [2] auth (3 files)
- [3] config (2 files)
Run /versioning:commit again to commit another group.
Example 1: Blog Feature Changed files:
src/pages/blog/index.tsxsrc/components/BlogCard.tsxsrc/lib/blog-api.tsDetected: All contain "blog" ā Group: blog
Example 2: Auth + API Changed files:
src/lib/auth.tssrc/middleware.ts (imports from auth.ts)src/pages/api/login.tsDetected: Import chain + "auth" keyword ā Group: auth
Example 3: Mixed Changes Changed files:
src/pages/blog/index.tsxsrc/lib/auth.tspackage.jsonDetected: 3 separate groups:
blog (1 file)auth (1 file)config (1 file)| Error | Message | Suggestion |
|---|---|---|
| Not a git repo | "Not a git repository" | "Run from a git project directory" |
| No changes | "No changed files found" | "Make some changes first" |
| User cancelled | "Commit cancelled" | - |
| Git commit fails | "Commit failed: <error>" | "Check git status" |
# Smart detection - shows groups, pick one
/versioning:commit
# Shows: [1] blog (5 files), [2] auth (3 files), [3] config (2 files)
# User picks: 1
# Commits only blog files
# Preview groups without committing
/versioning:commit --dry-run
# Shows detected groups, exits without committing