Before we start, this guide assumes that you already have Claude Code installed and configured on your machine. If you haven’t set it up yet, you can find the official installation instructions here.

A clear and consistent commit message convention is essential for the maintainability and understanding of any project. In this post, I’ll show you how to use Claude Code, the AI assistant by Anthropic, to automate and improve the writing of your commit messages in just a few minutes.

1. Create custom /commit command

The first step is to tell Claude how you want your commit messages to be written. To do this, create a file named commit.md inside the .claude/commands folder at the root of your project.

In this file, you can define the guidelines or instructions that you want Claude to follow when generating commits. For example:

---
description: "Creates well-formatted commits with conventional commit messages and emoji"
allowed-tools:
  [
    "Bash(git add:*)",
    "Bash(git status:*)",
    "Bash(git commit:*)",
    "Bash(git diff:*)",
    "Bash(git log:*)",
  ]
---

# Claude Command: Commit

Creates well-formatted commits with conventional commit messages and emoji.

## Usage

```
/commit
/commit --no-verify
```

## Process

1. Check staged files, add all if none staged
2. Analyze diff for multiple logical changes
3. Suggest splitting if needed
4. Create commit with emoji conventional format
5. Husky handles pre-commit hooks automatically

## Commit Format

`<emoji> <type>: <description>`

**Types:**

- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation
- `style`: Formatting
- `refactor`: Code restructuring
- `perf`: Performance
- `test`: Tests
- `chore`: Build/tools

**Rules:**

- Imperative mood ("add" not "added")
- First line <72 chars
- Atomic commits (single purpose)
- Split unrelated changes

## Emoji Map

✨ feat | πŸ› fix | πŸ“ docs | πŸ’„ style | ♻️ refactor | ⚑ perf | βœ… test | πŸ”§ chore | πŸš€ ci | 🚨 warnings | πŸ”’οΈ security | 🚚 move | πŸ—οΈ architecture | βž• add-dep | βž– remove-dep | 🌱 seed | πŸ§‘β€πŸ’» dx | 🏷️ types | πŸ‘” business | 🚸 ux | 🩹 minor-fix | πŸ₯… errors | πŸ”₯ remove | 🎨 structure | πŸš‘οΈ hotfix | πŸŽ‰ init | πŸ”– release | 🚧 wip | πŸ’š ci-fix | πŸ“Œ pin-deps | πŸ‘· ci-build | πŸ“ˆ analytics | ✏️ typos | βͺ️ revert | πŸ“„ license | πŸ’₯ breaking | 🍱 assets | ♿️ accessibility | πŸ’‘ comments | πŸ—ƒοΈ db | πŸ”Š logs | πŸ”‡ remove-logs | πŸ™ˆ gitignore | πŸ“Έ snapshots | βš—οΈ experiment | 🚩 flags | πŸ’« animations | ⚰️ dead-code | 🦺 validation | ✈️ offline

## Split Criteria

Different concerns | Mixed types | File patterns | Large changes

## Options

`--no-verify`: Skip Husky hooks

## Notes

- Husky handles pre-commit checks
- Auto-stage if no files staged
- Analyze diff for splitting suggestions
- **NEVER add Claude signature to commits**

The clearer and more specific your instructions, the better the results from Claude.

2. Restart the Claude Code CLI

To make the new command appear in the Claude Code interface, you need to restart the CLI. Simply close and reopen your terminal or restart the Claude Code process if it was already active.

Once this is done, you'll see the new /commit command ready to use.

To prevent Claude Code from automatically including co-authors in the generated commits, you can disable this by adding the following line to the .claude/settings.local.json file:

{
  "includeCoAuthoredBy": false
}

This is especially useful if you work in a team or prefer to keep commits clean from additional annotations.

4. Use the /commit Command

With everything set up, you can now use the command directly in the Claude Code CLI by typing:

/commit

Claude will analyze the changes in your code and generate a commit message following the guidelines you defined in the commit.md file. If you're not satisfied with the result, you can always ask Claude to rephrase or adapt the message.


Conclusion

Integrating Claude Code into your workflow for writing commit messages not only saves you time but also helps maintain a high standard of quality and clarity in your change history. As with everything in development, the key lies in defining good rules and iterating until you find the format that best fits your team or project.


βœ… Useful References:


Thanks for reading me 😊