GPT-5.6 coding prompt patterns: 12 templates for Codex / Cursor that get it right on the first try
12 GPT-5.6 family prompt templates optimized for coding: architecture understanding, incremental implementation, bug localization, code review, test generation, refactoring, dependency upgrades. Pair with Codex CLI / Cursor / Aider.
Coding prompts follow a different logic than generic prompts. 'Help me optimize this code' sends the model off into the weeds. Coding prompts need precise context, an explicit output format, and boundary cases. This article is 12 GPT-5.6-tested coding prompt templates that cover the full dev workflow, paired with Codex CLI / Cursor / Aider.
Template 1: Architecture comprehension
Get the AI to understand the whole codebase structure.
You are a senior engineer. Read the code in {repo_path} and answer:
1. What is the overall architecture? Draw a mermaid module-dependency diagram.
2. Data flow: from user request to response, which modules does it pass through?
3. What are the key design decisions, and where are they in the code?
4. To add a new feature {feature}, which files should I edit?
Read-only. No edits. Output markdown. Do not write code.
Use case: onboarding new hires, picking up legacy projects, getting context before a code review.
Template 2: Incremental implementation
Implement a new feature with minimal diff.
Task: add a new feature {description} to {repo_path}.
Requirements:
- Edit only the files needed (avoid unrelated changes)
- Preserve existing API compatibility
- Add unit tests (cover normal / exception / boundary cases)
- Run existing tests; ensure nothing breaks
- Output: list of changed files + a diff summary per file
Reference implementation: {reference_repo}/{file_path} (if any).
Use case: feature increment, calling a new endpoint from another service.
Template 3: Bug localization
Pin down a specific bug, get root cause + fix.
Bug: {bug_description}
Reproduce: {steps}
Expected: {expected}
Actual: {actual}
Tasks:
1. Read the relevant code {file_paths}, identify the root cause (no guessing - give line numbers)
2. Provide the fix (minimal diff)
3. Provide a regression test case
4. Assess fix risk (does it affect other modules?)
Use case: production bug fix, flaky-test localization.
Template 4: Unit test generation
Generate complete unit tests for an existing function.
Generate unit tests for {function_name} in {file_path}.
Requirements:
- Use {framework} (pytest / jest / go test)
- Coverage: normal / boundary (empty / max / min) / exception (invalid input / timeout)
- Mock external dependencies (database / HTTP / third-party)
- Target coverage: >= 90%
- Output: complete test file + coverage report
Reference: existing test style {existing_test_path}.
Use case: lift coverage, TDD a new feature.
Template 5: Code review
Review a PR.
Review this PR: {diff}
Evaluate on five dimensions:
1. Correctness: is the logic right? Are boundary cases handled?
2. Security: any prompt injection / XSS / SQL injection / authorization bypass?
3. Performance: any N+1 query / O(N^2) algorithm / memory leak?
4. Maintainability: naming / structure / documentation?
5. Tests: do they cover the core path? Flaky risk?
Output format:
- Blockers (must fix): list specific issues + line numbers + suggested fixes
- Nice-to-have: list potential improvements
- Highlights: list things done well
Use case: PR review, AI-assisted code review.
Template 6: Refactoring
Make a code segment clearer, keep external behavior identical.
Refactor {code_block} in {file_path}.
Requirements:
- Keep external behavior identical (all existing tests must pass)
- Improve: readability / modularity / error handling / naming
- Do not introduce new dependencies
- Output: complete refactored code + change rationale
Note: refactoring is not rewriting - aim for 'better structure', not 'different behavior'.
Any behavior change must be explicitly flagged.
Use case: tech-debt cleanup, modernize legacy code.
Template 7: Doc generation
Generate high-quality docs for code.
Generate docs for {file_path}.
Requirements:
- Module-level: docstring / README explaining what the module does, why it exists, key design decisions
- Function-level: every exported function gets a docstring (inputs / outputs / exceptions / examples)
- Type-level: every exported interface / type gets a comment
- Complex logic: inline comments explain the 'why', not the 'what'
Style reference: {existing_doc_path}.
Use case: open-source docs, internal API docs.
Template 8: Dependency upgrade
Upgrade a project dependency to a new version.
Upgrade {package_name} from {old_version} to {new_version}.
Tasks:
1. Read the changelog ({changelog_url}) and identify breaking changes
2. Find every file that uses this dependency ({grep_results})
3. Modify code to fit the new API
4. Run tests to verify
5. Output: list of changed files + adaptation notes
Use case: framework upgrade (React / Next.js / Vue), library major-version upgrade.
Template 9: PR description generation
Generate a PR description / PR body.
Based on this PR diff ({diff}) generate the PR description.
Format:
## What
- What was changed (1-3 sentences)
## Why
- Why? What problem does this solve?
## How
- How (key design decisions)
## Test
- How verified (unit / integration / manual)
## Risk
- Risks? Rollback plan?
## Screenshot (UI changes)
- Screenshot / GIF (optional)
Use case: PR automation pipeline.
Template 10: Commit message generation
git diff --staged | codex exec "Generate a conventional commit message from this diff. Format:
<type>(<scope>): <subject>
<body>
<footer>
type: feat / fix / docs / refactor / test / chore
subject: <= 50 chars, imperative mood ('add' not 'added')
body: explain why + how, wrap at 72 chars
footer: link to issue (Closes #123)"
Use case: git-hook automated commit messages.
Template 11: Comment translation
Translate comments from one language to another.
Translate comments in {file_path}.
Requirements:
- Keep code unchanged, only comments change
- Preserve technical terms untranslated (function / class names / API names)
- Stay concise: if the original comment is verbose, you may trim during translation
- Output: complete file
Use the cheapest model (gpt-5.6-luna); comment translation does not need heavy reasoning.
Template 12: Performance analysis
Pin down the performance bottleneck in code.
Analyze the performance of {function_name} in {file_path}.
Tasks:
1. Time complexity (best / average / worst)
2. Space complexity
3. Any of: N+1 queries / redundant computation / unnecessary copies / blocking I/O?
4. Expected latency on {test_data_size} data
5. Optimization suggestions (line-by-line)
Use case: perf optimization, production-incident perf localization.
5-step playbook: 'understand a codebase'
A full prompt flow for picking up a new project:
# Step 1: Architecture comprehension (Template 1)
codex exec "$(cat template-1.txt)" --repo ./repo
# Step 2: Find the core modules
codex exec "List the 5 most important files in ./repo and explain why" --repo ./repo
# Step 3: Run tests, see coverage
codex exec "Run the tests in ./repo, output a coverage report, list files with < 50% coverage" --repo ./repo
# Step 4: Find tech debt
codex exec "Find 10 'could be improved' spots in ./repo, rank by impact" --repo ./repo
# Step 5: Write the onboarding doc
codex exec "Based on the above outputs, write an ONBOARDING.md for new engineers" --repo ./repo > ONBOARDING.md
Five steps, ten minutes - new hires are productive.
Common anti-patterns
| Anti-pattern | Problem | Fix |
|---|---|---|
| "Help me optimize this code" | Too open, AI free-styles | "Optimize N's algorithm complexity from O(N^2) to O(N log N), preserve existing API" |
| No file paths | AI does not know what to edit | Explicit edit only file X |
| No output format requirement | Output drifts | "Output a diff / complete file / mermaid diagram" |
| No boundary cases | Only happy path tested | "Cover: empty input / oversize input / illegal characters / concurrency" |
| No test requirement | Code without tests | "Must add tests covering XX cases" |
| "Do not introduce new dependencies" omitted | AI installs everything | Explicit constraint |
Model selection
| Task | Recommended model | Why |
|---|---|---|
| Architecture comprehension / complex refactor | gpt-5.6-sol | Strongest reasoning |
| Daily code generation | gpt-5.6-terra | Best price/performance |
| Bug localization / comment translation | gpt-5.6-luna | 1/5 the cost |
Empirical split: Codex CLI on coding tasks runs 70% Terra + 25% Sol + 5% Luna. Defaulting everything to Sol wastes money.
Next steps
- New to Codex CLI? Read Getting started with OpenAI Codex CLI: from install to daily use.
- Want team Codex workflow? Read Codex Team Workflow: worktrees, reviews, and CI integration.
- Want Codex in CI? Read Codex CLI in GitHub Actions: production-grade CI integration.
- Want generic prompt patterns? Read Prompt Engineering Core Patterns: 8 templates that double GPT performance.
Key points
- Code prompts need three ingredients: precise context + explicit output format + boundary cases. Without them the model guesses and drifts.
- 12 templates cover: architecture, incremental implementation, bug localization, unit testing, code review, refactoring, doc generation, dependency upgrade, PR description, commit message, comment translation, performance analysis. Each ships the use case and anti-patterns.
- GPT-5.6 Sol fits complex architecture comprehension and cross-file refactor; Terra fits daily code generation; Luna fits comment translation and simple bug localization. Picking wrong costs both money and time.
- When pairing with Codex CLI / Cursor, the prompt must contain: (1) file paths (so AI knows where to edit); (2) the expected diff scope (do not let AI self-discover); (3) test requirement ('existing tests stay green + new tests added').
- The biggest anti-pattern in coding prompts is open-ended phrasing ('help me optimize this code'). Replace with concrete goals ('optimize N's algorithm complexity from O(N^2) to O(N log N), preserve existing API') and output quality doubles.
Frequently asked questions
Official references
Related articles
Prompt evaluation and failure debugging: LLM-as-judge + regression tests + Debug mode
After prompts go to production: LLM-as-judge auto-scoring, regression test sets, failure case taxonomy (hallucination / off-topic / format error), Debug mode logging, token / cost visualization.
Read articlePrompt Engineering Advanced: Multi-Turn Context, Structured Outputs, and GPT-5.6 Tuning
Part two of Prompt Engineering: multi-turn context management, structured outputs (JSON Schema), few-shot patterns, long-context strategy, and reasoning.effort interaction.
Read articlePrompt Engineering Core Patterns: 8 Templates That 2× GPT Output
A systematic walkthrough of 8 high-frequency prompt patterns — role prompting, few-shot, chain-of-thought, ReAct, self-consistency — each with a reusable template.
Read articleSubscribe to GPTMap Weekly
One email every Monday: curated OpenAI updates, deep dives, and best practices. No ads, unsubscribe anytime.