Home ChatGPT Prompts Coding

ChatGPT Prompts for Coding

Write functions, review code, generate tests, and architect systems faster.
Works with ChatGPT, Claude, and Gemini.

30 Ready Prompts
Copy with One Click
Framework-Tagged

30 Prompts — Coding

Click any prompt to copy
Function from Spec
Zero-Shot

Write a [language] function called [function_name] that:
[specification in plain English]
Include input validation, error handling, and a docstring. Add 3 unit test examples at the bottom.

Code Review
CRISP

Review the following [language] code for bugs, performance issues, and security vulnerabilities:
[code block]
Format your response as: Critical Issues → Warnings → Style Suggestions → Positive Notes.

Bug Explainer
COT

Explain why the following code produces the error: [error message]:
[code block]
Walk through the execution step-by-step. Then provide the corrected code with an explanation of the fix.

Refactoring Plan
MECE

Suggest a refactoring plan for the following [language] module:
[code block]
Group issues by: readability, performance, testability, and maintainability. Prioritise by effort vs impact. Show before/after for the top 3 changes.

SQL Query Writer
Zero-Shot

Write a SQL query for the following task:
Tables: [table schema]
Task: [plain English description]
Optimise for performance. Include a comment explaining each major clause. Dialect: [MySQL/PostgreSQL/SQLite].

API Endpoint Design
REST

Design a RESTful API endpoint for [feature].
Include: HTTP method, URL path, request body schema (JSON), response body schema, status codes, authentication requirement, and rate limit note.
Language/framework: [stack].

Regex Builder
Zero-Shot

Write a regular expression to match: [pattern description].
Language: [language]. Provide: the regex, a plain-English explanation of each part, 3 matching examples, and 2 non-matching examples.

Unit Test Generator
Zero-Shot

Generate comprehensive unit tests for the following function:
[code block]
Framework: [Jest/PyTest/JUnit/etc]. Cover: happy path, edge cases, invalid inputs, and boundary conditions. Aim for 85%+ code coverage.

README Writer
Zero-Shot

Write a README.md for the project: [project name].
Include: badges, description, features list, installation steps, usage examples (with code blocks), configuration options, contributing guide, and license.
Tech stack: [stack].

Code Documentation
Zero-Shot

Add comprehensive documentation to the following [language] code:
[code block]
Use the standard docstring format for [language]. Document: purpose, parameters (type + description), return value, exceptions, and a usage example.

Algorithm Explanation
COT

Explain the [algorithm name] algorithm to a [beginner/intermediate/senior] developer.
Include: the core idea (1 paragraph), step-by-step walkthrough with a concrete example, time/space complexity analysis, and when to use vs avoid it.

Data Structure Selector
COT

I need to store [data description] and perform these operations: [operations list].
Recommend the best data structure for this use case. Explain your reasoning, compare 2 alternatives, and show a code snippet for the recommended approach in [language].

Performance Profiling
Zero-Shot

The following [language] code is slow on inputs of size [scale]:
[code block]
Identify bottlenecks with Big-O analysis. Provide an optimised version. Estimate the speedup factor and explain the trade-offs.

Error Handling Wrapper
Zero-Shot

Add robust error handling to the following [language] code:
[code block]
Use try/catch/finally appropriately. Log errors with context. Return meaningful error messages to callers. Don't swallow exceptions silently.

Environment Setup Script
STEPS

Write a setup script for a new developer joining the [project name] project.
OS: [OS]. Stack: [stack].
Script should: install dependencies, set up environment variables (with placeholder values), run DB migrations, and seed test data. Include error checks at each step.

Webhook Handler
Zero-Shot

Write a webhook handler in [language/framework] for events from [service].
Events to handle: [event types].
Include: signature verification, idempotency check, async processing, and a success/failure response. Add logging.

Caching Strategy
Zero-Shot

Design a caching strategy for [system/feature] using [Redis/Memcached/in-memory].
Data to cache: [data type]. Read frequency: [frequency]. Invalidation trigger: [trigger].
Provide: cache key schema, TTL recommendation, code snippet, and cache stampede prevention.

Docker Setup
STEPS

Write a Dockerfile + docker-compose.yml for a [language/framework] app.
Services needed: [services e.g. app, db, redis]. Env: development.
Include: multi-stage build, non-root user, health checks, volume mounts, and environment variable handling.

Auth Flow Design
Zero-Shot

Design a JWT authentication flow for a [type of app].
Include: login endpoint, token generation (payload fields), token verification middleware, refresh token logic, and logout/revocation.
Language: [language]. Show code for each step.

Migration Script
Zero-Shot

Write a database migration script to [migration description].
Database: [DB type]. Table(s) affected: [tables].
Include: up migration, down migration (rollback), data backfill if needed, and a pre-flight check query.

CI/CD Pipeline Config
Zero-Shot

Write a GitHub Actions workflow for a [language] project.
Triggers: push to main + PRs. Steps: lint → test → build → deploy to [target].
Include: caching dependencies, environment secrets, test coverage report, and Slack notification on failure.

Code Smell Detection
Zero-Shot

Identify code smells in the following [language] codebase excerpt:
[code block]
List each smell, explain why it's problematic, and provide a refactored example. Categories: duplication, coupling, cohesion, naming, complexity.

Type Definition Generator
Zero-Shot

Generate TypeScript type definitions for the following JSON API response:
[JSON example]
Use interface for objects, union types for enums, and optional (?) where fields can be absent. Add JSDoc comments for non-obvious fields.

Security Audit Checklist
Zero-Shot

Audit the following [language] code for OWASP Top 10 vulnerabilities:
[code block]
For each finding: vulnerability type, CWE ID, affected line(s), severity (Critical/High/Medium/Low), and remediation code snippet.

Load Testing Script
Zero-Shot

Write a load test script using [k6/Locust/JMeter] for the [endpoint/API].
Scenario: ramp from 10 to [max users] over [duration]. Target RPS: [target].
Include: assertions on p95 latency < [threshold]ms, error rate < 1%, and a summary report setup.

Microservice Interface
Zero-Shot

Design the interface contract for a [service name] microservice.
Language: [language]. Communication: [REST/gRPC/event].
Include: service boundary, public methods/endpoints, request/response schemas, error codes, and event schemas if applicable.

Code Generator Prompt
Zero-Shot

Build a code generator that takes [input spec format] and outputs [output type].
Language: [language]. Template engine: [Jinja2/Handlebars/custom].
Handle: missing fields with defaults, validation of required fields, and output formatting.

Dependency Upgrade Plan
Zero-Shot

Create a safe upgrade plan for migrating [package] from v[current] to v[target] in a [language] project.
Include: breaking changes checklist, files likely affected, testing strategy, rollback plan, and estimated effort in hours.

State Machine Design
Zero-Shot

Design a state machine for [entity e.g. order, subscription] with these states: [states].
Define: valid transitions, trigger events, guard conditions, and side effects per transition.
Show as: table + code implementation in [language].

Async Pattern Implementation
Zero-Shot

Implement [async pattern: queue, pub-sub, saga] for the following use case:
[use case description]
Language: [language]. Include: producer code, consumer code, error handling, retry logic, and dead-letter queue setup.

How to use these prompts
  • Replace [placeholders in brackets] with your specific details before sending.
  • Add context about your audience, tone, or format to get more tailored results.
  • Chain prompts — use one output as input to the next for complex tasks.
  • Works with ChatGPT, Claude, Gemini, and other LLMs.
Build Custom Prompts

Use our AI prompt builder to create prompts tailored to your exact needs.

Try Prompt Builder
Learn the Frameworks

The badges on each prompt reference proven prompt engineering frameworks.

Browse 60+ Frameworks →
All ChatGPT Prompt Categories