Skip to content

Widthdom/CodeIndex

Repository files navigation

cdidx

日本語版はこちら / Japanese version

Build and Test CodeQL Release

.NET 8 C# Platform License SQLite

The AI-native local code index that cuts token waste in terminal and MCP workflows.

cdidx indexes a repository once, then serves full-text, symbol, and dependency queries from a local SQLite FTS5 database. Instead of making an AI agent rescan the same tree on every turn, you can reuse the local index and hand the model smaller, structured payloads.

cdidx .                          # Index current directory
cdidx search "authenticate"      # Full-text search
cdidx definition UserService     # Find symbol definitions
cdidx find "guard" --path src/Auth.cs
cdidx deps --path src/           # File-level dependency graph
cdidx mcp                        # Start MCP server for AI tools

46 languages supported. 24 MCP tools. Incremental updates. Zero config.

Why cdidx

Most code search tools optimize for either desktop UI workflows or one-off text scanning in a shell. cdidx is built for a different loop: local repositories that need to be searched repeatedly by both humans and AI agents.

  • CLI-first — designed for terminal workflows, scripts, and automation.
  • AI-native — --json output and MCP structured results are built in, not bolted on.
  • Token-efficient — compact snippets, map, inspect, and path filters reduce repeated scans and round-trips.
  • Local-first — SQLite database lives with the project in .cdidx/.
  • Incremental — refresh only changed files with --files or --commits.

It is not an IDE replacement or desktop search app. It is a small local search runtime you can script, automate, and hand to AI tools.

Use rg when you want a zero-setup one-off scan. Use cdidx when the same repository will be searched again and again.

cdidx vs rg

rg cdidx
Best at One-off text scans Repeated local code search
Setup None One-time index build
Search model Reads files every time Queries a local SQLite FTS5 index
Output for automation Plain text Human-readable, JSON, and MCP
AI integration Needs parsing Structured by design
Token cost in AI loops Re-sends broad repo context repeatedly Reuses the index and fetches short, scoped results
Updates after edits Re-run search Refresh only changed files

30-Second Quick Start

# One-liner install (no .NET required)
curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/main/install.sh | bash
cdidx .
cdidx search "handleRequest"

That is the whole loop:

  1. cdidx . builds or refreshes .cdidx/codeindex.db
  2. cdidx search ... returns results from the local index
  3. after edits, refresh with cdidx . --files path/to/file.cs or cdidx . --commits HEAD

Installation

Option A: One-liner install (no .NET required)

Works in containers, CI, and any Linux/macOS environment — no .NET SDK needed.

curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/main/install.sh | bash

Install a specific version (fetches the installer from that tag to avoid version skew):

curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/v1.5.0/install.sh | bash -s -- v1.5.0

Supported platforms: linux-x64, linux-arm64, osx-arm64 (glibc-based Linux only; Alpine/musl is not supported). Installs to ~/.local/bin by default (override with CDIDX_INSTALL_DIR).

Dockerfile example:

# Install cdidx into /usr/local/bin so it's on PATH immediately
RUN export CDIDX_INSTALL_DIR=/usr/local/bin \
    && curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/main/install.sh | bash

Option B: NuGet Global Tool

Requires .NET 8.0 SDK.

dotnet tool install -g cdidx

That's it. cdidx is now available as a command.

Upgrade

If you already have cdidx installed, update to the latest version:

dotnet tool update -g cdidx

Option C: Build from source

Requires .NET 8.0 SDK.

dotnet build src/CodeIndex/CodeIndex.csproj -c Release
dotnet publish src/CodeIndex/CodeIndex.csproj -c Release -o ./publish

Then add the binary to your PATH:

Linux:

sudo cp ./publish/cdidx /usr/local/bin/cdidx

macOS:

sudo cp ./publish/cdidx /usr/local/bin/cdidx

If /usr/local/bin is not in your PATH (Apple Silicon default shell):

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zprofile
source ~/.zprofile

Windows:

# PowerShell (run as Administrator)
New-Item -ItemType Directory -Force -Path C:\Tools
Copy-Item .\publish\cdidx.exe C:\Tools\cdidx.exe

# Add to PATH permanently (current user)
$path = [Environment]::GetEnvironmentVariable('Path', 'User')
if ($path -notlike '*C:\Tools*') {
    [Environment]::SetEnvironmentVariable('Path', "$path;C:\Tools", 'User')
}

Restart your terminal after adding to PATH.

Verify

cdidx --version

Quick Start

Index a project

cdidx ./myproject
cdidx ./myproject --rebuild     # full rebuild from scratch
cdidx ./myproject --verbose     # show per-file details

By default, cdidx index stores the database in <projectPath>/.cdidx/codeindex.db, even if you run the command from another directory.

Default output:

â ¹ Scanning...
  Found 42 files

Indexing...
  ████████████████████░░░░░░░░░░░░  67.0%  [28/42]

Done.

  Files   : 42
  Chunks  : 318
  Symbols : 156
  Skipped : 28 (unchanged)
  Graph   : ready
  Issues  : ready
  Fold    : ready
  Elapsed : 00:00:02

Machine-readable output also reports the post-run readiness bits directly:

cdidx ./myproject --json
{"status":"success","mode":"incremental","summary":{"files_total":42,"chunks_total":318,"symbols_total":156,"references_total":420,"files_scanned":42,"files_skipped":28,"files_purged":0,"errors":0},"graph_table_available":true,"issues_table_available":true,"fold_ready":true,"elapsed_ms":2012}

With --verbose, each file also shows a status tag so you can see exactly what happened:

  [OK  ] src/app.cs (12 chunks, 5 symbols)
  [SKIP] src/utils.cs
  [DEL ] src/old.cs
  [ERR ] src/bad.cs: <message>

[OK ] = indexed successfully, [SKIP] = unchanged / skipped, [DEL ] = deleted from DB (file removed from disk), [ERR ] = failed (verbose mode includes stack trace)

This is useful for debugging indexing issues or verifying which files were actually processed.

If you only need to upgrade an older .cdidx/codeindex.db to Unicode-aware --exact, you do not need a full rebuild:

cdidx backfill-fold

This recomputes name_folded / *_folded columns from the existing DB rows and stamps fold_ready without reparsing source files. The target must already be an existing CodeIndex DB; blank or missing paths are rejected instead of creating a new database.

Search code

cdidx search "authenticate"              # full-text search
cdidx search "handleRequest" --lang go   # filter by language
cdidx search "TODO" --limit 50           # more results
cdidx search "auth*" --fts               # raw FTS5 syntax (prefix search)
cdidx search "Run();" --exact-substring  # case-sensitive exact substring, no FTS5

Output:

