How I use Claude Code in Devcontainers
Sometimes I just want to have YOLO mode for Claude Code with isolation so my local system doesn’t get messy by accident with random files. Here comes devcontainers:
A development container (or dev container for short) allows you to use a container as a full-featured development environment. It can be used to run an application, to separate tools, libraries, or runtimes needed for working with a codebase, and to aid in continuous integration and testing.1
Devcontainer is a great tool that I regularly use to interact with AI and do dev work without cluttering my machine with various tools.
I primarily use the CLI, and I was happy to find that they have a CLI to manage it.
Prerequisites#
- Podman or Docker (I prefer Podman as it runs rootless by default)
- npm
Setup#
1. Install the devcontainers CLI#
npm install -g @devcontainers/cli
2. Create the config file#
Create the following in your folder:
.devcontainer/devcontainer.json
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/anthropics/devcontainer-features/claude-code:1.0": {}
}
}
If you want tighter isolation, you can refer to Claude Code’s official docs for further customization.
3. Start the devcontainer#
devcontainer up --workspace-folder . --docker-path podman
4. Exec in#
You can directly exec into Claude Code or start the shell:
Claude:
devcontainer exec --workspace-folder . --docker-path podman claude
Bash:
devcontainer exec --workspace-folder . --docker-path podman bash
Tip: You can use TMUX to disconnect and reconnect later.
5. Stop the devcontainer#
podman ps
podman stop ID
podman rm ID
Summary#
If you are looking to run Claude Code in YOLO mode, devcontainers are great. You can quickly spin up an isolated environment and Claude Code will only have access to the mounted directory you specify in devcontainer.json.
Devcontainers simplify doing your dev work without Claude Code accidentally touching your local system or creating random files.