Feeding Code Context
Give the model the signatures, types, data shapes, and errors it needs so its code fits your real project, not a generic one.
TL;DR
- Generated code fits your project only if the model can see your types, signatures, and data shapes.
- Include the smallest set of real code the answer depends on, plus the exact error if debugging.
- Show interfaces and examples of real data, not just prose descriptions.
Anchor With Types
Paste InterfacesReal type definitions pin field names and shapes so calls are correct.
type User = { id: string;
email: string; active: boolean };Paste SignaturesShow the functions the new code must call, so it calls them right.
function findUser(id: string):
User | undefinedShow Real DataA redacted sample reveals the true shape better than a description.
{ "id": "u_12", "email": "a@b.co",
"active": true }Scope The Snippet
The Relevant SlicePaste the function and types involved, not the whole module.
// the failing function + its types,
// not 600 unrelated linesName The EnvironmentOne line about where the code runs replaces pasting the scaffolding.
"Runs in a Next.js server action;
`db` is a Prisma client."Signatures Of HelpersIf the code calls a helper, show its signature, not its whole body.
// available: formatMoney(n: number): stringDebugging Context
Full ErrorInclude the complete message and stack trace, not a paraphrase.
TypeError: x is not a function
at handler (api.ts:42:10)The Triggering InputShow the input that caused the failure so the model can reproduce it.
Input: { items: [] } // empty cartMinimal ReproA tiny reproducing snippet beats the whole feature for finding the cause.
Smallest code that still throws.Context Hygiene
Label What Is WhatMark each block so the model knows types from code from errors.
# Types:
# Current code:
# Error:
# Task:Keep It CurrentPaste the version you are actually running, not an old copy.
Stale paste -> advice for code
that no longer exists.Redact SecretsStrip tokens, keys, and real user data before pasting.
API_KEY=... -> API_KEY=<redacted>Tips
- Paste type definitions and function signatures first; they anchor the output to your actual API.
- Include a sample of real input/output (redacted) so the model handles the true data shape.
Warnings
- Describing types in words instead of pasting them invites the model to invent fields that do not exist.
- Pasting entire files buries the relevant lines and burns context; paste the slice that matters.
In Practice
A request to add a function, grounded in the actual types and helper signatures it must use. The model now writes code that compiles against your project instead of a generic guess.
- Labeled blocks separate the types, the available helpers, and the task.
- Pasting the real interfaces stops the model inventing fields.
- Helper signatures tell it exactly what it may call.
- A one-line environment note replaces pasting the surrounding scaffolding.
# Types
type Order = { id: string; items: Item[]; total: number };
type Item = { sku: string; qty: number; price: number };
# Available helpers (signatures only)
formatMoney(cents: number): string
findOrder(id: string): Order | undefined
# Environment
Runs in a Next.js 15 server action; prices are in cents.
# Task
Write `orderSummary(id: string): string` that finds the
order, sums item qty * price, and returns
"<n> items, <formatted total>". Return 'Order not found'
if missing. Use the helpers above; no new deps.FAQ
Whatever it cannot infer and the answer depends on: the relevant types and interfaces, the signatures of functions it will call, the real data shape, the framework and versions, and, when debugging, the exact error and a minimal repro. Give that, not the whole repo.
Paste them. A real interface tells the model the exact field names and types, so it calls your code correctly. Describing 'a user object with some fields' invites invented properties that fail at compile time.
Enough that the snippet makes sense on its own: the function in question, the types it touches, and a one-line note on where it runs. If a called helper matters, paste its signature too. Everything else can be summarized.
Include the full error message and stack trace, the function that threw, the relevant types, and the input that triggered it. The error plus a minimal repro is often more valuable than any amount of surrounding code.