Conventional commits

From FerroxLabs/murage · View interactive version

Conventional commits is an AI agent skill from the GitHub repository FerroxLabs/murage. Guides expert-level conventional commits implementation: version-control and best-practices decision frameworks, production-ready patterns, and concrete templates for conventional commits workflows. Use when the user asks about conventional commits, conventional commits configuration, or version-con

How to use this skill

Skill file

Conventional Commits

When to Use

Use this skill when:

Do NOT use this skill when:


Process

1. Establish the Conventional Commits Format Foundation

Before configuring any tooling, ensure the user understands the exact specification structure:

2. Map Commit Types to SemVer Outcomes

Understanding the version bump rules is essential for configuring automated release tools correctly:

3. Choose and Configure the Right Toolchain

Select tools based on the project's runtime, CI environment, and team size:

Commit Message Linting:

Interactive Commit Authoring:

Git Hook Management:

Automated Release and Changelog:

4. Configure commitlint Rules in Detail

The default @commitlint/config-conventional is a good start but most projects need customization:

5. Set Up CI Enforcement (Beyond Local Hooks)

Local hooks are bypassed with --no-verify and don't run in most CI environments. Always add server-side validation:

6. Configure Automated Changelog and Release

Set up the release automation pipeline based on the chosen tool:

For semantic-release:

For release-please:

CHANGELOG format: By default, @semantic-release/release-notes-generator uses Angular changelog format with sections: "Bug Fixes", "Features", "Performance Improvements", "Reverts", and "BREAKING CHANGES". Customize section headers via the writerOpts configuration

7. Handle Monorepo and Multi-Package Scopes

Monorepos require extra conventions to make commit scopes meaningful and release tools functional:

8. Document Team Conventions in a CONTRIBUTING.md

No tooling substitutes for clear human documentation:


Output Format

When helping a user set up Conventional Commits, produce a structured implementation plan using this format:

## Conventional Commits Implementation Plan

### Project Profile
| Attribute          | Value                              |
|--------------------|------------------------------------|
| Runtime/Language   | [e.g., Node.js 20, Python 3.11]    |
| Package Manager    | [npm / yarn / pnpm / pip / go mod] |
| Repo Structure     | [single-package / monorepo]        |
| CI Platform        | [GitHub Actions / GitLab CI / etc] |
| Merge Strategy     | [squash / merge commit / rebase]   |
| Release Target     | [npm / PyPI / Docker / internal]   |
| Automation Level   | [manual / semi-auto / full-auto]   |

---

### Commit Message Format Reference

**Structure:**
<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

**Type → SemVer Mapping:**
| Type       | Version Bump | Included in CHANGELOG |
|------------|-------------|----------------------|
| feat       | MINOR       | Yes                  |
| fix        | PATCH       | Yes                  |
| perf       | PATCH       | Yes                  |
| revert     | PATCH       | Yes                  |
| docs       | none        | No (default)         |
| style      | none        | No                   |
| refactor   | none        | No (default)         |
| test       | none        | No                   |
| build      | none        | No                   |
| ci         | none        | No                   |
| chore      | none        | No                   |
| BREAKING CHANGE (footer) | MAJOR | Yes          |
| ! suffix   | MAJOR       | Yes                  |

**Allowed Scopes:** [list scopes specific to this project]

---

### Toolchain Configuration

#### commitlint.config.js

module.exports = {

extends: ['@commitlint/config-conventional'],

rules: {

'type-enum': [2, 'always', [

'feat', 'fix', 'docs', 'style', 'refactor',

'perf', 'test', 'build', 'ci', 'chore', 'revert'

]],

'scope-enum': [2, 'always', [/* project-specific scopes */]],

'scope-empty': [1, 'never'], // warn if scope missing

'subject-case': [2, 'never', ['sentence-case', 'pascal-case', 'upper-case']],

'header-max-length': [2, 'always', 72],

'body-max-line-length': [2, 'always', 100],

'footer-max-line-length': [2, 'always', 100],

}

};


#### .husky/commit-msg

#!/usr/bin/env sh

. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"


#### package.json scripts

{

"scripts": {

"prepare": "husky install",

"commit": "cz",

"release": "semantic-release"

}

}


#### CI Commit Lint Workflow (GitHub Actions)

name: Lint Commits

on:

pull_request:

types: [opened, synchronize, reopened, edited]

jobs:

commitlint:

runs-on: ubuntu-latest

steps:

with:

fetch-depth: 0

with:

node-version: '20'

cache: 'npm'


---

### Release Configuration

#### .releaserc.json (semantic-release)

{

"branches": ["main"],

"plugins": [

["@semantic-release/commit-analyzer", {

"releaseRules": [

{ "type": "refactor", "release": "patch" },

{ "type": "docs", "scope": "README", "release": "patch" }

]

}],

"@semantic-release/release-notes-generator",

["@semantic-release/changelog", {

"changelogFile": "CHANGELOG.md"

}],

"@semantic-release/npm",

["@semantic-release/git", {

"assets": ["CHANGELOG.md", "package.json", "package-lock.json"],

"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"

}],

"@semantic-release/github"

]

}


---

### Good Commit Examples

feat(auth): add OAuth2 PKCE flow for mobile clients

Implements RFC 7636 proof key for code exchange to support

public clients that cannot securely store a client secret.

Affects the /oauth/authorize and /oauth/token endpoints.

Closes #142

fix(api): handle null response from payment gateway

The Stripe SDK returns null for declined cards in sandbox mode.

Previous code assumed a non-null response object, causing a

TypeError on the /checkout endpoint.

Fixes #389

feat(api)!: rename /users endpoint to /accounts

BREAKING CHANGE: The /users REST endpoint has been renamed to

/accounts across all API versions. Clients must update their

base URLs. Migration guide available in docs/migration/v4.md.


---

### Installation Commands

Core tooling

npm install --save-dev \

@commitlint/cli \

@commitlint/config-conventional \

commitizen \

cz-conventional-changelog \

husky

Release automation

npm install --save-dev \

semantic-release \

@semantic-release/changelog \

@semantic-release/git \

@semantic-release/github

Initialize

npx commitizen init cz-conventional-changelog --save-dev --save-exact

npx husky install

npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'


