LocalCommit: Offline Conventional Git Commits with Local LLMs

LocalCommit: Offline Conventional Git Commits with Local LLMs

# devchallenge# weekendchallenge# hf26challenge
LocalCommit: Offline Conventional Git Commits with Local LLMsGaurav Sethi

This is a submission for the Hacktoberfest Weekend Challenge: Build for a Friend...

This is a submission for the Hacktoberfest Weekend Challenge: Build for a Friend (https://dev.to/challenges/hacktoberfest-weekend-2026-10-01)

What I Built

I built LocalCommit, a lightweight CLI tool that inspects your staged git diffs and drafts concise Conventional Commit messages (feat(auth): add refresh token rotation) running entirely on your local machine using Ollama.
I built this for my friend Manish, a software engineer working under strict client non-disclosure agreements. Manish's team requires strict Conventional Commits for automated changelogs and semantic releases, but company policy strictly forbids piping source code or git diffs to proprietary cloud LLM APIs (like OpenAI or Anthropic). Whenever Manish makes multi-file changes across large codebases, writing detailed conventional commit messages by hand slows down their workflow.
LocalCommit solves this by reading git diff --staged and running inference on an open-weights model locally. Zero tokens leave the machine, no API keys are required, and the tool works even when working offline on a train or during an internet outage.

Demo

Here is how running LocalCommit looks in terminal:

$ git add src/auth/token.ts src/middleware/jwt.ts
$ npx localcommit
[localcommit] Checking staged changes...
[localcommit] Sending diff to qwen2.5-coder:3b...

Proposed commit message:
  feat(auth): implement refresh token rotation and validation

Commit with this message? [y/N/e (edit)/r (regenerate)]: y
[main 7f2a1b9] feat(auth): implement refresh token rotation and validation
 2 files changed, 48 insertions(+), 6 deletions(-)
You can confirm with [y] to commit immediately, hit [e] to edit in place, [r] to regenerate with a slightly different phrasing, or [n] to cancel without touching git state.
Enter fullscreen mode Exit fullscreen mode

Code

The source code and setup instructions are open source on GitHub:

GitHub logo Gaurav5189 / LocalCommit

Local-first CLI for generating conventional commit messages via Ollama.

LocalCommit

Local-first CLI for generating conventional commit messages with Ollama.

LocalCommit reads your staged Git diff, generates a Conventional Commit message with the configured local model, and asks for confirmation before committing.

Requirements

  • Node.js 18+
  • Git CLI
  • Ollama
  • A model configured in the root model file (default: qwen2.5-coder:3b)

If Ollama is not installed, follow the platform-specific instructions in INSTRUCTION.md.

Setup

npm run setup
Enter fullscreen mode Exit fullscreen mode

The setup command verifies Node.js and Git, checks that Ollama is running, downloads qwen2.5-coder:3b if it is missing, installs dependencies, and builds the project.

If setup reports that Ollama is unavailable, install it and start the Ollama service by following INSTRUCTION.md.

Usage

Start Ollama in a separate terminal if it is not already running:

ollama serve
Enter fullscreen mode Exit fullscreen mode

Stage your changes in a Git repository, then run:

npx localcommit
Enter fullscreen mode Exit fullscreen mode

Inside a checkout of this project, npx localcommit resolves the local package binary. To use it from…


Repository link: Gaurav5189/LocalCommit

How I Built It

LocalCommit is written in TypeScript and connects to Ollama (https://ollama.com/) running locally:

  1. Default Model: By default, it targets qwen2.5-coder:3b—a fast, open-weights code model capable of running with low latency on modest CPU or laptop GPU hardware without draining battery.
  2. Context Auto-Detection: Instead of assuming a static token limit, LocalCommit queries Ollama's /api/ps and /api/show endpoints at runtime to discover the exact context window allocated by your environment.
  3. Two-Stage Summarization for Large Diffs:
  4. Small diffs fit in a single prompt and produce an immediate message.
  5. For larger, multi-file changes exceeding the context window, it switches to a hierarchical strategy: it prioritizes source code files (src/, tests/), generates concise per-file summaries bounded by a strict 60-second budget, and feeds that synthesized context into a final commit prompt.
  6. Deterministic Post-Processing: Small local models can occasionally output markdown fences or descriptive preambles. LocalCommit passes the raw output through a deterministic formatting engine that enforces standard type(scope): subject syntax, cleans generic scopes, and converts verbs into imperative mood (add, fix, refactor).
  7. Cross-Platform Host Detection: Handles network boundary quirks across Linux, macOS, Windows, and containerized setups (like Docker) by probing OLLAMA_HOST, 127.0.0.1:11434, and localhost:11434.

Why Does Open Innovation Matter?

Open-weights models and local runtimes like Ollama make use cases possible that cloud AI endpoints fundamentally cannot support:

  • Complete Data Sovereignty & Privacy: Codebases under NDAs, proprietary IP, or internal air-gapped networks cannot send raw git diffs over external APIs. Open models let developers use AI assistance without ever leaking code.
  • Offline Reliability: You don't need active Wi-Fi, metered bandwidth, or cloud service uptime to commit your work.
  • Zero Ongoing Costs & No API Keys: Developers don't have to manage credit cards, rate limits, or monthly token bills.
  • Flexibility to Swap Models: You can drop in any local model (e.g. llama3.2, codellama, deepseek-coder) simply by editing the model file or setting the LOCALCOMMIT_MODEL environment variable.

My Agent Session

The development session where I debugged the container connectivity issues and fixed the Ollama host resolution:

LocalCommit: Fixing cross-platform Ollama connectivity for containers
You

The setup script and CLI are failing to connect to Ollama in GitHub Codespaces because localhost resolves to ::1 but Ollama binds to [REDACTED]. Need multi-host resolution and proper URL construction.

Agent

I'll create a shared Ollama client utility for host resolution and fix both the setup script and CLI.

You

Build succeeded but setup still fails - need to debug the http.get call in setup.js

Agent

Found the issue - urlObj.toString() + '/api/tags' creates double slash. Fixed with new URL(path, base).

You

Setup now works. But when model in 'model' file doesn't match installed Ollama model, error message is unclear. Add guidance to run 'npm run setup'.

Agent

Added special case handling for 404 'model not found' error with actionable message pointing to 'npm run setup'.

You

Now help me write a DEV post for Hacktoberfest Weekend Challenge submission.

Prize Categories

  • Hacktoberfest Weekend Challenge: Build for a Friend
  • Open-Source AI / Open Weights Integration (Llama 3.3, Qwen 2.5, gemma 4)
  • Local Inference & Edge AI (Ollama 100% offline laptop execution)

LICENSE

This project is open source and available under the MIT License.