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

  1. 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
    
  2. Identify what a prebuild caches. Prebuilds run onCreateCommand and 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"
    }
    
  3. 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.
  4. 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 start
    

    If engineer rebuild-minutes/month exceed the prebuild Actions+storage bill, prebuilds win; otherwise local rebuilds are cheaper.

Common Pitfalls

SymptomRoot CauseRemediation
Prebuild bill climbs unexpectedly”On push” trigger on a high-traffic branch in many regionsRestrict regions; switch low-priority repos to scheduled
Prebuild doesn’t speed up creationExpensive work in postCreateCommand, not onCreateCommandMove source-independent setup to onCreateCommand
Stale prebuild servedTrigger didn’t fire on the dependency changeAdd the lockfiles to the prebuild trigger paths
Local rebuilds still slowNo cache volumesAdd 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.