src/Auth/Login.cs:15-30
  public bool Authenticate(string user, string pass)
  {
      var hash = ComputeHash(pass);
      return _store.Verify(user, hash);
  ...

src/Auth/TokenService.cs:42-58
  public string GenerateToken(User user)
  {
      var claims = BuildClaims(user);
      return _jwt.CreateToken(claims);
  ...

(2 results)

Human-readable search output is centered around the first matching line when possible, instead of always showing the start of the chunk.

Use --json for machine-readable output (AI agents):

{"path":"src/Auth/Login.cs","start_line":15,"end_line":30,"content":"public bool Authenticate(...)...","lang":"csharp","score":12.5}
{"path":"src/Auth/TokenService.cs","lang":"csharp","chunk_start_line":1,"chunk_end_line":80,"snippet_start_line":40,"snippet_end_line":47,"snippet":"if (claims.Count == 0)\\n    throw new InvalidOperationException();\\nreturn GenerateToken(claims);","match_lines":[42,47],"highlights":[{"line":47,"text":"return GenerateToken(claims);","terms":["GenerateToken"]}],"context_before":2,"context_after":3,"score":9.8}

Search symbols (functions, classes, etc.)

cdidx symbols UserService              # find by name
cdidx symbols UserService OrderService AuthService   # multi-name OR (positional)
cdidx symbols --name UserService --name OrderService # multi-name OR (--name)
cdidx symbols Run --exact-name         # exact name match (no `RunAsync` / `RunImpact` expansion)
cdidx symbols --kind class             # all classes
cdidx symbols --kind function --lang python

Use --exact-name when you already have a precise candidate list (e.g. names returned from an earlier search / inspect / map call). Names are compared case-insensitively for equality instead of substring, so Run will not also pull in RunAsync, RunImpact, etc. --exact-name composes with --name, positional names, and all existing filters. The older --exact spelling still works on these commands for backward compatibility, but --exact-name avoids the semantic clash with search. The fold is NFKC + Unicode CaseFold: common non-ASCII pairs such as Ä / À, fullwidth  / Run, ligatures, sharp-S (Straße / STRASSE), and Greek final sigma (Σ / ς / σ) now collapse correctly. Unicode CaseFold remains locale-invariant, so Turkish dotted İ still folds to i\u0307 rather than plain i. DBs with stale fold metadata fall back to ASCII COLLATE NOCASE until the DB contains only current folded keys. Prefer cdidx backfill-fold to refresh stored folded keys without reparsing. A plain cdidx index . is also enough if the scan rewrites or purges every stale row; otherwise use cdidx index . --rebuild. Use status --json → fold_ready to detect which path is active.

Output:

class      UserService                              src/Services/UserService.cs:8-72
function   GetUserById                              src/Services/UserService.cs:24-41
function   CreateUser                               src/Services/UserService.cs:45-61
(3 symbols)

With --json, symbol results also include definition ranges, optional body ranges, signature text, container symbol, visibility, and return type when the language extractor can infer them:

{"path":"src/Services/UserService.cs","lang":"csharp","kind":"function","name":"GetUserById","line":24,"start_line":24,"end_line":41,"body_start_line":26,"body_end_line":41,"signature":"public async Task<User> GetUserById(int id)","container_kind":"class","container_name":"UserService","visibility":"public","return_type":"Task<User>"}

search, definition, references, callers, callees, symbols, files, and find also share repeatable --path <pattern> (multiple values are OR'd together), repeatable --exclude-path <pattern>, and --exclude-tests filters. Search results prefer source files over tests and docs, and search boosts files whose symbol names or paths match the query exactly.

search --json and MCP search return compact match-centered snippets instead of whole chunks. Each result includes chunk_start_line, chunk_end_line, snippet_start_line, snippet_end_line, snippet, match_lines, highlights, context_before, and context_after. Use --snippet-lines <n> to shrink or widen the excerpt window (default: 8, max: 20).

Resolve a definition

cdidx definition ResolveGitCommonDir
cdidx definition ResolveGitCommonDir --path src/CodeIndex/Cli --exclude-tests
cdidx definition ResolveGitCommonDir --body --json

definition uses indexed symbol ranges plus chunk reconstruction to return the actual declaration text, and optional body content when the language extractor can infer a body range.

Inspect one symbol in one round-trip

cdidx inspect ResolveGitCommonDir --exclude-tests
cdidx inspect ResolveGitCommonDir --exclude-tests --json

inspect bundles the primary definition, nearby symbols from the same file, references, callers, callees, file metadata, workspace freshness metadata, and call-graph support metadata so AI clients can answer many symbol-oriented questions without chaining several separate commands. When a language is unsupported for references / callers / callees, inspect --json now says so explicitly instead of leaving AI clients to infer that from empty arrays.

Find references, callers, and callees

cdidx references ResolveGitCommonDir --exclude-tests
cdidx callers ResolveGitCommonDir --exclude-tests --json
cdidx callees AddToGitExclude --exclude-tests

These commands use the indexed reference graph and are intended for languages where cdidx already extracts named symbols and call-like references: Python, JavaScript/TypeScript, C#, Go, Rust, Java, Kotlin, Ruby, C/C++, PHP, Swift, Dart, Scala, Elixir, Lua, and VB.NET (18 languages). F# uses space-separated call syntax so graph queries are not supported; use search instead. For docs, config, markup, or other unsupported languages, fall back to search.

When you pass --lang for an unsupported language, human-readable graph commands now say so explicitly, and MCP graph tools expose graph_language, graph_supported, and graph_support_reason alongside the empty result list.

Outline a single file

cdidx outline src/CodeIndex/Cli/GitHelper.cs
cdidx outline src/CodeIndex/Cli/GitHelper.cs --json

Shows all symbols in a single file ordered by line, with kind, signature, visibility, and container nesting. Lets AI agents understand file structure in one call instead of reading the whole file or chaining symbols + definition.

Reconstruct a file excerpt

cdidx excerpt src/CodeIndex/Cli/GitHelper.cs --start 19 --end 28
cdidx excerpt src/CodeIndex/Cli/GitHelper.cs --start 19 --end 28 --before 3 --after 3 --json

Find a substring inside a known file

cdidx find "graph table" --path src/CodeIndex/Cli/QueryCommandRunner.cs
cdidx find "Graph Table" --path src/CodeIndex/Cli/QueryCommandRunner.cs --exact --before 1 --after 1 --json

find fills the gap between repo-wide search and line-number-based excerpt: when you already know the target file, it returns matching line numbers, columns, and short surrounding context from the indexed file without falling back to raw-text tools.

List files

cdidx files                            # all indexed files
cdidx files --lang csharp              # only C# files
cdidx files --path src/Services --exclude-path Migrations

Output:

csharp          120 lines  src/Services/UserService.cs
csharp           85 lines  src/Controllers/UserController.cs
csharp           42 lines  src/Models/User.cs
(3 files)

Check status

cdidx status

Output:

Files   : 42
Chunks  : 318
Symbols : 156
Refs    : 912
Languages:
  csharp         28
  python         10
  javascript      4

Map the repo before searching

cdidx map --path src/ --exclude-tests
cdidx map --path src/ --exclude-tests --json

map is the fastest way to orient both a human and an AI agent before deeper queries. Use it to get languages, modules, hot files, and likely entrypoints, then narrow with inspect, search, or definition. For the full freshness and metadata contract of status --json, map --json, inspect --json, and MCP analyze_symbol, see DEVELOPER_GUIDE.md.

Options

Option Applies to Description
--db <path> All commands Database file path. index defaults to <projectPath>/.cdidx/codeindex.db; query commands default to .cdidx/codeindex.db in the current directory.
--json All commands JSON output (for AI/machine use)
--limit <n> Query commands Max results (default: 20; map uses it per section)
--lang <lang> Query commands Filter by language
--path <pattern> search, definition, references, callers, callees, symbols, files, find, map, inspect Restrict results to paths containing this text. Repeatable; multiple values are OR'd together
--exclude-path <pattern> search, definition, references, callers, callees, symbols, files, find, map, inspect Exclude paths containing this text (repeatable)
--exclude-tests search, definition, references, callers, callees, symbols, files, find, map, inspect Exclude likely test files and prefer production code
--snippet-lines <n> search Search snippet length for human-readable output and JSON/MCP snippets (default: 8, max: 20)
--fts search Use raw FTS5 query syntax instead of literal-safe quoting
--exact search, find, symbols, definition, references, callers, callees, inspect Backward-compatible shorthand. Prefer --exact-substring for search, keep --exact for find, and prefer --exact-name for symbol / graph commands plus inspect. JSON and MCP degraded-state metadata remain exact_index_available / degraded_reason (plus legacy camelCase aliases in MCP).
--exact-substring search Preferred explicit name for search exactness: case-sensitive exact substring (FTS5 bypassed).
--exact-name symbols, definition, references, callers, callees, inspect Preferred explicit name for symbol-name exactness: NFKC + Unicode CaseFold exact equality (Ä / À,  / Run, ligatures, sharp-S, and Greek final sigma collapse). Unicode CaseFold remains locale-invariant, so Turkish dotted İ is still distinct from plain i. Falls back to ASCII COLLATE NOCASE while the DB still contains stale fold metadata; prefer cdidx backfill-fold, or use a plain cdidx index . if it rewrites or purges every stale row, otherwise --rebuild. status --json exposes fold_ready so AI clients can tell which path is active. When a read-only legacy DB is missing the fallback exact-match indexes, human-readable output warns and CLI JSON / MCP structuredContent expose degraded-state metadata.
--kind <kind> definition, symbols Filter by symbol kind (function/class/struct/interface/enum/property/event/delegate/namespace/import)
--body definition, inspect Include reconstructed body content when the language extractor can infer the body range
--count search, definition, references, callers, callees, symbols, files, find, unused Return only the result count (with --json: a single count object; graph-aware commands may add trust metadata)
--start <line> excerpt Start line for excerpt reconstruction
--end <line> excerpt End line for excerpt reconstruction (defaults to --start)
--before <n> excerpt, find Include extra context lines before the requested excerpt or match
--after <n> excerpt, find Include extra context lines after the requested excerpt or match
--rebuild index Delete existing DB and rebuild
--verbose index Show per-file status ([OK ]/[SKIP]/[DEL ]/[ERR ])
--commits <id...> index Update only files changed in specified commits. Prefer this after a normal commit because git history includes rename/delete paths.
--files <path...> index Update only the specified files. Safe for known in-place edits or new files; old rename/delete paths are not purged unless you also list them explicitly.
--since <datetime> files Filter to files modified since this ISO 8601 timestamp
--no-dedup search Disable overlapping-chunk deduplication for raw results
--reverse deps Reverse lookup: show files that depend ON the matched path
--top <n> Query commands Alias for --limit

Exit codes

Code Meaning
0 Success
1 Usage error (invalid arguments)
2 Not found (no search results, missing directory)
3 Database error

Debugging reader errors

If a query fails with a SQLite reader error such as The data is NULL at ordinal N, set CDIDX_DEBUG=1 and rerun. The failing SQL, bound parameters, and the last-read row's columns will be printed to stderr so the offending record can be located. No-op when unset.

Text values (chunk content, context, paths, signatures, string parameters) are redacted by default — only the length and a short SHA256 prefix are emitted, so diagnostics can be pasted into issues without leaking indexed source code. Numeric columns, column names, NULL markers, and SQL text are shown as-is. To include raw text content in a local troubleshooting session, set CDIDX_DEBUG=unsafe instead (never paste this output publicly).

CDIDX_DEBUG=1 cdidx unused            # redacted text / テキスト䌏字化
CDIDX_DEBUG=unsafe cdidx unused       # raw content, local only / 生テキスト、ロヌカルのみ

How it works

cdidx scans your project directory, splits each source file into overlapping chunks, and stores everything in a SQLite database with FTS5 full-text search. Incremental mode (default) first purges database entries for files that no longer exist on disk, then checks each file's last-modified timestamp against the database — only files whose timestamp exactly matches are skipped, and any difference (newer or older) triggers re-indexing. Newly appeared files are indexed as new entries. This means re-indexing after a branch switch only processes the files that actually differ.

Git integration

cdidx index automatically adds .cdidx/ to .git/info/exclude. You don't need to edit .gitignore.

.git/info/exclude is a standard Git mechanism that works just like .gitignore. Many tools use .git/info/exclude or store data inside .git/ to avoid polluting .gitignore — git-lfs, git-secret, git-crypt, git-annex, Husky, pre-commit, JetBrains IDEs, VS Code (GitLens), Eclipse, etc.

Git branch switching

The database reflects the working tree at the time of the last index. After switching branches, simply re-run cdidx . — files that no longer exist on disk are purged from the database, newly appeared files are indexed, and existing files are re-indexed only when their timestamp differs. The update is proportional to the number of changed files, not the total project size.

Situation What happens
File unchanged across branches Skipped (instant)
File content changed Re-indexed
File deleted after checkout Purged from DB
File added after checkout Indexed as new

Supported languages

Language Extensions Symbols
Python .py yes
JavaScript .js, .jsx yes
TypeScript .ts, .tsx yes
C# .cs yes
Go .go yes
Rust .rs yes
Java .java yes
Kotlin .kt yes
Ruby .rb yes
C .c, .h yes
C++ .cpp, .cc, .cxx, .hpp, .hxx yes
PHP .php yes
Swift .swift yes
Dart .dart yes
Scala .scala, .sc yes
Elixir .ex, .exs yes
Lua .lua yes
R .r, .R yes
Haskell .hs, .lhs yes
F# .fs, .fsx, .fsi yes
VB.NET .vb, .vbs yes
Razor/Blazor .cshtml, .razor yes (as C#)
Protobuf .proto yes
GraphQL .graphql, .gql yes
Gradle .gradle yes
Makefile Makefile yes
Dockerfile Dockerfile yes
Zig .zig yes
XAML .xaml, .axaml --
MSBuild .csproj, .fsproj, .vbproj, .props, .targets --
Shell .sh, .bash, .zsh, .fish --
PowerShell .ps1 yes
Batch .bat, .cmd --
CMake .cmake, CMakeLists.txt --
SQL .sql --
Markdown .md --
YAML .yaml, .yml --
JSON .json --
TOML .toml --
HTML .html --
CSS .css, .scss yes
Vue .vue --
Svelte .svelte --
Terraform .tf --

All languages are fully searchable via FTS5. Languages with Symbols = yes also support structured queries by function/class/import name.

Prerequisites: sqlite3

AI agents that query the database directly via SQL need the sqlite3 CLI.

OS Status
macOS Pre-installed
Linux Usually pre-installed. If not: sudo apt install sqlite3
Windows winget install SQLite.SQLite or scoop install sqlite

AI Integration

cdidx helps AI tools by replacing repeated repo-wide scans with a reusable local index.

  • search --json and MCP search return compact match-centered snippets instead of large file dumps, and --snippet-lines lets you cap payload size up front.
  • map, inspect, definition, deps, and impact reduce multi-step repository exploration into fewer round-trips.
  • --path, repeatable --exclude-path, and --exclude-tests keep results focused before you spend tokens on excerpts or follow-up prompts.
  • status --json, map --json, and inspect --json expose freshness and git-state signals so an agent can decide whether the index is trustworthy.
  • unused --json and MCP unused_symbols expose bucketed dead-code triage metadata plus graph-support signals, so machine clients can distinguish likely-private cleanup from public/config/reflection suspects and from unsupported-language empty pages.
  • cdidx mcp gives Claude Code, Cursor, Windsurf, Copilot, and Codex a native MCP server instead of forcing them to scrape shell text.

For the full MCP tool list, JSON field contracts, exact-match metadata, and fallback behavior on legacy databases, see DEVELOPER_GUIDE.md.

Setup: Add to CLAUDE.md

To let AI agents use the generated index, place a CLAUDE.md in your project root (the template below is for downstream projects that adopt cdidx — contributors working on the cdidx repo itself should follow CLAUDE.md in this repo, which routes execution through the locally built dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll instead of a bare cdidx command):

# Code Search Rules

This project uses **cdidx** for fast code search via a pre-built SQLite index (`.cdidx/codeindex.db`).
**Query this database** instead of using `find`, `grep`, or `ls -R`.

## Setup

First check if `cdidx` is available:

```bash
cdidx --version
```

**If not found**, install it:

```bash
# No .NET required — downloads a self-contained binary
curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/main/install.sh | bash
```

Or, if .NET 8+ SDK is available:

```bash
dotnet tool install -g cdidx
```

**If already installed**, update to the latest version:

```bash
# Re-run the installer to upgrade
curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/main/install.sh | bash
```

If install fails (no network, unsupported platform), skip to the **"Direct SQL queries"** section below — you can query `.cdidx/codeindex.db` directly with `sqlite3`, provided the database was already built. If neither `cdidx` nor `sqlite3` is available, use the Claude Code built-in `Grep` / `Glob` tools (or your harness's equivalent) — do not fall back to shell `rg` / `grep` / `find` or a global `cdidx` in a Claude Code session, since those may be blocked by a repo-tracked deny list and bypassing them can hide stale-binary bugs.

Before searching, update the index so results are accurate:

```bash
cdidx .   # incremental update (skips unchanged files)
```

## Keeping the index up to date (requires cdidx)

After editing files, update the database so search results stay accurate:

```bash
cdidx . --files path/to/changed_file.cs   # update specific files you modified
cdidx . --commits HEAD                     # update all files changed in the last commit
cdidx . --commits abc123                   # you can also pass a specific commit hash
cdidx .                                    # full incremental update (skips unchanged files)
```

**Rule: whenever you modify source files, run one of the above before your next search.**
If the checkout changed because of `git reset`, `git rebase`, `git commit --amend`, `git switch`, or `git merge`, prefer `cdidx .` so stale files are purged against the current worktree instead of only refreshing commit-local paths.

## Query strategy

- Start with `map` when you need a quick overview of languages, modules, and likely hot spots before issuing symbol or text queries.
- Check `status --json` when freshness matters. Use `indexed_at`, `latest_modified`, `git_head`, and `git_is_dirty` to decide whether you need to re-run `cdidx .` before trusting results. If you already started with `map --json`, treat `indexed_at` / `latest_modified` there as filter-scoped freshness and `workspace_indexed_at` / `workspace_latest_modified` as the whole-workspace view.
- Use `inspect` when you already have a candidate symbol name and want bundled definition/caller/callee/reference context in one round-trip. Add `--exact` to match leaf-command precision — `exact` is propagated into every bundled sub-query so `inspect Run --exact` will not drag in `RunAsync` / `RunImpact`. `inspect --json` also carries `workspace_indexed_at`, `workspace_latest_modified`, `project_root`, `git_head`, and `git_is_dirty` for trust decisions.
- Use `definition` when you need the declaration text for a named symbol, and add `--body` when the implementation body matters.
- Use `references`, `callers`, and `callees` for symbol-aware call graph questions in Python, JavaScript/TypeScript, C#, Go, Rust, Java, Kotlin, Ruby, C/C++, PHP, Swift, Dart, Scala, Elixir, Lua, and VB.NET (18 languages). F# uses space-separated call syntax so graph queries are not supported; use `search` instead. Add `--exact` when you already have a precise name (e.g. resolved from `symbols --exact` / `inspect`) so `references Run` no longer pulls in `RunAsync` / `RunImpact` / etc. — same for `callers` / `callees` / `definition`.
- Use `impact` for pre-edit ripple checks on callable symbols. When the query resolves, within the active `--lang` / `--path` / `--exclude-path` / `--exclude-tests` scope and graph-supported languages only, to a single class / struct / interface definition and no symbol-level callers exist, `impact` / MCP `impact_analysis` may return heuristic file-level dependency hints instead of a silent false negative; same-name non-callable siblings such as `namespace` or `import` definitions do not block that fallback, and pure non-callable queries return `non_callable_symbol_kind` guidance instead of an unexplained zero. To reduce noise, those hints are emitted only for files that both reference one of the target type's member names and also carry same-file structured type evidence in indexed symbol metadata such as signatures or return types, rather than raw comment/string text matches. That evidence path is Unicode-aware, so fullwidth/accented identifiers follow the same exact-match semantics as the rest of the impact resolver. The hints are still not authoritative because the current graph does not record the resolved target file/type for each call, but they are returned as normal successful output: `count` / `file_count` describe the visible returned set, while `confirmed_count` / `confirmed_file_count` stay at the symbol-level caller totals so clients can inspect `impact_mode`, `heuristic`, `hint_count`, and `truncated`. `impact --json --count` uses the same `*_count` field names as the full payload. When the scoped query resolves to multiple class-like definitions (for example partial classes or same-name definitions sharing one file), the zero-result payload explains that and suggests `deps --path <definition-path> --reverse` or a more specific member query.
- Use `symbols` for named code entities in symbol-aware languages (32 languages including Python, JavaScript/TypeScript, C#, Go, Rust, Java, Kotlin, Ruby, C/C++, PHP, Swift, Dart, Scala, F#, VB.NET, Elixir, Lua, R, Haskell, Shell, SQL, Terraform, Protobuf, GraphQL, Gradle, Makefile, Dockerfile, Zig, PowerShell, CSS/SCSS). Add `--exact` when you already have a precise candidate list (e.g. names from a prior `inspect` / `map` / `search` result) so `Run` no longer expands to `RunAsync` / `RunImpact` — pairs cleanly with repeated `--name`.
- Use `outline` to see the full symbol structure of a single file without reading its content.
- Use `search` for raw text, comments, strings, or languages without structured symbol extraction such as XAML, Markdown, YAML, JSON, TOML, HTML, Vue, Svelte.
- Add `--exclude-tests` unless you are explicitly investigating tests.
- Add `--path <text>` and repeatable `--exclude-path <text>` before broad searches so results stay inside the relevant module.
- Add `--snippet-lines <n>` to `search` when you need tighter JSON output before handing results to another model or tool.
- Use `files` to discover candidate paths, `find` to re-locate exact text inside known files, then `excerpt` to fetch only the needed lines instead of opening entire files.
- Use `deps` to understand file-level dependencies — which files reference symbols from other files. Add `--reverse` to find what depends on a given file (impact analysis).
- Use `unused` to find potentially dead code — symbols defined but never referenced (only meaningful for graph-supported languages). Results are bucketed so private/file-local candidates stay earlier than public/exported or config/reflection suspects, and returned pages use bounded overfetch plus cross-bucket diversification before `--limit` is applied so one noisy bucket is less likely to hide the rest without silently capping large `--limit` requests. The suspect bucket is reserved for public/exported properties that look config-bound or, for C#, have nearby serializer/ORM-style attributes. Unsupported `--lang` filters now return an empty page with `graph_supported=false` instead of fake unused hits. CLI JSON uses per-symbol `unused_bucket` / `unused_confidence` / `unused_reason`, MCP uses `unusedBucket` / `unusedConfidence` / `unusedReason`, and both include page-scoped `returned_bucket_counts`. Zero-result JSON pages keep the same schema (`count`, empty `symbols`, empty page counts, and graph trust metadata) instead of going silent, and `unused --json` returns that payload with exit code `0` so machine clients can consume it as a normal empty page. When `--lang` is specified, CLI JSON also includes `graph_supported` / `graph_support_reason` so AI clients can tell whether the language actually has indexed call-graph support.
- Use `hotspots` to find the most-referenced symbols — central, high-impact code that changes may affect widely.
- Use `files --since <datetime>` or `search --since <datetime>` to focus on recently modified code.
- Use `--dry-run` with `index` to preview what would be indexed without writing to the database.
- Use `--count` to get result counts before fetching full data (saves tokens for AI agents).
- If you encounter a bug, unexpected behavior, or think of a feature that would improve cdidx, file an issue at https://github.com/Widthdom/CodeIndex/issues describing what happened and the expected behavior.

## CLI (recommended if cdidx is available)

```bash
cdidx map --path src/ --exclude-tests --json
cdidx inspect "Authenticate" --exclude-tests
cdidx search "keyword" --path src/ --exclude-tests --snippet-lines 6
cdidx definition "ClassName" --path src/Services --body
cdidx callers "Authenticate" --lang csharp --exclude-tests
cdidx callees "HandleRequest" --path src/ --exclude-tests
cdidx symbols "ClassName" --lang csharp --exclude-tests
cdidx find "guard" --path src/app.py --after 2
cdidx excerpt src/app.py --start 10 --end 20
cdidx files --lang python --path src/
cdidx status --json
```

## Direct SQL queries (fallback if cdidx is unavailable)

The queries below require `sqlite3`. If it is not installed, suggest the user install it:
- **macOS**: pre-installed
- **Linux**: `sudo apt install sqlite3`
- **Windows**: `winget install SQLite.SQLite` or `scoop install sqlite`

### Full-text search
```sql
SELECT f.path, c.start_line, c.content
FROM fts_chunks fc
JOIN chunks c ON c.id = fc.rowid
JOIN files f ON f.id = c.file_id
WHERE fts_chunks MATCH 'keyword'
LIMIT 20;
```

### Search by function/class name
```sql
SELECT f.path, s.name, s.line
FROM symbols s
JOIN files f ON f.id = s.file_id
WHERE s.kind = 'function' AND s.name LIKE '%keyword%';
```

### Incremental updates for CI / hooks

Instead of re-indexing the entire project, AI agents can update only the files that changed:

```bash
# Update only files changed in specific commits
# Prefer this after a normal commit because git history also carries rename/delete paths
cdidx ./myproject --commits abc123 def456

# Update only specific files after known in-place edits or new-file additions
# Old rename/delete paths are not purged unless you also list them explicitly
cdidx ./myproject --files src/app.cs src/utils.cs
```

Prefer `--commits` for commit-driven automation. Use `--files` for editor/save hooks that only touch existing paths or add new files. After `git reset`, `git rebase`, `git commit --amend`, `git switch`, or `git merge`, prefer a full `cdidx ./myproject --json` refresh so repo-wide stale paths are purged against the current checkout.

These options make it practical to keep the index up-to-date in real time, even on large codebases, without pretending that every delta workflow purges stale paths equally.

MCP Server (for Claude Code, Cursor, Windsurf, etc.)

cdidx includes a built-in MCP (Model Context Protocol) server. MCP is a standard protocol that lets AI coding tools communicate with external programs. When you run cdidx mcp, cdidx starts listening on stdin/stdout — your AI tool sends search requests as JSON, and cdidx returns results instantly from the pre-built index.

Tool results include structured JSON in structuredContent plus a short text summary in content, so AI tools can parse typed data without scraping large text blocks.

flowchart LR
    tools["Claude Code<br/>Cursor<br/>Windsurf"]
    server["cdidx<br/>mcp server"]
    tools -->|"stdin (JSON-RPC)"| server
    server -->|"stdout (JSON-RPC)"| tools
Loading

Setup — add to your AI tool's config:

Claude Code (.claude/settings.json or .mcp.json):

{
  "mcpServers": {
    "cdidx": {
      "command": "cdidx",
      "args": ["mcp", "--db", ".cdidx/codeindex.db"]
    }
  }
}

Cursor (.cursor/mcp.json):

{
  "mcpServers": {
    "cdidx": {
      "command": "cdidx",
      "args": ["mcp", "--db", ".cdidx/codeindex.db"]
    }
  }
}

Windsurf (.windsurf/mcp.json):

{
  "mcpServers": {
    "cdidx": {
      "command": "cdidx",
      "args": ["mcp", "--db", ".cdidx/codeindex.db"]
    }
  }
}

GitHub Copilot (VS Code — .vscode/mcp.json):

{
  "servers": {
    "cdidx": {
      "type": "stdio",
      "command": "cdidx",
      "args": ["mcp", "--db", ".cdidx/codeindex.db"]
    }
  }
}

OpenAI Codex CLI (codex.json or ~/.codex/config.json):

{
  "mcpServers": {
    "cdidx": {
      "command": "cdidx",
      "args": ["mcp", "--db", ".cdidx/codeindex.db"]
    }
  }
}

Once configured, the AI can directly call these tools:

Tool Description
search Full-text search across code chunks
definition Reconstruct a symbol declaration and optional body
references Find indexed references for supported languages
callers List callers for a named symbol in supported languages
callees List callees for a named symbol in supported languages
symbols Find functions, classes, interfaces, imports, and namespaces by name
files List indexed files
find_in_file Find literal substring matches inside known indexed files with line/column context
excerpt Reconstruct a specific line range from indexed chunks
map Summarize languages, modules, hotspots, and likely entrypoints
analyze_symbol Bundle definition, nearby symbols, references, callers, callees, file metadata, workspace trust metadata, and graph support metadata
outline Show all symbols in a single file with line numbers, signatures, and nesting
status Database statistics
deps File-level dependency edges from the reference graph
impact_analysis Compute transitive callers of a symbol, with single-type fallback to heuristic file-level dependency hints and partial-definition hints
unused_symbols Find symbols defined but never referenced, with confidence buckets for dead-code triage
symbol_hotspots Find most-referenced symbols (high-impact code)
batch_query Execute multiple queries in a single call (MCP only, max 10)
validate Report encoding issues (U+FFFD, BOM, null bytes, mixed line endings)
languages List all supported languages, file extensions, and capabilities
ping Lightweight connection check
index Index or re-index a project directory
backfill_fold Upgrade folded-name keys in an existing DB without reparsing source files
suggest_improvement Submit structured improvement suggestions or error reports

No CLAUDE.md hacks or SQL templates needed — the AI interacts with cdidx natively.

If you only need to upgrade an older .cdidx/codeindex.db for Unicode --exact, or to repair fold metadata drift by regenerating folded keys without reparsing source files, run:

cdidx backfill-fold

This recomputes persisted name_folded / *_folded columns from existing DB rows and stamps fold_ready when verification succeeds. The target must already be an existing CodeIndex DB; blank or missing paths are rejected instead of creating a new database.

Graph-oriented MCP tools such as references, callers, and callees also return graph_language, graph_supported, and graph_support_reason when a language filter is provided, so clients can distinguish unsupported languages from genuine zero-hit queries.

All MCP tools include annotations (readOnlyHint, destructiveHint, idempotentHint, openWorldHint) so AI clients can auto-approve safe read-only queries without prompting the user.

Why cdidx over grep/ripgrep for AI workflows?

grep / rg cdidx
Output format Plain text (needs parsing) Structured JSON (search/symbols-style hits stream as JSON lines; summaries/counts and degraded zero-result graph responses use one object)
Search speed on large repos Scans every file each time Pre-built FTS5 index
Symbol awareness None Functions, classes, imports
Token footprint across repeated turns Broad raw context Short indexed snippets
Incremental update N/A --commits, --files

AI Feedback

cdidx includes a suggest_improvement MCP tool for AI agents that hit gaps or bugs. Suggestions are saved locally to .cdidx/suggestions.json, and are sent to GitHub only when the user explicitly provides CDIDX_GITHUB_TOKEN. Payload details and source-code leak guardrails are documented in the Developer Guide.

Releasing a new version

Maintainers / forkers only — the full release procedure now lives in DEVELOPER_GUIDE.md#release-workflow. MAINTAINERS.md is the maintainer index.

The short version: version.json is the single source of truth, and the maintainer checklist covers branch/PR triage, changelog promotion, tagging, and clean-install verification.

More

  • Developer Guide — Architecture, database schema, AI response contracts, release workflow, design decisions
  • Testing Guide — Test suite layout, helper utilities, cross-platform rules, and test maintenance conventions
  • Self-Improvement Loop — Ready-to-use operating contract for iterative AI-driven cdidx improvements

cdidx日本語

.NET 8 C# Platform License SQLite

タヌミナルずMCPワヌクフロヌでAIのトヌクン浪費を枛らす、AIネむティブなロヌカルコヌドむンデックス。

cdidx は、リポゞトリを䞀床むンデックスし、その埌の党文怜玢・シンボル怜玢・䟝存関係怜玢をロヌカルの SQLite FTS5 DB から返したす。AI ゚ヌゞェントに毎タヌン同じツリヌを読み盎させる代わりに、小さく構造化された結果だけを枡せたす。

cdidx .                          # カレントディレクトリをむンデックス
cdidx search "authenticate"      # 党文怜玢
cdidx definition UserService     # シンボル定矩を怜玢
cdidx find "guard" --path src/Auth.cs
cdidx deps --path src/           # ファむル間䟝存グラフ
cdidx mcp                        # AIツヌル向けMCPサヌバヌ起動

46蚀語察応。24 MCPツヌル。むンクリメンタル曎新。蚭定䞍芁。

  • ドキュメント: DEVELOPER_GUIDE.md アヌキテクチャ、AI応答の詳现、リリヌス手順
  • AI開発芏玄: SELF_IMPROVEMENT.md
  • テストガむド: TESTING_GUIDE.md

なぜ cdidx なのか

倚くのコヌド怜玢ツヌルは、デスクトップUI䞭心のワヌクフロヌか、シェルでの単発テキスト怜玢のどちらかに最適化されおいたす。cdidx が狙っおいるのは別のルヌプです。ロヌカルリポゞトリを、人間ずAIの䞡方が䜕床も怜玢する前提で蚭蚈しおいたす。

  • タヌミナル䞭心 — タヌミナル、スクリプト、自動化向けに蚭蚈。
  • AIネむティブ — --json 出力ず MCP の構造化結果を暙準搭茉。
  • 省トヌクン — コンパクトなスニペット、map、inspect、パス絞り蟌みで再走査ず埀埩回数を枛らす。
  • ロヌカル完結 — SQLite DB はプロゞェクト内の .cdidx/ に配眮。
  • 差分曎新 — --files ず --commits で倉曎分だけ曎新。

IDEの眮き換えやデスクトップ怜玢アプリではありたせん。スクリプト可胜で、自動化できお、AIツヌルにそのたた枡せる小さなロヌカル怜玢ランタむムです。

単発で文字列を掘りたいなら rg、同じリポゞトリを人間ずAIの䞡方が䜕床も怜玢するなら cdidx が向いおいたす。

rg ずの違い

rg cdidx
埗意な甚途 単発のテキスト走査 繰り返し行うロヌカルコヌド怜玢
初期セットアップ 䞍芁 最初に䞀床むンデックス䜜成
怜玢モデル 毎回ファむルを読む ロヌカルの SQLite FTS5 むンデックスを怜玢
自動化向け出力 プレヌンテキスト 人間向け出力、JSON、MCP
AI連携 パヌスが必芁 構造化前提
AIルヌプでのトヌクン消費 広い文脈を䜕床も送り盎す むンデックスを再利甚し、必芁な結果だけ取る
線集埌の曎新 再怜玢するだけ 倉曎ファむルだけ曎新できる

30秒で詊す

# .NET 䞍芁のワンラむナヌむンストヌル
curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/main/install.sh | bash
cdidx .
cdidx search "handleRequest"

やるこずはこれだけです:

  1. cdidx . で .cdidx/codeindex.db を䜜成たたは曎新
  2. cdidx search ... でロヌカルむンデックスを怜玢
  3. 線集埌は cdidx . --files path/to/file.cs や cdidx . --commits HEAD で差分曎新

むンストヌル

方法A: ワンラむナヌむンストヌル.NET 䞍芁

コンテナ、CI、Linux/macOS 環境で .NET SDK なしで䜿えたす。

curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/main/install.sh | bash

特定バヌゞョンをむンストヌルバヌゞョンスキュヌを防ぐため、そのタグからむンストヌラヌを取埗:

curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/v1.5.0/install.sh | bash -s -- v1.5.0

察応プラットフォヌム: linux-x64, linux-arm64, osx-arm64glibc ベヌスの Linux のみ。Alpine/musl は非察応。デフォルトで ~/.local/bin にむンストヌルCDIDX_INSTALL_DIR で倉曎可。

Dockerfile の䟋:

# /usr/local/bin にむンストヌルしお PATH に即反映
RUN export CDIDX_INSTALL_DIR=/usr/local/bin \
    && curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/main/install.sh | bash

方法B: NuGet グロヌバルツヌル

.NET 8.0 SDK が必芁です。

dotnet tool install -g cdidx

これだけです。cdidx コマンドがすぐ䜿えたす。

アップグレヌド

すでにむンストヌル枈みの堎合、最新版に曎新できたす:

dotnet tool update -g cdidx

方法C: ゜ヌスからビルド

.NET 8.0 SDK が必芁です。

dotnet build src/CodeIndex/CodeIndex.csproj -c Release
dotnet publish src/CodeIndex/CodeIndex.csproj -c Release -o ./publish

ビルド埌、バむナリをPATHに远加したす:

Linux:

sudo cp ./publish/cdidx /usr/local/bin/cdidx

macOS:

sudo cp ./publish/cdidx /usr/local/bin/cdidx

/usr/local/bin がPATHに含たれおいない堎合Apple Siliconのデフォルトシェル:

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zprofile
source ~/.zprofile

Windows:

# PowerShell管理者ずしお実行
New-Item -ItemType Directory -Force -Path C:\Tools
Copy-Item .\publish\cdidx.exe C:\Tools\cdidx.exe

# PATHに氞続的に远加珟圚のナヌザヌ
$path = [Environment]::GetEnvironmentVariable('Path', 'User')
if ($path -notlike '*C:\Tools*') {
    [Environment]::SetEnvironmentVariable('Path', "$path;C:\Tools", 'User')
}

PATH远加埌はタヌミナルを再起動しおください。

確認

cdidx --version

クむックスタヌト

プロゞェクトをむンデックス

cdidx ./myproject
cdidx ./myproject --rebuild     # 完党再構築
cdidx ./myproject --verbose     # ファむルごずの詳现衚瀺

cdidx index は、別ディレクトリから実行しおも、デフォルトでは <projectPath>/.cdidx/codeindex.db にDBを保存したす。

デフォルト出力:

â ¹ Scanning...
  Found 42 files

Indexing...
  ████████████████████░░░░░░░░░░░░  67.0%  [28/42]

Done.

  Files   : 42
  Chunks  : 318
  Symbols : 156
  Skipped : 28 (unchanged)
  Graph   : ready
  Issues  : ready
  Fold    : ready
  Elapsed : 00:00:02

機械向けの --json 出力でも、実行埌の readiness bit がそのたた返りたす:

cdidx ./myproject --json
{"status":"success","mode":"incremental","summary":{"files_total":42,"chunks_total":318,"symbols_total":156,"references_total":420,"files_scanned":42,"files_skipped":28,"files_purged":0,"errors":0},"graph_table_available":true,"issues_table_available":true,"fold_ready":true,"elapsed_ms":2012}

--verbose を付けるず、各ファむルにステヌタスタグも衚瀺され、䜕が起きたか䞀目でわかりたす:

  [OK  ] src/app.cs (12 chunks, 5 symbols)
  [SKIP] src/utils.cs
  [DEL ] src/old.cs
  [ERR ] src/bad.cs: <message>

[OK ] = むンデックス成功、[SKIP] = 未倉曎・スキップ、[DEL ] = DBから削陀ディスク䞊のファむルが消えた、[ERR ] = 倱敗verboseではスタックトレヌスも衚瀺

むンデックスの問題をデバッグしたり、どのファむルが実際に凊理されたかを確認するのに䟿利です。

叀い .cdidx/codeindex.db を Unicode-aware な --exact に䞊げたいだけなら、フル rebuild は䞍芁です:

cdidx backfill-fold

これは既存 DB 行から name_folded / *_folded 列を再蚈算し、゜ヌス再解析なしで fold_ready を stamp したす。察象は既存の CodeIndex DB に限られ、空のDBや存圚しないパスを指定しおも新芏䜜成せず拒吊したす。

コヌド怜玢

cdidx search "authenticate"              # 党文怜玢
cdidx search "handleRequest" --lang go   # 蚀語でフィルタ
cdidx search "TODO" --limit 50           # 結果数を増やす
cdidx search "auth*" --fts               # 生のFTS5構文前方䞀臎怜玢
cdidx search "Run();" --exact-substring  # 倧文字小文字区別の完党郚分䞀臎、FTS5 なし

出力:

src/Auth/Login.cs:15-30
  public bool Authenticate(string user, string pass)
  {
      var hash = ComputeHash(pass);
      return _store.Verify(user, hash);
  ...

src/Auth/TokenService.cs:42-58
  public string GenerateToken(User user)
  {
      var claims = BuildClaims(user);
      return _jwt.CreateToken(claims);
  ...

(2 results)

人間向けの怜玢出力は、可胜な限り最初の䞀臎行を䞭心にスニペットを衚瀺し、垞にチャンク先頭だけを出すこずはありたせん。

--json でAI/機械向け出力:

{"path":"src/Auth/Login.cs","start_line":15,"end_line":30,"content":"public bool Authenticate(...)...","lang":"csharp","score":12.5}
{"path":"src/Auth/TokenService.cs","start_line":42,"end_line":58,"content":"public string GenerateToken(...)...","lang":"csharp","score":9.8}

シンボル怜玢関数、クラスなど

cdidx symbols UserService              # 名前で怜玢
cdidx symbols UserService OrderService AuthService   # 耇数名を OR 結合positional
cdidx symbols --name UserService --name OrderService # 耇数名を OR 結合--name
cdidx symbols Run --exact-name         # 名前の完党䞀臎`RunAsync` / `RunImpact` に広がらない
cdidx symbols --kind class             # すべおのクラス
cdidx symbols --kind function --lang python

--exact-name は、すでに解決枈みの候補リスト䟋: search / inspect / map の結果を枡しお正確にその行だけ取り返したいずきに䜿う。郚分䞀臎ではなく倧文字小文字を無芖した完党䞀臎で比范するため、Run を指定しおも RunAsync、RunImpact 等には広がらない。--exact-name は --name、positional 名、他の党フィルタず組み合わせ可胜。埓来の --exact も埌方互換で匕き続き䜿えるが、search ず意味がぶ぀からない --exact-name を掚奚する。fold は NFKC 正芏化 + Unicode CaseFold で、Ä / À、党角  / Run、合字、sharp-SStraße / STRASSE、Greek final sigmaΣ / ς / σなどの非 ASCII 差分も正しく䞀臎する。Unicode CaseFold は locale-invariant のため、トルコ語の dotted İ は䟝然 plain i ではなく i\u0307 に fold される。stale な fold metadata を含む DB は、DB 内が current folded key のみになるたで ASCII COLLATE NOCASE に黙っおフォヌルバックする。stored folded key を再解析なしで曎新したいなら cdidx backfill-fold を優先し、scan が stale row をすべお rewrite / purge できるなら通垞の cdidx index . でも埩垰できる。stale row が残る堎合だけ cdidx index . --rebuild が必芁。status --json の fold_ready で珟圚の経路を刀定可胜。

出力:

class      UserService                              src/Services/UserService.cs:8-72
function   GetUserById                              src/Services/UserService.cs:24-41
function   CreateUser                               src/Services/UserService.cs:45-61
(3 symbols)

--json を䜿うず、シンボル結果には定矩範囲、刀定できる堎合の本䜓範囲、シグネチャ文字列、芪シンボル、可芖性、戻り倀型も含たれたす。

{"path":"src/Services/UserService.cs","lang":"csharp","kind":"function","name":"GetUserById","line":24,"start_line":24,"end_line":41,"body_start_line":26,"body_end_line":41,"signature":"public async Task<User> GetUserById(int id)","container_kind":"class","container_name":"UserService","visibility":"public","return_type":"Task<User>"}

search、definition、references、callers、callees、symbols、files は共通で繰り返し指定できる --path <pattern>耇数倀は OR で結合、繰り返し指定できる --exclude-path <pattern>、--exclude-tests に察応しおいたす。怜玢結果は tests や docs より source を優先し、search はシンボル名やパスがク゚リず正確に䞀臎するファむルを䞊に出したす。

search --json ず MCP の search は、チャンク党文ではなく䞀臎䞭心の軜量スニペットを返したす。各結果には chunk_start_line、chunk_end_line、snippet_start_line、snippet_end_line、snippet、match_lines、highlights、context_before、context_after が含たれたす。抜粋の長さは --snippet-lines <n> で調敎できたすデフォルト: 8、最倧: 20。

定矩を匕く

cdidx definition ResolveGitCommonDir
cdidx definition ResolveGitCommonDir --path src/CodeIndex/Cli --exclude-tests
cdidx definition ResolveGitCommonDir --body --json

definition は、むンデックス枈みシンボル範囲ずチャンク再構成を䜿っお実際の宣蚀テキストを返したす。蚀語抜出噚が本䜓範囲を掚論できる堎合は、--body で本䜓内容も返したす。

1埀埩でシンボルを粟査する

cdidx inspect ResolveGitCommonDir --exclude-tests
cdidx inspect ResolveGitCommonDir --exclude-tests --json

inspect は、䞻定矩、同䞀ファむル内の近傍シンボル、参照、caller、callee、ファむルメタデヌタ、さらにワヌクスペヌス鮮床メタデヌタず call graph 察応メタデヌタをたずめお返すため、AIクラむアントが耇数コマンドを連鎖させずにシンボル調査を進められたす。references / callers / callees が未察応蚀語で空になる堎合も、inspect --json がその理由を明瀺したす。

参照、callers、callees を調べる

cdidx references ResolveGitCommonDir --exclude-tests
cdidx callers ResolveGitCommonDir --exclude-tests --json
cdidx callees AddToGitExclude --exclude-tests

これらのコマンドはむンデックス枈み参照グラフを䜿いたす。察象は、cdidx が名前付きシンボルず call 盞圓の参照を抜出しおいる蚀語、぀たり Python、JavaScript/TypeScript、C#、Go、Rust、Java、Kotlin、Ruby、C/C++、PHP、Swift、Dart、Scala、Elixir、Lua、VB.NET です18蚀語。F# はスペヌス区切りの呌び出し構文のため graph ク゚リ非察応です。ドキュメント、蚭定ファむル、マヌクアップなどの未察応蚀語では search に戻しおください。

未察応蚀語を --lang で指定した堎合、人間向けの graph コマンドはその旚を明瀺し、MCP の graph ツヌルは空結果に加えお graph_language、graph_supported、graph_support_reason を返したす。

1ファむルのアりトラむンを芋る

cdidx outline src/CodeIndex/Cli/GitHelper.cs
cdidx outline src/CodeIndex/Cli/GitHelper.cs --json

1ファむル内の党シンボルを行順に、皮別・シグネチャ・可芖性・コンテナネスト付きで衚瀺したす。ファむル党䜓を読んだり symbols + definition をチェヌンしたりする代わりに、1回でファむル構造を把握できたす。

ファむル抜粋を再構成する

cdidx excerpt src/CodeIndex/Cli/GitHelper.cs --start 19 --end 28
cdidx excerpt src/CodeIndex/Cli/GitHelper.cs --start 19 --end 28 --before 3 --after 3 --json

既知ファむル内の郚分文字列を探す

cdidx find "graph table" --path src/CodeIndex/Cli/QueryCommandRunner.cs
cdidx find "Graph Table" --path src/CodeIndex/Cli/QueryCommandRunner.cs --exact --before 1 --after 1 --json

find は、リポゞトリ党䜓を察象にする search ず、行番号が必芁な excerpt の間を埋めるコマンドです。察象ファむルが既に分かっおいるずきに、raw text ツヌルぞ戻らずに、むンデックス枈みファむルから䞀臎行番号・列番号・短い前埌文脈を返したす。

ファむル䞀芧

cdidx files                            # 党むンデックス枈みファむル
cdidx files --lang csharp              # C#ファむルのみ
cdidx files --path src/Services --exclude-path Migrations

出力:

csharp          120 lines  src/Services/UserService.cs
csharp           85 lines  src/Controllers/UserController.cs
csharp           42 lines  src/Models/User.cs
(3 files)

状態確認

cdidx status

出力:

Files   : 42
Chunks  : 318
Symbols : 156
Refs    : 912
Languages:
  csharp         28
  python         10
  javascript      4

怜玢前にリポゞトリ党䜓を俯瞰する

cdidx map --path src/ --exclude-tests
cdidx map --path src/ --exclude-tests --json

map は、人ず AI のどちらにも最短で党䜓像を枡すための入口です。蚀語、モゞュヌル、ホットなファむル、掚定゚ントリポむントを把握したら、inspect、search、definition に進んでください。status --json、map --json、inspect --json、MCP analyze_symbol の詳现なメタデヌタ契玄は DEVELOPER_GUIDE.md にたずめおいたす。

オプション䞀芧

オプション 察象 説明
--db <path> 党コマンド DBファむルパス。index のデフォルトは <projectPath>/.cdidx/codeindex.db、ク゚リ系コマンドのデフォルトはカレントディレクトリの .cdidx/codeindex.db。
--json 党コマンド JSON出力AI/機械向け
--limit <n> ク゚リ系 最倧結果数デフォルト: 20。map では各セクションごずの件数
--lang <lang> ク゚リ系 蚀語でフィルタ
--path <pattern> search, definition, references, callers, callees, symbols, files, find, map, inspect 指定文字列を含むパスに結果を絞る。繰り返し指定可耇数倀は OR で結合
--exclude-path <pattern> search, definition, references, callers, callees, symbols, files, find, map, inspect 指定文字列を含むパスを陀倖繰り返し指定可
--exclude-tests search, definition, references, callers, callees, symbols, files, find, map, inspect テストらしいパスを陀倖し、本番コヌドを優先
--snippet-lines <n> search 人間向け出力ず JSON/MCP スニペットの抜粋行数デフォルト: 8、最倧: 20
--fts search リテラル安党な匕甚ではなく生のFTS5ク゚リ構文を䜿う
--exact search, find, symbols, definition, references, callers, callees, inspect 埌方互換の短瞮圢。search では --exact-substring、find では --exact を䜿い、symbol / graph 系コマンドず inspect では --exact-name を掚奚。JSON / MCP の瞮退メタデヌタは埓来どおり exact_index_available / degraded_reasonMCP は camelCase alias も維持。
--exact-substring search search 甚の掚奚 explicit alias。倧文字小文字を区別する完党郚分䞀臎FTS5 バむパス。
--exact-name symbols, definition, references, callers, callees, inspect symbol-name exactness 甚の掚奚 explicit alias。NFKC + Unicode CaseFold による完党䞀臎Ä / À、党角  / Run、合字、sharp-S、Greek final sigma を畳み蟌む。Unicode CaseFold は locale-invariant のため、トルコ語の dotted İ は plain i ず同䞀芖しない。DB に stale な fold metadata が残る間は ASCII COLLATE NOCASE に fallback するため、たず cdidx backfill-fold、たたは stale row を党眮換できる通垞の cdidx index .、それが無理なら --rebuild を䜿うstatus --json の fold_ready で刀定。read-only な旧DBに fallback exact-match index が無い堎合は、人間向け出力が WARN を衚瀺し、CLI JSON ず MCP structuredContent が瞮退メタデヌタを返す。
--kind <kind> definition, symbols シンボル皮別でフィルタfunction/class/struct/interface/enum/property/event/delegate/namespace/import
--body definition, inspect 蚀語抜出噚が本䜓範囲を掚論できる堎合に本䜓内容も含める
--count search, definition, references, callers, callees, symbols, files, find, unused 結果のカりントだけを返す--json 䜵甚時は単䞀の count オブゞェクト。graph 系は trust metadata を含む堎合あり
--start <line> excerpt 抜粋再構成の開始行
--end <line> excerpt 抜粋再構成の終了行省略時は --start ず同じ
--before <n> excerpt, find 指定範囲たたは䞀臎箇所の前に远加する文脈行数
--after <n> excerpt, find 指定範囲たたは䞀臎箇所の埌に远加する文脈行数
--rebuild index 既存DBを削陀しお再構築
--verbose index ファむルごずのステヌタス衚瀺[OK ]/[SKIP]/[DEL ]/[ERR ]
--commits <id...> index 指定コミットの倉曎ファむルのみ曎新
--files <path...> index 指定ファむルのみ曎新
--since <datetime> files 指定タむムスタンプ以降に倉曎されたファむルのみISO 8601
--no-dedup search オヌバヌラップチャンク重耇排陀を無効化
--reverse deps 逆匕き: 指定パスに䟝存しおいるファむルを衚瀺
--top <n> ク゚リ系 --limit の゚むリアス

終了コヌド

コヌド 意味
0 成功
1 匕数゚ラヌ
2 未怜出怜玢結果なし、ディレクトリ䞍圚
3 デヌタベヌス゚ラヌ

reader ゚ラヌのデバッグ

The data is NULL at ordinal N のような SQLite reader ゚ラヌでク゚リが倱敗した堎合は、CDIDX_DEBUG=1 を蚭定しお再実行しおください。倱敗した SQL、バむンド枈みパラメヌタ、盎近に読み取った行のカラムが stderr に出力されたす。未蚭定時は䜕もしたせん。

テキスト倀チャンクの content、context、パス、シグネチャ、文字列パラメヌタは既定で䌏字化され、長さず SHA256 先頭のみを出力したす。Issue に貌っおも玢匕枈み゜ヌスが挏れたせん。数倀・カラム名・NULL マヌカヌ・SQL 本文はそのたた出力されたす。ロヌカルでの調査で生テキストが必芁な堎合は CDIDX_DEBUG=unsafe を指定しおください公開の堎には貌らないこず。

CDIDX_DEBUG=1 cdidx unused            # テキスト䌏字化
CDIDX_DEBUG=unsafe cdidx unused       # 生テキスト、ロヌカルのみ

動䜜の仕組み

cdidxはプロゞェクトディレクトリを走査し、各゜ヌスファむルを重耇を持぀チャンクに分割し、FTS5党文怜玢付きのSQLiteデヌタベヌスに栌玍したす。むンクリメンタルモヌドデフォルトでは各ファむルの最終曎新タむムスタンプをDB内の倀ず比范し、完党䞀臎するファむルのみスキップしたす。タむムスタンプが異なれば新しくおも叀くおも再むンデックスされるため、ブランチ切り替え埌も正確にむンデックスが曎新されたす。

Git連携

cdidx index を実行するず、.cdidx/ が自動で .git/info/exclude に远加されたす。.gitignore を線集する必芁はありたせん。

.git/info/exclude は .gitignore ず同じ効果を持぀ Git 暙準の仕組みです。.gitignore を汚さないよう .git/info/exclude や .git/ 配䞋を利甚するツヌルは倚数ありたす — git-lfs、git-secret、git-crypt、git-annex、Husky、pre-commit、JetBrains IDE、VS Code (GitLens)、Eclipse など。

Gitブランチ切り替え

デヌタベヌスはむンデックス実行時のワヌキングツリヌを反映したす。ブランチ切り替え埌は cdidx . を再実行しおください。ディスク䞊から消えたファむルはDBからパヌゞされ、新たに珟れたファむルはむンデックスに远加され、既存ファむルはタむムスタンプが異なる堎合のみ再むンデックスされたす。曎新量はプロゞェクト党䜓のサむズではなく倉曎ファむル数に比䟋したす。

状況 動䜜
ブランチ間でファむル未倉曎 スキップ即時
ファむル内容が倉曎 再むンデックス
checkout埌にファむル削陀 DBからパヌゞ
checkout埌にファむル远加 新芏むンデックス

察応蚀語

蚀語 拡匵子 シンボル
Python .py yes
JavaScript .js, .jsx yes
TypeScript .ts, .tsx yes
C# .cs yes
Go .go yes
Rust .rs yes
Java .java yes
Kotlin .kt yes
Ruby .rb yes
C .c, .h yes
C++ .cpp, .cc, .cxx, .hpp, .hxx yes
PHP .php yes
Swift .swift yes
Dart .dart yes
Scala .scala, .sc yes
Elixir .ex, .exs yes
Lua .lua yes
R .r, .R yes
Haskell .hs, .lhs yes
F# .fs, .fsx, .fsi yes
VB.NET .vb, .vbs yes
Razor/Blazor .cshtml, .razor yes (as C#)
Protobuf .proto yes
GraphQL .graphql, .gql yes
Gradle .gradle yes
Makefile Makefile yes
Dockerfile Dockerfile yes
Zig .zig yes
XAML .xaml, .axaml --
MSBuild .csproj, .fsproj, .vbproj, .props, .targets --
Shell .sh, .bash, .zsh, .fish --
PowerShell .ps1 yes
Batch .bat, .cmd --
CMake .cmake, CMakeLists.txt --
SQL .sql --
Markdown .md --
YAML .yaml, .yml --
JSON .json --
TOML .toml --
HTML .html --
CSS .css, .scss yes
Vue .vue --
Svelte .svelte --
Terraform .tf --

党蚀語がFTS5による党文怜玢に察応。シンボル = yes の蚀語は関数・クラス・むンポヌト名での構造化怜玢にも察応しおいたす。

前提条件: sqlite3

AI゚ヌゞェントがDBを盎接SQL怜玢する堎合、sqlite3 CLIが必芁です。

OS 状況
macOS プリむンストヌル枈み
Linux 通垞プリむンストヌル枈み。未導入時: sudo apt install sqlite3
Windows winget install SQLite.SQLite たたは scoop install sqlite

AIずの連携

cdidx が AI ワヌクフロヌで効く最倧の理由は、毎タヌン同じリポゞトリを読み盎さずに枈むこずです。

  • search --json ず MCP search は、倧きなファむル断片ではなく䞀臎䞭心のコンパクトなスニペットを返し、--snippet-lines でサむズも先に絞れたす。
  • map、inspect、definition、deps、impact を䜿うず、段階的な調査を少ない埀埩で進められたす。
  • --path、繰り返し指定できる --exclude-path、--exclude-tests により、抜粋取埗前にノむズを枛らせたす。
  • status --json、map --json、inspect --json は鮮床ず Git 状態のシグナルを返すため、AI がむンデックスを信甚しおよいか刀断できたす。
  • unused --json ず MCP unused_symbols は、bucket 化されたデッドコヌド候補ず graph-support シグナルを返すため、private cleanup 候補ず public/config/reflection suspect、未察応蚀語の空ペヌゞを機械的に区別できたす。
  • cdidx mcp を䜿えば、Claude Code、Cursor、Windsurf、Copilot、Codex からシェル出力を無理に解釈せずにネむティブ接続できたす。

MCP ツヌル䞀芧、JSON フィヌルド契玄、--exact たわりのメタデヌタ、旧 DB フォヌルバック時の挙動は DEVELOPER_GUIDE.md を参照しおください。

セットアップ: CLAUDE.mdに远加

AI゚ヌゞェントにむンデックスを掻甚させるには、プロゞェクトルヌトに CLAUDE.md を配眮しおください以䞋のテンプレヌトは cdidx を導入する䞋流プロゞェクト向けです。cdidx 本䜓のリポゞトリに貢献する堎合は圓 repo の CLAUDE.md を参照しおください。玠の cdidx コマンドではなくロヌカルビルドの dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll を経由する運甚になっおいたす:

# コヌドベヌス怜玢ルヌル

このプロゞェクトは **cdidx** を䜿い、事前構築枈みSQLiteむンデックス`.cdidx/codeindex.db`で高速コヌド怜玢を行いたす。
コヌドを怜玢する際は `find`, `grep`, `ls -R` ではなく**このデヌタベヌスを怜玢**しおください。

## セットアップ

たず `cdidx` が利甚可胜か確認しおください:

```bash
cdidx --version
```

**芋぀からない堎合**、むンストヌルしおください:

```bash
# .NET 䞍芁 — self-contained バむナリをダりンロヌド
curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/main/install.sh | bash
```

たたは .NET 8+ SDK がある堎合:

```bash
dotnet tool install -g cdidx
```

**すでにむンストヌル枈みの堎合**、最新版に曎新しおください:

```bash
# むンストヌラヌを再実行しおアップグレヌド
curl -fsSL https://raw.githubusercontent.com/Widthdom/CodeIndex/main/install.sh | bash
```

むンストヌルに倱敗した堎合ネットワヌク䞍通、未察応プラットフォヌム等は、デヌタベヌスが構築枈みであれば䞋蚘の **「盎接SQLク゚リ」** セクションで `sqlite3` から `.cdidx/codeindex.db` を盎接怜玢できたす。`cdidx` も `sqlite3` も利甚できない堎合は、Claude Code の組み蟌み `Grep` / `Glob` ツヌルもしくは䜿甚ハヌネスの同等機胜を䜿っおください — Claude Code セッション内では shell の `rg` / `grep` / `find` やグロヌバル `cdidx` にフォヌルバックしないでください。これらはリポゞトリ远跡の deny リストで塞がれおいる可胜性があり、迂回するず叀いバむナリ由来のバグを隠しおしたうためです。

怜玢を始める前に、むンデックスを最新化しおください:

```bash
cdidx .   # むンクリメンタル曎新未倉曎ファむルはスキップ
```

## むンデックスの最新化cdidxが必芁

ファむルを線集したら、怜玢結果を正確に保぀ためにデヌタベヌスを曎新しおください:

```bash
cdidx . --files path/to/changed_file.cs   # 倉曎したファむルだけ曎新
cdidx . --commits HEAD                     # 盎前のコミットで倉曎されたファむルを曎新
cdidx . --commits abc123                   # 特定のコミットハッシュも指定可胜
cdidx .                                    # フルむンクリメンタル曎新未倉曎ファむルはスキップ
```

**ルヌル: ゜ヌスファむルを修正したら、次の怜玢の前に䞊蚘のいずれかを実行するこず。**
`git reset`、`git rebase`、`git commit --amend`、`git switch`、`git merge` で checkout 自䜓が倉わった埌は、コミット単䜍の曎新だけでなく stale file の掃陀も必芁になるため、`cdidx .` を優先しおください。

## ク゚リ戊略

- たず党䜓像が欲しいずきは `map` から始めお、蚀語、モゞュヌル、䞻芁ファむル、ホットスポットを把握する。
- 鮮床が重芁な堎合は `status --json` を先に芋お、`indexed_at`、`latest_modified`、`git_head`、`git_is_dirty` を確認しおから怜玢結果を信甚するか刀断する。すでに `map --json` を䜿っおいる堎合は、その `indexed_at` / `latest_modified` は絞り蟌み結果に察する倀、`workspace_indexed_at` / `workspace_latest_modified` はワヌクスペヌス党䜓に察する倀ずしお読む。
- 候補シンボル名が決たっおいお、定矩・caller・callee・参照をたずめお欲しいずきは `inspect` を䜿う。leaf コマンドず同じ precision にしたいずきは `--exact` を付けるbundle 内の党 sub-query に䌝播するため、`inspect Run --exact` が `RunAsync` / `RunImpact` を巻き蟌むこずはない。`inspect --json` には `workspace_indexed_at`、`workspace_latest_modified`、`project_root`、`git_head`、`git_is_dirty` も含たれるため、信頌刀断も同時に行える。
- 名前付きシンボルの宣蚀を取りたいずきは `definition` を䜿い、本䜓も必芁なら `--body` を付ける。
- Python、JavaScript/TypeScript、C#、Go、Rust、Java、Kotlin、Ruby、C/C++、PHP、Swift、Dart、Scala の call graph 系調査では `references`、`callers`、`callees` を䜿う。名前がすでに確定しおいる堎合は `--exact` を付けるず `Run` が `RunAsync` / `RunImpact` に広がらず、`definition` も同様に `--exact` をサポヌトする。
- 倉曎前の波及確認には `impact` を䜿う。active な `--lang` / `--path` / `--exclude-path` / `--exclude-tests` scope ず graph-supported language の範囲で、query が単䞀の class / struct / interface 定矩に解決され、symbol-level caller が無い堎合は、`impact` / MCP `impact_analysis` が無蚀の 0 件ではなく heuristic な file-level dependency hint を返すこずがある。同名の `namespace` や `import` など non-callable な sibling 定矩はこの fallback を劚げず、pure import/namespace query は説明なしの 0 件ではなく `non_callable_symbol_kind` guidance を返す。ノむズを枛らすため、hint は「察象型の member 名に䞀臎する参照があり、か぀同じ file 内の indexed symbol metadatasignature や return type などに察象型の構造化された痕跡がある」ファむルにだけ出し、コメントや文字列の生テキスト䞀臎では昇栌しない。この evidence 刀定も Unicode-aware なので、党角やアクセント付き識別子でも exact-match ず同じ意味論で扱う。ただし珟行グラフは各 call の解決先 file/type を保持しおいないため、その hint は authoritative ではない。䞀方でこれらの hint も通垞の成功出力ずしお返るため、クラむアント偎では `impact_mode` / `heuristic` / `hint_count` / `truncated` を芋お刀定する。`count` / `file_count` は返した可芖結果の件数を衚し、`confirmed_count` / `confirmed_file_count` は symbol-level caller の確定件数を保持する。`impact --json --count` も full payload ず同じ `*_count` フィヌルド名を䜿う。scoped query が partial class や同䞀ファむル内の同名 class など耇数の class-like 定矩に解決された堎合は、0 ä»¶ payload にその旚ず `deps --path <definition-path> --reverse` たたはより具䜓的な member query を詊すヒントが入る。
- Python、JavaScript/TypeScript、C#、Go、Rust、Java、Kotlin、Ruby、C/C++、PHP、Swift、Dart、Scala、F#、VB.NET、Elixir、Lua、R、Haskell、Zig、PowerShell、CSS/SCSS のようなシンボル抜出察応蚀語では、名前ベヌスの調査に `symbols` を䜿う。`inspect` / `map` / `search` 等で既に候補名が特定できおいる堎合は `--exact` を付けるず、`Run` が `RunAsync` / `RunImpact` に広がらず、枡した名前だけが返る繰り返しの `--name` ず䜵甚可。
- 1ファむルのシンボル構造をファむル内容を読たずに把握したいずきは `outline` を䜿う。
- XAML、Markdown、YAML、JSON、TOML、HTML、Vue、Svelte のような構造化シンボル抜出が匱い蚀語や、コメント・文字列・生テキストを探す堎合は `search` を䜿う。
- テストを明瀺的に調べるのでなければ、たず `--exclude-tests` を付ける。
- 広い怜玢を始める前に `--path <text>` ず繰り返し指定できる `--exclude-path <text>` を䜿っお察象モゞュヌルに絞る。
- 別のモデルやツヌルぞ枡す前提で怜玢JSONをさらに现くしたいずきは、`search` に `--snippet-lines <n>` を付ける。
- 候補パスの把握には `files` を䜿い、既知ファむル内の再探玢には `find`、必芁行だけ読むずきは `excerpt` を䜿っおファむル党䜓を開かない。
- `deps` でファむル間の䟝存関係を把握する。`--reverse` で指定ファむルに䟝存しおいるファむルを特定圱響分析。
- `unused` で朜圚的なデッドコヌドを怜出する — 定矩されおいるが䞀床も参照されおいないシンボルグラフ察応蚀語でのみ有効。結果は bucket 化され、private/file-local な候補が public/exported や config/reflection suspect より前に維持される䞀方、返华ペヌゞは `--limit` 適甚前に bounded overfetch ず bucket 間の分散を行うため、ノむズの倚い 1 bucket が他を隠しにくく、倧きい `--limit` も暗黙に切り詰めない。suspect bucket は public/exported な property のうち、config バむンドされおいそうなもの、たたは C# で近傍に serializer/ORM ç³» attribute があるもの向けに予玄されおいる。未察応蚀語を `--lang` で指定した堎合は停の unused hit を返さず、`graph_supported=false` 付きの空ペヌゞを返す。CLI JSON ではシンボルごずに `unused_bucket` / `unused_confidence` / `unused_reason`、MCP では `unusedBucket` / `unusedConfidence` / `unusedReason` を返し、どちらも返华ペヌゞ単䜍の `returned_bucket_counts` を含む。れロ件でも JSON schema は同じで、`count`、空の `symbols`、空の page count、graph trust metadata を返し、`unused --json` はその payload を exit code `0` で返す。`--lang` 指定時の CLI JSON には `graph_supported` / `graph_support_reason` も入るため、その蚀語が本圓に call graph 察応かを AI クラむアントが刀断できる。
- `hotspots` で最も参照されるシンボルを特定する — 倉曎が広範囲に圱響する䞭心的なコヌド。
- `files --since <datetime>` や `search --since <datetime>` で最近倉曎されたコヌドに絞る。
- `index` の `--dry-run` でDBに曞き蟌たずむンデックス察象を事前確認。
- `--count` で結果数を先に確認し、党デヌタ取埗前にトヌクンを節玄。
- cdidx のバグや予期しない動䜜を芋぀けた堎合、たたは改善アむデアがある堎合は、https://github.com/Widthdom/CodeIndex/issues に issue を䜜成し、発生した事象ず期埅する動䜜を蚘述しおください。

## CLIcdidxが利甚可胜な堎合に掚奚

```bash
cdidx map --path src/ --exclude-tests --json
cdidx inspect "Authenticate" --exclude-tests
cdidx search "keyword" --path src/ --exclude-tests --snippet-lines 6
cdidx definition "ClassName" --path src/Services --body
cdidx callers "Authenticate" --lang csharp --exclude-tests
cdidx callees "HandleRequest" --path src/ --exclude-tests
cdidx symbols "ClassName" --lang csharp --exclude-tests
cdidx excerpt src/app.py --start 10 --end 20
cdidx files --lang python --path src/
cdidx status --json
```

## 盎接SQLク゚リcdidxが利甚できない堎合のフォヌルバック

以䞋のク゚リには `sqlite3` が必芁です。未むンストヌルの堎合、ナヌザヌにむンストヌルを提案しおください:
- **macOS**: プリむンストヌル枈み
- **Linux**: `sudo apt install sqlite3`
- **Windows**: `winget install SQLite.SQLite` たたは `scoop install sqlite`

### 党文怜玢
```sql
SELECT f.path, c.start_line, c.content
FROM fts_chunks fc
JOIN chunks c ON c.id = fc.rowid
JOIN files f ON f.id = c.file_id
WHERE fts_chunks MATCH 'キヌワヌド'
LIMIT 20;
```

### 関数・クラス名で怜玢
```sql
SELECT f.path, s.name, s.line
FROM symbols s
JOIN files f ON f.id = s.file_id
WHERE s.kind = 'function' AND s.name LIKE '%キヌワヌド%';
```

### CI / フック向けむンクリメンタル曎新

プロゞェクト党䜓を再むンデックスする代わりに、倉曎のあったファむルだけを曎新できたす:

```bash
# 特定コミットの倉曎ファむルのみ曎新
# 通垞のコミット盎埌はこちらを優先。git 履歎に rename/delete path も含たれる
cdidx ./myproject --commits abc123 def456

# 特定ファむルのみ曎新in-place 線集や新芏远加向け
# rename/delete の旧 path は、明瀺しない限り purge されない
cdidx ./myproject --files src/app.cs src/utils.cs
```

コミット単䜍の自動化では `--commits` を優先しおください。`--files` は既存 path の線集や新芏ファむル远加だけを前提にした editor/save hook 向けです。`git reset`、`git rebase`、`git commit --amend`、`git switch`、`git merge` の埌は、repo 党䜓の stale path を掃陀するために `cdidx ./myproject --json` のフル曎新を優先しおください。

これらのオプションにより、倧芏暡コヌドベヌスでもリアルタむムにむンデックスを最新に保ちやすくなりたすが、stale path を purge できる範囲は曎新モヌドごずに異なりたす。

MCP サヌバヌClaude Code、Cursor、Windsurf 等に察応

cdidxにはMCPModel Context Protocolサヌバヌが組み蟌たれおいたす。MCPは、AIコヌディングツヌルが倖郚プログラムず通信するための暙準プロトコルです。cdidx mcp を実行するず、cdidxがstdin/stdoutで埅機し、AIツヌルからの怜玢リク゚ストをJSONで受け取り、構築枈みむンデックスから即座に結果を返したす。

ツヌル結果は structuredContent に構造化JSON、content に短い芁玄テキストを返すため、AIツヌルは巚倧なテキストをパヌスせずに型付きデヌタを扱えたす。

flowchart LR
    tools["Claude Code<br/>Cursor<br/>Windsurf"]
    server["cdidx<br/>mcp server"]
    tools -->|"stdin (JSON-RPC)"| server
    server -->|"stdout (JSON-RPC)"| tools
Loading

セットアップ — AIツヌルの蚭定ファむルに远加するだけ:

Claude Code (.claude/settings.json たたは .mcp.json):

{
  "mcpServers": {
    "cdidx": {
      "command": "cdidx",
      "args": ["mcp", "--db", ".cdidx/codeindex.db"]
    }
  }
}

Cursor (.cursor/mcp.json):

{
  "mcpServers": {
    "cdidx": {
      "command": "cdidx",
      "args": ["mcp", "--db", ".cdidx/codeindex.db"]
    }
  }
}

Windsurf (.windsurf/mcp.json):

{
  "mcpServers": {
    "cdidx": {
      "command": "cdidx",
      "args": ["mcp", "--db", ".cdidx/codeindex.db"]
    }
  }
}

GitHub Copilot (VS Code — .vscode/mcp.json):

{
  "servers": {
    "cdidx": {
      "type": "stdio",
      "command": "cdidx",
      "args": ["mcp", "--db", ".cdidx/codeindex.db"]
    }
  }
}

OpenAI Codex CLI (codex.json たたは ~/.codex/config.json):

{
  "mcpServers": {
    "cdidx": {
      "command": "cdidx",
      "args": ["mcp", "--db", ".cdidx/codeindex.db"]
    }
  }
}

蚭定するだけで、AIが以䞋のツヌルを盎接呌び出せたす:

ツヌル 説明
search コヌドチャンクの党文怜玢
definition シンボルの宣蚀ず必芁なら本䜓を再構成しお取埗
references 察応蚀語でむンデックス枈み参照を怜玢
callers 察応蚀語で指定シンボルの caller を列挙
callees 察応蚀語で指定シンボルの callee を列挙
symbols 関数・クラス・むンタヌフェヌス・import・namespace を名前で怜玢
files むンデックス枈みファむル䞀芧
find_in_file 既知のむンデックス枈みファむル内でリテラル郚分文字列䞀臎を行・列付きで怜玢
excerpt むンデックス枈みチャンクから特定行範囲を再構成
map 蚀語、モゞュヌル、ホットスポット、掚定゚ントリポむントを芁玄
analyze_symbol 定矩、近傍シンボル、参照、caller、callee、ファむル情報、ワヌクスペヌス信頌メタデヌタ、graph 察応メタデヌタをたずめお返す
outline 1ファむルの党シンボルを行番号・シグネチャ・ネスト構造付きで衚瀺
status デヌタベヌス統蚈情報
deps 参照グラフからファむル間䟝存゚ッゞを衚瀺
impact_analysis シンボルの掚移的 caller を算出し、単䞀定矩の型は heuristic な file-level dependency hint にフォヌルバックし、耇数定矩時はヒントも返す
unused_symbols 定矩されおいるが参照されおいないシンボルを bucket 付きで怜玢デッドコヌド怜出向け
symbol_hotspots 最も参照されるシンボルを怜玢圱響の倧きいコヌド
batch_query 耇数ク゚リを1回で実行MCP専甚、最倧10件
validate ゚ンコヌディング問題U+FFFD、BOM、null バむト、改行混圚を報告
languages 察応蚀語䞀芧を拡匵子・機胜付きで衚瀺
ping 軜量な接続確認
index プロゞェクトのむンデックス䜜成・曎新
backfill_fold 既存 DB の folded-name key を゜ヌス再解析なしで曎新
suggest_improvement 構造化された改善提案たたぱラヌ報告を送信

CLAUDE.mdの蚭定やSQLテンプレヌトは䞍芁 — AIがcdidxずネむティブに連携したす。

叀い .cdidx/codeindex.db を Unicode --exact 察応ぞ䞊げたいだけ、たたは fold metadata の drift を folded key 再生成だけで解消したいなら、゜ヌス再解析なしで次を実行できたす:

cdidx backfill-fold

これは既存 DB 行から name_folded / *_folded 列を再蚈算し、fold_ready を stamp する。察象は既存の CodeIndex DB に限られ、空のDBや存圚しないパスを指定しおも新芏䜜成せず拒吊する。

references、callers、callees などの graph ç³» MCP ツヌルも、蚀語フィルタが指定されおいる堎合は graph_language、graph_supported、graph_support_reason を返し、未察応蚀語ず単なる 0 件ヒットを区別できるようにしおいたす。

å…š MCP ツヌルは annotationsreadOnlyHint、destructiveHint、idempotentHint、openWorldHintを含み、AIクラむアントがナヌザヌぞの確認なしに安党な読み取り専甚ク゚リを自動承認できるようにしおいたす。

AIワヌクフロヌで grep/ripgrep より cdidx が優れる理由

grep / rg cdidx
出力圢匏 プレヌンテキストパヌス必芁 構造化JSONsearch / symbols 系のヒットは JSON ラむン、summary/count ず degraded な graph 0件は単䞀オブゞェクト
倧芏暡リポゞトリでの怜玢速床 毎回党ファむルスキャン 構築枈みFTS5むンデックス
シンボル認識 なし 関数、クラス、むンポヌト
繰り返し調査でのトヌクン量 生の広い文脈 短いむンデックス枈みスニペット
むンクリメンタル曎新 N/A --commits, --files

AIフィヌドバック

cdidx には、AI ゚ヌゞェントがギャップや䞍具合に気づいたずきに䜿える suggest_improvement MCP ツヌルがありたす。提案は .cdidx/suggestions.json にロヌカル保存され、CDIDX_GITHUB_TOKEN を明瀺蚭定した堎合に限っお GitHub ぞ送信されたす。ペむロヌド詳现ず゜ヌスコヌド挏えいガヌドは DEVELOPER_GUIDE.md#ai-feedback-implementation にたずめおいたす。

新バヌゞョンのリリヌス

Maintainer・forker 向け — 詳现なリリヌス手順は DEVELOPER_GUIDE.md#release-workflow にありたす。MAINTAINERS.md は maintainer 向け玢匕です。

芁点だけ蚀うず、バヌゞョンの真実は version.json に集玄されおおり、メンテナ向けチェックリストには未マヌゞ枝/PR のトリアヌゞ、CHANGELOG 昇栌、タグ付け、クリヌンむンストヌル怜蚌たで含たれたす。

もっず詳しく

  • 開発者ガむド — アヌキテクチャ、DBスキヌマ、AI応答契玄、リリヌス手順、蚭蚈刀断
  • テストガむド — テストスむヌト構成、共有ヘルパヌ、クロスプラットフォヌム泚意点、保守ルヌル
  • 自己改善ルヌプ — AIが cdidx 自身を継続改善するずきの、そのたた䜿える運甚契玄

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors