Prompts / Coding & Software Engineering

ChatGPT prompt for a coding assistant

This prompt asks an AI coding assistant to work within your actual stack, interfaces, and constraints. Use it for a well-scoped feature, bug fix, or refactor when you want code you can inspect and test.

PromptOpen ChatGPTOpen Claude
Act as a careful senior engineer helping me implement [TASK OR BUG] in [PROJECT CONTEXT AND STACK]. The relevant existing code, interfaces, or error output is [RELEVANT CODE OR LOGS]. The required behavior and constraints are [ACCEPTANCE CRITERIA]. I can run these commands or tests: [AVAILABLE TEST OR BUILD COMMANDS].

Do not invent APIs, files, package behavior, database columns, environment variables, or test results. If a missing dependency, interface contract, security requirement, or product decision prevents a safe implementation, ask up to 3 focused questions before proposing a patch. Otherwise, reason from the code I supplied.

First, state a concise implementation plan that identifies affected files, data flow, invariants, and the smallest safe change. Then provide:
1. The code changes as complete file patches or clearly delimited replacements, preserving the project’s apparent conventions.
2. A short explanation of how the change satisfies each acceptance criterion.
3. Tests: include unit, integration, or manual test cases appropriate to the change, with inputs and expected outputs.
4. Edge cases and failure handling, including invalid input, empty or missing values, retries or concurrency where relevant, authorization boundaries, and backward compatibility.
5. A rollback or migration note if state, schema, public behavior, or stored data changes.

Prefer simple, maintainable code over unnecessary abstraction. Validate external input at the boundary, avoid exposing secrets in logs or errors, and preserve error context useful to operators. If you offer alternatives, recommend one and state its trade-off in one sentence.

Before answering, self-check that every referenced identifier exists in the supplied context or is explicitly marked as an assumption, and that the tests would fail before the fix and pass after it. Flag any acceptance criterion that the proposed code does not fully meet.

Fill in

PlaceholderWhat to enterExample
[TASK OR BUG]Describe the feature to build or the observed failure, including expected and actual behavior.Add a POST /api/invitations endpoint that rejects duplicate pending invitations and returns 201 for a new email
[PROJECT CONTEXT AND STACK]State the language, framework, runtime, dependency constraints, and relevant architectural context.Node 22, TypeScript, Express, PostgreSQL via Prisma; REST API uses Zod validation and Vitest
[RELEVANT CODE OR LOGS]Paste the smallest set of related files, function signatures, tests, or error logs needed to understand the work.routes/users.ts exposes POST /api/users; prisma schema has Invitation with email, status, createdAt; current duplicate requests create two rows
[ACCEPTANCE CRITERIA]List observable conditions the completed change must satisfy, including compatibility or performance constraints.Normalize email casing; return 409 for an existing pending invitation; allow a new invitation after a revoked one; do not reveal invitation tokens
[AVAILABLE TEST OR BUILD COMMANDS]Enter the commands you can run locally or in CI to validate the change.npm test -- invitation; npm run typecheck; npm run lint

How to use

  1. Paste the relevant interface, tests, and error output instead of describing a codebase from memory.
  2. State observable acceptance criteria, including the response code or user-facing behavior you expect.
  3. Inspect the patch for invented files, APIs, and assumptions before applying it to your project.
  4. Follow up with: “Now write only the Vitest cases that prove the duplicate and revoked-invitation behavior.”

Variations

Bug investigation

Use this when you need a diagnosis before deciding on a fix.

Variation
Investigate this software failure: [OBSERVED BEHAVIOR]. The expected behavior is [EXPECTED BEHAVIOR]. Here are the reproduction steps, logs, and relevant code: [EVIDENCE]. The system context is [STACK AND DEPLOYMENT CONTEXT]. Produce a ranked list of plausible root causes, the evidence for and against each, and the smallest diagnostic checks to distinguish them. Do not claim a root cause without evidence or propose broad rewrites. End with a recommended next experiment and its expected outcomes. Check that every hypothesis explains the reported symptoms.

Code review

Use this when a proposed diff needs a focused technical review.

Variation
Review this proposed change for [FEATURE OR RISK AREA]: [DIFF OR CODE]. The existing behavior and constraints are [CONTEXT]. Return findings ordered by severity: correctness, security, data integrity, performance, compatibility, and test gaps. For each finding, cite the relevant code path, explain the concrete failure scenario, and propose a minimal correction. Do not invent repository conventions or report stylistic preferences as defects. If there are no material findings, say so and name the residual risks. Check that each finding is actionable and supported by the supplied code.

Refactor plan

Use this when behavior must stay stable while code structure improves.

Variation
Plan a behavior-preserving refactor of [COMPONENT OR MODULE]. Current code and tests are [CODE AND TESTS]; the maintenance problem is [PROBLEM]. Produce a staged plan with seams to extract, invariants to preserve, tests to add before refactoring, and a small first patch. Identify public APIs, data formats, and side effects that must not change. Do not rewrite working code merely for style. Include rollback signals and a verification command for each stage. Check that every stage can be merged independently without changing intended behavior.

Tips

  • Give the AI the failing test or exact request and response; a symptom such as “login is broken” is too ambiguous to code against.
  • Ask it to preserve contracts at module boundaries, especially response shapes, database migrations, and event payloads.
  • For state-changing endpoints, test duplicate requests, retries, unauthorized callers, and partial failure rather than only the happy path.
  • Treat generated dependency upgrades and schema changes as separate decisions unless they are essential to the requested fix.

FAQ

Can I paste production code into an AI coding assistant?

Only if your organization permits it. Remove secrets, customer data, tokens, and proprietary material that should not leave your approved environment.

Should I ask for the code or the plan first?

For a small, well-understood change, ask for both. For unclear failures or unfamiliar systems, get a diagnosis and validation plan before applying code.

Can AI-generated tests prove a fix is safe?

They improve confidence but do not prove safety. Run the project’s checks and add tests around the behavior most likely to regress.

Related prompts

All Coding & Software Engineering prompts →

Get a few prompts like this every week

Something Big is a free AI newsletter read by 50,000+ professionals. One email a week with prompts and tools that work, plus what changed in AI and what to do about it.