mdsearch - Fast full-text search for Markdown knowledge bases
Local full-text search CLI for Markdown knowledge bases, Obsidian vaults, and note collections. Powered by MiniSearch, with automatic indexing, fuzzy search, contextual snippets with line numbers, and LLM-ready output.
LLM-ready workflows
mdsearch helps AI tools and LLM workflows retrieve relevant context from Markdown knowledge bases. Search results are available in structured formats designed for AI agents, automation, and context retrieval.
For maximum token efficiency and streamlined context retrieval, we recommend using the dedicated mdsearch skill which provides automated, ready-to-use workflows for your LLM agents:
https://github.com/onigetoc/mdsearch-skill
Installation
Global installation (recommended)
npm install -g @onigetoc/mdsearch
After global install, use mdsearch directly (no npx):
mdsearch "<query>"
mdsearch "<query>" <folder>
Run without installation (npx)
npx @onigetoc/mdsearch "<query>" [<folder>]
Folder defaults to the current directory if omitted. The index is auto-built on first run (cache in .mdsearch/).
Examples
mdsearch "karpathy llm wiki"
mdsearch "karpathy llm wiki" notes-test
mdsearch "term" --no-fuzzy
mdsearch "term" --fuzzy 0.4
mdsearch "term"
mdsearch "term" --boost-title 5 --boost-headings 3 --boost-text 1
mdsearch "term" --limit 5
mdsearch "term" --context 0
mdsearch "term" --context 4
mdsearch "term"
mdsearch "term" --json
mdsearch "term" --context 4 --llm-context
mdsearch "minis" --prefix
mdsearch "karpathy llm" --phrase
mdsearch "karpathy llm" --and
mdindex ~/my-notes
mdindex ~/my-notes --cache-dir .mycache
mdsearch "term" --reindex
mdsearch "term" ~/my-notes --cache-dir .mycache
mdsearch --version
mdsearch --help
mdsearch --list
mdsearch --list --reindex
Local dev test only
node src/search-md.mjs "<query>"
Options
--no-fuzzy | boolean | false | Disable fuzzy matching (exact search only) |
--prefix | boolean | false | Enable prefix search (match term prefixes) |
--phrase | boolean | false | Exact phrase search (sequence of terms in order) |
--and | boolean | false | Require all terms (default is OR — any term matches) |
--boost-title | number | 3 | Weight multiplier for matches in document title |
--boost-headings | number | 2 | Weight multiplier for matches in headings |
--boost-text | number | 1 | Weight multiplier for matches in body text |
--limit | number | 10 | Maximum number of results to return |
--context | number | 2 | Lines of context before/after match (0 = snippet disabled) |
--json | boolean | false | Output results as JSON |
--llm-context | boolean | false | Compact LLM-friendly output format |
--reindex | boolean | false | Force rebuild the search index |
--cache-dir | string | .mdsearch | Custom cache directory name |
--list | boolean | false | List all indexed files |
--version | boolean | false | Show version number |
--help | boolean | false | Show help message |
Cache structure
.mdsearch/ contains:
index.json - serialized MiniSearch index
meta.json - folder signature (file count + max mtime), id → absolute path mapping
If the signature changes (file added/removed/modified), search-md.mjs detects it and re-indexes automatically.
Output formats
All formats include line numbers and normalized scores (0.00 - 1.00).
| Terminal | line 42: → matching content with highlighted match line |
| JSON | { "path": "...", "line": 42, "score": 0.92, "snippet": "..." } |
| LLM context | Confidence: 0.92 for each result, clean body without markers |