Overview
chainloop trace hooks into Claude Code and Git to automatically capture what happens during AI-assisted coding sessions — models used, tokens consumed, tools invoked, code changes produced, and more. Every git push bundles this data into a cryptographically signed attestation using the CHAINLOOP_AI_CODING_SESSION material type.
This gives security and engineering teams full visibility into how AI agents contribute to your codebase, without changing how developers work.
chainloop trace currently supports Claude Code sessions. Support for additional AI coding agents is planned.Why trace AI coding sessions
AI coding agents are productive — but without visibility, teams can’t answer basic questions:- Which commits were AI-assisted, and what models were used?
- How much did a session cost in tokens and dollars?
- What tools did the agent invoke, and how many times?
- What code changes did the agent produce?
chainloop trace answers all of these automatically. Combined with Chainloop’s policy engine, you can enforce governance rules — for example, requiring that AI-assisted commits use approved models or stay within token budgets.
How it works
chainloop trace init installs lightweight hooks into both Git and Claude Code that work together:
- When a Claude Code session starts, a hook records the session ID and begins copying session data (the JSONL transcript) into
.git/chainloop-trace/. - When you commit, a post-commit hook records the commit SHA, message, and which Claude Code session produced it.
- When you push, a pre-push hook parses all captured session data, correlates commits with sessions, and creates a signed Chainloop attestation with the full evidence.
.git/chainloop-trace/ is cleaned up automatically. The attestation lives in Chainloop, tied to your project and workflow.

Getting started
Prerequisites
- Chainloop CLI installed and authenticated
- A Chainloop project to associate traces with
- Git repository with Claude Code configured
Initialize tracing
Runchainloop trace init from your repository root:
- Creates the
.git/chainloop-trace/directory for local state - Installs Git hooks (
post-commitandpre-push) - Installs Claude Code hooks (
SessionStart,PreToolUse, andSessionEnd) into.claude/settings.json
.chainloop.yml file with a projectName field, you can omit the --project flag — the CLI resolves it automatically.
Work as usual
Once initialized, there’s nothing else to do. Write code with Claude Code, commit, and push. The hooks handle everything in the background.Remove tracing
To uninstall all hooks and clean up local state:.claude/settings.json, and the .git/chainloop-trace/ directory. If existing hooks were backed up during installation, they are restored.
Hooks in detail
Git hooks
| Hook | When it runs | What it does |
|---|---|---|
post-commit | After every git commit | Records commit SHA, message, timestamp, and active session ID to .git/chainloop-trace/commits/ |
pre-push | Before every git push | Parses all session data, builds evidence, and pushes a signed attestation to Chainloop |
Claude Code hooks
| Hook | When it runs | What it does |
|---|---|---|
SessionStart | When a Claude Code session begins | Records the session ID and starts copying session JSONL data |
PreToolUse | Before each tool invocation | Ensures the session is tracked (handles cases where SessionStart was missed) |
SessionEnd | When a Claude Code session ends | Performs a final copy of the session JSONL and marks the session as inactive |
.claude/settings.json:
What gets captured
TheCHAINLOOP_AI_CODING_SESSION evidence includes:
Session metadata
- Session ID, start/end time, and duration
- Claude Code version and session slug
Model and token usage
- Primary model and all models used during the session
- Input, output, and cache tokens
- Estimated cost in USD (based on published Anthropic pricing)
Tool usage
- Every tool the agent invoked (Read, Write, Edit, Bash, Grep, etc.)
- Invocation count per tool and total invocations
Conversation summary
- Total messages, user messages, and assistant messages
Subagent details
- Each subagent spawned: type, description, and token usage
Git context
- Repository URL, branch, and working directory
- Commit range (start SHA to end SHA) and full list of commits
- Merge-base detection against main/master
Code changes
- Files modified, created, deleted, renamed, or copied
- Lines added and removed
- Per-file status breakdown
Evidence structure
Applying policies
DefineCHAINLOOP_AI_CODING_SESSION in your contract to attach policies to traced sessions:
contract.yaml
Example: restrict to approved models
check-approved-models.yaml
Example: enforce token budget
check-token-budget.yaml
Inspecting traces in the platform
Once a trace attestation has been pushed, you can inspect it directly in the Chainloop Web UI. Navigate to the workflow run that contains theCHAINLOOP_AI_CODING_SESSION material.
Rendered view
The platform renders a structured summary of the session — model usage, token consumption, estimated cost, tool invocations, code changes, and git context — all in an easy-to-read format.
Raw view
Switch to the raw view to see the full JSON evidence as captured by the hooks. This is useful for debugging policies or understanding the exact data available for Rego evaluation.
Relationship to AI config collection
chainloop trace and the AI config collector are complementary:
| AI Config Collector | Chainloop Trace | |
|---|---|---|
| What it captures | Static configuration files (CLAUDE.md, settings, MCP config, rules, skills) | Runtime session data (tokens, tools, code changes, costs) |
| When it runs | During chainloop attestation init --collectors aiagent | Automatically on every git push via hooks |
| Material type | CHAINLOOP_AI_AGENT_CONFIG | CHAINLOOP_AI_CODING_SESSION |
| Use case | Governance over how agents are configured | Visibility into what agents actually did |
Related resources
- How to collect AI agent configuration — Collect static AI agent configuration files
- Material Types — Full list of supported material types
- How to write custom policies — Write Rego policies for your evidence
- Policies concept — How policies work in Chainloop
