Expand description
Commit attribution utilities for tracking Claude’s contributions.
This module provides functionality to track and attribute file changes to Claude or human contributors for git commit attribution.
Structs§
- Attribution
Data - Full attribution data for git notes JSON.
- Attribution
Snapshot Message - Attribution snapshot message for persistence.
- Attribution
State - Attribution state for tracking Claude’s contributions to files.
- Attribution
Summary - Summary of Claude’s contribution for a commit.
- File
Attribution - Per-file attribution details for git notes.
- File
Attribution State - Per-file attribution state.
- File
Change - File change for bulk tracking.
- Session
Baseline - Session baseline for tracking file state at session start.
- Surface
Breakdown - Surface breakdown for attribution.
Enums§
Functions§
- attribution_
restore_ state_ from_ log - Restore attribution state from log snapshots on session resume.
- build_
surface_ key - Build a surface key that includes the model name. Format: “surface/model” (e.g., “cli/claude-sonnet”)
- calculate_
commit_ attribution - Calculate final attribution for staged files. Compares session baseline to committed state.
- compute_
content_ hash - Compute SHA-256 hash of content.
- create_
empty_ attribution_ state - Create an empty attribution state for a new session.
- expand_
file_ path - Expand a relative path to absolute path.
- get_
attribution_ repo_ root - Get the repo root for attribution operations.
Uses get_cwd() which respects agent worktree overrides,
then resolves to git root to handle
cd subdircase. Falls back to get_original_cwd() if git root can’t be determined. - get_
client_ surface - Get the current client surface from environment.
- get_
file_ mtime - Get a file’s modification time (mtimeMs), falling back to Date.now() if the file doesn’t exist.
- get_
repo_ class_ cached - Synchronously return the cached repo classification. Returns None if the async check hasn’t run yet.
- get_
staged_ files - Get staged files from git.
- increment_
prompt_ count - Increment promptCount and save an attribution snapshot. Used to persist the prompt count across compaction.
- is_
internal_ model_ repo - Check if the current repo is in the allowlist for internal model names. This is a placeholder - would need proper async integration.
- is_
internal_ model_ repo_ cached - Synchronously return the cached result of is_internal_model_repo(). Returns false if the check hasn’t run yet (safe default: don’t leak).
- normalize_
file_ path - Normalize file path to relative path from cwd for consistent tracking. Resolves symlinks to handle /tmp vs /private/tmp on macOS.
- restore_
attribution_ state_ from_ snapshots - Restore attribution state from snapshot messages.
- sanitize_
model_ name - Sanitize a model name to its public equivalent. Maps internal variants to their public names based on model family.
- sanitize_
surface_ key - Sanitize a surface key to use public model names. Converts internal model variants to their public equivalents.
- state_
to_ snapshot_ message - Convert attribution state to snapshot message for persistence.
- track_
bulk_ file_ changes - Track multiple file changes in bulk.
- track_
file_ creation - Track a file creation by Claude (e.g., via bash command). Used when Claude creates a new file through a non-tracked mechanism.
- track_
file_ deletion - Track a file deletion by Claude (e.g., via bash rm command). Used when Claude deletes a file through a non-tracked mechanism.
- track_
file_ modification - Track a file modification by Claude. Called after Edit/Write tool completes.