Codespaces prebuild vs local rebuild cost comparison
The decision between paying for Codespaces prebuilds and absorbing local rebuild time is a real budget question, not a preference. Prebuilds trade GitHub Actions minutes and storage for near-instant container creation; local rebuilds trade engineer wall-clock time for zero cloud spend. This page models both so you can pick per repository. It extends the GitHub Codespaces vs Local DevContainers cluster.
Prerequisites
- A repository with a working
devcontainer.json - Admin access to configure prebuilds (Settings → Codespaces → Prebuilds)
- A rough measure of your current cold-create time
How-To Steps
-
Measure the local cold rebuild as your baseline:
devcontainer up --workspace-folder . --remove-existing-container 2>&1 | tail -1 # Note total time; multiply by rebuilds/engineer/week -
Identify what a prebuild caches. Prebuilds run
onCreateCommandand Feature installs ahead of time, so move expensive work there (see feature and lifecycle hook sequencing):{ "image": "mcr.microsoft.com/devcontainers/javascript-node:20@sha256:7c3e...", "onCreateCommand": "npm ci && npm run build:deps", "remoteUser": "vscode" } -
Enable a prebuild scoped to the branches that matter, and configure its trigger:
- Region(s): match where your team works.
- Trigger: “On push” for hot branches, or scheduled for slower-moving repos to cap Actions minutes.
-
Model the monthly cost. Prebuild cost ≈ (Actions minutes per build × builds/month) + (prebuild storage GB × regions × $/GB-month). Local cost ≈ (rebuild minutes × rebuilds/month × loaded engineer rate).
Prebuild: triggers on every push to main → storage in 2 regions Local: 14 engineers × ~6 rebuilds/week × 4 min cold startIf engineer rebuild-minutes/month exceed the prebuild Actions+storage bill, prebuilds win; otherwise local rebuilds are cheaper.
Common Pitfalls
| Symptom | Root Cause | Remediation |
|---|---|---|
| Prebuild bill climbs unexpectedly | ”On push” trigger on a high-traffic branch in many regions | Restrict regions; switch low-priority repos to scheduled |
| Prebuild doesn’t speed up creation | Expensive work in postCreateCommand, not onCreateCommand | Move source-independent setup to onCreateCommand |
| Stale prebuild served | Trigger didn’t fire on the dependency change | Add the lockfiles to the prebuild trigger paths |
| Local rebuilds still slow | No cache volumes | Add named-volume caches before blaming architecture |
Conclusion
The invariant: prebuilds only pay off when the cached work lives in onCreateCommand and your aggregate engineer rebuild-time exceeds the prebuild storage-plus-compute bill. Measure your real cold-start time first; optimize local caching before paying for prebuilds.
FAQ
Does a prebuild eliminate postCreateCommand?
No. postCreateCommand still runs at creation because it can depend on the final source. Only onCreateCommand and Feature installs are baked into the prebuild image.
Are prebuilds billed even when unused? Storage is billed per region for as long as the prebuild exists, independent of use. Delete prebuilds for archived branches and limit regions to control it.
Related
- GitHub Codespaces vs Local DevContainers — the parent comparison cluster.
- Setting up GitHub Codespaces billing limits — capping the spend this analysis surfaces.
- Offline development: Codespaces vs local devcontainer tradeoffs — the connectivity dimension.