Skip to content

feat: add breadcrumb detection for Cursor via hooks#16

Open
sehajc wants to merge 2 commits intoblock:mainfrom
sehajc:02-25-feat_add_breadcrumb_detection_for_cursor_via_hooks
Open

feat: add breadcrumb detection for Cursor via hooks#16
sehajc wants to merge 2 commits intoblock:mainfrom
sehajc:02-25-feat_add_breadcrumb_detection_for_cursor_via_hooks

Conversation

@sehajc
Copy link

@sehajc sehajc commented Feb 25, 2026

Summary

  • Enables aittributor to detect Cursor via tier 4 (breadcrumb) detection, complementing existing process-based detection (tiers 1-3).
  • Sets breadcrumb_dir to ~/.cursor/attribution and breadcrumb_ext to jsonl on the Cursor agent definition.
  • Adds a test validating the Cursor breadcrumb format works with the existing find_session_file_with_cwd pipeline.

Motivation

Cursor is currently detected only via process scanning. If a developer uses Cursor to generate code, closes the editor, and commits later from a terminal, aittributor misses the attribution. This is the same gap that breadcrumbs solve for Claude (~/.claude/projects/) and Codex (~/.codex/sessions/).

How it works

A Cursor afterFileEdit hook (configured in ~/.cursor/hooks.json) writes a breadcrumb file to ~/.cursor/attribution/<repo-slug>.jsonl containing {"cwd":"<repo-root>"} every time the AI edits a file. The format is intentionally compatible with aittributor's existing extract_cwd_from_json parser — no changes to the detection pipeline are needed.

At commit time, aittributor's tier 4 breadcrumb check walks ~/.cursor/attribution/, finds recent .jsonl files (mtime < 2h), and matches the cwd field against the current repo. If matched, Co-authored-by: Cursor <cursoragent@cursor.com> is appended.

Cursor hook setup (user-level, ~/.cursor/hooks.json)

{
  "version": 1,
  "hooks": {
    "afterFileEdit": [
      { "command": "./hooks/write-attribution-breadcrumb.sh" }
    ]
  }
}

Breadcrumb writer (~/.cursor/hooks/write-attribution-breadcrumb.sh)

#!/bin/bash
input=$(cat)
file_path=$(echo "$input" | jq -r '.file_path // empty')
[ -z "$file_path" ] && exit 0
repo_root=$(cd "$(dirname "$file_path")" 2>/dev/null && git rev-parse --show-toplevel 2>/dev/null)
[ -z "$repo_root" ] && exit 0
breadcrumb_dir="$HOME/.cursor/attribution"
mkdir -p "$breadcrumb_dir"
repo_slug=$(echo "$repo_root" | tr '/' '_')
echo "{\"cwd\":\"$repo_root\"}" >"$breadcrumb_dir/${repo_slug}.jsonl"
exit 0

Distribution

The hook files can be distributed to engineers via:

  • Dotfile managers (e.g., symlink hooks.json and the script into ~/.cursor/ as part of your org's shared dotfiles)
  • Cursor enterprise hooks (/Library/Application Support/Cursor/hooks.json on macOS, deployed via MDM)
  • Manual setup (copy both files into ~/.cursor/)

See the Cursor hooks docs for details on user-level vs enterprise-level vs project-level hook configuration.

Test plan

  • cargo test — all 21 tests pass including new test_cursor_breadcrumb_format
  • End-to-end: ran hook to write breadcrumb, then aittributor --debug confirmed Cursor detected via breadcrumb path
  • Verified detection works when Cursor is closed (breadcrumb persists, process scan misses — only tier 4 fires)

Cursor's afterFileEdit hook can write breadcrumbs to
~/.cursor/attribution/<repo>.jsonl with a "cwd" field.
This enables aittributor to detect Cursor involvement
even when the editor is closed at commit time.

The breadcrumb format is compatible with the existing
find_session_file_with_cwd logic — no changes needed
to the detection pipeline.
@sehajc sehajc marked this pull request as ready for review February 25, 2026 22:43
@sehajc sehajc requested a review from alecthomas as a code owner February 25, 2026 22:43
@alecthomas
Copy link
Collaborator

Seems reasonable, but getting the hook installed will be the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants