Skip to content

Repository files navigation

penmit

License: MIT npm version Node.js >= 22 CI

penmit = pen + commit - a portmanteau for writing commit messages.

AI-powered git commit message generator that writes conventional commit messages from your staged diff. Supports Ollama (local and cloud), Anthropic, and OpenAI. Built-in secret redaction ensures API keys, tokens, and passwords in your diff never reach cloud providers.

$ git add .
$ penmit

Provider: Local (Ollama) - Model: llama3.2
⠸ Generating commit message

  feat: add user authentication with JWT support

  Accept (a/Enter), Regenerate (r), Edit (e), Esc/Ctrl+C to cancel:  > _

Features

  • Local-first - any Ollama model, fully offline, no data leaves your machine
  • Secret redaction - automatically scans your diff for API keys, tokens, passwords, and private keys before sending to any cloud provider
  • Cloud support - Ollama Cloud, Anthropic (Claude), or OpenAI; keys go directly to the provider, never to any penmit server
  • No vendor lock-in - switch providers anytime with a single flag
  • Staged diff only - only reads what you've staged; never touches your full repo
  • Zero workflow changes - just replace git commit with penmit
  • Interactive prompt - accept, regenerate, or edit the message before committing
  • Conventional commits - output follows the type: description format
  • Setup wizard - remembers your provider and model preference
  • Zero runtime dependencies - a single binary with no node_modules at runtime
  • Open source - MIT licensed and fully auditable on GitHub

Note: The quality of the generated commit message depends entirely on the model you choose. Smaller or less capable models may produce vague, overly long, or incorrectly formatted messages. If the output looks off, try regenerating or switch to a more capable model.

Requirements

Installation

npm install -g penmit

Quick Start

Local mode (Ollama)

  1. Install and start Ollama - follow the official Ollama installation guide.

  2. Pull a model (browse the Ollama library for all available models):

    ollama pull llama3.2
  3. Stage your changes and run:

    git add .
    penmit

    On first run, a setup wizard walks you through picking a provider and model. Your choice is saved and reused next time.

Ollama Cloud mode

Set your Ollama Cloud API key and run:

export OLLAMA_API_KEY=your_key_here
git add .
penmit

Or pass it inline for a one-off:

OLLAMA_API_KEY=your_key penmit

Anthropic (Claude)

Set your Anthropic API key and run:

export ANTHROPIC_API_KEY=your_key_here
git add .
penmit

Or pass it inline:

ANTHROPIC_API_KEY=your_key penmit

OpenAI (Codex / GPT)

Set your OpenAI API key and run:

export OPENAI_API_KEY=your_key_here
git add .
penmit

Or pass it inline:

OPENAI_API_KEY=your_key penmit

Usage

penmit [command] [options]

Commands:
  config                Show effective settings and where each value comes from
  models                List available models for the effective provider

Options:
  -m, --model <name>    Model to use (overrides saved default for this run)
  --local               Use local Ollama for this run
  --cloud               Use Ollama Cloud for this run
  --anthropic           Use Anthropic (Claude) for this run
  --openai              Use OpenAI for this run
  --setup               Re-run the setup wizard to change saved defaults
  --max-length <n>      Max commit message length (default: 72, saved to config)
  --max-diff-bytes <n>  Max staged diff size in bytes before warning (default: 20480)
  --no-redact           Disable secret redaction for cloud providers
  --json                Output as JSON (use with config or models)
  --reset               Delete saved settings and return to defaults
  -y, --yes             Skip confirmation prompt (use with --reset)
  -v, --version         Print version
  -h, --help            Show this help

Examples

# Use your saved defaults
penmit

# Show your effective settings (provider, model, key, endpoint) and their sources
penmit config

# List models available for your current provider
penmit models

# List Ollama Cloud models (some are subscription-gated)
penmit models --cloud

# Override the model for this run only
penmit --model mistral

# Force Ollama Cloud with a specific model
penmit --cloud --model gpt-oss:20b

# Use Anthropic for this run
penmit --anthropic

# Use OpenAI with a specific model
penmit --openai --model gpt-4o

# Enforce a max commit message length (saved for future runs)
penmit --max-length 50

# Raise the large-diff warning threshold to 50KB
penmit --max-diff-bytes 51200

# Re-run setup to switch provider or model
penmit --setup

# Delete saved settings entirely
penmit --reset

# Delete saved settings without confirmation
penmit --reset --yes

Environment Variables

Variable Description
ANTHROPIC_API_KEY Enables Anthropic (Claude). Overrides saved provider to anthropic.
OPENAI_API_KEY Enables OpenAI. Overrides saved provider to openai.
OLLAMA_API_KEY Enables Ollama Cloud. Overrides saved provider to cloud.
OLLAMA_HOST Custom local Ollama address (default: localhost:11434).
DEBUG=1 Print raw request/response payloads for troubleshooting.

Configuration

Provider and model preferences are saved to a config file after the first interactive run:

Platform Path
macOS / Linux ~/.config/penmit/config.json
Windows %APPDATA%\penmit\config.json

To change your saved defaults, re-run the setup wizard:

penmit --setup

To delete your saved settings entirely and start fresh:

penmit --reset

Secret Redaction

When using a cloud provider (Anthropic, OpenAI, or Ollama Cloud), penmit automatically scans your staged diff and redacts secrets before sending it. This runs by default - no setup required.

Detected patterns include:

  • AWS access keys and secret keys
  • GitHub, Slack, Stripe, and npm tokens
  • Anthropic, OpenAI, and Google API keys
  • PEM private keys (full key block, not just the header)
  • Bearer tokens
  • Connection strings with embedded passwords (e.g. postgres://user:pass@host)
  • Generic api_key, secret_key, access_token, password, etc. assignments

When secrets are found, you'll see a warning:

Redacted 2 potential secret(s) from the diff before sending to Anthropic.

The commit message is generated from the redacted diff. Your actual diff and git history are never modified.

Custom patterns

Add project-specific patterns in .penmitrc.json at the root of your repo:

{
  "redactPatterns": [
    { "name": "Internal API Key", "pattern": "\\bmyapp_secret_[a-z0-9]{12,}\\b" }
  ]
}

Or in your global config (~/.config/penmit/config.json) to apply across all repos.

Patterns are regular expressions. Use a capture group to redact only the secret value while preserving context:

{
  "redactPatterns": [
    { "name": "Internal Header", "pattern": "X-Internal-Token:\\s*(.{16,})" }
  ]
}

Disabling redaction

penmit --no-redact

Redaction is skipped entirely in local mode (Ollama) since your diff never leaves your machine.

Large Diff Protection

When your staged diff exceeds 20KB (default), penmit warns you before sending it to the LLM:

Staged diff is 45.2KB, which exceeds the 20.0KB limit.
Large diffs may be slow/expensive to process and produce lower-quality messages.
Proceed anyway? [y/N]

You can adjust the threshold (saved for future runs):

penmit --max-diff-bytes 51200   # 50KB

Or skip the prompt entirely with --yes / -y.

Interactive Prompt

After a commit message is generated, you are given three options:

Key Action
a / A / Enter Accept and run git commit -m "..."
r / R Regenerate with the same model
e / E Edit the message in a prompt
Esc / Ctrl+C Cancel and exit

Contributing

Contributions are welcome. Please open an issue first to discuss significant changes.

git clone https://github.com/iAmmar7/penmit.git
cd penmit
npm install
npm run build
npm test

License

MIT

About

AI commit message generator powered by Ollama, Anthropic, and OpenAI. Local-first, zero dependencies, built-in secret redaction.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages