Skip to content

Commit ba7a7c0

Browse files
authored
feat: introduce Claude Code integration (#141)
* Modify MCP Prompts, Error Msgs, Schema Descriptions to make sure LLM Understanding MCP Input args Better * Add Claude Code System Prompt, Commands and Hooks for Better ABCoder Workflow Usage * Remove Parts about API/Method Doc * Introduce Claude Code Integration * Add settings.json for Claude Hooks Configuration * Chore: Adjust Format * Upload Missing Hooks * Rename commands with abcoder prefix
1 parent 0cc5873 commit ba7a7c0

File tree

15 files changed

+928
-23
lines changed

15 files changed

+928
-23
lines changed

README.md

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,107 @@ see [UniAST Specification](docs/uniast-zh.md)
7979
8080
8181
## Tips:
82-
82+
8383
- You can add more repo ASTs into the AST directory without restarting abcoder MCP server.
8484
8585
- Try to use [the recommended prompt](llm/prompt/analyzer.md) and combine planning/memory tools like [sequential-thinking](https://github.com/modelcontextprotocol/servers/tree/main/src/sequentialthinking) in your AI agent.
8686
8787
88+
## Claude Code Integration
89+
90+
ABCoder provides deep integration with [Claude Code](https://claude.ai/code) through the AST-Driven Coding workflow, enabling hallucination-free code analysis and precise execution.
91+
92+
### Setup
93+
94+
1. **Install ABCoder Claude Configuration**
95+
96+
Copy [`docs/.claude/`](docs/.claude/) to your home directory or project root:
97+
98+
```bash
99+
cp -r docs/.claude ~/
100+
```
101+
102+
2. **Configure ABCoder MCP Server**
103+
104+
Configure in Claude Code's `~/.claude.json` (the hook uses `abcoder parse go/ts . -o ~/.asts/repo.json` for the default AST folder):
105+
106+
```json
107+
{
108+
"mcpServers": {
109+
"abcoder": {
110+
"command": "abcoder",
111+
"args": ["mcp", "~/.asts"]
112+
}
113+
}
114+
}
115+
```
116+
117+
3. **Configure Hooks**
118+
119+
Claude Code will automatically read hooks from [`~/.claude/settings.json`](docs/.claude/settings.json) to enable:
120+
- Auto-detect language and generate AST before calling `mcp__abcoder` tools
121+
- Display ABCoder workflow SOP to Claude after `list_repos`
122+
- Remind to call `get_ast_node` recursively
123+
124+
### AST-Driven Coding Workflow
125+
126+
[`.claude/hooks`](docs/.claude/hooks) provide a 4-layer analysis chain from repository to node details:
127+
128+
```
129+
list_repos → get_repo_structure → get_package_structure → get_file_structure → get_ast_node
130+
│ │ │ │ │
131+
└── repo_name └── mod/pkg list └── file list └── node list └── dependencies/references
132+
```
133+
134+
### Claude Code Slash Commands
135+
136+
[`.claude/commands`](docs/.claude/commands) provide three custom slash commands to streamline development:
137+
138+
| Command | Function | Description |
139+
|---------|----------|-------------|
140+
| [`/abcoder:schd`](docs/.claude/commands/abcoder:schd.md) | Design implementation | Analyze codebase using ABCoder, design technical solution |
141+
| [`/abcoder:task <name>`](docs/.claude/commands/abcoder:task.md) | Create coding task | Generate standardized CODE_TASK document |
142+
| [`/abcoder:recheck <task>`](docs/.claude/commands/abcoder:recheck.md) | Verify solution | Critically check CODE_TASK feasibility, useful when a CODE_TASK contains external dependencies |
143+
144+
### Workflow
145+
146+
```
147+
User Request
148+
149+
150+
/abcoder:schd ──────────→ Design Solution (ABCoder Analysis)
151+
│ │
152+
▼ ▼
153+
/abcoder:task ─────────→ CODE_TASK (with Technical Specs, including accurate `get_ast_node` call args)
154+
│ │
155+
▼ ▼
156+
/abcoder:recheck ────→ Verify Solution (ABCoder Validation. After `/abcoder:task` Claude Code will tell you what the external dependencies CODE_TASK contains, use `/abcoder:recheck` to analyze external ast_node and technical detail with ABCoder)
157+
│ │
158+
▼ ▼
159+
sub-agent ─────────→ Execute Implementation
160+
```
161+
162+
### Configuration Files
163+
164+
| File | Purpose |
165+
|------|---------|
166+
| [`CLAUDE.md`](docs/.claude/CLAUDE.md) | Core AST-Driven Coder role definition |
167+
| [`settings.json`](docs/.claude/settings.json) | Hooks and permissions configuration |
168+
| [`hooks/`](docs/.claude/hooks/) | Automation scripts (parse/prompt/reminder) |
169+
| [`commands/`](docs/.claude/commands/) | Slash command definitions (abcoder:task/abcoder:schd/abcoder:recheck) |
170+
| [`tmpls/CODE_TASK.md`](docs/.claude/tmpls/CODE_TASK.md) | Coding task template |
171+
172+
### Dependencies
173+
174+
- Claude Code CLI
175+
- abcoder MCP server (provides `mcp__abcoder` tools)
176+
- sequential-thinking MCP server (provides `mcp__sequential_thinking` tools, optional)
177+
178+
> For detailed configuration, see [docs/.claude/README.md](docs/.claude/README.md)
179+
180+
> Watch the demo video [here](https://github.com/cloudwego/abcoder/pull/141)
181+
182+
88183
## Use ABCoder as an Agent (WIP)
89184

90185
You can also use ABCoder as a command-line Agent like:

docs/.claude/CLAUDE.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# AST-Driven Coding
2+
3+
你是 AST-Driven Coder,通过整合 `mcp__abcoder``mcp__sequential_thinking`,为用户提供无幻觉上下文、模糊需求质询、诚实推理和精确执行。
4+
5+
## MCP 工具使用体系
6+
7+
### 工具优先级决策
8+
**代码分析优先级**: `mcp__abcoder` > Read/Search
9+
10+
| 工具 | 适用场景 | 核心价值 |
11+
|------|----------|----------|
12+
| `mcp__abcoder` | 本地代码深度分析 | UniAST + LSP无幻觉理解代码结构、类型信息、调用链。优于Read/Search |
13+
| `mcp__sequential_thinking` | 复杂问题分解 | 多步骤问题的系统化思考 |
14+
15+
## ABCoder SOP
16+
1. 问题分析:
17+
- 基于用户问题分析相关关键词
18+
- MUST 使用 `list_repos` 确认`repo_name`
19+
20+
2. 代码定位 (repo→package→node→ast node relationship):
21+
- 2.1 定位package: 基于 `get_repo_structure` 返回的package list选择目标package
22+
- 2.2 定位node: 通过 `get_package_structure` 返回的file信息,确认目标node;无法确认时,调用 `get_files_structure`
23+
- 2.3 确认ast node relationship: 递归调用 `get_ast_node` 获取node详细(dependencies, references, inheritance, implementation, grouping)
24+
25+
### 开发中的 abcoder 使用
26+
- 编写前:使用 `get_package_structure` 分析相似代码模式,`get_ast_node` 学习项目最佳实践
27+
28+
## 分阶段开发理念
29+
30+
IMPORTANT: 开发前,MUST 与用户对齐CODE_TASK需求;对于CODE_TASK中不明确的任务(例如任务需要的SDK Method定义、返回值的JSON/IDL),质询用户
31+
IMPORTANT: 开始开发前,阐述此次CODE_TASK的调用链路、相关SDK Method定义、cURL JSON定义
32+
### 开发阶段
33+
1. MVP阶段:核心功能可工作,基本类型安全
34+
2. 完善阶段:错误处理、边界情况、测试覆盖
35+
3. 优化阶段:性能优化、代码重构、文档完善
36+
37+
## 代码质量标准
38+
39+
### 实现要求(按优先级)
40+
MUST:
41+
- Never 使用简化/Mock实现,使用真实SDK/cURL
42+
- 类型安全:核心逻辑必须有明确类型定义
43+
- 基本错误处理:处理可预见的异常情况
44+
45+
SHOULD:
46+
- 完整的边界条件处理
47+
- 性能敏感场景的优化
48+
- 复杂逻辑的注释说明
49+
50+
COULD:
51+
- 100%遵循SOLID编码规范
52+
- 极致的性能优化
53+
54+
### 验证标准
55+
- 关键路径和边界条件 MUST 有测试
56+
- 通过 linter 和类型检查
57+
- 手动验证主要用户场景
58+
59+
## 用户协作模式
60+
61+
| 用户行为 | 响应策略 |
62+
|----------|----------|
63+
| 模糊需求 | 使用 `mcp__sequential_thinking` 澄清,提供具体选项 |
64+
| BUG修复 | 使用 `mcp__abcoder__get_ast_node` 详细分析,根本解决 |
65+
| 重构替换 | 使用 `semgrep``comby` 结构化搜索替换 |
66+
| 代码分析请求 | MUST 使用 `mcp__abcoder` SOP |
67+
68+
## 执行要求
69+
70+
1. 绝不假设 - 任何不确定代码,MUST 通过`mcp__abcoder__get_ast_node`工具验证
71+
2. 工具链整合 - 充分利用ABCoder等工具提升效率
72+
3. 质量内建 - 代码质量要求融入每个环节
73+
4. 渐进交付 - 复杂任务分解为可验证的小步骤
74+
75+
- **使用SubAgent时提醒使用ABCoder** - 当需要使用subAgent(如@agent-Explore@agent-coding-executor)进行代码分析时,应该提醒SubAgent使用`mcp__abcoder__get_ast_node`以获得更准确的分析结果
76+
- **Never 说英语**:MUST 使用中文

docs/.claude/README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# AST-Driven Coding 配置
2+
3+
Claude Code 的 AST 驱动开发配置,通过 MCP 工具、钩子和斜杠命令实现无幻觉的代码分析和精确执行。
4+
5+
## 目录结构
6+
7+
```
8+
.claude/
9+
├── CLAUDE.md # 核心指令:AST-Driven Coder 角色定义
10+
├── settings.json # 钩子配置:PreToolUse/PostToolUse
11+
├── hooks/ # 钩子脚本
12+
│ ├── parse.sh # 自动检测语言并生成 AST
13+
│ ├── prompt.sh # 显示工作流程 SOP
14+
│ └── reminder.sh # 提醒递归调用 get_ast_node
15+
├── commands/ # 斜杠命令定义
16+
│ ├── abcoder:task.md # /abcoder:task - 创建编码任务
17+
│ ├── abcoder:schd.md # /abcoder:schd - 设计实现方案
18+
│ └── abcoder:recheck.md # /abcoder:recheck - 技术方案核对
19+
└── tmpls/ # 文档模板
20+
└── CODE_TASK.md # 编码任务模板
21+
```
22+
23+
## 核心理念
24+
25+
**AST-Driven Coding**: 基于 UniAST + LSP 的无幻觉代码分析
26+
27+
| 原则 | 说明 |
28+
|------|------|
29+
| 绝不假设 | 不确定代码 MUST 通过 `mcp__abcoder__get_ast_node` 验证 |
30+
| 代码分析优先级 | `mcp__abcoder` > Read/Search |
31+
| 直接使用原则 | 预先分析提供完整上下文,SubAgent 直接执行无需重分析 |
32+
| 分阶段开发 | MVP → 完善 → 优化 |
33+
34+
## MCP 工具
35+
36+
### mcp__abcoder
37+
38+
本地代码深度分析工具,提供四层 AST 结构:
39+
40+
```
41+
list_repos → get_repo_structure → get_package_structure → get_file_structure → get_ast_node
42+
│ │ │ │ │
43+
└── repo_name └── mod/pkg list └── file list └── node list └── dependencies/references/inheritance
44+
```
45+
46+
**SOP 流程**:
47+
1. 问题分析 → `list_repos` 确认 repo_name
48+
2. 定位 package → `get_repo_structure` 选择目标 package
49+
3. 定位 node → `get_package_structure` 确认目标 node
50+
4. 获取关系 → `get_ast_node` 递归获取完整信息
51+
52+
### mcp__sequential_thinking
53+
54+
多步骤问题的系统化思考工具,用于复杂问题分解和模糊需求质询。
55+
56+
## 钩子系统
57+
58+
| 钩子 | 事件 | 匹配工具 | 作用 |
59+
|------|------|----------|------|
60+
| parse.sh | PreToolUse | get_repo_structure, get_file_structure, get_package_structure, get_ast_node | 自动检测语言并生成 AST 到 `~/.asts/` 目录 |
61+
| prompt.sh | PostToolUse | list_repos | 显示 ABCoder 工作流程 SOP |
62+
| reminder.sh | PostToolUse | get_repo_structure, get_package_structure, get_file_structure | 提醒递归调用 get_ast_node |
63+
64+
## 斜杠命令
65+
66+
### /abcoder:task <名称>
67+
68+
创建 CODE_TASK 文档,生成 `./task/{{MMDD}}/{{NAME}}__CODE_TASK.md`
69+
70+
**格式要求**:
71+
- action: create/modify/delete
72+
- 涉及 SDK: 指定 Package/Method 名称
73+
- 涉及 curl: 提供完整命令和响应结构
74+
- 提供具体验证方法
75+
76+
### /abcoder:schd
77+
78+
使用 mcp__abcoder 设计实现方案
79+
80+
**Guardrails**:
81+
- 最大化复用已有功能
82+
- 优先最小改动
83+
- 禁止编写代码、禁止使用 agent
84+
85+
### /abcoder:recheck <任务>
86+
87+
批判性检查 CODE_TASK 技术可行性
88+
89+
**检查项**:
90+
- 方案可实现性
91+
- 技术风险
92+
- 代码复用和改动最小化
93+
94+
## 工作流
95+
96+
```
97+
用户需求
98+
99+
100+
/abcoder:schd ──────────────→ 设计方案(abcoder分析)
101+
│ │
102+
▼ ▼
103+
/abcoder:task ────────→ CODE_TASK(含技术规格)
104+
│ │
105+
▼ ▼
106+
/abcoder:recheck ─────→ 方案核对(abcoder验证)
107+
│ │
108+
▼ ▼
109+
coding-executor ──────→ 执行实现
110+
```
111+
112+
## 安装
113+
114+
1. 复制 `.claude/` 目录到项目根目录或用户主目录
115+
2. 确保 `settings.json` 中的钩子路径正确
116+
3. 确保 `~/.claude/tmpls/` 目录存在且包含模板文件
117+
118+
## 依赖
119+
120+
- Claude Code CLI
121+
- abcoder MCP 服务器(提供 mcp__abcoder 工具)
122+
- sequential-thinking MCP 服务器(提供 mcp__sequential_thinking 工具)
123+
124+
## 相关文档
125+
126+
- [hooks/README.md](hooks/README.md) - 钩子系统详解
127+
- [commands/README.md](commands/README.md) - 斜杠命令详解

0 commit comments

Comments
 (0)