Purpose
CopilotForXcode is an Xcode Source Editor Extension that provides GitHub Copilot, Codeium, and ChatGPT support for Xcode. It is designed to integrate AI code suggestions, chat, and code modification capabilities into the Xcode editing environment.
Main Capabilities
Code Suggestions
The app can provide real-time code suggestions based on opened files, powered by GitHub Copilot and Codeium. It offers two display modes:
- Nearby Text Cursor: Displays suggestions based on the text cursor position.
- Floating Widget: Displays suggestions next to the indicator component.
When using Nearby Text Cursor mode, set the real-time suggestion debounce to 0.1. When the code updates, the app automatically fetches suggestions, and you can press Escape to cancel.
Suggestion-related commands include:
- Get Suggestions: Fetches suggestions for the file being edited at the current cursor position.
- Next Suggestion: Switches to the next suggestion among multiple suggestions.
- Previous Suggestion: Switches to the previous suggestion among multiple suggestions.
- Accept Suggestion: Adds the suggestion to the code.
- Reject Suggestion: Removes the suggestion annotation.
Chat Functionality
The chat functionality is powered by ChatGPT and requires an OpenAI account to be set up before use. Chat can obtain the following information: selected code in the active editor, the file's relative path, error and warning labels in the active editor, and the text cursor position. The chat panel has two tabs: one that can be shared in Xcode, and another that is only available in the current file. The chat panel can be dragged out to detach, and after detaching it remains visible even when Xcode is inactive; click the message bubble button next to the indicator component to reattach it. The command to open chat is Open Chat.
The chat panel supports chat plugins that may not require an OpenAI API Key. For example, when using the /shell plugin, enter the corresponding command, and enter the corresponding command when ending the plugin.
Prompt to Code (Modifying Code in Natural Language)
Use natural language to refactor existing code or write new code. It is recommended when you need to update specific code snippets. Example scenarios include:
- Improving code readability.
- FixingFix errors in code.
- Add documentation to code.
- Split large functions into smaller functions.
- Generate code with a specific template via custom commands.
- Polish and correct grammar and spelling errors in documentation.
- Translate localizable string files.
Related commands:
- Write or Edit Code: Opens the modification window to write or edit selected code using natural language.
- Accept Modification: Accepts the modification result.
Custom Commands
You can create custom commands for running chat and modifications, with personalized prompts. They can be accessed from the Xcode menu bar and the context menu of the indicator component. There are three types of custom commands:
- Modification: Runs a modification on the selected code and updates or writes code according to the given prompt; additional information can be provided through the additional system prompt field.
- Send Message: Opens the chat window and immediately sends the message (if provided); more information can be provided through the additional system prompt field.
- Custom Chat: Opens the chat window and immediately sends the message (if provided); the entire system prompt can be overridden through the system prompt field.
- Single Round Dialog: Sends a message to a temporary chat, suitable when you want to run terminal commands with /run.
Template parameters can be used in custom commands.
Usage
Prerequisites
A public network connection is required.
Recommended features:
- GitHub Copilot users: Node must be installed to run Copilot LSP, and a valid GitHub Copilot subscription is required.
- Codeium users: A valid Codeium account is required.
- Access to other LLMs.
Chat and Prompt to Code features:
- A valid OpenAI API Key.
Permissions:
- Accessibility API. If you are concerned about keylogging and do not trust the binary, it is recommended to review the code and build it yourself. You can specifically search the code for CGEvent.tapCreate, AXObserver, AX___, etc.
Installation and Setup
The installation process is slightly complicated. A quick overview:
- Install the app to the Applications folder and open it once.
- Enable the source code editor extension.
- Grant the Accessibility API permission to the extension app.
- Set up the account in the host appand the model.
- Optional: Update each feature's settings and set key bindings.
It can be installed via Homebrew, or Copilot for Xcode.app can be downloaded manually from the latest release. Please make sure the app is located in the Applications folder. After opening the app, the app will create a launch agent to set up a background service to perform the actual work.
Enable the extension
Enable the extension in System Settings.app:
- macOS 15: Click System Settings from the Apple menu in the top-left corner of the screen, navigate to General, then Login Items & Extensions, click Xcode Source Editor, and check Copilot for Xcode.
- macOS 14: Click System Settings from the Apple menu in the top-left corner of the screen, navigate to Privacy & Security, click Extensions toward the bottom, click Xcode Source Editor, and check Copilot.
- Earlier versions: If using macOS Monterey, enter the Extensions menu in System Preferences.app via the dedicated icon.
The first time you open the app and run a command, the extension will request the necessary permissions. You can also manually grant the required permissions in the Privacy & Security tab of System Settings.app. When granting Accessibility API permission, click Accessibility and drag CopilotForXcodeExtensionService.app into the list. You can locate the extension app by clicking Reveal Extension App in Finder in the host app. If you encounter a reminder that permission has already been granted, remove the permission from the list and add it again to re-grant it.
Set key bindings
Using key bindings will make the extension work better. It seems that default key bindings cannot be added for commands, but you can set them in Xcode Settings > Key Bindings. You can enter copilot in the search bar to filter the list. The recommended settings should not cause conflicts: basically use ⌥⇧ as the "access" modifier combination for all bindings. Another convenientway to access commands is to use the ⇧⌘/ shortcut to search for commands in the menu bar.
Currently, only one global hotkey can be set, used to show/hide the component under the General tab of the host app. When this hotkey is not set to be globally enabled, it only works when the service app or Xcode is active.
Set up the suggestion feature
GitHub Copilot:
- In the host app, navigate to Service - GitHub Copilot to access account settings.
- Click Install to install the language server.
- Optional: Set the Node path. The default value is node. Copilot for Xcode.app will try to find Node from the following directories: /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin. If Node is installed elsewhere, you can run which node in Terminal to get the correct path. If you use a Node version manager that provides a shim executable, you need to find the path to the actual executable.
- Click Sign In, and you will be redirected to the verification website provided by GitHub. The user code will be copied to the clipboard.
- After signing in, return to the app and click Confirm Sign-in to complete the process.
- Go to Feature - Suggestion and update the feature provider to GitHub Copilot.
- The installed language server is located at ~/Library/Application Support/com.intii.CopilotForXcode/GitHub Copilot/executable/.
Codeium:
- In the host app, navigate to Service - Codeium to access account settings.
- Click Sign In, and you will be redirected to codeium.com. After signing in, a token will be provided, which you need to copy and paste back into the app to complete sign-in.
- Go to Feature - Suggestion and update the feature provider to Codeium.
- The key is stored in the keychain. When the helper app accesses the key for the first time, it will prompt for the password; please choose Always Allow.
- The installed language server is located at ~/Library/Application Support/com.intii.CopilotForXcode/Codeium/executable/.
Setting up chat functionality
- In the host app, navigate to Service - Chat Model.
- Update the OpenAI model, creating a new model if necessary. Use the test button to verify the model.
- Optional: set up an embedding model in Service - Embedding Model; some chat features require it.
- Go to Feature - Chat and update the chat/embedding feature provider to the model you just updated or created.
Managing CopilotForXcodeExtensionService.app
This app runs when Copilot for Xcode.app or Xcode.app is opened. It can be quit via the tentacle-like item in the menu bar. You can also set it to quit automatically when the above two apps are closed.
Updates
You can use the in-app updater, or manually download from the latest release. After updating, please open Copilot for Xcode.app once and restart Xcode to reload the extension. If you find that some features no longer work, first try re-granting the app permissions.
Use cases
- Get real-time code suggestions during everyday coding in Xcode.
- Chat with ChatGPT inside Xcode to get code-related context information.
- Refactor, fix, or generate specific code snippets using natural language.
- Generate code from specific templates or perform repetitive modification tasks via custom commands.
- For developers who need to integrate GitHub Copilot or Codeium into their Xcode workflow.
Limitations
- Requires a public network connection.
- Suggestion features require Node (GitHub Copilot) and a valid GitHub Copilot subscription or Codeium account.
- Chat and Prompt to Code features require a valid OpenAI API Key.
- Requires granting Accessibility API permission.
- Files in gitignore will not receive suggestions. Chat and Prompt to Code features also cannot access them unless code is manually selected from them.
- The extension uses various tricks to monitor Xcode's state, which may fail or be inaccurate, especially when runningmultiple Xcode windows or when located on different monitors.
- If files were already open before the helper app started, you need to switch to those files to send open-file notifications.
- If you do not want the suggestion feature to trigger in company projects, you can disable it globally and enable it only for specific projects.
- For license details, see LICENSE.