AI Commit Message Writer: how it works and how to build one
Write a clear git commit message from a diff or notes. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Paste the output of git diff, or a few notes on what you changed, and get a commit message with a short subject and a body that explains why. Supports Conventional Commits.
When to use it
- Cleaner git history
- Teams using Conventional Commits
- Summarizing a large change
How to use it
- Log in.
- Paste your diff or notes and pick a format.
- Copy the message into git commit.
Try it free with an Eskillsfy account: https://eskillsfy.com/tools/ai-commit-message
How it works
A diff shows what changed; a good commit message says why. The model reads the diff or your notes and writes a subject under 72 characters plus a short body.
Conventional Commits (feat:, fix:, docs:) is a common format that tools use to build changelogs and pick version numbers, so it is offered as an option.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any Node.js project.
server/routes/ai-commit-message.js (js)
// Express route. The prompt stays on the server, so the endpoint can only do this one job.
import { Router } from "express";
const router = Router();
const SYSTEM = (option) => `Write a git commit message for the user's diff. Format: ${option}. Subject under 72 characters, blank line, short body explaining why.`;
router.post("/ai-commit-message", requireUser, async (req, res) => {
const input = String(req.body.input ?? "").trim();
if (!input || input.length > 8000) return res.status(400).json({ error: "Send 1 to 8,000 characters." });
const option = ALLOWED.includes(req.body.option) ? req.body.option : ALLOWED[0];
// Any chat model works here: Gemini on Vertex AI, the Claude API, etc.
const r = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: { "x-api-key": process.env.ANTHROPIC_API_KEY, "anthropic-version": "2023-06-01", "content-type": "application/json" },
body: JSON.stringify({ model: process.env.AI_MODEL, max_tokens: 2048, system: SYSTEM(option), messages: [{ role: "user", content: input }] }),
});
if (!r.ok) return res.status(502).json({ error: "The AI service did not answer." });
const data = await r.json();
res.json({ output: data.content.map((b) => b.text ?? "").join("").trim() });
});
export default router;
Make it production-ready
- Put the API key in a secret manager and read it from an environment variable, never in frontend code.
- Require a login and add a per-user daily limit so one person can’t run up your bill.
- Validate the option against a fixed list so users can’t inject their own instructions.
- Show a loading state and a clear error when the provider is slow or down.
Questions
How do I copy my diff?
Run git diff –staged in your terminal and paste the output.
Free with an Eskillsfy account.