Index Content
ctx_indexIndex large documentation, API references, or code files into a searchable knowledge base. Splits markdown by headings, preserves code blocks, and returns metadata for on-demand retrieval via search.
Instructions
Store content in a searchable knowledge base (BM25 over FTS5). Splits markdown by headings, keeps code blocks intact, and persists the raw chunks. The full content stays in storage — retrieve any section on-demand via ctx_search; nothing is summarized or truncated.
WHEN:
Documentation from Context7, Skills, or MCP tools (API docs, framework guides, code examples)
API references (endpoint details, parameter specs, response schemas)
MCP tools/list output (exact tool signatures and descriptions)
Skill prompts and instructions that are too large to keep verbatim in conversation
README files, migration guides, changelog entries
Any content with code examples you may need to reference precisely later
WHEN NOT:
Log files, test output, CSV, or build output — use ctx_execute_file, which processes in-sandbox without persisting bytes
Single-use ephemeral content you will not query later — keep it inline if it fits, or ctx_execute_file it
RETURNS:
Indexing metadata: chunk counts (total, code-bearing), source label, and the exact ctx_search call shape to query the indexed content. Raw content is NOT echoed back — it lives in storage, retrievable via ctx_search(source: ""). When path is provided, a content hash is stored so ctx_search results auto-flag staleness on future calls.
EXAMPLE: ctx_index(content: "# React useEffect\n\nThe Effect Hook lets you ...", source: "react-useeffect-docs") EXAMPLE: ctx_index(path: "/path/to/large-spec.md", source: "openapi-v2-spec")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | Raw text/markdown to index. Provide this OR path, not both. | |
| path | No | File OR directory path to read and index (content never enters context). Provide this OR content. Directory paths trigger a bounded recursive walk (#687). | |
| source | No | Label for the indexed content (e.g., 'Context7: React useEffect', 'Skill: frontend-design') | |
| include | No | Directory-only: glob patterns to include (default: all matching extensions). | |
| exclude | No | Directory-only: glob patterns to exclude. Merged with defaults (node_modules, .git, dist, build, .next, coverage, .venv, __pycache__, .DS_Store). | |
| maxDepth | No | Directory-only: max recursion depth from root (default: 5). | |
| maxFiles | No | Directory-only: hard cap on files indexed (default: 200) — FTS5 blow-up guard. | |
| extensions | No | Directory-only: allowed file extensions (default: .md .mdx .txt .json .yaml .yml .ts .tsx .js .jsx .py .rs .go .sh). | |
| respectGitignore | No | Directory-only: apply nearest .gitignore (default: true). | |
| followSymlinks | No | Directory-only: follow directory symlinks (default: false — cycle hazard + escape risk). |