Rules

  1. NEVER allow the ! breaking change shorthand without also requiring a BREAKING CHANGE: footer. The ! is a visual hint for humans but many tools (including older versions of semantic-release) only detect the footer. Require both for maximum compatibility.
  1. NEVER lint only the HEAD commit in CI. Feature branches accumulate commits over time. Always lint the full range from the base branch SHA to the head SHA -- use --from $BASE_SHA --to $HEAD_SHA. Linting only HEAD misses all intermediate commits.
  1. ALWAYS use fetch-depth: 0 in CI checkout steps. Without full history, git log and commitlint --from cannot resolve ancestor SHAs and will fail silently or throw errors about missing refs.
  1. NEVER configure release tools to run on every push to a feature branch. Release automation must only run on protected branches (typically main, master, or named release branches). Running semantic-release on feature branches will create spurious tags and publish pre-release versions unexpectedly.
  1. ALWAYS include [skip ci] in the release commit message. The automated commit that bumps version files and writes CHANGELOG.md must not trigger another CI run. Omitting [skip ci] (or the CI platform's equivalent) creates an infinite pipeline loop.
  1. NEVER enforce scope as required globally without documenting the exact allowed scope list. If scope-empty is set to error level, every developer must know the allowed values. Undocumented scope enforcement causes constant commitlint failures and forces --no-verify bypasses.
  1. ALWAYS configure the commit-msg hook to receive the message file path ($1), not pipe stdin. Commitlint requires the file path argument: commitlint --edit "$1". Piping git log -1 --pretty=%B | commitlint will not work for pre-commit hooks and bypasses the actual staged message file.
  1. NEVER use generic scopes like misc, various, other, or general. These defeat the purpose of scopes entirely. If a commit affects too many areas to name a scope, it should be split into multiple commits. If it truly cannot be scoped, omit the scope rather than use a meaningless value.
  1. ALWAYS configure commitlint's body-max-line-length rule. Without this, automated changelog generators can produce malformatted entries from commits with very long unbroken body text. 100 characters per line is the recommended maximum.
  1. NEVER rely solely on local Git hooks for enforcement in a team setting. Any developer can bypass hooks with --no-verify, and hooks are not installed automatically when someone clones the repo (unless npm install triggers prepare). CI-side linting is the authoritative enforcement layer -- local hooks are a developer convenience, not a security control.

Edge Cases

Squash-Merge Workflows

When the team uses GitHub's "Squash and Merge" strategy, individual commit messages within a PR are discarded. Only the squash commit message (defaulting to the PR title) ends up in the main branch history. In this case:

Monorepo with Independent Package Versioning

When a monorepo contains packages with independent version lifecycles (e.g., a CLI tool at v3.x and a UI library at v1.x):

Introducing Conventional Commits to an Existing Repository

When a repository has years of unstructured commit history and the team wants to adopt Conventional Commits:

Pre-release Versions and Release Channels

For projects that publish alpha, beta, or release-candidate versions:

Python and Non-Node.js Projects

For projects where Node.js is not part of the technology stack:

Handling Revert Commits

Revert commits have special rules that most teams overlook:

Repository Without an Existing package.json (Non-npm Projects)

When commitlint is needed in a repo that has no package.json (a pure Go service, Terraform modules, Helm charts):


Example

Input: "We have a Node.js REST API project with 5 developers, a monorepo with two packages (api-server and sdk-client), deploying to npm for the SDK and to Docker Hub for the API. We use GitHub and GitHub Actions, with a squash-merge PR strategy. We want full release automation with separate versions for each package. How do we implement Conventional Commits end to end?"


Output:

Conventional Commits Implementation Plan

Project Profile

| Attribute | Value |

|------------------|-------------------------------------------|

| Runtime/Language | Node.js 20, TypeScript |

| Package Manager | npm workspaces |

| Repo Structure | Monorepo -- packages/api-server, packages/sdk-client |

| CI Platform | GitHub Actions |

| Merge Strategy | Squash merge (PR title = commit message) |

| Release Targets | sdk-client -- npm; api-server -- Docker Hub |

| Automation Level | Full auto via release-please |


Commit Message Format Reference

Structure:

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

[optional body]

[optional footer(s)]

Type → SemVer Mapping:

| Type | Version Bump | Included in CHANGELOG |

|------------|-------------|----------------------|

| feat | MINOR | Yes |

| fix | PATCH | Yes |

| perf | PATCH | Yes |

| revert | PATCH | Yes |

| docs | none | No (default) |

| style | none | No |

| refactor | none | No |

| test | none | No |

| build | none | No |

| ci | none | No |

| chore | none | No |

| BREAKING CHANGE (footer) | MAJOR | Yes |

| ! suffix | MAJOR | Yes |

Allowed Scopes for this repo:


Squash-Merge PR Title Enforcement

Because the team uses squash merges, the PR title becomes the commit on main. Enforce the PR title directly:

.github/workflows/pr-title-lint.yml:

name: Lint PR Title
on:
  pull_request:
    types: [opened, edited, synchronize, reopened]

jobs:
  lint-pr-title:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      - run: npm ci
      - name: Validate PR title
        run: echo "${{ github.event.pull_request.title }}" | npx commitlint --verbose

Individual commit messages within the PR branch are developer convenience only -- they are not enforced and do not reach main. Document this in CONTRIBUTING.md to prevent confusion.


commitlint Configuration

commitlint.config.js (repo root):

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [2, 'always', [
      'feat', 'fix', 'docs', 'style', 'refactor',
      'perf', 'test', 'build', 'ci', 'chore', 'revert', 'deps'
    ]],
    'scope-enum': [2, 'always', [
      'api-server', 'sdk-client', 'workspace', 'ci',
      'api-server/deps', 'sdk-client/deps'
    ]],
    'scope-empty': [2, 'never'],           // scope is required for this monorepo
    'subject-case': [2, 'never', ['sentence-case', 'pascal-case', 'upper-case']],
    'header-max-length': [2, 'always', 72],
    'body-max-line-length': [2, 'always', 100],
    'footer-max-line-length': [2, 'always', 100],
  }
};

package.json (repo root):

{
  "name": "my-monorepo",
  "private": true,
  "workspaces": ["packages/*"],
  "scripts": {
    "prepare": "husky install",
    "commit": "cz"
  },
  "devDependencies": {
    "@commitlint/cli": "^19.0.0",
    "@commitlint/config-conventional": "^19.0.0",
    "commitizen": "^4.3.0",
    "cz-conventional-changelog": "^3.3.0",
    "husky": "^9.0.0"
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  }
}

.husky/commit-msg:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no -- commitlint --edit "$1"

Initialization commands:

npm install
npx husky install
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
chmod +x .husky/commit-msg

Release Automation with release-please

release-please is chosen over semantic-release here because:

.github/workflows/release-please.yml:

name: Release Please
on:
  push:
    branches:
      - main

