Create a well-formatted git commit with proper hygiene and standards
Creates well-formatted git commits following repository-specific standards and conventions.
/plugin marketplace add kenotron-ms/amplifier-setup/plugin install git@amplifier-setupoptional commit messageCreate a well-formatted git commit following repository conventions with proper commit hygiene.
šÆ Smart Standards Discovery: This command automatically discovers and follows repository-specific commit standards by reading documentation files (CLAUDE.md, CONTRIBUTING.md, MAINTENANCE.md). It adapts commit messages to match each repository's conventions.
All git commands must run in the actual project directory, not the Claude worktree.
The commands will use PROJECT_DIR environment variable if set, otherwise fall back to the current directory ($PWD).
At the start of this command, set PROJECT_DIR:
# Use PROJECT_DIR if set, otherwise use current directory
PROJECT_DIR="${PROJECT_DIR:-$PWD}"
echo "Working in: $PROJECT_DIR"
Then for all git commands, use:
cd "$PROJECT_DIR"
git <command>
# Interactive commit (analyze changes and suggest message)
/git:commit
# Commit with custom message
/git:commit "feat: add user authentication"
Commit message: $ARGUMENTS
Follow these steps in order:
Run these commands to understand the current state:
cd "$PROJECT_DIR"
git status
git diff --stat
git diff --cached --stat
Check:
Use knowledge-archaeologist agent to discover repository commit conventions:
Task knowledge-archaeologist: "Search for commit message standards in
CLAUDE.md, CONTRIBUTING.md, MAINTENANCE.md. Extract:
- Commit message format (conventional commits, custom format)
- Prefix conventions (feat:, fix:, docs:, etc.)
- Message style guidelines
- Required elements (issue references, signatures)
- Examples of good commits from git log"
Common patterns to look for:
Review git status and diff:
cd "$PROJECT_DIR"
git status --porcelain
git diff --cached --stat
git log -5 --oneline # See recent commit style
Categorize changes:
Check for sensitive data:
.env, credentials.json, or similar files are stagedBased on repository standards and changes, generate appropriate commit message.
Conventional Commits format (if repo uses it):
<type>(<scope>): <subject>
<body>
<footer>
Types:
feat: New featurefix: Bug fixdocs: Documentation onlyrefactor: Code refactoringtest: Adding or updating testschore: Maintenance tasksstyle: Formatting, missing semicolonsperf: Performance improvementsci: CI/CD changesbuild: Build system changesExample commit messages:
# Feature with body
feat: add JWT authentication
Implement JWT-based authentication for API endpoints.
Includes token generation, validation, and refresh mechanism.
- Add JWT utilities module
- Update authentication middleware
- Add tests for token flow
# Bug fix
fix: resolve memory leak in cache implementation
The cache was not properly cleaning up expired entries,
causing memory usage to grow over time.
Closes #123
# Documentation
docs: update API documentation for auth endpoints
# Refactoring
refactor: simplify user authentication logic
# Multiple changes
feat: implement user authentication
- Add JWT token generation
- Add authentication middleware
- Update API endpoints to require auth
- Add comprehensive test coverage
š¤ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Present suggested message to user:
Suggested commit message:
---
feat: add user authentication with JWT
Implement JWT-based authentication system including:
- Token generation and validation
- Refresh token mechanism
- Authentication middleware
- Comprehensive test coverage
Files changed:
- src/auth.py (new file, 245 lines)
- src/middleware.py (modified, +67 lines)
- tests/test_auth.py (new file, 156 lines)
š¤ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---
Accept this message?
1. Yes, commit with this message
2. Edit the message
3. Cancel commit
Your choice: _
If files are already staged:
cd "$PROJECT_DIR"
git diff --cached --name-only
echo "Files already staged"
If no files staged (stage all changes):
cd "$PROJECT_DIR"
git add .
echo "Staged all changes"
Verify what's staged:
cd "$PROJECT_DIR"
git status --short
Commit with message:
cd "$PROJECT_DIR"
# Use heredoc for multi-line messages
git commit -m "$(cat <<'COMMIT_MSG'
feat: add user authentication with JWT
Implement JWT-based authentication system including:
- Token generation and validation
- Refresh token mechanism
- Authentication middleware
- Comprehensive test coverage
š¤ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
COMMIT_MSG
)"
Handle pre-commit hook results:
If hooks modify files:
# Check if pre-commit modified files
cd "$PROJECT_DIR"
if [ -n "$(git status --porcelain)" ]; then
echo "ā ļø Pre-commit hooks modified files"
echo "Modified files:"
git status --short
echo ""
echo "Options:"
echo "1. Amend commit with hook changes"
echo "2. Review changes first"
echo "3. Abort commit"
echo ""
echo "Your choice: _"
fi
If user chooses to amend:
cd "$PROJECT_DIR"
# Check authorship of last commit
AUTHOR=$(git log -1 --format='%an %ae')
echo "Last commit author: $AUTHOR"
# Only amend if it's safe
if git status | grep -q "Your branch is ahead"; then
git add .
git commit --amend --no-edit
echo "ā Commit amended with pre-commit changes"
else
echo "ā ļø Cannot amend - commit may have been pushed or is not yours"
echo "Creating new commit instead..."
git add .
git commit -m "chore: apply pre-commit hook fixes"
fi
Show commit details:
cd "$PROJECT_DIR"
echo ""
echo "ā Commit created successfully!"
echo ""
git log -1 --stat
echo ""
git show --name-status HEAD
Inform user:
ā Changes committed successfully!
Commit: <commit-hash>
Branch: <branch-name>
Next steps:
1. Push to remote: git push
2. Create PR: /git:submit-pr
3. Continue working on feature
What would you like to do?
Before committing, scan for potential secrets:
cd "$PROJECT_DIR"
# Check staged files for common secret patterns
git diff --cached | grep -iE "(password|api_key|secret|token|credential|private_key)"
# Warn about specific files
git diff --cached --name-only | grep -E "(.env|credentials|secrets|.*\.pem|.*\.key)$"
If found, warn user:
ā ļø Potential sensitive data detected!
Found in staged files:
- .env (environment variables)
- config/credentials.json (credentials file)
Patterns detected:
- Line 45: API_KEY = "sk-..."
- Line 67: PASSWORD = "..."
Are you sure you want to commit these files?
1. No, unstage sensitive files (git reset)
2. Yes, I've verified they're safe
3. Cancel commit
Your choice: _
cd "$PROJECT_DIR"
CURRENT_BRANCH=$(git branch --show-current)
if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "master" ]; then
echo "ā ļø WARNING: You're on the '$CURRENT_BRANCH' branch!"
echo ""
echo "It's recommended to commit on a feature branch."
echo ""
echo "Options:"
echo "1. Create feature branch now (recommended)"
echo "2. Continue committing to $CURRENT_BRANCH"
echo "3. Cancel commit"
echo ""
echo "Your choice: _"
fi
cd "$PROJECT_DIR"
# Check for large files (>1MB)
git diff --cached --name-only | while read file; do
if [ -f "$file" ]; then
size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null)
if [ "$size" -gt 1048576 ]; then
size_human=$(numfmt --to=iec-i --suffix=B $size 2>/dev/null || echo "$size bytes")
echo "ā ļø Large file detected: $file ($size_human)"
fi
fi
done
ā Clear and concise:
feat: add user authentication with JWT
Implement JWT-based authentication including token generation,
validation, and refresh mechanism.
ā Explains why, not just what:
fix: resolve memory leak in cache implementation
The cache was not properly cleaning up expired entries,
causing memory to grow unbounded over time.
ā Groups related changes:
refactor: simplify authentication logic
- Extract JWT utilities to separate module
- Remove duplicate validation code
- Add comprehensive error handling
ā Too vague:
fix bug
update code
changes
ā Too detailed (should be in code):
change variable name from userAuth to userAuthentication and
update all references in auth.py lines 45, 67, 89...
ā Multiple unrelated changes:
add auth + fix cache + update docs + refactor utils
This command works seamlessly with the /new-feature workflow:
/git:commit at any phase to commit progressExample usage during feature development:
# After Phase 2 (Design)
/git:commit "feat: complete architecture design for user auth"
# After Phase 4 (Implementation) - Chunk 1
/git:commit "feat: implement core authentication module"
# After Phase 4 (Implementation) - Chunk 2
/git:commit "feat: add authentication API endpoints"
# After Phase 6 (Verification)
/git:commit "feat: complete user authentication feature
All tests passing, documentation updated, ready for deployment."
Ready to create well-formatted commits following repository standards!