Skip to content
This repository was archived by the owner on Apr 5, 2026. It is now read-only.

Commit c2efd82

Browse files
HerbHallclaude
andcommitted
feat: add rules drift detection to SessionStart and devkit-sync status
SessionStart.sh now compares entry counts between ~/.claude/rules/ and the devkit clone, warning when files have diverged. The devkit-sync status workflow includes a drift report showing push/pull direction. Lightweight implementation: 6 grep calls total, no file content reads. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3cb1804 commit c2efd82

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

claude/hooks/SessionStart.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,47 @@ devkit_symlink_health() {
199199

200200
devkit_symlink_health "$(_devkit_resolve_path)"
201201

202+
# ===== Rules Drift Detection =====
203+
# Compare entry counts between ~/.claude/rules/ and devkit clone.
204+
# Warns when copies have diverged so user can push or pull.
205+
devkit_drift_check() {
206+
local devkit_path="$1"
207+
[ -z "$devkit_path" ] && return 0
208+
[ ! -d "$devkit_path/claude/rules" ] && return 0
209+
210+
local local_rules="$HOME/.claude/rules"
211+
[ ! -d "$local_rules" ] && return 0
212+
213+
local files="autolearn-patterns.md known-gotchas.md workflow-preferences.md"
214+
local drifted=0
215+
216+
for f in $files; do
217+
[ ! -f "$local_rules/$f" ] && continue
218+
[ ! -f "$devkit_path/claude/rules/$f" ] && continue
219+
220+
local local_count devkit_count
221+
local_count=$(grep -c '^## [0-9]' "$local_rules/$f" 2>/dev/null || echo 0)
222+
devkit_count=$(grep -c '^## [0-9]' "$devkit_path/claude/rules/$f" 2>/dev/null || echo 0)
223+
224+
if [ "$local_count" != "$devkit_count" ]; then
225+
local direction
226+
if [ "$local_count" -gt "$devkit_count" ]; then
227+
direction="local $local_count > devkit $devkit_count (push needed)"
228+
else
229+
direction="local $local_count < devkit $devkit_count (pull needed)"
230+
fi
231+
echo "DevKit drift: $f -- $direction"
232+
drifted=$((drifted + 1))
233+
fi
234+
done
235+
236+
if [ "$drifted" -gt 0 ]; then
237+
echo "DevKit: $drifted rules file(s) out of sync. Run /devkit-sync push or pull."
238+
fi
239+
}
240+
241+
devkit_drift_check "$(_devkit_resolve_path)"
242+
202243
# ===== CLAUDE.md Detection =====
203244

204245
# Skip if we're in the home directory

claude/skills/devkit-sync/workflows/status.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,24 @@ Show current sync state including symlink health, git status, and drift report.
3939
Local: N *.local.md files
4040
```
4141

42-
4. **Flag issues** if any symlinks are broken, missing, or are real files instead of symlinks.
42+
4. **Rules drift report** -- compare entry counts between `~/.claude/rules/` and `<devkit>/claude/rules/` for each rules file:
43+
44+
```bash
45+
for f in autolearn-patterns.md known-gotchas.md workflow-preferences.md; do
46+
local_count=$(grep -c '^## [0-9]' ~/.claude/rules/$f 2>/dev/null || echo 0)
47+
devkit_count=$(grep -c '^## [0-9]' <devkit>/claude/rules/$f 2>/dev/null || echo 0)
48+
echo "$f: local=$local_count devkit=$devkit_count"
49+
done
50+
```
51+
52+
Include in formatted status:
53+
54+
```text
55+
Drift: autolearn-patterns (local 99 = devkit 99 ✓)
56+
known-gotchas (local 82 > devkit 79 -- push needed)
57+
workflow-preferences (local 16 = devkit 16 ✓)
58+
```
59+
60+
Direction: local > devkit means "push needed", local < devkit means "pull needed".
61+
62+
5. **Flag issues** if any symlinks are broken, missing, or are real files instead of symlinks.

0 commit comments

Comments
 (0)