commit-msg is a customizable git commit message parser and validator written in Node.js. It validates a given string based on best practices and can be used as a git hook, command line tool and/or directly through the API.
Only use it if you agree with the guidelines it follows and if the customization it offers is enough to meet your needs. I will not accept changes that do not adhere to the general rules outlined in the guidelines document, unless they come with very compelling reasons.
Note: This module is currently in active development (hence the 0.x version) and a stable v1.0.0 will be released in a few weeks. For this to happen it just needs more testing from the community, because the feature set is rather complete.
The commands below should be run from your project's root directory.
IMPORTANT: On Windows, make sure you run the commands using administrator rights. Eg. open PowerShell using Run as administrator.
npm install commit-msg
This will install (symlink) the commit-msg
and update hooks in your repo's hooks/
directory so you are ready to start committing. If any of these hooks
already exist, a message will be displayed and the hooks will remain untouched.
To disable the hooks installation see Configuration.
You can also install it globally using npm install commit-msg -g in which
case you can use the command line validator as commit-msg -h.
Just run the install command again or npm update commit-msg if you have
a package.json file.
npm uninstall commit-msg
You can configure this module by specifying a commitMsg key in your
package.json file. Possible configurations are:
config objectYou can disable the hooks installation in 2 ways:
no[Client|Server]Hook key to true in your package.json:json
{
"commitMsg": {
"noClientHook": true,
"noServerHook": true
}
}
commitMsg.no[Client|Server]Hook key to true in git config:sh
git config commitMsg.noClientHook true
git config commitMsg.noServerHook true
You can disable the validation by setting commitMsg: {disable: true, ...}
in your package.json file.
If you know what you're doing you can skip the validation
altogether using git commit --no-verify. Be aware that this
will bypass the pre-commit and commit-msg hooks.
The default usage is through git hooks, that install automatically when you install the module in a git repository. There are also other possible usages, explained below.
On the client side the commit-msg hook validates
every commit you make, helping you follow the guidelines possibly
enforced by the remote server you're pushing to.
If you get your commits rejected by the server, see Changing commit messages.
The update hook can be installed in a (bare) repository
on a remote server to enforce your own commit message guidelines.
To greatly improve the validation speed make sure you have the optional prerequisites installed.
The validator includes a script for validating messages
directly from the command line. It is located at
bin/validate and you can access it from anywhere using
node <path-to-bin/validate>, eg:
# example acessing 'help' from your project root
node node_modules/commit-msg/bin/validate -h
Examples below assume the module is installed at node_modules/commit-msg
in your project root.
Also see a note on performance.
node node_modules/commit-msg/bin/validate 'Fix bug'
git rev-list --all --no-merges | node node_modules/commit-msg/bin/validate stdin
# don't forget to replace <Author>
git rev-list --all --no-merges -10 --author='<Author>' | node node_modules/commit-msg/bin/validate stdin
For more examples see the script help.
You can create your own references by simply putting your reference file in the lib/references directory. Take a look at the github reference for details on how to implement one.
Don't forget to disable the github reference to prevent it from being used.
To do this specify references: {github: false}
in your package.json file (see configuration).
For some examples you can check out the commit-msg hook, the validate script or the test files.
CommitMessageCommitMessage.parse(message[, config], callback)message (string) The message to parseconfig (true|string|Config, optional) The config object,
a string or true.true is given, it will search for the first package.json file
starting from the current directory up, and use the commitMsg
config from it, if any.callback(err, instance) (function) The callback that will be called
with the following params:err (Error)instance (CommitMessage)This is the designated initializer (also validates the message).
CommitMessage.parseFromFile(file[, config], callback)file (string) The file path to parse the message from<commitMessageInstance>.message: stringReturn the original message as a string.
<commitMessageInstance>.formattedMessages: stringReturn all errors and warnings as a string, one per line, in the same order as they were generated, including colors.
<commitMessageInstance>.validate(callback)callback(err, instance) (function) The callback that will be called
after the validation finisheserr (Error)instance (CommitMessage)This is called automatically by the static methods parse() and
parseFromFile().
<commitMessageInstance>.hasErrors(): booleanReturn true if there are any errors after validation.
<commitMessageInstance>.hasWarnings(): booleanReturn true if there are any warnings after validation.
CommitMessage.ConfigCommitMessage.Config([cfg]): objectcfg (object, optional) An object that will overwrite the
default config object.For example, to generate a warning instead of an error for the capitalized first letter check use:
CommitMessage.parse(
msg,
CommitMessage.Config({
capitalized: { type: CommitMessage.Error.WARNING }
}),
function(err, instance) { /* ... */ }
);
CommitMessage.ErrorCommitMessage.Error.ERROR: stringThe "error" string.
CommitMessage.Error.WARNING: stringThe "warning" string.

If you have problems see the TROUBLESHOOTING page.
$ claude mcp add node-commit-msg \
-- python -m otcore.mcp_server <graph>