staleness-gate
Skill7 starsChanged 9 months agoMITView on GitHub
Automatic index freshness gate. Called before any query command (search, fetch, refs, explore) to ensure the index exists and is up-to-date. Handles first-run setup, incremental re-indexing, and staleness detection — so users never need to manually index.
In this repository8 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- ctagsSkill
- detect-lspSkill
- fetchSkill
- indexSkill
- lspSkill
- rg-fallbackSkill
- searchSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 50
Check if .claude/codemunch/config.json exists — if not, run the detect-lsp skill first
- Distinctive: line 51
Run the index skill with full mode
- Distinctive: line 89
Only consider files with these extensions (adjust per detected languages in config):
- Distinctive: line 122
If fresh: proceed silently — no output to the user.
- Distinctive: line 160
If >50 files changed, fall back to full re-index (faster than incremental at that scale)
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Staleness Gate Skill
Ensures the codemunch index is fresh before any query runs. This skill is called automatically — users never invoke it directly.
Decision flow
1. Does .claude/codemunch/index.json exist?
NO → First-run: run detect-lsp skill, then full index skill → done
YES → Continue to step 2
2. Get index timestamp from index.json "generated" field
3. Find files changed since index was built:
git diff --name-only --diff-filter=ACMRD $(git log -1 --format=%H --before="$GENERATED_TIMESTAMP") HEAD
Also check for untracked source files:
git ls-files --others --exclude-standard
4. Filter to source files only (exclude non-code files like .md, .txt, images, etc.)
5. Are there changed source files?
NO → Index is fresh, proceed with query
YES → Run incremental re-index (step 6)
6. Incremental re-index:
- For each changed/added file: re-extract symbols using the best available engine
- For each deleted file: remove its symbols from the index
- Update the "generated" timestamp
- Update the "file_hashes" manifest
- Report: "Auto-updated index: +N symbols, -M symbols, K files re-indexed"Step 1 — Check index exists
# Check for index
if [ -f .claude/codemunch/index.json ]; then
echo "INDEX_EXISTS"
else
echo "NO_INDEX"
fiIf NO_INDEX:
- Check if
.claude/codemunch/config.jsonexists — if not, run the detect-lsp skill first - Run the index skill with full mode
- Report: "First-run: auto-built codemunch index (N symbols across M files)"
- Continue with the original query
Step 2 — Get index timestamp
# Extract the generated timestamp from index
python3 -c "
import json
with open('.claude/codemunch/index.json') as f:
idx = json.load(f)
print(idx.get('generated', ''))
" 2>/dev/null || jq -r '.generated' .claude/codemunch/index.jsonStep 3 — Find changed files since index was built
GENERATED="2026-03-11T02:14:00Z"
# Find the commit closest to when the index was built
BASE_COMMIT=$(git log -1 --format=%H --before="$GENERATED" 2>/dev/null)
if [ -z "$BASE_COMMIT" ]; then
# No commit found before timestamp — index predates all commits, do full re-index
echo "FULL_REINDEX_NEEDED"
else
# Get changed files since that commit
git diff --name-only --diff-filter=ACMRD "$BASE_COMMIT" HEAD 2>/dev/null
fi
# Also check untracked files (new files not yet committed)
git ls-files --others --exclude-standard 2>/dev/nullStep 4 — Filter to source files
Only consider files with these extensions (adjust per detected languages in config):
.ts .tsx .js .jsx .mjs .cjs
.py .pyi
.go
.rs
.rb .rake
.java .kt .kts
.cs
.php
.swift
.c .h .cpp .hpp .cc
.lua .zig .sh .bashExclude:
- Lock files (
package-lock.json,Cargo.lock,go.sum, etc.) - Generated files (check
.claude/codemunch/config.jsonexclude patterns) - Non-code files (
.md,.txt,.json,.yaml,.yml,.toml, images, etc.)
Step 5 — Decide: fresh or stale
CHANGED_COUNT=$(echo "$CHANGED_FILES" | grep -c '.')
if [ "$CHANGED_COUNT" -eq 0 ]; then
echo "INDEX_FRESH"
else
echo "INDEX_STALE:$CHANGED_COUNT files changed"
fiIf fresh: proceed silently — no output to the user.
Step 6 — Incremental re-index
For each changed file, re-extract symbols using the same engine logic as the index skill:
- Remove old symbols for changed/deleted files from the index
- Extract new symbols for changed/added files
- Merge into the existing index
- Update metadata:
generatedtimestamp,file_hashes,stats
# Remove symbols for changed files
python3 -c "
import json, sys
changed_files = sys.stdin.read().strip().split('\n')
with open('.claude/codemunch/index.json') as f:
idx = json.load(f)
# Remove symbols from changed files
idx['symbols'] = [s for s in idx['symbols'] if s['file'] not in changed_files]
print(json.dumps(idx))
" <<< "$CHANGED_FILES"Then run the index skill's engine pipeline (LSP → ctags → rg) on only the changed files, and append the new symbols.
Report (brief, inline — not a full index report):
🔄 Auto-updated index: 3 files re-indexed, +12 symbols, -8 symbols (1,251 total)Performance notes
- The staleness check itself is fast: one
git diff+ one JSON field read - Incremental re-index only processes changed files — not the whole project
- For projects with no changes since last index, this adds <100ms overhead
- If >50 files changed, fall back to full re-index (faster than incremental at that scale)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

