New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

claude-commit

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

claude-commit

AI-powered git commit message generator using Claude AI (API or Claude Code CLI)

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

AI Commit Generator

🇺🇦 Українська версія | 🇬🇧 English

AI-powered git commit message generator using Claude AI. Supports both Anthropic API and Claude Code CLI (for Claude Pro subscribers).

Features

  • Dual Generation Methods: Anthropic API or Claude Code CLI
  • Automatic Fallback: Falls back to CLI if API is unavailable
  • Multi-Language Support: English (default) or Ukrainian
  • AI-Powered Editing: Describe what to fix, AI applies changes automatically
  • Conventional Commits Format: Past tense, max 50 characters
  • Interactive Confirmation: Enter = confirm, Esc = cancel, e = edit
  • Fast & Efficient: Optimized prompts, 6000 char diff limit

Installation

Option A: Global Installation (NPM Package)

# Install globally
npm install -g claude-commit

# Or use with npx (no installation needed)
npx claude-commit

Option B: Local Installation (Per Project)

  • Clone or download this repository

    git clone https://github.com/uaoa/claude-commit.git
    cd claude-commit
    
  • Install dependencies

    npm install
    
  • Make script executable (Unix/Mac)

    chmod +x generate-commit.mjs
    
  • Add to your project's package.json

    {
      "scripts": {
        "commit": "node path/to/generate-commit.mjs"
      }
    }
    

Option C: With Claude Code CLI Only

If you have a Claude Pro subscription and want to use the CLI without an API key:

  • Install Claude Code CLI (if not already installed)

    # Follow instructions at: https://docs.claude.com/claude-code
    
  • Verify installation

    claude --version
    
  • Clone this repo and install dependencies

    git clone https://github.com/uaoa/claude-commit.git
    cd claude-commit
    npm install
    

Configuration

Method 1: With API Key

  • Get your API key from Anthropic Console

  • Create .env file in the project root:

    ANTHROPIC_API_KEY=sk-ant-your-key-here
    COMMIT_LANG=EN  # Optional: EN or UA (default: EN)
    

Method 2: With Claude Code CLI

No configuration needed! Just ensure Claude Code CLI is installed and authenticated.

Usage

Basic Usage

  • Stage your changes

    git add .
    # or
    git add specific-file.js
    
  • Run the generator

    # If installed globally
    claude-commit
    
    # If using npm script
    npm run commit
    
    # If using npx
    npx claude-commit
    
    # With language selection
    npm run commit -- --lang=en  # English
    npm run commit -- --lang=ua  # Ukrainian
    
  • Review the generated message

    • Press Enter or y to confirm and create commit
    • Press e to edit with AI assistance (describe what to fix)
    • Press n or Esc to cancel

AI-Powered Editing

When you press e, you can describe what needs to be fixed - AI will apply changes automatically!

Examples:

# Add scope
What to fix? add scope "auth"
# feat: added OAuth → feat(auth): added OAuth

# Change type
What to fix? this should be fix, not feat
# feat: added validation → fix: added validation

# Shorten (to 50 chars)
What to fix? shorten to 50 characters
# feat: added new functionality for user authentication through OAuth providers
# → feat: added OAuth authentication

# Fix tense
What to fix? should be in past tense
# feat: add function → feat: added function

# Translate to Ukrainian
What to fix? translate to Ukrainian
# feat: added feature → feat: додано функцію

AI maintains Conventional Commits format and applies changes intelligently!

Keyboard Controls

KeyAction
EnterConfirm and create commit
yConfirm and create commit
eOpen AI-powered editing
nCancel commit
EscCancel commit
Ctrl+CExit program

Commit Message Format

The script generates messages in Conventional Commits format:

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

Strict Rules:

  • Subject: max 50 characters, no period
  • Tense: ONLY past tense (what WAS DONE)
  • Verbs EN: added, fixed, updated, removed, refactored
  • Verbs UA: додано, виправлено, оновлено, видалено, рефакторено

Types:

  • feat - new feature
  • fix - bug fix
  • refactor - code refactoring
  • docs - documentation changes
  • style - formatting, styles
  • test - adding/updating tests
  • chore - other changes (build, CI, etc.)
  • perf - performance improvements

✅ Correct Examples:

English:

