Skip to content

Fix sync-ai-rules not triggering on rule file deletions#89

Open
Kush Agrawal (kush-duolingo) wants to merge 2 commits into
masterfrom
fix-sync-ai-rules-on-delete
Open

Fix sync-ai-rules not triggering on rule file deletions#89
Kush Agrawal (kush-duolingo) wants to merge 2 commits into
masterfrom
fix-sync-ai-rules-on-delete

Conversation

@kush-duolingo

Copy link
Copy Markdown
Contributor

pre-commit gathers staged files with --diff-filter=ACMRTUXB (everything except D), so deleting a .cursor/rules/*.mdc file never matches the hook's files pattern and the hook is silently skipped. This leaves orphaned outputs in .claude/rules/generated/.

Switches to always_run: true so the hook runs on every commit. The hook's internal wipe-and-regenerate logic already handles no-ops correctly -- it regenerates from whatever .cursor/rules/ files exist, deleting outputs for any that are gone.

Discovered while cleaning up duplicate rules in duolingo-android and duolingo-ios, where deleting cursor rules left behind orphaned claude rules that should have been auto-cleaned.

pre-commit gathers staged files with --diff-filter=ACMRTUXB, which
excludes D (deleted). When a .cursor/rules/*.mdc file is deleted,
it never matches the hook's files pattern, so the hook is silently
skipped and the corresponding .claude/rules/generated/*.md output
is left orphaned.

Switch to always_run: true so the hook runs on every commit. The
hook's internal wipe-and-regenerate logic already handles the case
where no source rules have changed (it regenerates from whatever
.cursor/rules/ files currently exist, deleting outputs for any
that are gone).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@artnc Art Chaidarun (artnc) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook takes 6 seconds on my laptop according to time pre-commit run sync-ai-rules --all-files. That's fine for the relatively rare commit that touches AI rule files but it's a pretty steep price to pay on every commit.

Pre-commit's author recommends the workaround of having the hook run git diff itself and inspect the output to determine whether the hook should no-op

(It's also kinda fishy that this hook takes so long in the first place - see #90)

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants