有人说用 claude code cli 和 glm4.5搭配,如果提示词写的足够好,可以跟 claude code sonne4,或者opus4.1相媲美。那么这个提示词应该怎么写呢?

这个说法的核心在于:
“在 Claude Code CLI(即 Claude 3.5 Sonnet 代码能力)里,把 GLM-4-Plus(或 GLM-4.5)当成一个「外部工具」调用,然后通过提示词让 Sonnet 只负责「分解任务 + 把关 + 调用 GLM-4-Plus」,从而把 GLM-4-Plus 的代码生成质量抬到接近 Sonnet 甚至 Opus 4.1 的水平。”

下面给出一条可落地的「万能提示词模板」,以及 7 条实战技巧。你只需把模板直接粘到 Claude Code CLI 的 system prompt(或 .claude.md)里即可。

──────────────────
【可直接 copy 的提示词模板】

You are Claude-Code-Lead, the senior architect who NEVER writes raw code directly.  
Your only job is to:

1. Decompose the user’s request into the smallest possible, verifiable sub-tasks.  
2. Decide whether each sub-task should be solved by:  
   a) calling the external GLM-4-Plus model, or  
   b) handled by yourself (review, merge, tests, docs).  
3. When calling GLM-4-Plus, ALWAYS use the following zero-shot prompt block:

---
GLM-4-Plus, act as a world-class engineer.  
Task: <copy the sub-task exactly>  
Constraints:  
- Output ONLY the final code.  
- No explanations unless explicitly asked.  
- Follow <language> style guide: <insert style guide link or bullet list>.  
- 100 % unit-test coverage is mandatory.  
- Prefer functional / immutable patterns where possible.  
- Max 200 LOC per file.  
---

4. After receiving GLM-4-Plus’s answer, perform:  
   • Syntax check (AST)  
   • Static analysis (pylint / eslint / go vet / …)  
   • Auto-generate or update unit tests  
   • Refactor if duplication > 5 %  
   • Commit each micro-change with conventional-commit message  
5. Loop until all sub-tasks pass CI.  
6. Finally, output a short README diff explaining the high-level design decisions.  

把上面内容存成 .claude.md 放到仓库根目录,或在 Claude Code CLI 启动时加 --system-prompt "$(cat .claude.md)" 即可。

──────────────────
【7 条实战技巧】

  1. 粒度控制
    把“实现整个功能”拆成“写一个纯函数”、“写一个 SQL 迁移”、“补全测试”。子任务越小,GLM-4-Plus 越容易一次做对,Claude 把关越简单。

  2. 风格指南内联
    在 GLM 提示里直接粘贴 3-5 条项目级规范(缩进、命名、错误处理),比泛泛地说“请遵守最佳实践”有效得多。

  3. 测试先行
    Claude 先让 GLM-4-Plus 生成 *_test.go / *.spec.ts,再生成实现代码,可以显著减少返工。

  4. 双模型回环
    如果 GLM-4-Plus 的初版代码有 smell,Claude 用第二条 prompt 让 GLM-4-Plus 自己 refactor,而不是亲手改。

    GLM-4-Plus, refactor the following code to eliminate duplication and reduce cyclomatic complexity to ≤ 5.  
    <paste code>
    
  5. 温度 0 + top-p 0.1
    GLM-4-Plus 的调用参数固定死,保证可重复性;Claude 负责创造性部分。

  6. 让 Claude 写 Commit Message
    每个 micro-commit 让 Claude 用 conventional-commit 规范(feat: add helper to parse ISO8601),方便后期 bisect。

  7. 兜底机制
    如果 GLM-4-Plus 连续两次输出仍无法通过 CI,Claude 降级到“手写修复”,并记录到 .claude-lessons.md,下次自动规避同类错误。

──────────────────
【一个最小可运行示例】

仓库根目录:

.claude.md         ← 放上面的提示词
.claude-lessons.md ← Claude 记录踩坑

终端:

claude --system-prompt "$(cat .claude.md)" \
       --model claude-3-5-sonnet \
       --tools glm4 \
       "add support for soft-deleting users in the accounts service"

Claude 会立即拆成 4 个子任务:

  1. 写 migration SQL(GLM-4-Plus)
  2. 改 domain model(GLM-4-Plus)
  3. 补 DAO 层测试(Claude 生成 table-driven test)
  4. 更新 API 文档(Claude 写 README diff)

──────────────────
总结
提示词的核心不是“把 GLM-4-Plus 变成 Sonnet”,而是让 Sonnet 做它最擅长的“任务分解 + 代码审查 + 流程管理”,把粗活扔给 GLM-4-Plus。只要拆分足够细、约束足够清晰,再配上线性迭代,整体输出质量就能逼近甚至偶尔超过单用 Sonnet 或 Opus。

posted @ 2025-09-04 18:07  AI健康  阅读(325)  评论(0)    收藏  举报