ChatGPT Prompts for Coding
Write functions, review code, generate tests, and architect systems faster.
Works with ChatGPT, Claude, and Gemini.
30 Prompts — Coding
Click any prompt to copyFunction from Spec
Zero-ShotWrite 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
CRISPReview 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
COTExplain 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
MECESuggest 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-ShotWrite 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
RESTDesign 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-ShotWrite 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-ShotGenerate 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-ShotWrite 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-ShotAdd 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
COTExplain 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
COTI 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-ShotThe 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-ShotAdd 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
STEPSWrite 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-ShotWrite 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-ShotDesign 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
STEPSWrite 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-ShotDesign 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-ShotWrite 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-ShotWrite 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-ShotIdentify 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-ShotGenerate 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-ShotAudit 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-ShotWrite 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-ShotDesign 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-ShotBuild 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-ShotCreate 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-ShotDesign 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-ShotImplement [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 BuilderLearn the Frameworks
The badges on each prompt reference proven prompt engineering frameworks.
Browse 60+ Frameworks →