Track AI code contributions for auditing and attribution. Use this skill BEFORE writing, editing, creating, or modifying any code files...
This project uses CodeLedger to automatically track which code was written by AI and which was written by humans. This is mandatory for all code changes to ensure proper attribution and auditing.
This skill includes pre-built ledger binaries for all platforms in the bin/ directory:
bin/
āāā ledger-windows-amd64.exe # Windows x64
āāā ledger-windows-arm64.exe # Windows ARM64
āāā ledger-darwin-amd64 # macOS Intel
āāā ledger-darwin-arm64 # macOS Apple Silicon (M1/M2/M3)
āāā ledger-linux-amd64 # Linux x64
āāā ledger-linux-arm64 # Linux ARM64
IMPORTANT: Use the bundled binary from this skill's bin/ directory. Do NOT assume ledger is in PATH.
First, detect the current platform and architecture to determine which binary to use:
# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
# Map to binary name
case "$OS" in
darwin) OS_NAME="darwin" ;;
linux) OS_NAME="linux" ;;
mingw*|msys*|cygwin*) OS_NAME="windows" ;;
*) OS_NAME="linux" ;; # default fallback
esac
case "$ARCH" in
x86_64|amd64) ARCH_NAME="amd64" ;;
arm64|aarch64) ARCH_NAME="arm64" ;;
*) ARCH_NAME="amd64" ;; # default fallback
esac
# Construct binary name
if [ "$OS_NAME" = "windows" ]; then
LEDGER_BIN="ledger-${OS_NAME}-${ARCH_NAME}.exe"
else
LEDGER_BIN="ledger-${OS_NAME}-${ARCH_NAME}"
fi
echo "Using binary: $LEDGER_BIN"
The binary is located in this skill's bin/ directory. Find the skill directory path:
# If skill is installed at project level: .claude/skills/codeledger/bin/
# If skill is installed at user level: ~/.claude/skills/codeledger/bin/
# Check project level first
if [ -d ".claude/skills/codeledger/bin" ]; then
SKILL_BIN=".claude/skills/codeledger/bin"
elif [ -d "$HOME/.claude/skills/codeledger/bin" ]; then
SKILL_BIN="$HOME/.claude/skills/codeledger/bin"
else
echo "Error: CodeLedger skill bin directory not found"
exit 1
fi
LEDGER="$SKILL_BIN/$LEDGER_BIN"
# Make executable (needed for Unix systems)
chmod +x "$LEDGER" 2>/dev/null || true
Now use $LEDGER to run any ledger command:
# Initialize (first time only)
"$LEDGER" init
"$LEDGER" install-hooks
# Before writing code
"$LEDGER" checkpoint pre
# After writing code
"$LEDGER" checkpoint post
# View stats
"$LEDGER" stats
For convenience, here's a one-liner to set up the LEDGER variable:
# Detect and set LEDGER path (copy this entire block)
OS=$(uname -s | tr '[:upper:]' '[:lower:]'); ARCH=$(uname -m); case "$OS" in darwin) OS_NAME="darwin";; linux) OS_NAME="linux";; mingw*|msys*|cygwin*) OS_NAME="windows";; *) OS_NAME="linux";; esac; case "$ARCH" in x86_64|amd64) ARCH_NAME="amd64";; arm64|aarch64) ARCH_NAME="arm64";; *) ARCH_NAME="amd64";; esac; if [ "$OS_NAME" = "windows" ]; then LEDGER_BIN="ledger-${OS_NAME}-${ARCH_NAME}.exe"; else LEDGER_BIN="ledger-${OS_NAME}-${ARCH_NAME}"; fi; if [ -d ".claude/skills/codeledger/bin" ]; then LEDGER=".claude/skills/codeledger/bin/$LEDGER_BIN"; elif [ -d "$HOME/.claude/skills/codeledger/bin" ]; then LEDGER="$HOME/.claude/skills/codeledger/bin/$LEDGER_BIN"; fi; chmod +x "$LEDGER" 2>/dev/null || true; echo "LEDGER=$LEDGER"
CodeLedger records attribution data in Git notes, enabling:
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā CodeLedger Workflow ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā ā
ā 1. BEFORE writing code āāāŗ "$LEDGER" checkpoint pre ā
ā (records current state) ā
ā ā
ā 2. Write/edit code āāāŗ [your code changes] ā
ā ā
ā 3. AFTER all edits done āāāŗ "$LEDGER" checkpoint post ā
ā (detects all changes) ā
ā ā
ā 4. Git commit āāāŗ Attribution auto-recorded ā
ā (via post-commit hook) ā
ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
You MUST run this command before making any code changes:
"$LEDGER" checkpoint pre
This command:
Expected output:
ā Pre-checkpoint recorded (session: a1b2c3d4)
If human changes are detected:
ā Detected human changes: 2 added, 1 modified, 0 deleted
ā Pre-checkpoint recorded (session: a1b2c3d4)
After running checkpoint pre, proceed with all your code changes:
No need to track file paths - CodeLedger automatically detects all changes.
You MUST run this command after finishing all code changes:
"$LEDGER" checkpoint post
This command:
Expected output:
ā Post-checkpoint recorded (session: a1b2c3d4)
Added: 3, Modified: 2, Deleted: 0
User request: "Create a utility function in src/utils.ts"
Correct execution:
# Set up LEDGER variable first (one-liner from above)
# ...
# Step 1: Record pre-checkpoint
"$LEDGER" checkpoint pre
# Step 2: Create/edit the file (your actual work)
# ... write code to src/utils.ts ...
# Step 3: Record post-checkpoint
"$LEDGER" checkpoint post
User request: "Fix the authentication bug in the login flow"
Correct execution:
# Step 1: Record pre-checkpoint FIRST
"$LEDGER" checkpoint pre
# Step 2: Fix the bug (may touch multiple files)
# ... edit src/auth/login.ts ...
# ... edit src/auth/session.ts ...
# ... edit tests/auth.test.ts ...
# Step 3: Record post-checkpoint after ALL edits
"$LEDGER" checkpoint post
User request: "Set up the project and add a new feature"
Correct execution:
# One-time initialization
"$LEDGER" init
"$LEDGER" install-hooks
# Then follow normal workflow
"$LEDGER" checkpoint pre
# ... write code ...
"$LEDGER" checkpoint post
$LEDGER variable at the start of coding taskscheckpoint pre BEFORE your first editcheckpoint post AFTER your last editledger is in PATH - always use $LEDGERcheckpoint pre multiple times without a checkpoint postcheckpoint post after completing edits| Task Type | Use Checkpoints? |
|---|---|
| Writing new code | ā Yes |
| Editing existing code | ā Yes |
| Creating new files | ā Yes |
| Deleting files | ā Yes |
| Refactoring code | ā Yes |
| Reading/explaining code | ā No |
| Answering questions | ā No |
| Running tests/builds | ā No |
Error: CodeLedger skill bin directory not found
ā The skill may not be properly installed. Check .claude/skills/codeledger/bin/ exists.
Permission denied
ā Run: chmod +x "$LEDGER"
checkpoint pre fails:Error: Not a git repository
ā This directory is not a Git repository. Checkpoints require Git.
Error: CodeLedger not initialized. Run 'ledger init' first
ā Run "$LEDGER" init to initialize CodeLedger in this repository.
checkpoint post fails:Error: No active session. Run 'ledger checkpoint pre' first
ā You forgot to run checkpoint pre before making changes.
No changes detected since pre-checkpoint.
ā No files were modified between pre and post checkpoints.
After commits are made, users can use these commands to view attribution data:
# View overall statistics
"$LEDGER" stats
# View attribution for a specific commit
"$LEDGER" show [commit-sha]
# Verify data integrity
"$LEDGER" verify
# Check CodeLedger status
"$LEDGER" status
# Push attribution notes to remote
"$LEDGER" push-notes
If you prefer to install ledger globally in your PATH instead of using the bundled binary:
bin/ to a directory in your PATHledger (or ledger.exe on Windows)ledger directly instead of "$LEDGER"See the project README.md for detailed installation instructions.
Every time you write or modify code:
$LEDGER variable (detect platform, find binary)"$LEDGER" checkpoint pre ā Start tracking"$LEDGER" checkpoint post ā Finish trackingThis ensures accurate AI code attribution for auditing purposes.