AI 编程行为指南:Agent 不担责,PR 控制在 600 行内
作者面向软件工程师群体,总结了在项目中实践 AI 编程的通用行为准则,刻意弱化工具与技巧之争(如是否 Spec 驱动),聚焦于协作方式本身。核心主张包括:AI Agent 拓展了人的能力但不对代码担责,人始终是代码的最终责任人,不提交自己不理解的代码;用「协作」而非「委派」的心智模型与 Agent 共事,不做只提需求不问实现的产品经理;拆分 PR(推荐 600 行以内),创建前用 AI 前置 review;先启用 Plan 模式做前置探索,理解了需求再写码;工具函数与库倾向采纳成熟方案而非让 AI 从零手撸;改动必须可自动验证,避免让 Review 兜底。文章后半部分针对初级工程师给出定制建议:质量优先于效率、用聊天模式参与修 Bug 而非全自动委派、先花固定时间独立设计再与 AI 对答案、回归官方文档、补齐设计模式与 DDD 等设计能力、有意识关注安全与并发等非功能性需求。
AI-assisted programming has advanced at breakneck speed. AI agents such as Claude Code and Codex have become indispensable helpers for many software engineers. Yet when it comes to putting AI programming into practice on a real project, everyone is still doing their own thing — each with their own tricks.
AI 编程发展迅猛,Claude Code、Codex 等 AI Agent 已成为许多软件工程师工作时必不可少的得力助手。然而,对于如何在项目中更好地实践 AI 编程,目前仍然是一副“八仙过海,各显神通”的模样。
If engineers on the same team never agree on the big questions of how to use AI tools, friction creeps into collaboration and the project suffers.
假如同一个团队里的工程师,在如何使用 AI 工具的“大问题”上没有达成共识,就会出现协作上的摩擦,对项目产生不良影响。
So this article tries to distill recommended practices for AI programming for software engineers, downplaying specific tools and tricks (Spec-driven or not?) and focusing on the more universal questions (should a junior engineer fully delegate bug fixes to an AI agent?).
因此,本文尝试面向软件工程师群体,对 AI 编程的推荐行为实践做一些总结,弱化具体的工具和技巧(比如 Spec 驱动还是不 Spec 驱动?),着眼于更通用的方面(比如初级工程师该完全委派 AI Agent 修 bug 吗?)。
The content is split into two parts: "For Everyone" and "For Junior Engineers." The junior-engineer section is tailored to the particular stage those engineers are at.
Note: parts of this article were co-created with jianan and wklken. The views here are distilled from the author's own working environment and may not fully apply to other projects — take what fits.
内容分为“对所有人”和“对初级工程师”两部分,其中“对初级工程师”部分,针对这类人群身处的特殊阶段,提供了一些量身定制的建议。
说明:本文部分内容由 jianan、wklken 参与共创;本文观点基于笔者所身处的工作环境总结而来,不一定完全适用于其他项目,酌情采纳;
Remember: the agent doesn't own the code.
An AI agent extends a person's capabilities — it's a kind of "stand-in" — but it bears no direct responsibility. The human remains the final owner of the code.
谨记 Agent 不对代码担责。
AI Agent 拓展了人的能力,是一种“分身”,但不直接承担任何责任,人依旧是代码的最终责任人。
Review the code AI generates and understand it. Never commit code you don't understand. How do you know you really understand something? The Feynman technique: can you explain it to someone with no background in it?
Don't lean on others (or AI) to do the final gatekeeping on your work at review time — that's a dereliction of your own responsibility.
Review AI 生成的代码,理解它们,不要提交自己不理解的代码。 如何判断自己是不是真的理解某件事?“费曼学习法”——你是否能向其他没有背景的人解释它?
不要过度依赖其他人(AI)在 Review 阶段对你的工作做最后把关,这是不负责任的表现。
Two mental models: "collaboration" means making decisions together with the other party on the basis of understanding; "delegation" means caring only about the end result.
To repeat: AI doesn't answer for the code, and it isn't accountable for the project's long-term maintainability either.
两种心智模型:“协作”意味着你在理解对方的基础上共同做决定,“委派”意味着你只关注最终结果。
重复一次:AI 不对代码担责,也不对项目的长期可维护性负责。
Don't play the product manager — handing down requirements in plain language from on high, with no interest in how they're implemented.
"I don't care how you build it, this requirement is simple!"
Dig into the program design and overall structure, and work the answer out together with the agent.
不要去模仿一位产品经理,仅用自然语言高高在上地提需求,不关注实现细节。
“怎么实现我不管,这个需求很简单!”
深入探索程序设计和整体结构,和 Agent 一起推敲出更优的答案。
AI writes code fast and in bulk, so it's easy to end up with PRs of thousands of changed lines.
A big PR makes review far harder; the review slides along the surface and quality control slips away.
Don't save up one giant "ultimate move" — keep PRs small (under 600 lines is a good target), move in small steps, and deliver in stages.
AI 写代码又快又多,很容易产出几千行改动的 PR。
大 PR 极大增加了 Review 难度,Review 过程容易浮于表面,最终导致工程质量不可控。
不憋“大招”,控制 PR 粒度(推荐<600行),小步快跑,分阶段交付。
If a PR really can't be split, provide a design document for it (a design_notes directory) to help reviewers follow along.
Note: a design document is not a spec spelled out down to the code level. It's a human-readable "manual" written at a higher level of abstraction. Write the core content or skeleton yourself; AI can help fill in details.
如果 PR 实在无法拆分,尽量提供 PR 的设计文档(design_notes 目录)以辅助 Reviewer 理解。
说明:设计文档并不是详细到代码级别的 Spec 规格说明,而是站在更高抽象层的,供人阅读的功能“说明书”。推荐由人编写核心内容或框架,AI 可辅助补全细节。
Make good use of plan mode, and explore up front.
For a new requirement, first get familiar with the relevant modules and domain knowledge and understand how the project currently implements things (AI can help you investigate and map it out).
Don't let AI start writing code before you genuinely understand the requirement; to repeat, use the Feynman technique to check whether you really do.
Ask questions first, or turn on plan mode to clarify the requirement with AI (and pick up some prompting skills along the way).
开发新需求,应当先熟悉相关模块/领域知识,了解项目当前实现等(可借助 AI 调查梳理)。
不要在真正理解需求前,就让 AI 开始写代码;重复一次:“费曼学习法”判断自己是否真正理解。
先提问或启用 plan 模式与 AI 澄清需求(学习 AI 提示词技巧)。
Don't let AI lead you by the nose — think independently, stay skeptical, and open up your thinking by questioning back. Only with a clear grasp of the problem can you judge whether AI's implementation is sound, and good judgment is priceless.
别被 AI 带着走,独立思考,怀疑主义,通过反问等方式来开拓思路。只有对问题有清晰的认知,才能判断 AI 的实现是否合理,而正确的判断无价。
For utility functions and libraries, AI tends toward rolling its own rather than pulling in a third-party package. That's not to say reinventing the wheel is always wrong, but…
For well-solved problems in common domains (gjson, say), lean toward having AI adopt a library instead of implementing it from scratch. How do you know which libraries are a good fit? Talk to AI, or go dig through the docs yourself — everyday accumulation matters. When several libraries will do, let a human pick the best fit for the project (feature match, activity level, future evolution, and so on).
对于工具函数和库,比起使用第三方库,AI 有种偏向于“自己手撸”的倾向。不是说“造轮子”一定不好,但是……
解决常见领域的成熟问题(例如 gjson),倾向让 AI 采纳库而不是自己实现。如何知道哪些库适合?跟 AI 聊,或自己动手查阅资料,日常积累不可少。多个库可用时,人判断最适合项目的(功能契合度、活跃度,未来演进等等)。
Before opening a new PR, use an AI agent to review your current changes and adjust the code based on its suggestions. An up-front AI review lightens the later human review and speeds up the iteration loop. Any review SKILL or a simple prompt will do. Here's an example prompt:
You are a code review expert. Compare against the master branch to see all the changes in this project, review them, and produce a report. I care most about:
- Logic errors or unhandled edge cases;
- Common designs or constructs that go against language best practices;
- Overly complex classes/interfaces/functions that could be simplified;
- Patterns that may be security risks (SQL injection, for instance);
- Reimplementations of functionality that a mature library or another module already provides (failure to reuse);
- Anything else that breaks project conventions, consistency, or quality.
Note: reviewing before you open the PR doesn't replace the AI and human review that comes after — it's just an up-front self-check.
创建新 PR 前,应当使用 AI Agent review 当前改动并根据建议调整代码。AI 前置 review 可减轻之后人工 review 的负担,提升迭代效率。可使用任何 review SKILL 或简单 prompt 完成。下面是一条示例 prompt:
你是一名代码评审专家。和 master 分支对比以了解当前项目的所有改动,review 这些改动并产出报告。我最关注这些内容:
- 代码逻辑错误或未考虑边界情况;
- 常见的不符合编程语言最佳实践的设计或写法;
- 过于复杂的可以被简化的类/接口/函数设计;
- 可能存在安全隐患的写法(例如 SQL 注入);
- 重新实现了成熟库或项目其他模块已实现的功能(未复用);
- 其他任何不符合项目规范、打破一致性,有问题的内容;
注意:创建 PR 前的 Review 并不直接替代之后的 AI 和人工 Review,这只是一种前置的自查。
For code AI implements, do the work of automated testing and self-testing. Never commit untested code and leave it to review to catch what falls through — review can't find everything, and some problems only surface when the code actually runs. The later a bug is found, the more it costs to fix. Write automated tests (unit tests, API tests, and so on) so an AI agent can verify changes on its own and stay in a verify-fix loop.
对于 AI 实现的代码,做好自动化测试和自测工作。杜绝提交未经测试的代码,去等待 Review 来“兜底”。代码 Review 不可能找到所有问题,有些问题只有实际执行才能触发。越后期发现的 bug,修复成本越高。鼓励编写自动化测试代码(单测、API 测试)等,做到 AI Agent 可自动验证,进入“验证<->修复”循环。
Stay curious: when AI's code brings up a library, pattern, or snippet you find novel, chase it down to the bottom.
Push your limits: shake off mental inertia and take on tasks you'd never have attempted "without an agent."
Do the right thing: if the requirement itself was wrong from the start, AI will race you down the wrong road at full speed — which is why "doing the right thing" has never mattered more.
保持好奇心:对 AI 的代码,其中觉得新奇的库、模式或代码片段,打破砂锅问到底。
拓展能力边界:打破思维惰性,去解决一些“如果没有 Agent”你绝不会去完成的任务。
做正确的事:如果一开始的需求就错了,AI 会帮你在错误的道路上极速狂奔,所以“做正确的事”从未像现在这么重要。
Junior engineers without much experience are still early in their understanding of the language and the project domain. Leaning too heavily on AI at this stage can undercut learning and, over the long run, hurt their growth. So here's advice aimed specifically at them:
经验不够丰富的初级工程师,对于编程语言和项目领域的理解尚处于早期,此时过度依赖 AI 或拖累学习效率,长远来看对能力发展有不良影响。因此,针对该类人群提供特定建议:
AI is an efficiency tool, but early in your career you should care more about quality than speed.
Shipping low-quality code fast is actually less efficient — it means review rounds that keep coming back, plus technical debt.
If a slower path teaches you more, take the slower path (once you've agreed on the deadline).
AI 虽然是提效工具,但处于初级阶段时,应当更注重质量而非速度。
快速地交付低质量的代码,实际上更低效(后续 review 反复调整、技术债务)。
如果更慢的方式,能让自己学到更多东西,那么选更慢的(沟通好 deadline 的前提下)。
AI agents are very good at fully automatic bug fixing, but for a junior engineer… don't just toss the whole thing at the agent and let it run unattended.
Work in chat mode: offer your own thinking and questions, and deepen your understanding of the project as you analyze the bug. That helps you grasp the code logic and architecture faster and more deeply.
To repeat: treat the agent as a collaborator to work alongside, not something to hand everything off to.
AI Agent 非常擅长全自动修复 Bug,但对于初级工程师……不建议一股脑全丢给 Agent,由 Agent 完全无监督地“自动化”修复。
用聊天模式,提出自己的思考和疑问,在分析 Bug 的过程中加深对项目的理解。这有助于更快、更深入地理解代码逻辑和架构。
重复一次:多把 Agent 作为协作者来共同工作,而不是完全委派给 Agent。
For any task, AI gives you the "most likely to hold up" answer, but it may not suit you. Following it blindly costs you the chance to broaden your own technical horizons.
Spend a fixed amount of time first (half an hour, say) designing your own approach, then ask AI and compare its thinking against yours — come up with your own answer before you check the key.
Push the agent to its limits to find out what it can really do.
对任何任务,AI 给出的是“最有可能成立”的答案,但它不一定适合你。盲目遵循,丧失了拓展自身技术视野的可能性。
先花一个固定的时间(如半小时)自己设计思路,之后询问对比 AI 给出的思路(先有解再“对答案”)。
鼓励极限探索 AI 的能力边界。
Have AI question you back, using Q&A to deepen your grasp of the project and the related technology — like having AI run a mock "interview" about the project.
Read the official docs: AI knowledge has a cutoff date and hallucinates, so documentation is still the first choice for really mastering a technology (slow is fast).
让 AI 反问自己,通过问答来加强对项目和相关技术的理解。类似让 AI 给你做一场关于项目的模拟“面试”。
读官方文档:AI 知识有截止日期,存在幻觉问题,文档仍然是深入掌握某项技术的首选(慢即是快)。
Fill in your gaps in software design and architecture patterns — learn design patterns, domain-driven design (DDD), and the like. At this stage AI isn't good at overall design; it's better at concrete, function-level implementation within a clear framework.
Good design and robust, flexible architecture are what keep a project iterating sustainably, and that needs a human at the helm. Build your own body of knowledge by reading books.
Watch the non-functional requirements: AI tends to default to "make the feature run" and overlooks the rest of engineering — security, maintainability, concurrency safety, scalability. Pay attention to them deliberately.
补充软件设计和架构模式方面的短板,了解和学习设计模式、领域驱动设计(DDD)等。现阶段 AI 并不擅长整体设计,更擅长在明确的框架下做具体的函数级实现。
良好的设计、健壮与灵活的架构,保证项目可持续迭代,离不开人来掌舵。通过阅读书籍构建自己的知识体系。
关注非功能性需求:AI 往往默认只关注“功能跑通”,忽视其他工程层面的问题:安全、可维护性、并发安全和扩展性等,有意识地去关注它们。
If you have a different view or something to add, the discussion is open.
如有不同看法或补充条目,欢迎讨论。