跪拜 Guibai
← All articles
Claude · Agent · AI Programming

Six Workflows That Make AI-Generated Code Actually Correct

By 沉默王二 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

AI coding agents are probabilistic; without deterministic guardrails, the same prompt produces different quality across runs. These six patterns give teams a repeatable workflow where correctness is checked by the machine, not by eyeballing the output.

Summary

The gap between generating code and generating correct code comes down to structure. A CLAUDE.md file acts as an onboarding manual that loads into every session, preventing the model from drifting on tech stack and conventions. Skills install domain-specific expertise per project, while hooks enforce deterministic rules outside the model—rejecting a commit that includes an .env file or auto-running a compile-and-fix loop until tests pass.

Visual tasks benefit from splitting the prompt into static description and dynamic interaction. Context is the most expensive resource in an agent session, so global Skills and MCP tools create noise; per-project configuration and manual /compact calls keep the context budget under control. A good prompt names the target file, the action, and the verification method, which raises execution accuracy sharply.

Anthropic's newly released Fable 5 model, available free for Pro and Max users until June 22, handled a multi-step PPT design task by fetching a third-party Skill, ingesting project materials, and producing a polished deck with minimal token waste.

Takeaways
Write a CLAUDE.md in the project root with tech stack, code conventions, directory structure, and forbidden commands—it loads into every new session automatically.
Install Skills per project, not globally, to avoid burning context budget on irrelevant tool descriptions.
Hooks run outside the model: PreToolUse can block dangerous operations, PostToolUse can auto-compile and feed errors back for repair, and Stop can persist session state.
Split visual-task prompts into static description (colors, layout, text) and dynamic interaction (mouse effects, touch, animations) for higher-quality Three.js output.
Run /compact manually when the model starts forgetting earlier decisions; it retains recent context and drops stale tokens.
A prompt that names the target file, the specific action, and the verification method (test, compile, manual check) produces far more accurate results than a vague request.
Claude Fable 5 is available free until June 22 for Pro and Max users and handled a multi-step PPT generation task by fetching a Skill, reading project materials, and assembling a polished deck.
Conclusions

CLAUDE.md and Skills are still prompt-level suggestions—the model can ignore them under enough pressure. Hooks are the first mechanism that enforces rules deterministically, which changes the reliability ceiling for agent-generated code.

Context is the real pricing unit in agent workflows, not tokens per request. Every global Skill or MCP tool you install is a permanent tax on every session, so per-project scoping is a cost-control measure, not just an organizational preference.

The three-element prompt structure (target, action, verification) is effectively a mini specification. It shifts the model from 'write some code' to 'produce an artifact that passes a test,' which is the difference between a demo and something deployable.

Concepts & terms
CLAUDE.md
A project-level instruction file placed in the repository root that Claude Code loads into the system prompt at the start of every session, functioning as a persistent onboarding manual for the AI agent.
Hook (Claude Code)
A code-level interception rule that runs outside the model at specific trigger points—PreToolUse, PostToolUse, or Stop—to enforce deterministic checks such as blocking dangerous commands or auto-running tests.
Skill (Claude Code)
A domain-specific knowledge pack installed per project that adds specialized instructions and reference documents to the agent's context, improving accuracy on tasks like web research or PPT generation.
/compact
A Claude Code command that manually triggers context compression, retaining recent conversation and key decisions while discarding early, redundant tokens to stay within the context window.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