You have a GitHub Codespace with a prebuilt container and want GitHub Copilot to work inside it without manual extension installation or setup each time. Prebuilt containers save startup time by caching your dev environment, but Copilot configuration must be baked into that image or the Codespace’s devcontainer.json. If Copilot is missing or not activated after your Codespace loads, the prebuild is not the cause — the configuration steps were skipped. This article explains how to configure Copilot in a prebuilt Codespace container so it is ready the moment your environment starts.
Key Takeaways: Configuring Copilot in Prebuilt Codespaces
- devcontainer.json > extensions array: Add “GitHub.copilot” and “GitHub.copilot-chat” to ensure Copilot is installed automatically.
- Prebuild definition > devcontainer.json path: Point the prebuild to the same configuration file that lists Copilot extensions.
- Settings sync or machine-level config: Use dotfiles or a postCreateCommand to enable Copilot settings that survive a prebuild refresh.
Why Copilot May Be Missing in a Prebuilt Codespace
A prebuilt Codespace is a snapshot of your container after a successful build. GitHub triggers a prebuild on each push to your repository and stores the resulting image. When you open a new Codespace from that branch, it pulls the prebuilt image instead of rebuilding from scratch. This shaves minutes off the start time.
However, if the original devcontainer.json did not include the Copilot extension, the prebuilt image will not contain it either. The prebuild process runs the same devcontainer.json as a normal Codespace. If the extensions array is empty or missing, no VS Code extensions are installed. Copilot will not appear in the installed extensions list, and the Copilot icon in the activity bar will be absent.
Another cause is a misconfigured prebuild definition. You can create multiple prebuilds for different branches or devcontainer.json paths. If the prebuild points to a devcontainer.json that does not include Copilot, the resulting image will lack it. The fix is always the same: verify the devcontainer.json used by the prebuild contains the correct extension IDs.
Steps to Add Copilot to a Prebuilt Codespace Container
Method 1: Edit the devcontainer.json Directly
- Open your repository’s .devcontainer folder
Navigate to the root of your repository. If you do not have a .devcontainer folder, create one. Inside it, create or edit a file named devcontainer.json. - Add the Copilot extension IDs to the extensions array
Locate or create the “extensions” key. Add “GitHub.copilot” and “GitHub.copilot-chat”. Your file should look like this:{
"name": "My Codespace",
"extensions": [
"GitHub.copilot",
"GitHub.copilot-chat"
]
} - Commit and push the change
Stage the devcontainer.json file, commit it with a message like “Add Copilot extensions to devcontainer”, and push to the branch that triggers your prebuild. - Trigger a new prebuild
Go to your repository on GitHub.com. Click the Settings tab, then Codespaces, then Prebuild configuration. Find the prebuild definition for your branch and click the three-dot menu. Select New prebuild. This rebuilds the container image with the updated extensions. - Create a new Codespace from the updated prebuild
On the main repository page, click the Code button, select the branch, and choose Codespaces. Click Create codespace on branch. Wait for the environment to load. Open the Extensions panel in VS Code and confirm Copilot and Copilot Chat are installed.
Method 2: Use a Custom Dockerfile With Copilot Preinstalled
- Create or update your Dockerfile
Place a Dockerfile inside the .devcontainer folder. The Dockerfile runs before the devcontainer.json extensions are applied. You can install Copilot at the image level using a VS Code command, but the recommended approach is to rely on the extensions array because it is simpler. If you prefer a Dockerfile, use a base image that already includes Copilot, such as a Microsoft-supplied dev container image that bundles the extension. - Reference the Dockerfile in devcontainer.json
Add the “build” property pointing to your Dockerfile:{
"build": {
"dockerfile": "Dockerfile"
},
"extensions": [
"GitHub.copilot",
"GitHub.copilot-chat"
]
} - Commit, push, and trigger a prebuild
Same as Method 1 steps 3 and 4. The prebuild will use the Dockerfile to build the container and then install the extensions listed.
Method 3: Enable Copilot via a postCreateCommand
- Add a postCreateCommand to devcontainer.json
This command runs after the container is created. Use it to install Copilot if the extensions array is not available for some reason. Add this to devcontainer.json:"postCreateCommand": "code --install-extension GitHub.copilot && code --install-extension GitHub.copilot-chat" - Commit, push, and trigger a prebuild
As before. Note that postCreateCommand runs during the prebuild, so the extensions become part of the cached image.
If Copilot Still Has Issues After Configuration
Copilot Is Installed but Not Showing Suggestions
Open the Command Palette with Ctrl+Shift+P and run Copilot: Sign In. If you are not authenticated, Copilot cannot provide suggestions. Ensure your GitHub account has an active Copilot subscription. For organizations, verify that the Copilot policy allows Codespaces usage.
Prebuild Fails After Adding Copilot Extensions
Check the prebuild logs in GitHub.com under Settings > Codespaces > Prebuild configuration. Click the prebuild definition and view the latest run. A failure usually indicates a syntax error in devcontainer.json. Validate your JSON with a linter. If the extensions array contains a typo, the prebuild will fail silently and the image will not update.
Copilot Chat Is Missing Even Though Copilot Is Present
The extension IDs are separate. Confirm that both “GitHub.copilot” and “GitHub.copilot-chat” are in the extensions array. If you only added the first, the Chat panel will not appear. After adding the missing ID, trigger a new prebuild.
Devcontainer.json Extension Setting vs Dockerfile: Key Differences
| Item | Extensions Array in devcontainer.json | Custom Dockerfile |
|---|---|---|
| Setup complexity | Low — add two lines of JSON | Medium — requires writing and maintaining a Dockerfile |
| Prebuild compatibility | Fully supported — extensions are installed during prebuild | Supported, but extension installation still depends on devcontainer.json |
| Extension version control | Always gets the latest version from the marketplace | You can pin a specific version in the Dockerfile |
| Portability | Works in any Codespace, regardless of base image | Requires the Dockerfile to be present in the repository |
| Update frequency | Automatic on each prebuild | Manual — you must rebuild the image to update extensions |
For most teams, the extensions array is the best choice. It is simpler, automatically updates Copilot, and does not require maintaining a separate Dockerfile. Use a custom Dockerfile only when you need to control the exact version of Copilot or when you are bundling other tools into the same image.
After you configure Copilot in your prebuilt Codespace, verify the setup by opening a Python, JavaScript, or TypeScript file. Type a comment like // function to calculate fibonacci and press Enter. Copilot should generate a code suggestion within one to two seconds. If it does not, run the sign-in command from the Command Palette.
You can also enable Copilot’s inline suggestions by default. Add this to your settings.json inside devcontainer.json: "editor.inlineSuggest.enabled": true. This ensures suggestions appear without pressing Alt+\. For teams, store this setting in a .vscode/settings.json file that is committed to the repository so every Codespace user gets the same behavior.