設定

零設定是預設——唯一的選擇性檔是自訂副檔名對映與排除規則
codegraph.json(專案根目錄)· gitignore 優先 · 內建排除不可覆蓋

零設定預設

CodeGraph 開箱即零設定:語言支援依副檔名自動,沒什麼要逐語言接線。唯一的選擇性檔是 codegraph.json,放在專案根目錄。

開箱即跳過:

排除 / 納入

想把東西排除:加進 .gitignore。想把預設排除的目錄拉回來(例如你真的想索引 vendored 依賴):加否定式 !vendor/

.gitignore 無法丟掉你已 commit 的目錄。對已 commit 的 vendored theme / SDK(例如 Metronic theme 在 static/),在 codegraph.jsonexclude 下列出(gitignore 風格 pattern,對 repo-root-relative 路徑比對,index/sync/watch 都適用):

{
  "exclude": ["static/", "**/vendor/**"]
}

反過來,當真原始碼被刻意 gitignore(專案同時用第二套 VCS——SVN、Perforce——把自己原始碼 gitignore 掉),用 include 強制拉回(includeexclude 的反面;includeIgnored 只救回 embedded git repos,不是普通原始碼):

{
  "include": ["Tools/", "Local/typescript/"]
}

CodeGraph 在 index/sync/watch 時從磁碟發現這些檔、覆寫 .gitignore。顯式 exclude 仍優先;內建跳過(node_modulesdist.git)永不重開。

自訂副檔名

專案用非標準副檔名對應受支援語言時(例如 .dota_lua 是 Lua、.tpl 是 PHP),用 extensions 對映:

{
  "extensions": {
    ".dota_lua": "lua",
    ".tpl": "php"
  }
}

每個值是受支援的語言 id。對映會疊在內建預設之上、衝突時取勝,所以也能改指內建(例如 ".h": "cpp")。commit 這個檔與團隊共享。打錯語言或格式壞掉的檔只會警告並跳過,不會中斷索引;改完對映要 codegraph index 重跑。

相關環境變數(速查)

變數作用
CODEGRAPH_WATCH_DEBOUNCE_MSwatcher debounce 窗口(100ms–60s,預設 2000)
CODEGRAPH_MCP_TOOLSMCP 工具 allowlist(預設只有 explore)
CODEGRAPH_NO_DAEMON跳過共享背景 server,每個 session 自己跑
CODEGRAPH_DIR換 .codegraph 目錄名(Windows/WSL 共存用)
CODEGRAPH_TELEMETRY=0 / DO_NOT_TRACK=1關閉匿名 telemetry
看完這頁你應該能說出:三個開箱即跳過的規則、exclude vs include 的語意(含為何不能靠 .gitignore 丟已 commit 目錄)、extensions 對映的合併/覆蓋規則、以及改對映後要 re-index。