Stop Your AI From Writing Commit Messages for Code You Didn't Stage
Suppose you add a todo validation test and tidy another test in the same file, then stage only the new test.
If your AI assistant writes a commit message describing both edits, the message promises a change that isn't in the commit. π¬
Agent Toolbox includes Good Commit, a reusable instruction file that tells an AI coding assistant to inspect the Git index before proposing a message. Below is a reproducible example using its small JavaScript demo.
π§ͺ Try It in a Fresh Clone
You'll need:
- Git
- Node.js (to run the demo tests)
- An AI assistant that can read files and run Git commands
No npm dependencies are required.
git clone https://github.com/zmo2s/agent-toolbox.git
cd agent-toolbox
git switch -c demo/partially-staged
1. Add a new test
Append this test to test/todo.test.js:
test("rejects an omitted title", () => {
assert.throws(() => addTodo(), /Todo title is required/);
});
Stage that addition:
git add test/todo.test.js
2. Make a second edit, but don't stage it
Rename the first test from creates a todo to creates an incomplete todo, and leave that rename unstaged.
Both edits are in the same file, but only the new test belongs in the next commit.
3. Inspect both patches and run the tests
git status --short
git diff --cached
git diff
npm test
What to expect:
| Command | Should show |
git status --short | MM test/todo.test.js |
git diff --cached | Only the appended test (staged) |
git diff | Only the rename (unstaged) |
π‘ In MM, the first M means staged changes and the second M means unstaged changes.
Test counts may change as the project grows.
π€ Ask for a Commit Message
From inside the clone, send your assistant this prompt:
Read .codex/skills/good-commit/SKILL.md and propose a commit message for my current changes.
An illustrative subject line:
test(core): β
cover omitted todo titles
β
What a good response looks like
The assistant should:
- Say that the proposal covers the staged test addition
- Mention the unstaged test-name edit separately
The assistant should not:
- β Include the rename in the commit description
- β Restage the entire file
- β Create a commit just because you asked for a message
Exact wording may vary. The key check: does the message match git diff --cached?
π Reuse It in Your Own Project
- Copy the Good Commit skill into your repository at:
.codex/skills/good-commit/SKILL.md
- Use the explicit prompt shown above.
- Want the
/skill-commit shortcut? You'll also need the routing instructions from AGENTS.md.
β οΈ Note: The skill provides instructions, not a guarantee of model behavior. Always review the patch and the proposed message before committing.
You can try this workflow without installing the separate Security Guardian policy.
π Help Improve the Examples
First-time contributors are welcome! Some ideas:
- π Document a breaking-change commit with migration guidance
- π Show separate messages for unrelated changes
Before starting, check the existing issues and open PRs, and follow the contribution guide.
π Repo: github.com/zmo2s/agent-toolbox