GitHub Codespaces Prebuilds: Faster Startup, Higher Cost
Prebuilds can cut GitHub Codespaces creation time, but they cost Actions minutes and storage. Learn when to enable them and how to verify.
18 Oct 2026, 13:44 UTC

You are waiting for the container to build
You open a codespace from a feature branch and the terminal shows “Building dev container…” while Docker pulls base images, runs package installs, and configures toolchains. On a large repository, that can take several minutes before you see a shell prompt. If your team creates codespaces multiple times a day, the waiting adds up.
GitHub Codespaces prebuilds build the dev container image ahead of time using GitHub Actions, so a developer can start from a cached image instead of building from scratch. Prebuilds can shorten creation time, but they consume Actions minutes and Codespaces storage, and they do not remove every initialization step. This post explains when to enable them, what to configure, and how to verify the result.
What a prebuild changes
A dev container is a Docker image configured for development, defined by files in a .devcontainer/ directory. Normally, Codespaces builds that image when you create a codespace. A prebuild runs that same build on GitHub’s infrastructure after you push to a branch, then stores the resulting image. When you open a codespace on that branch, Codespaces can start from the cached image and skip much of the build.
Post-create lifecycle commands still run when a developer starts the codespace, so prebuilds reduce but do not eliminate all initialization time.
Configure a dev container and enable prebuilds
Start with a dev container definition. This example uses a Node.js image and installs one VS Code extension:
{
"name": "Node.js project",
"image": "mcr.microsoft.com/devcontainers/javascript-node:20",
"customizations": {
"vscode": {
"extensions": ["dbaeumer.vscode-eslint"]
}
}
}
Save this as .devcontainer/devcontainer.json in the repository root and commit it. Then open the repository on GitHub, go to Settings > Codespaces > Prebuilds, and enable prebuilds for the branches you want, such as main and active release branches. GitHub builds the image through Actions when changes are pushed to those branches.
Where to run: repository settings in a browser, with write access to the repository and Codespaces enabled for the organization or personal account. Required permissions: repository administrator or maintainer, depending on organization policy.
Risks: enabling prebuilds on many long-lived branches increases monthly Actions and storage usage. Do not add runtime secrets, database passwords, or user-specific tokens to the dev container image; prebuilds run in a different context than an active codespace.
Cost, eligibility, and trade-offs
- Actions minutes: each prebuild consumes minutes proportional to the image build time.
- Codespaces storage: stored prebuilt images count against your Codespaces storage quota.
- Branch sprawl: enabling prebuilds on every active branch can noticeably raise billing for large repositories.
- Not instant: post-create setup still runs, and the first codespace after a configuration change may build the image again.
- Eligibility: availability depends on repository plan, organization settings, and Codespaces quotas.
Verify that prebuilds are working
- Open the repository on GitHub, go to Settings > Codespaces > Prebuilds, and confirm an active configuration exists for the target branch.
- Open the Actions tab and look for a completed prebuild run for that branch and dev container definition.
- Create a codespace from the branch and compare creation time to the previous manual build. Treat the first creation after a change as a baseline, since it may still build the image.
Turn prebuilds off if costs outweigh the savings
If prebuilds are not reducing wait times meaningfully, or if Actions minutes are higher than expected, return to Settings > Codespaces > Prebuilds and disable the configuration. This stops future prebuilds; existing cached images remain until they expire or are cleaned up according to GitHub’s retention policy.
Prebuilds are worth it when teams create codespaces frequently from stable branches and the container build takes more than a minute or two. For short-lived feature branches or repositories with infrequent codespace use, on-demand builds may be cheaper and simpler.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.