@claude-powers/slash-commands
Version:
π Claude Powers - Essential slash commands for Claude Code
389 lines (317 loc) β’ 10.4 kB
Markdown
# Auto Commit Command
Generates automatic commits with intelligent descriptions based on detected changes in the project.
## Description
The `/auto-commit` command analyzes pending changes in the Git repository and automatically generates:
- **Descriptive commit messages** following standard conventions
- **Impact analysis** of changes made
- **Automatic categorization** of change type (feat, fix, docs, etc.)
- **Detection of breaking changes** and important changes
- **Validation** before commit to prevent errors
- **Improvement suggestions** in the generated message
## Usage
```
/auto-commit [--type] [--scope] [--message] [--validate] [--format]
```
### Parameters
- `--type`: Force a specific type (feat, fix, docs, style, refactor, test, chore)
- `--scope`: Specify the scope of the change (component, module, etc.)
- `--message`: Add additional custom message
- `--validate`: Run validations before commit (lint, tests, build)
- `--format`: Commit format (conventional, angular, simple)
- `--interactive`: Interactive mode to review before committing
- `--dry-run`: Show the generated message without committing
### Examples
```
/auto-commit
/auto-commit --type=feat --scope=authentication
/auto-commit --message="implement social login" --validate=true
/auto-commit --format=conventional --interactive
/auto-commit --dry-run
/auto-commit --type=fix --validate=lint,test
```
## Automatic Change Analysis
### Change Type Detection
#### π feat (New features)
- New files added
- New functions or methods
- New React components
- New routes or endpoints
- New main dependencies
#### π fix (Bug fixes)
- Changes in conditionals or logic
- Typo corrections
- Improved error handling
- CSS or style fixes
- Import corrections
#### π docs (Documentation)
- Changes in .md files
- Comment updates
- README modified
- JSDoc changes
#### π style (Formatting/style)
- Format-only changes
- Linting adjustments
- Whitespace
- Import organization
#### β»οΈ refactor (Refactoring)
- Code reorganization
- Function extraction
- Name changes
- Optimizations without functional change
#### β
test (Tests)
- .test.* or .spec.* files
- __tests__ folders
- Testing configuration
#### π§ chore (Maintenance tasks)
- package.json modified
- Build configuration
- Automation scripts
- .gitignore updated
### Scope Detection
```javascript
// Automatically detects scope based on:
src/components/auth/ β scope: "auth"
src/pages/dashboard/ β scope: "dashboard"
backend/api/users/ β scope: "users-api"
styles/theme/ β scope: "theme"
docs/setup/ β scope: "docs"
```
### Impact Analysis
- **Breaking Changes**: Changes in public APIs, function removal
- **Major**: Important new features, large refactors
- **Minor**: Minor new features, improvements
- **Patch**: Bug fixes, documentation, style
## Configuration
The command uses `.claude/auto-commit-config.json`:
```json
{
"format": "conventional",
"validation": {
"runLint": true,
"runTests": false,
"checkBuild": false,
"maxFileChanges": 50
},
"templates": {
"feat": "{type}({scope}): {description}\\n\\n{details}\\n\\n{footer}",
"fix": "{type}({scope}): {description}\\n\\n{details}\\n\\n{footer}",
"docs": "{type}({scope}): {description}",
"style": "{type}: {description}",
"refactor": "{type}({scope}): {description}\\n\\n{details}",
"test": "{type}({scope}): {description}",
"chore": "{type}: {description}"
},
"scopes": {
"autoDetect": true,
"predefined": [
"auth",
"api",
"ui",
"components",
"utils",
"config",
"docs",
"tests"
]
},
"rules": {
"maxSubjectLength": 100,
"bodyWrap": 72,
"requireBody": ["feat", "fix", "refactor"],
"requireBreakingChange": true,
"requireTicketNumber": false
},
"ai": {
"useIntelligentDescriptions": true,
"contextAnalysis": true,
"suggestImprovements": true,
"detectBreakingChanges": true
}
}
```
## Command Output
### Change Analysis
```
π€ CLAUDE POWER - AUTO COMMIT ANALYSIS
======================================
π DETECTED CHANGES:
βββββββββββββββββββ¬ββββββββββ¬ββββββββββββββ
β Type β filesβ Lines β
βββββββββββββββββββΌββββββββββΌββββββββββββββ€
β Modified β 8 β +156 -42 β
β New β 3 β +203 β
β Deleted β 1 β -67 β
β Renamed β 2 β ~ β
βββββββββββββββββββ΄ββββββββββ΄ββββββββββββββ
π INTELLIGENT ANALYSIS:
π src/components/auth/
β¨ [FEAT] LoginForm.tsx - New login component
β¨ [FEAT] AuthContext.tsx - Auth context
π src/pages/
π [FIX] dashboard.tsx - Fix navigation error
π docs/
π [DOCS] README.md - Update installation guide
π― DETECTED TYPE: feat
π·οΈ SUGGESTED SCOPE: auth
β‘ IMPACT: Minor (new functionality)
```
### Generated Message
```
π¬ GENERATED COMMIT MESSAGE:
=====================================
feat(auth): implement authentication system with social login
- Add LoginForm component with validation
- Implement AuthContext for state management
- Fix navigation in dashboard after login
- Update setup documentation
Allows users to authenticate using:
- Traditional email/password
- Login with Google OAuth
- Login with GitHub OAuth
Breaking changes: None
Closes: #123, #124
```
### Pre-commit Validations
```
π PRE-COMMIT VALIDATIONS:
==========================
β
ESLint: 0 errors, 2 warnings
β
Prettier: Correct format
β
TypeScript: Successful compilation
β οΈ Tests: 2 pending tests for new components
β
Build: Successful generation
β
File size: Within limits
π¦ RESULT: β
READY TO COMMIT
```
### Interactive Options
```
π PROCEED WITH COMMIT?
Proposed message:
> feat(auth): implement authentication system with social login
Options:
[Y] Yes, commit
[E] Edit message
[A] Add details
[C] Change type/scope
[V] View full diff
[N] Cancel
Choice:
```
## Advanced Integrations
### Webhooks and Notifications
```json
{
"integrations": {
"slack": {
"enabled": true,
"webhook": "https://hooks.slack.com/...",
"channel": "#dev-commits"
},
"jira": {
"enabled": true,
"autoLink": true,
"transitionTickets": false
},
"github": {
"autoLabel": true,
"linkIssues": true,
"assignReviewers": true
}
}
}
```
### Custom Templates
```json
{
"customTemplates": {
"hotfix": "hotfix: {description}\\n\\nUrgent fix for: {issue}\\n\\nTested: {testDetails}",
"release": "release: version {version}\\n\\n{changelogSummary}\\n\\nBreaking Changes:\\n{breakingChanges}",
"security": "security: {description}\\n\\nβ οΈ Security fix\\n\\nCVE: {cve}\\nSeverity: {severity}"
}
}
```
## Special Use Cases
### Merge/Release Commits
```bash
# Auto-generate message for merge
/auto-commit --type=merge --message="feat/user-dashboard into main"
# Release commit with automatic changelog
/auto-commit --type=release --message="v2.1.0" --changelog=true
# Urgent hotfix
/auto-commit --type=hotfix --validate=minimal --priority=high
```
### Multiple Contexts
```bash
# Commit for specific feature
/auto-commit --scope=dashboard --context=feature/user-dashboard
# Cross-platform commit
/auto-commit --platform=web,mobile --sync=true
# Commit with dependencies
/auto-commit --dependencies=updated --security-check=true
```
### AI Contextual Analysis
```
π§ AI CONTEXTUAL ANALYSIS:
=========================
π DETECTED PATTERNS:
β’ This commit continues the work on authentication started 3 commits ago
β’ Component-driven development pattern detected
β’ Code follows established project conventions
π‘ SUGGESTIONS:
β’ Consider adding tests for LoginForm.tsx
β’ Change in AuthContext may affect other components
β’ Document new OAuth providers in wiki
π― COMMIT QUALITY:
β’ Message: 9/10 (clear and descriptive)
β’ Scope: 10/10 (well defined)
β’ Impact: 8/10 (important change well documented)
```
## Automation and CI/CD
### GitHub Actions
```yaml
name: Auto Commit Quality Check
on:
push:
branches: [feature/*, develop]
jobs:
commit-quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Validate commit message
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
npx claude-power validate-commit "$COMMIT_MSG"
- name: Analyze commit quality
run: |
npx claude-power analyze-commit --output=json > commit-analysis.json
- name: Comment on PR if quality issues
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const analysis = JSON.parse(fs.readFileSync('commit-analysis.json'));
if (analysis.score < 8) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## π Commit Quality Analysis\n\nScore: ${analysis.score}/10\n\n${analysis.suggestions.join('\n')}`
});
}
```
### Pre-commit Hook Integration
```bash
#!/bin/sh
# .git/hooks/prepare-commit-msg
# If no message or very basic, generate an automatic one
if [ -z "$2" ] || [ "$2" = "message" ]; then
echo "π€ Generating intelligent commit message..."
AUTO_MSG=$(npx claude-power auto-commit --dry-run --format=conventional)
echo "$AUTO_MSG" > "$1"
echo "β
Message generated. Edit if necessary."
fi
```
---
*Part of the **Claude Power** ecosystem - Automate your workflow with AI* π