feat(auth): added Google OAuth provider
fix(api): fixed validation error
refactor(store): optimized state management
docs(readme): updated installation instructions
style(button): formatted button components

Ukrainian:

feat(auth): додано Google OAuth провайдер
fix(api): виправлено помилку валідації
refactor(store): оптимізовано управління станом
docs(readme): оновлено інструкції встановлення

❌ Wrong (imperative mood):

feat: add feature           # WRONG
fix: fix bug                # WRONG
feat: додати функцію        # WRONG

✅ Correct (past tense):

feat: added feature         # CORRECT
fix: fixed bug              # CORRECT
feat: додано функцію        # CORRECT

Generation Methods Priority

The script selects the method in this order:

  • First: Try to use API (if ANTHROPIC_API_KEY exists)
  • Fallback: If API unavailable → Claude Code CLI
  • Error: If both methods unavailable → error message

Language Configuration

Option 1: Via CLI Argument (One-time)

npm run commit -- --lang=en  # English
npm run commit -- --lang=ua  # Ukrainian

Option 2: Via ENV Variable (.env file)

# Add to .env for permanent use
COMMIT_LANG=EN  # or UA (default: EN)

Priority:

  • CLI argument --lang=
  • ENV variable COMMIT_LANG
  • Default: EN

Examples

Example 1: New Feature

$ git add src/auth/oauth.js
$ npm run commit

🚀 Git Commit Generator
📝 Language: English

🤖 Generating commit message via API...

Generated commit message:
feat(auth): added Google OAuth provider

Confirm and create commit?
  Enter/y - yes
  e - edit
  n/Esc - cancel

[Press Enter]

✅ Commit created successfully!

Example 2: Bug Fix with Editing

$ git add src/api/users.js
$ npm run commit

🚀 Git Commit Generator
📝 Language: English

🤖 Generating commit message via Claude Code CLI...

Generated commit message:
feat(api): added validation for user endpoint

Confirm and create commit?
  Enter/y - yes
  e - edit
  n/Esc - cancel

[Press e]

Current message: feat(api): added validation for user endpoint
What to fix? this should be fix, not feat

🤖 Editing commit message...

Generated commit message:
fix(api): added validation for user endpoint

Confirm and create commit?
  Enter/y - yes
  e - edit
  n/Esc - cancel

[Press Enter]

✅ Commit created successfully!

Example 3: Fallback to CLI

$ npm run commit

🚀 Git Commit Generator
📝 Language: Ukrainian

🤖 Generating commit message via API...
⚠️  API unavailable: Invalid API key
Switching to Claude Code CLI...

🤖 Generating commit message via Claude Code CLI...

Generated commit message:
refactor(store): оптимізовано управління корзиною

✅ Commit created successfully!

Troubleshooting

Error: "No staged changes"

# Check status
git status

# Add files
git add .

Error: "No way to generate commit message found"

Solution 1 - Use API:

# Add key to .env file
echo "ANTHROPIC_API_KEY=sk-ant-..." >> .env

Solution 2 - Use Claude Code CLI:

# Install Claude Code
# https://docs.claude.com/claude-code

# Verify installation
which claude
claude --version

Error: "API unavailable"

The script will automatically switch to Claude Code CLI if it's installed.

If CLI is also unavailable:

Error: "Claude Code CLI unavailable"

# Check if Claude Code is installed
which claude

# If not installed, install via instructions
# https://docs.claude.com/claude-code

Method Comparison

CriteriaClaude APIClaude Code CLI
Cost~$0.01-0.02 per commitIncluded in subscription
SpeedFasterSlower
ReliabilityHighDepends on CLI
SetupRequires API keyRequires CLI
Offline❌ No❌ No

Technical Details

Model:

  • API: Claude Sonnet 4.5 (claude-sonnet-4-5-20250929)
  • CLI: Uses subscription model

Tokens:

  • Max tokens for response: 500 (generation), 300 (editing)
  • Diff limit: 6000 characters
  • Temperature: 0.3 (for stability)

Dependencies:

  • @anthropic-ai/sdk (optional, for API method)
  • Node.js 18+ (for ES modules)
  • Git (required)

Publishing to NPM

Want to fork and publish your own version? See the Publishing Guide for detailed instructions.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details

Support

Author

Zakharii Melnyk

Made with ❤️ using Claude AI

Keywords

git

FAQs

Package last updated on 08 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts