# CLI 参考

> codeweb 全部子命令与参数，对照当前版本的 --help 输出核实。

---

LLMS 索引： [llms.txt](/codeweb/zh/llms.txt)

---

所有面向项目的命令都接受 `-p, --project <DIR>`(默认 `.`)，以及下方全局选项。本页记录启用全部 feature 的 codeweb v0.9.11。

## 全局选项 {#global-options}

| 选项 | 取值 | 含义 |
| --- | --- | --- |
| `--lang` | `zh-CN`、`en`(默认 `zh-CN`) | 输出语言 |
| `--threads` | 整数 | 并行解析的工作线程数。默认 `max(4, logical_cpus - 2)`。同时遵循 `RAYON_NUM_THREADS`;命令行参数优先 |
| `-V, --version` | — | 打印版本(当前 0.9.11) |

不带子命令时，codeweb 以 legacy 模式运行:`codeweb [INPUT] --format <dot&#124;json&#124;mermaid&#124;ndjson> --output <FILE> [--include-unresolved] [--sql-only]` 直接解析文件或目录并输出导出结果。

## 项目生命周期 {#project-lifecycle}

| 命令 | 关键参数 | 用途 |
| --- | --- | --- |
| `codeweb init <NAME>` | `-d, --dir <DIR>`(可重复)、`--root <DIR>`、`--force` | 创建 `codeweb.toml` + `.codeweb/`，登记分析路径，并立即执行首次分析(MCP 工具 `codeweb_init` 与之相反，只初始化不做分析)。目标 `--root` 非空且无 `codeweb.toml` 时需要 `--force` |
| `codeweb analyze` | `-p, --project` | 全量或增量分析(基于指纹) |
| `codeweb diff` | `-p, --project` | 距上次分析变更的文件 |
| `codeweb stats` | `-p, --project` | 按类型统计节点/边数量 |
| `codeweb files` | `-p, --project` | 已分析文件及节点数 |

## 追踪与巡检 {#tracing-and-inspection}

| 命令 | 关键参数 | 用途 |
| --- | --- | --- |
| `codeweb trace <FROM>` | `-s, --style tree&#124;path`、`--exact`、`--regex`、`--all-matches`、`--fail-on-multiple`、`--builtfunc` | 节点的上游与下游 |
| `codeweb detail [NAMES]...` | `-s, --style tree&#124;path`、`-d, --depth 1&#124;0&#124;-1`、`-f, --files`、`--related-ddl`、`-v, --verbose`、`--summarize-tables`、`--exact`、`--regex`、`--all-matches`、`--fail-on-multiple`、`--builtfunc` | 逐节点上下游，可附源码上下文 |
| `codeweb inspect [NODES]...` | `-m, --max-depth`(默认 15)、`--max-paths`(默认 10)、`-s, --style summary&#124;paths&#124;both&#124;tree`、`--unreachable`、`--exact`、`--regex`、`--all-matches`、`--fail-on-multiple` | 连接两个及以上节点的有向路径 |
| `codeweb impact` | `--file <FILE>`(可重复)或 `--node <NODE>`(互斥)、`-f, --format json&#124;text`(默认 json)、`-d, --depth`(默认 1)、`-e, --edge-types`(默认 all)、`--exact`、`--regex` | 文件内节点或单个符号的上下游影响 |
| `codeweb trace-sql [SQL]` | `-f, --file <FILE>` 或位置参数 SQL / `-` 表示 stdin | 按 SQL 片段搜索 `mapper`/`sql` 节点，回溯 Java 方法 |

## 深度分析 {#analysis}

| 命令 | 关键参数 | 用途 |
| --- | --- | --- |
| `codeweb lineage <TARGET>` | `--direction upstream&#124;downstream&#124;both`(默认 both)、`--depth`(默认 5)、`--format tree&#124;json&#124;dot&#124;mermaid`、`--view tree&#124;entity&#124;relation&#124;grouped`、`--flow-only` | 表/列血缘。见[血缘分析](/codeweb/zh/docs/lineage/) |
| `codeweb columns` | `--procedure <NAME>` 或 `--package <NAME>`(必填二选一)、`--table <NAME>`、`--format json&#124;seed-hints`(默认 json)、`--discriminator <COL>`(可重复) | 聚合列级分析。见[列级分析](/codeweb/zh/docs/column-analysis/) |
| `codeweb predicates` | `--procedure <NAME>`(必填)、`--format json` | PL `IF`/`CASE` 谓词解析为表列 |
| `codeweb conflicts` | `--severity high&#124;medium`(默认 high)、`-f, --format json&#124;text`(默认 json)、`--table <NAME>` | 跨过程表锁冲突(静态分析) |
| `codeweb partition` | `-k, --k <K>`、`--auto`、`--gamma <GAMMA>`、`--max-iterations <N>`、`--min-delta-q <Q>`、`--min-component-size <N>`(默认 1)、`--table-projection [<tau:lambda:k>]`、`-o, --output <FILE>` | 聚类节点做系统分解;导出含 `cluster_*` 子图的 DOT |
| `codeweb mark` | `-n, --node <NODE>`(可重复)、`-c, --csv <CSV>`(必填)、`-o, --output <FILE>` | 按与图节点的关系标记 WDR SQL detail CSV 行 |

## 查询与导出 {#query-and-export}

| 命令 | 关键参数 | 用途 |
| --- | --- | --- |
| `codeweb query` | `-f, --file <FILE>`(`-` 表示 stdin)或 `-s, --spec <JSON>` | 执行声明式 [QuerySpec](/codeweb/zh/docs/trace-and-query/#declarative-queries) |
| `codeweb export` | `-f, --format dot&#124;json&#124;mermaid&#124;ndjson`(默认 dot)、`-o, --output <FILE>`(缺省 stdout)、`--filter <SUBSTR>` | 导出全图或种子节点周边子图 |
| `codeweb dedup` | `-o, --output <FILE>`(默认原地)、`--dry-run` | 合并重复节点与边 |
| `codeweb import` | `-f, --file <FILE>`、`-o, --output <FILE>`、`-p, --prefix <PREFIX>`、`-n, --name <NAME>`、`--force` | 导入 CGEF JSON 文件。见[CGEF](/codeweb/zh/docs/cgef/) |
| `codeweb merge` | `-o, --output <FILE>`(必填)、`--name <NAME>`(默认 `merged`)、`[STORES]...` | 合并多个 store 并去重 |

## 交互与服务 {#interactive-and-server}

| 命令 | Feature | 关键参数 | 用途 |
| --- | --- | --- | --- |
| `codeweb tui` | `tui` | `-p, --project` | 终端浏览器，支持搜索与节点详情 |
| `codeweb serve` | `serve` | `-a, --addr`(默认 `127.0.0.1:3000`)、`--open`、`--log-level info&#124;debug` | HTTP 服务 + 浏览器 UI。见 [HTTP API](/codeweb/zh/docs/serve/) |
| `codeweb mcp` | `mcp` | `-p, --project` | stdio 上的 MCP 服务。见 [MCP 工具](/codeweb/zh/docs/mcp/) |

需要 feature 的子命令在未启用时不存在;默认构建下执行 `codeweb serve` 会报无法识别的命令。

---

反链：

- [快速上手](/codeweb/zh/docs/getting-started/)
