Positioning and Purpose
agentdiff is an open-source, Git-native AI code provenance tool. It integrates with mainstream AI coding agents—Claude Code, Cursor, Copilot, Codex, Windsurf, OpenCode, Gemini—and writes permanent, commit-scoped attribution records into the repository. Each record captures the agent name, model, prompt excerpt, and precise line ranges, and is signed using ed25519. Everything can be queried via the CLI, with no server required.
The tool is positioned as a "source code line attribution layer"—recording which agent wrote which line, as signed evidence. Attribution is recorded and signed at the time of writing, so it is persistent evidence rather than after-the-fact estimation.
Main Capabilities
- Cross-agent collection: Integrates with Claude Code, Cursor, Codex, Copilot, Windsurf, OpenCode, Gemini via hooks.
- What is recorded: Each AI-assisted edit generates a trace entry containing the agent name and model (such as claude-code, claude-sonnet-4-6), a short prompt excerpt (the first approximately 100 characters requested from the AI), optional structured context from MCP or record-context.py (intent, files_read, flags, trust score), the affected file paths and line ranges, timestamp, and session ID.
- Signing and verification: Each trace entry can be signed with an ed25519 key pair, making tampering detectable. Signing keys are registered per developer in refs/agentdiff/keys/{key_id}:pub.key, and agentdiff verify looks up the signature's key_id in the key registry, so traces signed by any team member's key can be verified without manually exchanging public keys.
- Three-layer storage: The refs/agentdiff/* namespace lives outside refs/heads/*, so branch protection rules will not block it. UUIDs are preserved after squash/rebase/cherry-pick, and traces are not lost due to SHA rewrites.
- Policy enforcement: AI attribution rules can be defined in .agentdiff/policy.toml; agentdiff policy check exits with code 0 when it passes and 1 when it is violated, and the scope can be limited with --since <sha>.
- GitHub workflows: One command can write two workflow files—agentdiff-consolidate.yml (triggered on PR merge: merges branch traces into permanent storage and posts an attribution comment on the PR), agentdiff-policy.yml (triggered on every PR: runs the policy check and posts a GitHub check annotation if rules are violated).
- MCP context service: agentdiff-mcp is a stdio MCP server that exposes the record_context tool, allowing structured metadata to be written before commit; when an agent calls record_context, the prompt, model, session ID, files read, intent, and trust score are stored and attached to the next ledger entry.
Usage
Requirements: Python 3.7+ in PATH, Git 2.20+, Rust 1.85+ (installed automatically if missing).
Initial setup:
agentdiff configure— one-time global setup. Installs the Python collection scripts to ~/.agentdiff/scripts/ and registers hooks with the selected agents. In an interactive terminal, a Space/Enter multi-selector is shown; in scripts, --all or --agents cursor,codex can be used to avoid prompting. The Claude MCP server is registered only when Claude Code is selected. You can useagentdiff configure --allto directly install all supported integrations. configure also writes (or updates) a## AgentDiffsection in AGENTS.md in the current directory; this section is idempotent and can be skipped with --no-agents-md.agentdiff init— Configure per repository. Install git pre-commit, post-commit, and pre-push hooks, and configure the refs/agentdiff/* fetch refspec so that teammates' traces become visible after git fetch.
Note: configure installs the collection scripts globally, but collection is only triggered in repositories where agentdiff init has been run (the .git/agentdiff/ directory must exist). Running configure alone will not track any repository; you must run agentdiff init inside each repository you want to track.
Collection flow: When an AI agent makes an edit, its hook triggers and writes a JSON entry to <repo>/.git/agentdiff/session.jsonl . On commit: the pre-commit hook matches session entries against the staged diff and writes pending-ledger.json; the post-commit hook finally writes a trace entry (UUID key, Agent Trace v0.1 format) to the local buffer .git/agentdiff/traces/{branch}.jsonl, appending structured context such as intent, files_read, flags, trust, and signs it with ed25519 if a key is configured; the pre-push hook uploads the local trace buffer to the remote refs/agentdiff/traces/{branch} via the GitHub Git Database API, and automatically merges when pushing directly to main/master.
Storage locations: Locally at .git/agentdiff/session.jsonl (not committed, kept inside the .git/ directory); on GitHub at refs/agentdiff/traces/{branch}, pushed by agentdiff push or the pre-push hook.
Context workflow:agentdiff install-skill --scope project writes .cursor/skills/agentdiff-context/SKILL.md in the current repository; use --scope global as a personal default, and --force to overwrite an existing skill file. When used with --post-pr-comment, the context report is filtered to commits on the current PR branch, and an existing AgentDiff comment is updated where possible.
Privacy: Once pushed, prompt excerpts are visible to anyone with read access to the repository. If prompts contain sensitive business context, IP, or credentials, you can disable prompt collection by setting capture_prompts = false , in which case the prompt field is omitted from all trace entries. agentdiff does not send data to any server other than your own GitHub repository, with no external telemetry.
Configuration location: ~/.agentdiff/config.toml.
Use cases
- Repositories that need to audit the provenance and accountability of AI-generated code within a team.
- Multi-agent collaboration environments where you want to know which agent, which model, and what intent each line of code was written by.
- Teams that need to enforce AI attribution policies in the PR workflow.
Limitations
- Collection only takes effect in repositories where agentdiff init has been run; the .git/agentdiff/ directory must exist.
- Python 3.7+, Git 2.20+, and Rust 1.85+ must be available in PATH (installed automatically if missing).
- Prompt excerpts after pushing are visible to repository readers and must be disabled via capture_prompts = false.
License
Dual-licensed under MIT and Apache-2.0.