代码结构分析工具

code-tree 是一个 CLI 工具和 MCP 服务器,用于快速浏览项目结构和代码库,支持目录结构扫描、代码符号提取和多种编程语言的 AST 解析。

  • by febalist
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 febalist/code-tree

使用说明

代码树

一个CLI工具和MCP服务器,用于快速探索项目结构和代码库。

要求: 包子

特性

  • 🌳 目录结构扫描(如 tree)
  • 🔍 代码符号提取:类、函数、接口、类型
  • 📝 文档注释支持
  • 🚀 通过Tree sitter(WASM)进行精确的AST解析
  • 🎯 10+编程语言+Markdown
  • ⚡ 自动输出优化

安装

# Global installation
bun add -g @febalist/code-tree

# Or use with bunx (no installation needed)
bunx @febalist/code-tree .

用法

# Scan current directory
code-tree .

# Scan specific directory
code-tree src/

# Parse specific file
code-tree src/index.ts

# Multiple paths
code-tree src/ lib/

# With options
code-tree --depth 2 --no-symbols .
code-tree --ignore "*.test.ts" --ignore "*.spec.ts" src/

# Help
code-tree --help

参数

  • 位置参数:目录或文件的路径(默认值: .)
  • --depth <n>:最大遍历深度(默认值:10)
  • --symbols / --no-symbols:包含/排除代码符号(默认:自动)
  • --comments / --no-comments:包括/排除文档注释(默认:自动)
  • --ignore <pattern>:其他忽略模式(可重复)

输出示例

带符号的目录:

src/
├── index.ts
│     async run(args)
├── parser/
│   ├── index.ts
│   │     class ParserManager
│   │       async init()
│   │       private async loadLanguage(config: LanguageConfig): Promise<Language>
│   │       async parseFile(filePath: string): Promise<FileSymbols | null>
│   └── types.ts
│         type SymbolKind
│         interface CodeSymbol
│         interface FileSymbols

详细分类文件:

src/parser/index.ts

  class ParserManager
    async init()
      locateFile()
    private async loadLanguage(config: LanguageConfig): Promise<Language>
    async parseFile(filePath: string): Promise<FileSymbols | null>

支持的语言

  • TypeScript(.ts、.tsx)
  • JavaScript(.js、.jsx、.mjs、.cjs)
  • Python(.py、.pyw)
  • 去(.去)
  • PHP(.PHP)
  • 锈蚀(.rs)
  • Java(.Java)
  • C#(.cs)
  • Ruby(.rb)
  • Kotlin(.kt,.kts)
  • Swift(.Swift)
  • C/C++(.C、.h、.cpp、.hpp、.cc、.cxx、.hh、.hxx)
  • Markdown(.md、.mdx)

文件忽略

自动忽略:

  • .git, .svn, .hg, .DS_Store (总是)
  • node_modules, vendor, dist, build, __pycache__, venv, target, bin, obj, coverage
  • 图案来自 .gitignore
  • 通过以下方式定制图案 --ignore 参数

MCP服务器

code-tree 还提供了一个MCP(模型上下文协议)服务器,用于与Claude Code等LLM客户端集成。

MCP服务器公开了与CLI相同的功能和参数。

集成示例

添加到克劳德代码MCP配置:

{
  "mcpServers": {
    "code-tree": {
      "command": "bunx",
      "args": ["@febalist/code-tree", "mcp"]
    }
  }
}