Claude 代码实验:更多标记并不意味着更好的代码
Source: Dev.to
引言
随着新年的到来,许多公司正在加速 AI 工具的生产力应用,常常以 token 使用量作为 AI 采纳的衡量指标。在完成 Anthropic 的 “Claude Code in Action” 课程后,我着手验证一个简单的假设:
假设: Claude Code 的功能呈递减收益曲线——超过某一点后,更多的 token 并不会产生更好的代码。
实验概览
我使用四种不同的 Claude Code 技术各构建一次 CLI 井字棋游戏。每次运行我记录 token 使用量,运行 QA 代理寻找 bug,并让 senior‑engineer 角色评估代码质量。基于这些数据,我推导出 每 token 质量(QPT) 指标来比较这些技术。
测试的技术
| 技术 | 描述 |
|---|---|
| Zero‑shot | 直接提示,无上下文 |
| Plan Mode | 在执行前显式规划步骤 (--plan) |
| CLAUDE.md | 项目级上下文文件,无规划 |
| CLAUDE.md + Plan Mode | 结合上下文文件和规划步骤 |
所有运行均使用 claude --verbose 捕获 token 计数。每次实验均启动全新的 Claude 会话。
实验细节
1. Zero‑shot 提示
Can you create a CLI tic tac toe game using vanilla javascript with minimal dependencies? I would like it to be tested using jest and I would like it to be good quality code using classes.
2. Plan Mode
--plan
3. CLAUDE.md 上下文文件
项目目录中放置了一个 CLAUDE.md 文件(示例见下):

运行的命令:
create the game
4. CLAUDE.md + Plan Mode
--plan create the game
质量评估
使用基于角色的提示对生成的代码进行打分:
You are a senior engineer, can you assess this code for quality and give it a score 1‑5 on correctness, clarity, structure, maintainability, and extendability? Return the average of the scores.
手动 QA 代理
提供了一个 test.js 文件(见 gist),让代理进行 10 场游戏并报告 bug。四个迭代全部报告零 bug。
结果
| 方法 | Tokens | 质量(平均) | QPT |
|---|---|---|---|
| CLAUDE.md | 25,767 | 4.9 | 0.190 |
CLAUDE.md + --plan | 32,191 | 4.6 | 0.143 |
| Zero‑shot | 42,737 | 4.8 | 0.112 |
--plan | 52,910 | 4.8 | 0.091 |
结论
假设得到部分验证:代价最低的方式(仅 CLAUDE.md)交付了最高质量。随着 token 使用量增加,质量要么趋于平台要么下降。这表明 上下文质量比单纯的 token 量更重要。
“Context is Currency… If you don’t give the model the right background and constraints, it will confidently give you the wrong answer.” — Rani Zilpelwar
AI 采纳后的下一波浪潮可能会聚焦于 优化和 AI 投资回报率,并强调整 上下文工程。结构良好的上下文往往比单纯喂入更多 token 能产生更好的结果。

封面艺术:“Urania”,Giacinto Gimignani 绘,1852