This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a TypeScript project that implements a Git commit-msg hook tool, similar to Gerrit's commit-msg hook. The tool automatically generates and adds unique Change-Ids to Git commit messages.
The project follows a simplified single-package structure:
- Contains all the functionality including the command-line interface, user-facing commands, and core logic for commit message processing and hook functionality
npm run dev -- <command>- Run the CLI tool directly with ts-node for development (uses NODE_OPTIONS=--no-warnings to suppress experimental warnings)npm run build- Build the CLI packagenpm test- Run tests with Vitest
npx eslint src/ test/- Lint TypeScript filesnpx prettier --check src/ test/- Check code formattingnpx prettier --write src/ test/- Format code
npm install- Install dependencies and automatically build the projectnpm run build- Build the CLI package
commit-msg/
├── src/ # Source code
│ ├── bin/ # Entry point scripts
│ ├── commands/ # Command implementations
│ ├── services/ # Business logic services
│ └── utils/ # Utility functions
├── dist/ # Compiled output
├── scripts/ # Build and utility scripts
├── templates/ # Template files
└── test/ # Test files
-
CLI Entry Point (
src/bin/commit-msg.ts):- Uses Commander.js for command-line argument parsing
- Implements two main commands:
installandexec
-
Commands (
src/commands/):install.ts: Installs the commit-msg hook in a Git repositoryexec.ts: Executes the commit-msg hook logic on a commit message file
-
Core Interfaces:
- Contains interfaces for commit message processing and hook functionality
- Defined in
src/index.ts
The project uses a custom build script that handles TypeScript compilation, template copying, and setting executable permissions:
- Compiles TypeScript code from
src/todist/usingnpx tsc - Copies template files from
templates/todist/templates/ - Sets executable permissions on compiled bin files to ensure the CLI works correctly after installation
This is configured in the build script in package.json, which calls scripts/build.js.
- ESLint: Code quality checks with TypeScript support
- Prettier: Code formatting
- Husky + lint-staged: Pre-commit hooks that automatically format and lint staged files
- Commit messages must follow the Conventional Commits Specification
- Commit messages must be written in English.
- A good commit message should contain multiple lines: The first line is the title, the second line is blank, and the third line onwards contains a detailed description of the changes.
- In the detailed description of the commit message, explain the reason for the change (why), and include a concise description of the modification, rather than just describing how it was changed.
- Infer the reason for the commit from the prompt, combined with the code changes.
- Each line in the commit message should not exceed 72 characters; wrap lines if necessary (do not add extra blank lines).
- Use HereDoc format to run git commit commands, such as:
git commit -F- <<-EOF, instead of using multiple-m <message>parameters to create multi-line commit messages. Multiple-m <message>parameters will cause redundant blank lines to be inserted between commit message paragraphs.
- Make changes to TypeScript files in
src/ - Run
npm run buildto compile TypeScript to JavaScript - Test changes using
npm run dev -- <command> - Commit changes (pre-commit hooks will automatically format and lint)
The pre-commit hooks ensure code quality by running ESLint and Prettier on staged files before each commit.
This project uses npm version management. To update the version:
- Update the package version:
npm version [major|minor|patch] --no-git-tag-version - Build the project:
npm run build - Optionally create a git tag:
git tag v<version> - Push changes and tags:
git push && git push --tags
The project uses a prepack script that automatically runs the build process before publishing, ensuring all compiled files are up-to-date.
The CLI tool dynamically reads its version from package.json, so the --version parameter will always show the current version.