How to Use ChatGPT / Codex with Xcode (Step by Step)
On a Mac you can bring OpenAI help into Swift work three real ways: ChatGPT in Xcode Intelligence, ChatGPT macOS Work with Apps while Xcode is focused, and (on recent Xcode) Codex / agents via MCP. This lesson starts with Intelligence, then shows the other two honestly.
In short: open Xcode → Settings → Intelligence, turn on ChatGPT in Xcode, optionally sign in for higher limits, then chat beside your project. For deeper agent work, allow external agents and wire Codex with xcrun mcpbridge as Apple documents. Always Build and test yourself.
Why ChatGPT with Xcode
iOS students already live in Xcode. ChatGPT inside Intelligence keeps questions next to your Swift files. Work with Apps helps when you want the ChatGPT Mac app to see the frontmost editor. Codex/MCP is for longer agent loops on newer Xcode builds.
What you need
- Mac + recent Xcode: Intelligence features depend on your Xcode version — update from the App Store / developer downloads.
- ChatGPT access: You can often try without an account; signing in (Free/Plus/etc.) raises limits — re-check OpenAI/Apple screens, never invent quotas.
- Optional: ChatGPT Mac app: For Work with Apps (Option+Space / Chat Bar) with Xcode listed under Manage Apps.
- Optional: Codex CLI: For MCP: Apple documents
codex mcp add xcode -- xcrun mcpbridgeafter allowing external agents.
Path A — ChatGPT in Xcode Intelligence (start here)
- Xcode → Settings (or Preferences) → Intelligence.
- Under Chat, find ChatGPT in Xcode → Turn On. Confirm the dialogs.
- Optional: Sign In with your ChatGPT account for history / plan limits.
- Open a Swift file. Use the Intelligence chat / agent UI your Xcode build shows.
- Ask about the selection only. Review every proposed edit.
- Press Cmd+B and run your tests — do not trust chat alone.
Path B — ChatGPT Mac “Work with Apps”
- Install/update ChatGPT for macOS (OpenAI documents Work with Apps on recent Mac builds).
- ChatGPT → Settings → Work with Apps → Manage Apps → enable Xcode and grant permissions.
- Focus the Xcode editor (optionally select code). Open Chat Bar (Option+Space by default) and ask.
- ChatGPT includes open editor content up to a truncation limit — still avoid secrets.
Path C — Codex / external agents via MCP (advanced)
- Xcode → Settings → Intelligence → under Model Context Protocol, turn on Allow external agents to use Xcode tools.
- In Terminal (with Codex installed):
codex mcp add xcode -- xcrun mcpbridge(Apple’s documented shape). - Open your project in Xcode first, then prompt the external agent.
- Claude Code users have a parallel:
claude mcp add --transport stdio xcode -- xcrun mcpbridge— separate lesson family.
Configuration
AGENTS.md sketch (optional)# Xcode + ChatGPT / Codex notes - Prefer Swift API that matches the project's deployment target. - Do not invent bundle IDs, team IDs, or provisioning profile names. - Never ask the agent to read .env, xcconfig secrets, or keychain items. - After agent edits: Build (Cmd+B), then run unit tests you already have.
- Keep project hints in AGENTS.md / README — never put signing passwords there.
- Reasoning level controls (when shown) trade speed for deeper answers — start low for simple Swift questions.
First task (5 minutes)
In this Swift selection only: add input checks and suggest an XCTest. Do not change bundle identifiers, signing, or Info.plist keys.
- Apply only the lines you understand.
- Cmd+B. Fix compiler errors yourself if needed.
- Run the unit test target.
| Path | Best for |
|---|---|
| Intelligence → ChatGPT in Xcode | Day-to-day Swift questions inside Xcode |
| Work with Apps | Quick asks from ChatGPT Mac while Xcode is focused |
| Codex + mcpbridge | Longer agent loops on supported Xcode builds |
| GitHub Copilot for Xcode | Separate product — see Copilot in Xcode lesson |
- Never paste App Store Connect passwords, API keys, or customer data.
- Work with Apps sends editor context to ChatGPT — treat it like cloud AI.
Quick quiz
1. Where do you enable ChatGPT inside Xcode?
Xcode → Settings → Intelligence → ChatGPT in Xcode → Turn On.
2. Does Work with Apps need the ChatGPT Mac app?
Yes — enable Xcode under Work with Apps → Manage Apps.
3. MCP allow switch?
Intelligence → allow external agents to use Xcode tools.
4. Codex MCP sample command?
codex mcp add xcode -- xcrun mcpbridge (verify on Apple docs).
Save tokens and money
Select one function, not the whole target. Prefer Intelligence chat for small asks; save agent/MCP loops for multi-step refactors you will still review.