Skip to content

About

pre-commit to automatically add all AI prompts to your commit message

Resources

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

ai-prompt-auto-commit

Tests License: GPL v3 pre-commit Claude Code

Automatically records every AI prompt you send and appends them to your git commit messages — so your commit history always reflects the AI assistance that shaped the code.

How it works

  1. Claude Code saves every prompt to .prompts/ as a timestamped file, named after the model that answered it (via a UserPromptSubmit hook in .claude/settings.json, which runs .claude/hooks/record-prompt.py). Only prompts you actually wrote are recorded — the turns Claude Code injects on its own, such as background-task notifications, are skipped. Other models can also be instructed to record prompts.
  2. On git commit, the prepare-commit-msg hook reads all pending prompts and appends them to the commit message under an AI Prompts: section.
  3. After the commit, the post-commit hook moves the used prompts to .prompts/committed/, tagged with the commit hash, so they are archived but not reused.

Commit message example

Fix login redirect bug

AI Prompts:
claude-sonnet-4-6: why does the redirect fail after OAuth callback?
claude-sonnet-4-6: rewrite the session middleware to preserve the return URL

Example Commit

Requirements

Installation

1. Add to .pre-commit-config.yaml

Add the following to your repository's .pre-commit-config.yaml (create it if it doesn't exist):

default_install_hook_types: [pre-commit, prepare-commit-msg, post-commit]

repos:
  - repo: https://github.com/pycalendar/ai-prompt-auto-commit
    rev: v0.0.10
    hooks:
      - id: prepare-ai-repository
      - id: unstage-ai-prompts
      - id: append-ai-prompts
      - id: archive-ai-prompts

2. Install the hooks

This needs to be run for every clone:

pre-commit install

This installs all three git hooks (pre-commit, prepare-commit-msg, post-commit) in one step.

3. Set up the repository

This needs to be run once for each repository:

pre-commit run --hook-stage manual prepare-ai-repository

This runs the one-time setup (using the manual stage) and will:

  • Create a .prompts/ directory with a .gitignore that prevents prompt files from being committed
  • Install the prompt-recording script as .claude/hooks/record-prompt.py
  • Install the Claude Code UserPromptSubmit hook into .claude/settings.json so prompts are recorded automatically (merges safely with existing settings)

Updating

To update the hooks:

pre-commit autoupdate
git add .pre-commit-config.yaml
pre-commit run --hook-stage manual prepare-ai-repository

pre-commit refuses to run while .pre-commit-config.yaml has unstaged changes, hence the git add between the two.

Contributing prompt recording for another AI

.github/assistant-guidelines.md tells AI models how to record each of your prompts. We welcome your contribution!

Supported AI models

This pre-commit supports the following AI models:

Model ID in commit message
Any Claude model recorded automatically, e.g. claude-opus-5 or claude-sonnet-4-6
GitHub Copilot manual prompt recording

Claude model IDs are taken verbatim from the session transcript, so new models need no change here.

Claude

The recording is done automatically through the hooks. The model name is read from the session transcript, which records a model only once it has answered. The name is therefore the model that answered the previous turn: after a /model switch, the first prompt you send is still attributed to the model you switched away from, and only the ones after that are right. A prompt sent before the assistant has answered even once — the first prompt of a session — is recorded as unknown, because at that point nothing has stated which model is answering.

Trouble Shooting

If no files are created in .prompts:

  • Restart the editor or session.
  • Or open /hooks in Claude Code (the UI menu) to reload config.

After that, the hook will fire on every prompt.

GitHub Copilot

Prompt the AI:

Save all prompts according to the assistant guidelines

Scripts

You can record prompts manually or instruct the AI to use the script.

record-ai-prompt --prompt "<your prompt>" --model "<model used>"

Or pipe text into it:

printf "%s" "<your prompt>" | record-ai-prompt

File layout

.claude/
  settings.json                               ← calls the hook below on each prompt
  hooks/
    record-prompt.py                          ← installed by prepare-ai-repository
.prompts/
  2026-04-12T20-35-51_claude-sonnet-4-6.txt   ← pending (not yet committed)
  committed/
    2026-04-12T20-10-00_claude-sonnet-4-6_a2e1ca7....txt  ← archived after commit

.claude/hooks/record-prompt.py is rewritten every time prepare-ai-repository runs, so edit the copy in this project rather than the one in your repository.

Changelog

You can view the versions in the change log.

Release new versions

To release a new version:

./release 0.0.5

Related work

  • cairn - Tool-free convention that keeps, beside your code, a living spec of what the system does now plus a dated log of how it got there, readable by any agent, human or AI.

About

pre-commit to automatically add all AI prompts to your commit message

Resources

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages