
Building a coding copilot with GPT-5 Codex
How to wire a diff-based code editor to GPT-5 Codex without breaking user files.
GPT-5 Codex is tuned for editing existing code, not writing greenfield essays. Prompt it accordingly.
Ship diffs, not files#
Ask the model for a unified diff and apply it with patch on your side. Full-file rewrites lose comments, imports, and formatting.
python
SYSTEM = """You are a code editor. Reply ONLY with a unified diff.
Use the exact file paths shown. No prose."""Context selection#
- Include the file being edited
- Include direct imports (1 hop)
- Include the test file for the module
- Never include node_modules or generated code
Read the RAG-for-code guide for embedding-based context selection.
Models in this article
Review current prices, specifications and source-linked benchmarks.
Build this with TokenRex
TokenRex is an LLM marketplace by Asirex Labs. Choose an enabled model, create a private API key and use the supported endpoint shown in Docs. Check live prices before your first request.