AgentSkillsCN

git-commit-guardian

严格执行 Conventional Commits 格式,严格校验提交信息的质量(主题不超过 72 个字符,正文不超过 80 个字符),并有效杜绝 Claude Code 中的污染问题(如“共同作者”或“由…生成”的标记)。在提交代码、创建提交、执行 git commit,或当用户提及“提交”“git commit”“提交信息”“提交更改”“推送更改”时使用。

SKILL.md
--- frontmatter
name: git-commit-guardian
description: Enforces Conventional Commits format, validates message quality (72 char subject, 80 char body), and BLOCKS Claude Code pollution (co-author/generated-by markers). Use when committing, creating commits, git commit, or when user mentions "commit", "git commit", "commit message", "commit changes", "push changes".
allowed-tools: [Read, Bash, Grep, Glob]

Git Commit Guardian

Enforces professional commit message standards with Conventional Commits format and prevents AI attribution pollution.

Core Mission

This skill ensures every commit follows industry best practices while eliminating Claude Code's default commit pollution (co-author lines, generated-by footers). Commits should be clean, professional, and follow the Conventional Commits specification.

Problem Solved: Claude Code by default adds "Generated with Claude Code" footers and "Co-Authored-By: Claude" lines to every commit. This pollutes git history and exposes AI usage unnecessarily. This skill blocks such patterns and enforces clean commits.

Instructions

1. Intercept Commit Intent

Detect when user wants to commit:

  • Direct: "commit", "git commit", "commit changes"
  • Indirect: "push this", "save changes to git", "create a commit"
  • After completing work: "done, commit it"

Immediately activate and validate before any commit action.

2. Analyze Staged Changes

Before crafting commit message:

bash
# View staged files
git diff --cached --name-only

# View actual changes
git diff --cached

# Check for sensitive files (BLOCK if found)
git diff --cached --name-only | grep -E '\.(env|pem|key|credentials)$'

Determine appropriate commit type from changes:

  • New files with features → feat
  • Bug fixes → fix
  • Only docs/comments → docs
  • Only formatting → style
  • Code restructure, no behavior change → refactor
  • Performance improvements → perf
  • Test additions/fixes → test
  • Build system changes → build
  • CI configuration → ci
  • Maintenance/chores → chore

3. Validate Commit Message Format

Required format (Conventional Commits):

code
<type>[(scope)][!]: <description>

[optional body]

[optional footer]

Validation checklist:

  • Type is valid: feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert
  • Subject line ≤72 characters
  • Subject does NOT end with period
  • Subject uses imperative mood ("add" not "added", "fix" not "fixed")
  • Blank line between subject and body (if body exists)
  • Body lines wrapped at 80 characters
  • Breaking changes marked with ! or BREAKING CHANGE: footer

If validation fails:

code
COMMIT BLOCKED - Format Error

Subject line exceeds 72 characters (currently: 85)
Fix: Shorten to: "feat(compiler): add generic type support"

Original: "feat(compiler): add generic type parameter support for class-level generics in IR generation"

4. BLOCK Forbidden Patterns (CRITICAL)

These patterns MUST NEVER appear in commits:

code
FORBIDDEN PATTERNS - ALWAYS BLOCK

1. AI Attribution Footer:
   "Generated with [Claude Code]"
   "Generated with Claude Code"
   "Generated by Claude"
   "Generated by AI"

2. Co-Author Lines (any variation):
   "Co-Authored-By: Claude"
   "Co-authored-by: Claude"
   "Co-Authored-By: Claude Opus"
   "Co-Authored-By: Claude Sonnet"
   "Co-authored-by:.*Claude"
   "Co-authored-by:.*Anthropic"
   "Co-Authored-By:.*noreply@anthropic.com"

3. Emoji AI Markers:
   Lines starting with robot emoji followed by "Generated"

If forbidden pattern detected:

code
COMMIT BLOCKED - AI Attribution Detected

Found forbidden pattern in commit message:
  Line 5: "Co-Authored-By: Claude <noreply@anthropic.com>"

This project requires clean commits without AI attribution.
Remove the offending lines and retry.

Allowed footers: Closes #123, Fixes #456, BREAKING CHANGE:

This is NON-NEGOTIABLE. Always strip these before committing.

5. Craft Clean Commit Message

Message structure:

code
<type>(<scope>): <imperative description>

<optional body explaining what and why>

