Pasting an entire 2,000-line file wastes tokens and hurts answer quality. The goal is to give the AI exactly the context it needs to reason about your problem — and nothing more.
Pasting an entire 2,000-line file wastes tokens and hurts answer quality. The goal is to give the AI exactly the context it needs to reason about your problem — and nothing more.
db is a Postgres pool."# Bad: paste the whole 800-line user-service.ts
# → AI wades through unrelated code, may anchor on the wrong function
# Good: send only what matters
// file: src/services/user-service.ts
// context: called from POST /users; `db` is a Postgres pool (pg)
type User = { id: number; email: string };
async function createUser(email: string): Promise<User> {
const { rows } = await db.query( // <-- the function I need help with
"INSERT INTO users (email) VALUES ($1) RETURNING id, email",
[email],
);
return rows[0];
}
// Question: how do I handle a duplicate-email conflict here?
The second version gives the AI the function, its return type (User), and a one-line note about db — enough to answer precisely, with no irrelevant code to distract it.
It's not only about cost. Extra code is distraction: the model may latch onto an unrelated function, mirror a bug elsewhere in the file, or dilute its attention across thousands of irrelevant tokens. A focused prompt produces a focused, accurate answer.
Token budgets are finite and large dumps degrade both speed and quality. Sending the minimal relevant slice — the target function, its types, a context summary, and file paths — saves tokens and sharpens the answer by removing distractions. Curating context is a core skill of working effectively with AI: you're not hiding information, you're directing attention to what matters.