Guide · Claude Code provenance

How to Track Claude Code Prompts and Diffs in Git

Claude Code can edit real repositories. The missing workflow is durable provenance: prompt, agent identity, changed files, tests, and review context stored next to the commits.

Key takeaways
  • A human wires the hooks once (h5i hook setup --write); after that, prompt, trace, and diff capture happen automatically.
  • Manual capture (--intent) is for humans, CI, or Codex where no prompt-capture hook runs; hook-based capture is the automatic Claude Code path.
  • Because the prompt, edits, and test evidence live in Git, a reviewer can later reconstruct how a change came to be.

An auditable workspace is where prompt provenance lives: who asked, what the agent knew, what it changed, and what evidence supports the result, all versioned in your repo. Claude Code already works inside a Git repository. That means every edit can end in a normal commit and pull request. The problem is that Git does not automatically store the Claude Code prompt, the model identity, the files Claude observed, or the test evidence behind the change.

h5i fills that gap by capturing AI provenance as Git-sidecar data. The repository still behaves like a normal Git repo. The AI layer gives reviewers and future maintainers a way to answer, "what did Claude Code do, and why?"

What to capture

For Claude Code work, capture at least five fields: the task prompt, the agent name, the model if known, the changed commit, and the test result. For longer sessions, also capture context traces and decisions. Those records make the diff explainable without storing an entire chat transcript in the commit message.

Manual capture

Who types this: a human or a script, in any setup with no prompt-capture hook — Codex, CI, or a hand-run commit. You pass the prompt explicitly with --intent because nothing recorded it for you:

~/repo
$ h5i capture commit -m "add retry handling" \
  --agent claude-code \
  --model claude-sonnet-4-6 \
  --intent "add retry handling to the API client" \
  --tests

Then inspect it later:

~/repo
$ h5i recall log --limit 5
$ h5i recall blame src/api/client.py --show-prompt

Hook-based capture

Claude Code hooks are user-defined commands or endpoints that run at lifecycle events. Anthropic's hooks reference documents events such as SessionStart, UserPromptSubmit, PreToolUse, and PostToolUse, with JSON context passed to hook handlers. h5i uses that mechanism to make provenance capture less manual.

Who types this: a human, exactly once. Install the wiring and you are done:

~/repo
$ h5i hook setup --write  # writes ./.claude/settings.json (--scope user for ~/.claude); idempotent

After that, nobody types h5i hook claude … by hand — Claude Code's runtime fires the handlers automatically at four moments: h5i hook claude prompt (on UserPromptSubmit) captures the verbatim prompt, which then beats any agent-supplied --intent at commit time; h5i hook session-start (on SessionStart) injects prior context; h5i hook claude sync (on PostToolUse) records tool-use traces after edits; and h5i hook claude finish (on Stop) checkpoints the context when the turn stops. Codex wires only two handlers (SessionStart and Stop); it has no per-prompt or per-edit hook, which is why Codex commits fall back to the Manual capture path above.

What this gives reviewers

A reviewer can see the ordinary diff and the AI context around it. That context answers whether the prompt asked for exactly this behavior, whether the agent touched files outside scope, whether tests ran, and whether the agent recorded a risky assumption.

The better workflow is not "trust Claude Code because it wrote a clean diff." It is "review Claude Code with the prompt, diff, tests, and trace in one packet."

What not to put in commit messages

Do not turn every Claude Code transcript into a commit message. Commit messages should stay readable for humans scanning history. Detailed prompts, tool traces, long test logs, and uncertainty notes belong in sidecar provenance where they can be queried, redacted, and rendered into review surfaces when needed.

The split keeps Git useful. The commit title says what changed. h5i records why the agent changed it, which commands ran, which files were observed, and what evidence supports the result. Reviewers can expand that context without forcing every future git log reader through a transcript.

FAQ

Does this require rewriting Git history?

No. h5i stores provenance alongside Git history rather than changing the commit object after the fact.

Should the full prompt be public?

Not always. Teams should treat prompts as potentially sensitive and decide what to share. h5i sharing is explicit through h5i refs rather than automatic through plain git push.

Can this track diffs without Claude Code hooks?

Yes. You can use manual h5i capture commit and ordinary Git diffs. Hooks reduce the chance that humans forget to capture the context.

Sources and verification

This article avoids vendor-specific claims that were not checked against primary docs or local h5i CLI behavior.

Capture prompt provenance on every Claude Code commit

Try h5i on your next AI-assisted branch: create a sandboxed workspace, capture the run, and post a review-ready PR brief.

Star on GitHub Read the guides