<optional footer: Closes #123, BREAKING CHANGE:, etc.>

Good examples:

code
feat(compiler): add generic type parameter support

Implements class-level generic handling in IR generation.
Method-level generics use identity function pattern.

Closes #42
code
fix(fir): resolve annotation detection for nested interfaces

The FIR phase was not traversing nested interface declarations.
Added recursive visitor pattern to detect @Fake at all levels.
code
refactor(generation): extract factory generation to dedicated class

Separates concerns between implementation and factory generation
for better maintainability and testing.
code
docs: update installation guide for Gradle 8.x

Bad examples (NEVER produce these):

code
Add generic type parameter support

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
code
Updated some stuff
code
fix bug.

6. Execute Commit

Only after all validations pass:

bash
git commit -m "$(cat <<'EOF'
<validated commit message here>
EOF
)"

Verify commit succeeded:

bash
git log -1 --format="%H %s"

Output confirmation:

code
COMMIT SUCCESSFUL

Commit: a1b2c3d
Message: feat(compiler): add generic type parameter support

All validations passed:
- Conventional Commits format
- Subject: 47/72 characters
- No forbidden patterns
- Clean commit history maintained

7. Handle Edge Cases

Multiple logical changes:

code
Recommend splitting into multiple commits:
1. refactor(types): extract TypeResolver to separate file
2. feat(types): add variance handling for generic bounds
3. test(types): add unit tests for TypeResolver

Use: git add -p (patch mode) to stage selectively

Breaking changes:

code
feat(api)!: change factory function signature

BREAKING CHANGE: fakeXxx() now requires explicit configuration.
Migration: fakeXxx() → fakeXxx {}

Reverting commits:

code
revert: feat(compiler): add generic type parameter support

This reverts commit a1b2c3d.
Reason: Causing compilation errors in multi-module projects.

Supporting Files

Progressive disclosure for detailed documentation:

  • resources/conventional-commits-reference.md - Full Conventional Commits specification
  • resources/commit-message-patterns.md - Project-specific good/bad examples

Related Skills

This skill composes with:

  • bdd-test-runner - Run tests before committing
  • compilation-validator - Validate code compiles before committing

This skill enables:

  • Clean git history
  • Professional commit messages
  • Automated changelog generation (from conventional commits)
  • Semantic versioning automation

Best Practices

  1. One logical change per commit - Don't bundle unrelated changes
  2. Write for future readers - Explain why, not just what
  3. Use imperative mood - "add feature" not "added feature"
  4. Keep subject concise - 72 chars max, aim for 50
  5. Never include AI attribution - Clean, professional commits only
  6. Reference issues when relevant - Closes #123, Fixes #456
  7. Mark breaking changes explicitly - Use ! or BREAKING CHANGE: footer

Commit Type Reference

TypeWhen to UseExample
featNew feature for usersfeat(dsl): add configure block for behaviors
fixBug fix for usersfix(ir): resolve null pointer in type resolution
docsDocumentation onlydocs: add KMP setup guide
styleFormatting, no logic changestyle: apply ktfmt formatting
refactorCode restructure, same behaviorrefactor: extract visitor to separate class
perfPerformance improvementperf(analysis): cache interface metadata
testAdding/fixing teststest: add generic bounds test cases
buildBuild system, dependenciesbuild: upgrade Kotlin to 2.1.0
ciCI configurationci: add KMP matrix to GitHub Actions
choreMaintenance, toolingchore: update .gitignore patterns
revertReverting previous commitrevert: feat(api): change return type

Error Messages

Invalid Type

code
COMMIT BLOCKED - Invalid Commit Type

"update" is not a valid Conventional Commits type.

Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert

Suggested fix: "feat: ..." or "fix: ..." depending on change nature

Subject Too Long

code
COMMIT BLOCKED - Subject Exceeds 72 Characters

Current: 89 characters
Limit: 72 characters

Original: "feat(compiler): implement comprehensive generic type parameter support for all interface variations"

Suggested: "feat(compiler): add generic type parameter support"

AI Attribution Detected

code
COMMIT BLOCKED - AI Attribution Detected

Line 4: "Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>"

This project maintains clean commits without AI attribution.
Remove this line to proceed.

Known Limitations

  • Skill activates on keyword detection; may miss indirect commit references
  • Cannot enforce rules if user bypasses skill and runs raw git commands
  • Body line wrapping is advisory (80 chars) not strictly enforced

References