# Commit changes with a generated message

Have Claude Code read the diff, check for files that should not go in, and commit with a message that says what changed and why. It does not push.

Paste into: **Claude Code**, started in your project folder

## Prompt template

How the builder on the page fills in this template, so you can do the same:

- `{{key}}` becomes the text entered for that field, exactly as typed. Empty text, or text that is only whitespace (spaces, tabs or line breaks), counts as empty: a required field then becomes `[fill in: <label>]` with its label, and an optional field becomes nothing.
- For a choice field, `{{key}}` becomes the text of the chosen option, or of the default when none is chosen.
- Text between `{{#key}}` and `{{/key}}` stays only when that field is not empty; a choice field always counts as filled. The markers themselves are removed, and a marker that stands alone on its line takes its line break with it.
- Each value is inserted once, as it is: `{{…}}` inside a value stays as typed.

```text
Commit these changes with a message that summarizes what I did. Changes to commit: {{scope}}
{{#why}}

Why I made them:
{{why}}
{{/why}}

Before committing:
1. Run git status and read the full diff of what will be committed. Base the message on the diff, not on file names.
2. Check the diff for anything that should not be committed: secrets, local config, debug output, large generated files or unrelated edits. If you find any, stop and list them instead of committing.
3. Write the message in {{style}}.

How to commit: {{split}}.

The message: a short subject line that says what changed, then a body that says why when the subject does not make it obvious. Do not invent a reason. If the why is not clear from the diff{{#why}} and my notes{{/why}}, ask me.

Rules:
- Do not push, amend or rewrite existing commits, and do not edit any files.
- If a pre-commit hook fails, show me its output and stop. Do not skip hooks.

When done, show me the commit hash, the full message and the files in each commit.
```

## Fields

- `{{scope}}` (required): Changes to commit.
- `{{why}}`: Why you made the change. Optional. The diff shows what changed; only you may know why. Add a ticket number if your team uses them.
- `{{style}}`: Message format. Choose one:
  - the same style as the recent commits in this repository (check git log) (default)
  - the Conventional Commits format, with a type prefix such as fix: or feat:
- `{{split}}`: Number of commits. Choose one:
  - make one commit for all of it (default)
  - if the changes do unrelated things, propose separate commits and show me the grouping before committing

This site doesn't run Claude or show model output. Results depend on your input and the model you use.

## When to use this template

- You finished a change and want a commit message that matches what the diff actually contains, without writing it from memory.
- Your working tree mixes several edits, and you want them checked for stray files or grouped into separate commits before anything is recorded.
- Your repository has a commit style, such as a type prefix or a ticket number in the subject, and you want each message to follow it.

## When not to use it

- You want the changes pushed and turned into a pull request as well. Use the pull request template, which bounds pushing separately.
- The change is still in progress and you only want a checkpoint for yourself. A quick local commit or a stash is enough, and Claude Code checkpoints already let you rewind its own file edits.
- You are cleaning up history that is already pushed, such as squashing or rewording old commits. That rewrites shared history and needs your own judgment.

## Why this structure

- The changes field says what goes in, so Claude commits the files you meant rather than everything in the working tree.
- Step 1 bases the message on the full diff, because a message written from file names describes where the change is, not what it does.
- Step 2 tells Claude to stop and list secrets, local config or unrelated edits it finds instead of committing them. Once a file is committed and pushed, removing it cleanly is much harder.
- The why field and the rule against inventing a reason exist because the diff shows what changed but rarely why. A made-up reason in history misleads the next reader.
- The no-push rule bounds the task to your machine. In auto mode, Claude Code treats a boundary you state in the conversation, such as "do not push", as a reason to block that action.
- Asking for the hash, message and file list at the end gives you evidence to check in seconds, instead of opening git log yourself.

## Example input (fictional)

Changes to commit:

```
only the files in src/reports and its tests
```

Why you made the change:

```
Exports used the server timezone, so reports for other regions showed the wrong day.
```

Message format:

```
the same style as the recent commits in this repository (check git log)
```

Number of commits:

```
make one commit for all of it
```

## Follow-ups to send Claude

- Shorten the subject line to under 50 characters and move the details into the body.
- Split the last commit into two: one for the timezone fix and one for the new tests. Show me the plan before you change anything.
- Now push this branch and open a pull request with a description based on the commit messages. Ask me before pushing.

## Common mistakes

- Asking for a commit with no scope while unrelated edits sit in the working tree. Name the files or folders, or ask Claude to propose a grouping first.
- Accepting a message that only repeats the diff, such as "update report.js". Give the reason in the why field so the body explains the change.
- Allowing `git commit` without review and assuming nothing else runs. If you add it to your permission allowlist, still read the summary Claude shows after each commit.

## Related templates

- [Draft release notes from git history](https://awesomeclaudeprompts.com/prompts/release-notes-from-git/): Have Claude Code compare two git tags or branches and draft release notes grouped into breaking changes, features and improvements for your readers.
- [Resolve merge conflicts and explain the result](https://awesomeclaudeprompts.com/prompts/resolve-merge-conflicts/): Tell Claude Code what each branch was meant to do; it resolves the conflicts, runs your checks and explains what it kept from each side.
- [Open a pull request from a ticket](https://awesomeclaudeprompts.com/prompts/pull-request-from-ticket/): Point Claude Code at a ticket in your connected tracker; it reads it, implements the change on a new branch, runs the tests and prepares the pull request.

## Sources

- [Claude Code docs: Prompt library](https://code.claude.com/docs/en/prompt-library) (Anthropic documentation)
- [Claude Code best practices: Explore first, then plan, then code](https://code.claude.com/docs/en/best-practices#explore-first-then-plan-then-code) (Anthropic documentation)
- [Claude Code best practices: Configure permissions](https://code.claude.com/docs/en/best-practices#configure-permissions) (Anthropic documentation)
- [Claude Code best practices: Rewind with checkpoints](https://code.claude.com/docs/en/best-practices#rewind-with-checkpoints) (Anthropic documentation)
- [Claude Code docs: Boundaries you state in conversation](https://code.claude.com/docs/en/permission-modes#boundaries-you-state-in-conversation) (Anthropic documentation)

---

Awesome Claude Prompts is an independent project. It is not affiliated with, endorsed by, or sponsored by Anthropic. Claude is a trademark of Anthropic, PBC.
