Skip to main content
Browse docs
By Audience
Getting Started
Configuration
Use Cases
IDE Integration
Third-Party Integrations
Engineering Cache
Console
API Reference
Gateway
Workflow Guides
Templates
Providers and SDKs
Industry Guides
Advanced Guides
Browse by Role
Deployment Guides
In-Depth Guides
Tutorials
FAQ

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:

FeatureSourceRoutable Through Gateway
Xcode Predictive CompletionApple on-device modelNo — runs locally on your Mac
CopilotForXcodeExternal LLM via APIYes — 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

  1. Download the latest release from the CopilotForXcode GitHub releases page.
  2. Move Copilot for Xcode.app to your Applications folder.
  3. Open the app and follow the setup wizard.
  4. Grant the required Accessibility permissions in System Settings → Privacy & Security → Accessibility.
  5. 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):

  1. Set Format to OpenAI Compatible.

  2. Set API URL to:

    http://localhost:41002/v1/chat/completions
  3. Set API Key to your Keeptrusts access key or provider key.

  4. Choose your preferred Model (e.g., gpt-4o, claude-sonnet-4-20250514).

  5. 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:

  1. The gateway is running: curl http://localhost:41002/v1/models
  2. CopilotForXcode is using the correct API URL
  3. 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:

FeatureRecommended ModelReason
Inline Suggestionsgpt-4o-miniFast, cost-effective completions
Chat Panelclaude-sonnet-4-20250514Detailed 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

SymptomSolution
"Connection refused" in CopilotForXcodeVerify the gateway is running on port 41002
Suggestions never appearCheck System Settings → Extensions → Xcode Source Editor
Accessibility permission deniedGrant permission in System Settings → Privacy & Security
Slow completionsSimplify policy chain or enable engineering cache
401 Unauthorized in gateway logsVerify 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