permissions:
  contents: write
  pull-requests: write

jobs:
  release-please:
    runs-on: ubuntu-latest
    steps:
      - uses: googleapis/release-please-action@v4
        id: release
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          config-file: release-please-config.json
          manifest-file: .release-please-manifest.json

      # Only publish sdk-client to npm if its release PR was merged
      - uses: actions/checkout@v4
        if: ${{ steps.release.outputs['packages/sdk-client--release_created'] }}
      - uses: actions/setup-node@v4
        if: ${{ steps.release.outputs['packages/sdk-client--release_created'] }}
        with:
          node-version: '20'
          registry-url: 'https://registry.npmjs.org'
      - run: cd packages/sdk-client && npm ci && npm publish
        if: ${{ steps.release.outputs['packages/sdk-client--release_created'] }}
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

      # Only build and push Docker image if api-server release was created
      - name: Build and push Docker image
        if: ${{ steps.release.outputs['packages/api-server--release_created'] }}
        uses: docker/build-push-action@v5
        with:
          context: packages/api-server
          push: true
          tags: |
            myorg/api-server:${{ steps.release.outputs['packages/api-server--version'] }}
            myorg/api-server:latest

release-please-config.json:

{
  "packages": {
    "packages/api-server": {
      "release-type": "node",
      "changelog-path": "CHANGELOG.md",
      "tag-name-template": "api-server-v${version}",
      "bump-minor-pre-major": false,
      "draft": false
    },
    "packages/sdk-client": {
      "release-type": "node",
      "changelog-path": "CHANGELOG.md",
      "tag-name-template": "sdk-client-v${version}",
      "bump-minor-pre-major": true
    }
  },
  "bootstrap-sha": "abc1234"
}

.release-please-manifest.json (initial state):

{
  "packages/api-server": "2.4.1",
  "packages/sdk-client": "0.8.3"
}

The bootstrap-sha is the SHA of the last commit before adoption -- release-please only analyzes commits after this point.


Good PR Title Examples for This Project

feat(sdk-client): add TypeScript generics to request builder
fix(api-server): prevent race condition in session token refresh
feat(api-server)!: remove v1 REST endpoints

BREAKING CHANGE: All /v1/* endpoints have been removed.
Consumers must migrate to /v2/* equivalents as documented
in docs/migration/v1-to-v2.md. A compatibility shim is
available for the next 90 days at /v1-compat/*.
chore(sdk-client/deps): update axios from 1.6.2 to 1.7.0
feat(workspace): add shared ESLint config for monorepo

Developer Workflow Summary

1. Create feature branch:    git checkout -b feature/add-webhook-support
2. Make changes, then commit with wizard:
                             npm run commit
                             (select type: feat, scope: api-server,
                              description: add webhook delivery retry mechanism)
3. Open PR with title:       feat(api-server): add webhook delivery retry mechanism
4. CI validates PR title via commitlint -- must pass before merge allowed
5. Team reviews and approves PR
6. Squash merge to main      (PR title becomes the commit message on main)
7. release-please runs       (analyzes new commit, updates draft release PR)
8. When ready to release:    Merge the release-please PR
9. Post-merge:               sdk-client publishes to npm, api-server image pushes to Docker Hub

CONTRIBUTING.md Snippet

## Commit Message Guidelines

This repo uses [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
Because we squash-merge PRs, **your PR title** must follow the convention.
Individual commits within your branch are not enforced.

### Format

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


### Required Scopes
- `api-server` -- REST API changes
- `sdk-client` -- SDK library changes
- `workspace` -- Root-level tooling (eslint, tsconfig, husky)
- `ci` -- GitHub Actions workflow changes
- `api-server/deps` or `sdk-client/deps` -- Dependency updates

### Version Impact
- `feat(sdk-client): ...` -- bumps sdk-client minor version
- `fix(api-server): ...` -- bumps api-server patch version
- `feat(api-server)!: ...` with `BREAKING CHANGE:` footer -- bumps api-server major version
- `chore`, `docs`, `test`, `ci`, `style` -- no version bump

### Examples

feat(sdk-client): add batch request support

fix(api-server): handle empty request body in POST /orders

chore(workspace): update TypeScript to 5.4.0

feat(api-server)!: require authentication on all endpoints

BREAKING CHANGE: Previously, GET /health was unauthenticated.

All endpoints now require a Bearer token. See docs/auth.md.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.