Index of every page on this site: llms.txt
All skills
Run it yourself

Ranked content search over a text corpus you point it at, using BM25 (via xhluca/bm25s). Corpus-agnostic: cloned repos, project knowledge stores, uploaded files and archives, any local directory. In-memory BM25 index per invocation, with a session-local disk cache for repeat runs against the same corpus. Use for "rank these documents", "search this corpus", "which files are most about X", "find content about Y", or any multi-word concept query against a known body of text where grep would return everything or nothing. Needs a corpus on disk. Not for searching stored memories or prior-session decisions (remembering), not for a named symbol or a file's structure (tree-sitting), and not for a literal string you could grep.

Use this Skill: https://skilld.dev/gh/oaustegard/claude-skills/bm25

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈184 tokens for metadata: the name and description. ≈1.6k when used: this file. ≈1.2k more on demand in 2 files.

Description uses 9.2% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈736 characters, or 9.2%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

bm25

Ranked content search over any text corpus. One CLI, in-memory BM25 index per process, with a session-local disk cache so repeat invocations against the same corpus load in tens of milliseconds instead of rebuilding.

Setup

uv pip install --system --break-system-packages bm25s

Install is sub-second on a warm uv cache. That's the entire dependency.

Usage

BM25=/mnt/skills/user/bm25/scripts/bm25.py

# Local directory
python3 $BM25 ./repo 'csrf middleware'

# Multiple queries against the same in-memory index (build once, query many)
python3 $BM25 ./repo 'csrf middleware' 'session backend' 'queryset filter'

# Cloned GitHub repo via tarball (one HTTP call)
python3 $BM25 'github.com/django/django' 'atomic transaction'
python3 $BM25 'github.com/django/django@stable/5.0.x' 'atomic transaction'

# Project knowledge or uploads
python3 $BM25 project 'RAG scaling laws'
python3 $BM25 uploads 'tax loss harvesting'

# Filters
python3 $BM25 ./repo 'auth flow' --exclude 'tests/*' --exclude '*/tests/*'
python3 $BM25 ./repo 'config' --include '*.py' --include '*.toml'

# Interactive (REPL — single corpus, many queries)
python3 $BM25 ./repo --interactive

# JSON output for piping
python3 $BM25 ./repo 'auth flow' --json

Corpus types

Spec Meaning
./path or /abs/path Local directory
uploads /mnt/user-data/uploads/
project /mnt/project/
github.com/owner/repo[@ref] Tarball fetch via GitHub API (GH_TOKEN used if set)

Options

Option Default Description
--top-k N 10 Results per query
--include GLOB (auto) Repeatable. If set, only files matching one of these globs are indexed
--exclude GLOB Repeatable. Skip files matching these globs
--snippet-lines N 3 Lines of snippet context per hit (0 = none)
--max-file-bytes N 2,000,000 Skip files larger than this
--json Machine-readable output
--interactive / -i REPL mode for ad-hoc querying within one session
--stats Print discover + index timings as JSON
--no-cache Bypass the session-local index cache; build in-memory only

With no --include, a default set of text/code extensions is indexed (Python, JS/TS, Go, Rust, Markdown, JSON, YAML, etc.). Standard noise dirs are skipped unconditionally: .git, node_modules, __pycache__, .venv, dist, etc.

When to use bm25

Question shape Tool
"Find lines matching class.*Error" grep / ripgrep
"Show me where parse_input is defined" tree-sitting (find:/source:)
"Which files are about CSRF handling?" bm25
"Rank these docs by relevance to 'rate limiting strategies'" bm25
"What's the implementation of the atomic transaction context manager?" bm25, then tree-sitting source:
"Find code by natural-language concept (in a code repo)" searching-codebases (which has its own TF-IDF mode)

The boundary with searching-codebases: that skill is code-specific (routes between regex and TF-IDF, expands via tree-sitting AST). bm25 is the simpler general-purpose tool — any corpus, no AST awareness, no routing. Prefer searching-codebases for code; reach for bm25 when the corpus is mixed (docs + code), non-code (notes, transcripts, PDFs converted to text), or when you specifically want BM25's length-normalized scoring.

Design notes

  • Session-local disk cache at /home/claude/.bm25-cache/<key>/. The key is a hash of (resolved_corpus_path, include_globs, exclude_globs, max_file_bytes) plus every discovered file's path and content hash, so editing, adding or deleting a file invalidates it. A hit still reads the corpus to hash it but skips tokenizing and indexing (1,649 files: 0.35s hit vs ~1s rebuild). The cache lives in /home/claude, which is ephemeral, so it expires at the session boundary — same lifetime as the corpus state itself, no cross-session staleness. ~5–35MB per cached index, depending on corpus size.
  • --no-cache bypasses both load and save — useful to confirm a rebuild matches.
  • A corpus with no indexable terms (empty, or only one-character tokens) returns zero-score hits instead of crashing bm25s.
  • Reuse within a single invocation. The retriever stays in memory between queries in one process. Passing multiple queries positionally, or using --interactive, amortizes any rebuild cost across queries.
  • No AST awareness. Chunking is per-file. For symbol-level results in code, combine with tree-sitting queries on the same paths.
  • Tokenizer. Default bm25s.tokenize with stopwords disabled — over a small Django sample, AST-derived token streams (identifiers/strings/ comments only) gave near-identical rankings, so we don't bother.

Output format

Default (human-readable):

QUERY: csrf middleware
----------------------------------------------------------------------
  1.   5.51  django/core/checks/security/csrf.py
    def _csrf_middleware():
        return "django.middleware.csrf.CsrfViewMiddleware" in settings.MIDDLEWARE
  2.   5.34  docs/howto/csrf.txt
    ...

--json produces {"query": ..., "results": [{"path", "score", "snippet"}, ...]}.

Architecture

bm25.py CLI
  ├── resolve_corpus(spec)         → local Path (downloads tarball if github.com/...)
  ├── cache_key(...)               → 16-hex sha256 of inputs that determine the index
  ├── CorpusIndex.load(cache_dir)  → returns cached index if present, else None
  ├── CorpusIndex.build(...)       → walks files, tokenizes, indexes with bm25s
  ├── CorpusIndex.save(cache_dir)  → persists to /home/claude/.bm25-cache/<key>/
  ├── query(q, k)                  → ranked (doc_idx, score) pairs
  └── best_snippet(doc, q, lines)  → pick line w/ most query-term hits + context

Cache contents per directory:

  • bm25/ — bm25s.BM25.save() output (NumPy arrays + vocab)
  • corpus.pkl — pickled {paths, docs} so we can render snippets without re-reading the source files
  • manifest.json — corpus root, files count, built_at timestamp

No network beyond optional tarball fetch on github.com/... corpora. No state outside /home/claude/, which is ephemeral.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 alert5d3 checks · Risk MEDIUM
  • Gen Agent Trust Hub5d

    The skill implements a session-local caching mechanism using Python's pickle module, which is vulnerable to unsafe deserialization if the cache directory is compromised. It also facilitates the ingestion of arbitrary text from external corpora, creating a surface for indirect prompt injection.

  • Socket5d

    1 alert: gptAnomaly

  • Snyk5d

    Risk: CRITICAL · 2 issues

Signed by skilld at b9eb735. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last week
metadata
{
  "version": "0.2.2"
}

README badge

README badge for oaustegard/claude-skills/bm25