name: git-commit description: Stage and commit changes to git in one workflow with automatic pre-commit hook handling. Use when the user asks to commit changes, create a commit, save work to git, or similar git commit requests. Automatically generates commit messages and handles pre-commit failures by fixing linting/formatting errors.
Git Add and Commit
Streamline git commits by staging files, generating commit messages, and handling pre-commit hook failures automatically.
Branch Guard
Before starting, check the current branch:
- If on
mainormaster:- Run
gmasto ensure main is up to date - Suggest a branch name based on the task context (e.g.,
refactor/splash-validation,fix/login-error) - Ask the user: "You're on main. Want me to create and switch to
<suggested-branch>?" - Do NOT proceed until the user confirms and you've switched branches
- Run
- If already on a feature branch: proceed normally
Workflow
1. Stage Files
Default: Stage all changes
git add .
Specific files: If user specifies files or folders to exclude, stage only the desired files:
git add <specific-files>
2. Analyze Changes and Generate Commit Message
Before committing, run these commands in parallel to understand the changes:
git status
git diff --staged
git log -3 --oneline # See recent commit message style
Analyze the staged changes to craft a concise commit message (1-2 sentences) that:
- Summarizes the nature of changes (feature, fix, refactor, docs, test, etc.)
- Focuses on "why" rather than "what"
- Follows the repository's existing commit message style
- Uses appropriate prefix (add/update/fix/refactor/etc.) based on actual changes
Skill file handling: Changes under .claude/skills/ get special treatment:
- If skill changes are mixed with other (non-skill) changes: stage and commit everything together, but ignore the skill files when writing the commit message — focus the message only on the non-skill changes.
- If the only staged changes are skill files: treat them as the focus and write the commit message about the skill updates.
3. Create Commit
CRITICAL: Always run git commit with dangerouslyDisableSandbox: true. Pre-commit hooks invoke Docker-based checks (tsc typecheck via docker compose exec) that require Docker socket access, which the sandbox blocks.
git commit -m "Your commit message here."
- Keep the git commit to a single line
4. Handle Pre-Commit Failures
If the commit fails due to pre-commit hooks:
Identify the errors - Read the pre-commit output to understand what failed (linting, formatting, etc.)
Fix menial errors - Automatically fix:
- Code formatting issues (black, prettier, etc.)
- Linting errors (flake8, eslint, etc.)
- Import sorting
- Trailing whitespace
- Other style/formatting issues
Do NOT fix if changes would:
- Alter business logic
- Break functionality
- Require architectural decisions
- Need user input to resolve correctly
Re-stage and commit - After fixing errors:
git add . git commit -m "$(cat <<'EOF' Your original commit message here. EOF )"Report to user - Summarize what was fixed and complete the commit
5. Append Changelog Entry
After a successful commit, append a changelog entry per the global CLAUDE.md instructions:
- Run
date '+%m-%d-%Y %H:%M'to get the current date and time — this is mandatory, never skip it or assume the date from context/filenames - Use the
MM-DD-YYYYportion for the changelog filename (changelog/MM-DD-YYYY-changelog.md) - Use the
HH:MMportion for the entry timestamp - Append a
- [HH:MM] git-commit: <summary>entry
Important Notes
- Never use
--no-verifyto bypass pre-commit hooks unless explicitly requested - If pre-commit failures require non-menial changes, report to user and ask for guidance
- Verify commit success with
git statusafter completion - All commits must be authored by
u4i-claude-code[bot]— do not add anyCo-Authored-Bytrailers