Omniscio

OmniscioGuidesAn auto-commit hook

A Claude Code hook that commits after each batch of edits

A checkpoint after every change is the cheapest undo a session can have: git diff shows exactly what the last batch did, and git reset is one command away. Asking Claude to commit knows no such certainty — it is a request the model may follow partially, or late, or not at all.

A hook removes the model from that decision. Your command runs at a fixed point in the lifecycle, and the point that matters here is the end of a batch of edits.

Checked against Anthropic’s Claude Code hooks documentation on November 25, 2026. By the Omniscio team. Updated .

The hook, complete

Two things before the code: the script needs jq, and it needs to be executable. Install jq with brew install jq on macOS, sudo apt-get install jq on Debian and Ubuntu, or winget install jqlang.jq on Windows, then save the script to .claude/hooks/auto-commit.sh and run chmod +x on it. Without jq the hook does nothing at all and says nothing, which is the failure the last section of this page deals with.

#!/bin/bash
set -u
input=$(cat)
cwd=$(jq -r '.cwd // empty' <<<"$input")
[ -z "$cwd" ] && exit 0
cd "$cwd" 2>/dev/null || exit 0
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
for state in rebase-merge rebase-apply MERGE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_LOG; do
  [ -e "$(git rev-parse --git-path "$state")" ] && exit 0
done
git add -A 2>/dev/null || exit 0
git diff --cached --quiet && exit 0
changed=$(git diff --cached --name-only | wc -l | tr -d ' ')
git commit -q --no-verify -m "checkpoint: $changed file(s) edited by Claude Code" >/dev/null 2>&1
exit 0
{
  "hooks": {
    "PostToolBatch": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/auto-commit.sh",
            "timeout": 30
          }
        ]
      }
    ]
  }
}

A script without the execute bit does not run, and the shell’s message lands in the transcript notice rather than blaming your git setup. Windows has no execute bit, but a .sh saved with Windows line endings fails in Git Bash, so keep the file LF.

On Windows a shell-form command hook runs in Git Bash, so the script itself is fine there. Without Git Bash, set "shell": "powershell" on the handler and write the equivalent in PowerShell, or leave the hook off on that machine.

The problem it solves

A long session makes dozens of edits, and the point where they went wrong is rarely the point where you notice. Without checkpoints the only undo is the editor’s, which covers one file and one keystroke, or the conversation’s, which covers nothing on disk.

A checkpoint commit per batch turns that into a diff you can read and a commit you can throw away. It is not a substitute for a considered commit at the end of the work — the messages are generated and the cut points are arbitrary — and it is not a substitute for review. It is what makes the next mistake cheap.

What each line does

PartJob
"PostToolBatch"The event: it runs once after every tool call in a batch has resolved, before Claude Code sends the next request to the model.
No matcherPostToolBatch has no matcher support, so the block carries none. A matcher added to an event without matcher support is silently ignored.
"\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/auto-commit.sh"Finds the script at the project root, which is what that variable is for. The script then commits wherever the event says Claude is working.
"type": "command"Runs a shell command and hands it the event’s JSON on stdin.
jq -r '.cwd // empty'Reads the directory Claude is working in. It follows Claude into a worktree and after a cd, which $CLAUDE_PROJECT_DIR does not.
git rev-parse --is-inside-work-treeExits quietly when the folder is not a repository, so the hook is harmless in a scratch directory.
the state loopExits when a rebase, merge, cherry-pick, revert or bisect is in progress. A commit written into one of those states does real damage.
git add -AStages the whole working tree, not one file, because a batch can include Bash calls that the event cannot attribute to a path.
git diff --cached --quietExits 0 when nothing is staged, which is the common case after a batch of reads. Without it every read produces a failed commit.
--no-verifySkips the repository’s own pre-commit and commit-msg hooks. A checkpoint should not run a test suite, and a pre-commit hook that calls Claude would recurse.
timeout: 30Seconds. A command hook defaults to ten minutes, which is far too long to wait on a commit.

