Andrej Karpathy 提煉「CLAUDE.md 四大準則」引爆 GitHub,讓 AI 寫 Code 準確率飆破 90%

Let AI Obediently Listen with the God-Level Prompt Exposure! Recently on GitHub, a document named CLAUDE.md has surged to the top of the trending list. This file, based on the "Four Major Coding Principles" distilled from observations by former OpenAI AI director Andrej Karpathy, is like implanting the soul of a senior engineer into AI. Just placing it in the project root directory can boost the accuracy of AI tools like Claude Code from 65% to over 90%, thoroughly curing the bad habits of AI code tampering and over-engineering.
(Background recap: Claude Code new /goals command: separating execution and evaluation to prevent AI agents from slacking off and lying)
(Additional background: OpenAI founding member Andrej Karpathy announced joining Anthropic: returning to the forefront of LLM development)

As AI-assisted development tools like Claude Code and Cursor become increasingly popular, many developers face a common pain point: AI writes quickly but often "gets clever," not only making assumptions, over-designing, but also arbitrarily changing well-functioning code.

However, this problem now has the ultimate solution. Renowned AI expert and former OpenAI AI director Andrej Karpathy recently analyzed common failure modes of large language models (LLMs) when coding; subsequently, developers like Forrest Chang distilled his core ideas into a simple document called CLAUDE.md. This project (forrestchang/andrej-karpathy-skills) recently skyrocketed to the top of GitHub's trending list, garnering hundreds of thousands of stars.

Many developers have tested and happily reported that after adopting this file, the accuracy of AI-generated code jumped from around 65% to an astonishing over 90%.

Unveiling the "Four Golden Rules" of CLAUDE.md

This magical CLAUDE.md file essentially equips AI with a set of "Senior Engineer Code of Conduct." When placed in the project root, Claude Code automatically reads it and uses it as the highest behavioral guideline for the entire conversation. Its core contains the following four ironclad principles:

  • 1. Think Before Coding:
    "Don't assume. Don't hide confusion. Lay out trade-offs."
    Forcing AI to explicitly state its assumptions. If uncertain about requirements or facing multiple solutions, AI must actively stop and ask the user, rather than guessing blindly. When encountering unreasonable requests, AI is also empowered to "push back."
  • 2. Simplicity First:
    "Write only the minimal code needed to solve the problem. No speculation."
    Strictly prohibit AI from adding unnecessary "drama." No defensive code for unlikely future scenarios, nor complex abstractions for single tasks. The principle is simple: if a problem can be solved in 50 lines, don’t write 200.
  • 3. Precise Surgical Changes:
    "Only modify what you must. Only clean up what you messed up."
    Many developers love this. This rule strictly forbids AI from refactoring or changing adjacent code, comments, or formatting when fixing a specific bug. Every change must be directly traceable to a clear user requirement.
  • 4. Goal-Driven Execution:
    "Define success criteria. Iterate until achieved."
    Require AI to convert vague tasks into verifiable concrete goals. For example, for "fix a bug," AI’s standard steps should be: first write a test that reproduces the bug ➔, then modify the code ➔, and finally pass the test, forming a rigorous verification loop.

Why is this prompt so effective?

LLMs naturally tend to cater to user prompts and are highly prone to "hallucinate assumptions" and "scope creep." The greatness of CLAUDE.md lies in hardcoding human senior engineer’s "common sense and restraint" into a system prompt.

Through these four principles, AI is forced to become more cautious, focused, and results-verifiable. Many benefiting developers report that their Git diffs are now cleaner than ever, bugs are significantly reduced, and maintenance becomes easier. It no longer feels like commanding a runaway machine but truly experiencing pair programming with a reliable "Senior Engineer."

This page may contain third-party content, which is provided for information purposes only (not representations/warranties) and should not be considered as an endorsement of its views by Gate, nor as financial or professional advice. See Disclaimer for details.
  • Reward
  • Comment
  • Repost
  • Share
Comment
Add a comment
Add a comment
No comments
  • Pinned