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

  1. Generated code fits your project only if the model can see your types, signatures, and data shapes.
  2. Include the smallest set of real code the answer depends on, plus the exact error if debugging.
  3. Show interfaces and examples of real data, not just prose descriptions.

Anchor With Types

    Paste Interfaces

    Real type definitions pin field names and shapes so calls are correct.

    type User = { id: string;
      email: string; active: boolean };
    Paste Signatures

    Show the functions the new code must call, so it calls them right.

    function findUser(id: string):
      User | undefined
    Show Real Data

    A redacted sample reveals the true shape better than a description.

    { "id": "u_12", "email": "a@b.co",
      "active": true }

Scope The Snippet

    The Relevant Slice

    Paste the function and types involved, not the whole module.

    // the failing function + its types,
    // not 600 unrelated lines
    Name The Environment

    One line about where the code runs replaces pasting the scaffolding.

    "Runs in a Next.js server action;
    `db` is a Prisma client."
    Signatures Of Helpers

    If the code calls a helper, show its signature, not its whole body.

    // available: formatMoney(n: number): string

Debugging Context

    Full Error

    Include the complete message and stack trace, not a paraphrase.

    TypeError: x is not a function
      at handler (api.ts:42:10)
    The Triggering Input

    Show the input that caused the failure so the model can reproduce it.

    Input: { items: [] }  // empty cart
    Minimal Repro

    A tiny reproducing snippet beats the whole feature for finding the cause.

    Smallest code that still throws.

Context Hygiene

    Label What Is What

    Mark each block so the model knows types from code from errors.

    # Types:
    # Current code:
    # Error:
    # Task:
    Keep It Current

    Paste the version you are actually running, not an old copy.

    Stale paste -> advice for code
    that no longer exists.
    Redact Secrets

    Strip tokens, keys, and real user data before pasting.

    API_KEY=... -> API_KEY=<redacted>

Tips

  1. Paste type definitions and function signatures first; they anchor the output to your actual API.
  2. Include a sample of real input/output (redacted) so the model handles the true data shape.

Warnings

  1. Describing types in words instead of pasting them invites the model to invent fields that do not exist.
  2. Pasting entire files buries the relevant lines and burns context; paste the slice that matters.

In Practice

FAQ