首頁 / 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 個檔案