The exit code is deliberately 0 everywhere, including on the paths that do nothing. A PostToolBatch hook exits 2 to stop the agentic loop before the next model call, and a checkpoint that cannot be taken is not a reason to stop the session. Anything other than 0 or 2 is a non-blocking error, so a stray failure only puts a notice in the transcript.

Why PostToolBatch and not PostToolUse

PostToolUse fires once per tool. When Claude makes parallel tool calls, those hooks fire concurrently, which means two of them can run git add and git commit against the same index at the same moment. Git takes a lock for that, one wins, the other fails, and you get either a lost commit or a non-blocking error in the transcript.

PostToolBatch fires exactly once with the full batch, so the index is touched once. It also sees the whole batch, which is what a checkpoint is: not “this file changed” but “this round of work finished”.

The trade-off is what the hook can know about the calls. PostToolBatch passes tool_calls, an array of every call in the batch, with the same response shape the model sees rather than the structured output object PostToolUse gets. If you would rather commit per file, the per-tool event is the one to use, and you will need to serialise it yourself.

One rolling checkpoint instead of forty

A busy session can produce dozens of commits, which is noise in a review. If the commit on the tip is already a checkpoint, amend it instead of adding another, and the session keeps exactly one. Swap only the commit lines of the script above — keep everything from the shebang to the state loop, so the guard and the cwd read stay in place.

git add -A 2>/dev/null || exit 0
git diff --cached --quiet && exit 0
changed=$(git diff --cached --name-only | wc -l | tr -d ' ')
msg="checkpoint: $changed file(s) edited by Claude Code"
case "$(git log -1 --format=%s 2>/dev/null)" in
  checkpoint*) git commit -q --no-verify --amend -m "$msg" >/dev/null 2>&1 ;;
  *)           git commit -q --no-verify -m "$msg" >/dev/null 2>&1 ;;
esac
exit 0

That rewrites the tip commit every batch, so it is safe only while nothing has been pushed. The moment you push, go back to plain commits and squash before the pull request, or the next amend will need a force-push to reach the remote.

Either way the hook writes to the repository, so the script runs with your full user permissions. Anthropic’s own guidance is to review and test a hook command before adding it, which is worth taking literally for one that commits.

How to test that it fires

  1. Run the script by hand, with sample JSON. This is the test that separates a broken script from a hook that never ran:
    mkdir -p /tmp/actest && cd /tmp/actest && git init -q
    git config user.email you@example.com && git config user.name "Your Name"
    printf "a\n" > f.txt
    echo '{"cwd":"/tmp/actest"}' | /path/to/.claude/hooks/auto-commit.sh; echo $?
    git log --oneline
    You should see one commit and an exit code of 0. Run it a second time with no change to the file: nothing new is committed and the exit code is still 0.
  2. Check the hook is registered. Type /hooks in a session. It is a read-only browser that lists each hook under its event and says where it comes from; if the block is not there, the hook is not registered — usually invalid JSON, sometimes the wrong settings file, or a managed policy that limits which hooks may run.
  3. Ask for a real edit and read the log. Ask Claude to change one line of a source file, then run git log --oneline -3. A hook that works shows nothing in the conversation; the commit is the evidence.
  4. Read the debug log when it does not. Start with claude --debug-file /tmp/claude.log and watch it in another terminal with tail -f /tmp/claude.log, or run /debug mid-session. A hook that cannot start is recorded as a failed run, and its error text is copied into the log.

If step one works and the session still does nothing, the hook is not registered — which /hooks answers in a second.

What makes this hook go wrong

1. It commits everything that was already dirty

git add -A stages the tree, not the batch. A change you made by hand before the session, a generated file, a half-finished experiment — all of it lands in the checkpoint, and the checkpoint message claims Claude made it. Enable the hook from a clean tree, or swap git add -A for git add -u if you only ever want tracked files.

2. A secret goes into the history

A checkpoint commit is a commit: a .env that Claude read and then rewrote, a key pasted into a config file, a token in a scratch script. Anthropic’s security guidance says to skip sensitive files such as .env, .git/ and keys, and the place to enforce that is before the commit. A .gitignore entry and a hook that blocks .env access are both cheaper than rewriting history.

