首页 / Skills / 开发提效 / 上下文工程 Context Engineering
开发提效

上下文工程 Context Engineering

Addy OsmaniMITSkill 语言: 英文
协议已核对不含脚本低风险
演示真实运行记录 · claude-sonnet-5-5 · 2026年10月
My AI coding agent keeps ignoring our conventions on a Next.js 15 + TypeScript + Prisma + Tailwind project (fictional example): it uses default exports, invents helper functions that already exist in src/lib, and edits the Prisma schema without asking. I am about to start the "checkout" feature (src/checkout/ and src/lib/payments.ts). Please set up the agent's context properly: write the rules file in the current folder and a short task context block I can paste at the start of the session.
Skill: context-engineering

I wrote CLAUDE.md in the current folder. Since the project is fictional, I couldn't check it against real files, so a few parts are guesses (listed below).

The rules file covers your three problems directly:

  • Default exports: named exports only, with a short exception list for the files Next.js requires to be default.
  • Invented helpers: the agent must search src/lib/ before writing any helper. If it thinks one is missing, it has to say what it searched and ask first.
  • Prisma schema: it may not edit schema.prisma or run migrate or db push without approval. It must stop and describe the change instead.

It also tells the agent to ask rather than guess when requirements conflict or are missing.

Task context block to paste at the session start

TASK: Implement the "checkout" feature.

SCOPE (only touch these):
- src/checkout/        (new feature code: UI, server actions, types)
- src/lib/payments.ts  (payment logic)

READ FIRST, before writing anything:
- src/lib/payments.ts and `ls src/lib` (reuse existing helpers; list what you found)
- One existing feature folder in src/ as the pattern to follow: <PATH, e.g. src/cart/>
- The relevant Prisma models (read-only): <MODEL NAMES, e.g. Order, OrderItem, Payment>

CONSTRAINTS:
- Follow CLAUDE.md: named exports, reuse src/lib, no new deps.
- Do NOT modify prisma/schema.prisma. If checkout needs a schema change, stop and propose it.
- Never log or store raw card data; <PAYMENT PROVIDER, e.g. Stripe> handles it.

OPEN QUESTIONS (ask me, don't guess): <e.g. guest checkout? tax/shipping rules? failure and retry behavior?>

FIRST STEP: reply with a short plan (files to create or change, existing helpers you'll reuse), then wait for my go-ahead.

What you need to fill in

  • Commands: I assumed standard npm scripts. Check them against your package.json.
  • Pattern example: The example at the bottom is a placeholder. Swap in a real file from your repo, because one concrete example does more than any rule.
  • Block placeholders: Fill the <...> spots in the pasted block (pattern folder, Prisma models, payment provider, open questions).
  • Session length: Start a fresh session when checkout is done. If the session runs long, compact the history around 75% of the window and keep the task block and constraints intact.

Test run on a fictional Next.js project: the model wrote a CLAUDE.md in a temporary folder and a task context block, and said which parts were guesses (commands, the pattern example, placeholders). It could not check the rules against real project files.

它做什么

把上下文看作影响智能体输出质量的最大杠杆。它给出一个由最持久到最短暂的五层结构(规则文件、规格与架构、相关源码、报错输出、对话历史),并演示怎么写规则文件(CLAUDE.md、.cursorrules、AGENTS.md 等):技术栈、命令、约定、边界,再加一个模式示例。它还涵盖只加载相关的规格章节、编辑前先读这个文件和一个相似的例子、把外部文件里像指令的文字当作数据、只回传真正失败的报错、可重启的会话边界、三种打包策略(倾倒式、选择性包含、分层摘要),以及预算规则:约 75% 时就开始精简,先压缩再丢弃,把任务最关键的内容放在最后。它还要求把冲突和缺失的需求明确提出来,而不是猜。

输出

你项目的规则文件、一段可以在会话开头粘贴的简短任务上下文,以及你还需要补充的清单。

适合什么场景

为 AI 辅助开发配置项目,以及修复总是不遵守约定、乱造工具函数或长会话里跑偏的智能体。

说明与风险

低风险:纯指令文件,没有脚本。它会在你的项目里写一个规则文件(如 CLAUDE.md),并提到你可以接入的 MCP 服务,但不会替你安装。规则文件会改变你的智能体的行为,请阅读它写了什么。已用一个虚构的 Next.js 项目试用一次:写出了 CLAUDE.md 和一段任务上下文,并标明了它只能猜测的部分(命令、模式示例),因为它没法对照真实文件检查。作者 Addy Osmani,MIT 协议。

SKILL.md 原文包内共 2 个文件