commit-validator

oimiragieo's avatarfrom oimiragieo

Validates commit messages against Conventional Commits specification using programmatic validation. Replaces the git-conventional-commit-messages text file with a tool that provides instant feedback.

⭐1stars🔀0forks📁View on GitHub🕐Updated Jan 11, 2026

When & Why to Use This Skill

The Commit Message Validator is a specialized Claude skill designed to programmatically enforce the Conventional Commits specification. It provides instant feedback on commit formatting, ensuring that every entry in your project's history is structured, readable, and compatible with automated tooling like changelog generators and semantic versioning systems.

Use Cases

  • Local Pre-commit Hooks: Automatically validate commit messages on a developer's machine before they are finalized to prevent non-compliant entries from entering the local history.
  • CI/CD Pipeline Enforcement: Integrate into automated workflows (e.g., GitHub Actions or GitLab CI) to reject pull requests or commits that fail to meet team naming standards.
  • Standardizing Team Communication: Establish a unified language across engineering teams by enforcing consistent use of types like 'feat', 'fix', and 'chore'.
  • Automated Changelog Generation: Maintain a clean and structured Git history that enables the seamless creation of release notes and versioning updates based on commit types.
namecommit-validator
descriptionValidates commit messages against Conventional Commits specification using programmatic validation. Replaces the git-conventional-commit-messages text file with a tool that provides instant feedback.
version1.0.0
modelhaiku
allowed-toolsread, grep, bash
Commit Message Validator - Programmatically validates commit messages against the [Conventional Commits](https://www.conventionalcommits.org/) specification. - Before committing code - In pre-commit hooks - In CI/CD pipelines - During code review - To enforce team standards

Step 1: Validate Commit Message

Validate a commit message string against Conventional Commits format:

Format: <type>(<scope>): <subject>

Types:

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation only changes
  • style: Code style changes (formatting, etc.)
  • refactor: Code refactoring
  • perf: Performance improvements
  • test: Adding or updating tests
  • chore: Maintenance tasks
  • ci: CI/CD changes
  • build: Build system changes
  • revert: Reverting a previous commit

Validation Rules:

  1. Must start with type (required)
  2. Scope is optional (in parentheses)
  3. Subject is required (after colon and space)
  4. Use imperative, present tense ("add" not "added")
  5. Don't capitalize first letter
  6. No period at end
  7. Can include body and footer (separated by blank line)
**Implementation**

Use this regex pattern for validation:

const CONVENTIONAL_COMMIT_REGEX =
  /^(feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert)(\(.+\))?: .{1,72}/;

function validateCommitMessage(message) {
  const lines = message.trim().split('\n');
  const header = lines[0];

  // Check format
  if (!CONVENTIONAL_COMMIT_REGEX.test(header)) {
    return {
      valid: false,
      error: 'Commit message does not follow Conventional Commits format',
    };
  }

  // Check length
  if (header.length > 72) {
    return {
      valid: false,
      error: 'Commit header exceeds 72 characters',
    };
  }

  return { valid: true };
}
**Valid Examples**:
feat(auth): add OAuth2 login support
fix(api): resolve timeout issue in user endpoint
docs(readme): update installation instructions
refactor(components): extract common button logic
test(utils): add unit tests for date formatting
**Invalid Examples**:
Added new feature  # Missing type
feat:new feature   # Missing space after colon
FEAT: Add feature  # Type should be lowercase
feat: Added feature  # Should use imperative tense
**Pre-commit Hook** (`.git/hooks/pre-commit`):
#!/bin/bash
commit_msg=$(git log -1 --pretty=%B)
if ! node .claude/tools/validate-commit.js "$commit_msg"; then
  echo "Commit message validation failed"
  exit 1
fi
**CI/CD Integration**:
# .github/workflows/validate-commits.yml
- name: Validate commit messages
  run: |
    git log origin/main..HEAD --pretty=%B | while read msg; do
      node .claude/tools/validate-commit.js "$msg" || exit 1
    done
**Output Format**

Returns structured validation result:

{
  "valid": true,
  "type": "feat",
  "scope": "auth",
  "subject": "add OAuth2 login support",
  "warnings": []
}

Or for invalid messages:

{
  "valid": false,
  "error": "Commit message does not follow Conventional Commits format",
  "suggestions": [
    "Use format: <type>(<scope>): <subject>",
    "Valid types: feat, fix, docs, style, refactor, perf, test, chore, ci, build, revert"
  ]
}

Or for invalid messages:

{
  "valid": false,
  "error": "Commit message does not follow Conventional Commits format",
  "suggestions": [
    "Use format: <type>(<scope>): <subject>",
    "Valid types: feat, fix, docs, style, refactor, perf, test, chore, ci, build, revert"
  ]
}
1. **Validate Early**: Check commit messages before pushing 2. **Provide Feedback**: Show clear error messages with suggestions 3. **Enforce in CI**: Add validation to CI/CD pipelines 4. **Team Training**: Educate team on Conventional Commits format 5. **Tool Integration**: Integrate with Git hooks and IDEs