3. It commits in the middle of a rebase, merge, cherry-pick, revert or bisect

Git holds an operation open across several commands, and a commit written while one is in progress either aborts it or attaches to the wrong step. The state loop in the script above is the guard for all five; drop it and the first git rebase you run with the hook on will show you why it was there. If you edited the script, test the guard by creating .git/MERGE_HEAD by hand and confirming nothing is committed.

4. It commits work a Bash command did outside the repository

A hook runs in the directory Claude is in, and cwd follows a cd. A session that wanders into a vendored dependency or a second checkout commits there instead of where you expected. Read cwd before trusting the script in a monorepo.

5. Nothing happens at all

Three different things produce the same silence, and they are not the same failure. A missing jq leaves cwd empty, so the script exits 0 early: no commit, no notice, nothing in the transcript, because a hook that exits 0 is a success. An invalid settings file means the hook was never registered, so there is nothing to run and nothing to report. Only a script without the execute bit fails loudly, and its message arrives as a <hook name> hook error notice.

The script adds one more case on purpose: a failed git add or git commit becomes a quiet exit 0, so a held index lock or a missing git identity looks exactly like a batch with nothing to commit. That is the price of never blocking a turn, and the reason to run the script by hand once before trusting it.

Where Omniscio fits

A checkpoint hook belongs in the project, and the project is the right place for it: commit .claude/settings.json and the whole team gets the same checkpoints. Omniscio takes the other angle. Its Hooks panel composes the hooks it ships, and any you define, into every session it spawns, keeping them in its own database rather than writing into your global Claude configuration, with a global switch and per-project overrides.

The hooks examples hub collects the other recipes, the Claude Code hooks guide covers every event, and the hooks builder assembles a block like this one from the event, matcher and handler you pick. Omniscio runs on Windows, macOS and Linux, and the pricing page covers the plans.

How this page was written

Everything about events, batch behaviour, matcher support, input fields, exit codes, timeouts and handler fields was read from Anthropic’s Claude Code hooks reference on November 25, 2026, quoted from the page as it reads today.

The script was run on this machine against a throwaway repository for the two cases the test describes. No live Claude Code session was configured to run it, so the page describes the documented behaviour of the block and the measured behaviour of the script, not a watched session.

Sources

  • Anthropic’s Hooks reference, for the event list, PostToolBatch input and decision control, matcher support, exit codes, handler fields and the security guidance, read November 25, 2026.
  • Anthropic’s Automate actions with hooks, for the advice to test a hook by piping sample JSON into it, read November 25, 2026.

Common questions

Can Claude Code commit automatically after every edit?

Yes, with a hook that runs git after Claude’s tool calls. PostToolBatch is the event to use: it runs once after every tool call in a batch has resolved, so a run of parallel edits produces one commit instead of several racing on the same index.

Should the auto-commit hook run async?

Usually not. A checkpoint commit is fast, and PostToolBatch already runs after the batch has finished. Async buys nothing here and costs you the ordering: an async commit can still be running when the next batch starts, so two commits can collide. async is available on type: "command" handlers only.

Why did it commit the wrong files?

A hook commits the working tree, not a list of files the event names, so anything already dirty gets swept in. Start from a clean tree before you switch it on, or narrow git add to tracked files.

Does it fire while Claude is rebasing?

It will try unless you stop it. A commit made mid-rebase or mid-merge writes into a state git is holding open. The script here exits early whenever a rebase, merge, cherry-pick, revert or bisect is in progress.

Can I use this with a worktree?

Yes, and read the directory from the event rather than from $CLAUDE_PROJECT_DIR. That variable keeps pointing at the project root where the session started, while the cwd field follows Claude into a worktree. A script that commits at the project root would checkpoint the wrong checkout.

Every session, the same checkpoints

Omniscio runs your Claude Code sessions side by side and composes the hooks it ships, and any you define, into every one it spawns, so a checkpoint rule does not depend on which folder you opened.

The features page covers what else it does, pricing covers the plans, and you can download it for Windows, macOS or Linux.