Xcode with the Gateway
Apple's Xcode includes built-in predictive code completion powered by on-device models. While the built-in feature cannot be rerouted, third-party extensions like CopilotForXcode let you add OpenAI-compatible AI assistance to Xcode — and route it through the Keeptrusts gateway.
Use this page when
- You are working through Xcode with the Gateway as an implementation or operating workflow in Keeptrusts.
- You need the practical steps, expected outcomes, and related validation guidance in one place.
- If you need exact field-by-field reference instead of a workflow page, use the linked reference pages in Next steps.
Primary audience
- Primary: Technical Engineers
- Secondary: AI Agents, Technical Leaders
Prerequisites
- Keeptrusts gateway running locally (
kt gateway run) - macOS 13 or later with Xcode 15+
- CopilotForXcode installed
Understanding Xcode AI Options
Xcode offers two paths for AI-assisted coding:
| Feature | Source | Routable Through Gateway |
|---|---|---|
| Xcode Predictive Completion | Apple on-device model | No — runs locally on your Mac |
| CopilotForXcode | External LLM via API | Yes — point to the gateway endpoint |
Because Apple's built-in completion runs entirely on-device, it never sends code to an external API. The Keeptrusts gateway is relevant for third-party extensions that call cloud LLM providers.
Install CopilotForXcode
- Download the latest release from the CopilotForXcode GitHub releases page.
- Move
Copilot for Xcode.appto your Applications folder. - Open the app and follow the setup wizard.
- Grant the required Accessibility permissions in System Settings → Privacy & Security → Accessibility.
- Enable the Xcode Source Editor Extension in System Settings → Privacy & Security → Extensions → Xcode Source Editor.
Configure the Gateway Endpoint
Open CopilotForXcode and navigate to Service → Chat Model (or Suggestion Model):
-
Set Format to
OpenAI Compatible. -
Set API URL to:
http://localhost:41002/v1/chat/completions -
Set API Key to your Keeptrusts access key or provider key.
-
Choose your preferred Model (e.g.,
gpt-4o,claude-sonnet-4-20250514). -
Click Test to verify the connection.
Repeat for both the Chat Model and Suggestion Model if you want both features routed through the gateway.
Configure Suggestion Settings
For inline code suggestions, open the Suggestion tab:
Format: OpenAI Compatible
API URL: http://localhost:41002/v1/chat/completions
API Key: your-access-key
Model: gpt-4o
Max Tokens: 500
Temperature: 0.1
A low temperature (0.1) produces more deterministic completions, which also improves engineering cache hit rates.
Verify Traffic Flows Through the Gateway
Open a terminal and start the event tail:
kt events tail
Return to Xcode and trigger a completion or open the chat panel. You should see events appear in the terminal:
2024-01-15T10:32:15Z ALLOW gpt-4o tokens=340 latency=1.2s
If no events appear, check that:
- The gateway is running:
curl http://localhost:41002/v1/models - CopilotForXcode is using the correct API URL
- The API key is valid
Xcode Workspace Considerations
CopilotForXcode sends the current file context and surrounding code to the LLM. The Keeptrusts gateway evaluates this content against your policy chain:
- Secret redaction catches API keys and tokens embedded in Swift code before they reach the provider.
- PII policies filter personal data in comments and string literals.
- Content policies apply to both the code context sent and the completion received.
Using Multiple Models
You can configure different models for suggestions and chat:
| Feature | Recommended Model | Reason |
|---|---|---|
| Inline Suggestions | gpt-4o-mini | Fast, cost-effective completions |
| Chat Panel | claude-sonnet-4-20250514 | Detailed explanations and refactoring |
Both route through the same gateway endpoint, so policies apply uniformly.
Limitations
- Xcode's built-in completion runs on-device and cannot be intercepted by any external gateway.
- CopilotForXcode requires macOS Accessibility permissions, which your organization's MDM policy may restrict.
- Real-time suggestions are latency-sensitive. If the gateway policy chain adds noticeable delay, consider simplifying policies or enabling the engineering cache.
- Xcode Source Editor Extension context is limited to the current file. Multi-file context depends on the extension's implementation.
Troubleshooting
| Symptom | Solution |
|---|---|
| "Connection refused" in CopilotForXcode | Verify the gateway is running on port 41002 |
| Suggestions never appear | Check System Settings → Extensions → Xcode Source Editor |
| Accessibility permission denied | Grant permission in System Settings → Privacy & Security |
| Slow completions | Simplify policy chain or enable engineering cache |
401 Unauthorized in gateway logs | Verify your API key in CopilotForXcode settings |
For AI systems
- Canonical terms: Keeptrusts, Xcode with the Gateway, ide-integration.
- Exact feature, config, command, or page names: Xcode with the Gateway.
- Use the linked audience and reference pages in Next steps when you need deeper source material.
For engineers
- Use the commands, configuration examples, API payloads, or UI steps in this page as the working baseline for Xcode with the Gateway.
- Validate the result with the expected outcomes, troubleshooting notes, or linked workflow pages in this page and Next steps.
For leaders
- This page matters when planning rollout, governance, support ownership, or operating decisions for Xcode with the Gateway.
- Use the linked audience, architecture, and workflow pages in Next steps to connect this detail to broader implementation choices.
Next steps
- Recommended Policies for IDE Traffic — configure code-aware redaction
- Monitoring IDE AI Usage — track completions and cost per developer
- Troubleshooting — resolve common connection issues