Keep team Codespaces ready with dev containers and prebuilds
Configure devcontainer.json, postCreateCommand, and Codespaces prebuilds so your team starts coding faster without rebuilding tools on every launch.
20 Nov 2025, 06:39 UTC

The problem: every new Codespace rebuilds the world
A new engineer opens a Codespace for your repository and watches the terminal while package managers download dependencies, compilers build native modules, and extensions install one by one. By the time the editor is usable, the onboarding call is half over. The same delay repeats every time someone switches branches or returns after a weekend.
The useful takeaway is to treat the development environment as committed code. A devcontainer.json file declares the runtime, tools, and VS Code extensions. A postCreateCommand installs dependencies after the container starts. GitHub Codespaces prebuilds build that container ahead of time, so the workspace is waiting when the engineer opens it.
Define the environment in devcontainer.json
A dev container is a Docker container configured for development work. Codespaces creates it from .devcontainer/devcontainer.json in your repository. The postCreateCommand field runs after container creation and is a supported place to install dependencies or compile assets without enlarging the image.
Prebuilds are GitHub Actions workflows that create the container for configured branches before anyone opens a codespace. They trigger on pushes to those branches and on changes to dev container configuration files.
Worked example: Node.js service
Create .devcontainer/devcontainer.json in the repository root. You need write access to the repository, and GitHub Codespaces must be enabled for your account or organization.
{
"name": "Node.js service",
"image": "mcr.microsoft.com/devcontainers/javascript-node:",
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
},
"postCreateCommand": "npm ci"
}
Replace with the Node image version your team supports. When a member creates a codespace, Codespaces installs the listed extensions and runs npm ci after the container starts.
Open a terminal inside the codespace and run:
node --version
Expected check: the command prints the Node version from the image. Risk: if postCreateCommand needs a private registry password or environment variable, it will fail during a prebuild because those secrets are not available to the prebuild workflow.
Enable prebuilds
- Go to repository Settings, select Codespaces, then Prebuilds.
- Choose the branches to prebuild, such as
mainand active release branches. - Save the configuration. Prebuilds start on pushes to those branches and when
devcontainer.jsonchanges.
Editing devcontainer.json invalidates existing prebuilds and triggers new builds, which can increase GitHub Actions minutes usage. Start with one branch before enabling prebuilds repository-wide.
What persists across stops and restarts
Codespaces provides persistent storage for the /workspaces directory. If you stop a codespace and restart it later, files in /workspaces are still there. System packages and anything installed outside /workspaces are rebuilt from the image layers on restart, so do not rely on runtime-installed packages persisting across stops.
Machine type affects CPU, memory, and storage. You can specify it in devcontainer.json or choose it when creating the codespace. Compute charges accrue while the codespace is running, and storage charges apply while it exists, even if idle.
Trade-offs and limits
- Prebuilds shorten first-launch time but consume Actions minutes on every relevant push and config change.
postCreateCommandcannot depend on secrets during a prebuild; use it for public dependency installation only.- Storage is billed for idle codespaces, so delete or stop unused codespaces.
Verify before you adopt
- Add
.devcontainer/devcontainer.jsonto a repository and open the Codespaces creation page; confirm the configured extensions and machine type appear. - Start a codespace, run a tool installed by
postCreateCommand, stop the codespace, restart it, and confirm the tool remains available. - Open Settings > Codespaces > Prebuilds and inspect recent build status and logs for the target branch.
- Open the VS Code Codespaces panel and review the container creation log to confirm
postCreateCommandcompleted successfully.
This draft describes documented behavior but has not been executed against a live repository. Run the steps above in a non-production repository before relying on them in production.
Closing
Commit one devcontainer.json, enable prebuilds for main, and measure how much time the team saves on the first codespace launch. If prebuilds fail, check the Actions logs for missing secrets or network access rather than debugging inside a running codespace.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.