OTFotf
All posts
Codex

Six Tips for Coding with GPT-5

4 min
Six Tips for Coding with GPT-5

Straight from OpenAI: six practical tips for writing better code with GPT-5. Prompt structure, context management, and debugging workflows.

Overview

OpenAI's developer relations team distilled their internal best practices into six actionable tips for coding with GPT-5. These tips apply to both the Codex product and the GPT-5 API when used for code generation.

The tips focus on what's NEW about GPT-5's capabilities compared to GPT-4 — specifically its improved instruction following, longer context window, and better understanding of complex codebases.

The Six Tips

1. Be Explicit About Language and Framework

GPT-5 supports more languages and frameworks than any previous model. Always specify: 'Use TypeScript with strict mode,' 'Use Python 3.12 with type hints,' or 'Use Rust with the tokio async runtime.' Explicit tech stack instructions produce dramatically better code.

2. Provide Context Before Instructions

GPT-5's larger context window works best when context comes first. Paste relevant code, type definitions, and existing patterns BEFORE giving instructions. This mirrors how a human developer would read code before modifying it.

3. Use Step-by-Step for Complex Tasks

For multi-step operations, break them down: 'Step 1: Read the existing schema. Step 2: Add the new fields. Step 3: Update the migration. Step 4: Update the TypeScript types.' Sequential instructions produce more reliable output than monolithic requests.

4. Ask for Explanations After Code

Request code first, explanation second: 'Write the function, then explain your design decisions.' GPT-5 produces better code when generation isn't interrupted by explanation. Review the explanation to catch reasoning errors.

5. Test with Edge Cases in the Prompt

Include edge cases directly in your prompt: 'Handle empty arrays, null values, and arrays with a single element.' GPT-5 handles edge cases it's told about much better than edge cases it has to infer.

6. Use the System Message for Persistent Rules

Put coding conventions in the system message, not in every user prompt. 'Always use functional components. Never use any type. Always add JSDoc comments.' The system message persists across the conversation, reducing repetition.

Putting It Into Practice

Here is a concrete workflow to apply all six tips in a single coding session with GPT-5.

1

Start with a clear project brief

Write a 3-5 sentence description of your project goal, tech stack, and constraints. Paste this as your opening prompt so GPT-5 has full context from the start. Include any specific patterns or libraries you want enforced.

2

Scope your first request tightly

Rather than asking GPT-5 to build an entire feature, start with the smallest meaningful unit — a single function, component, or API endpoint. Review its output carefully before expanding scope.

3

Iterate with targeted follow-ups

Once the initial code is generated, use follow-up prompts that reference specific lines or functions. For example: "Refactor the `fetchData` function to add error handling and retry logic with exponential backoff."

4

Validate with tests

Ask GPT-5 to write tests for the code it just generated. This serves as both a quality check and documentation. If the tests reveal issues, paste the failures back for targeted fixes.

On this page