DEV Community

Cover image for Running Claude Code inside your dev containers
S Botto
S Botto

Posted on

Running Claude Code inside your dev containers

Following up on this other post, I recently started running Claude Code inside my dev containers as well. Turns out I sometimes need a bit more from my dev environment than what my sandbox can provide.

As a non-root user inside an ephemeral container, running heavy tests that require a whole bunch of dependencies is not too convenient... Sure, I could give that user more permissions, but reinstalling dependencies every single time I spin up a container can get annoying quite quickly.

I decided to handle each distinct use differently:
• Quick, disposable tests? Sandbox with ephemeral containers.
• Longer sessions working on complex projects? Dev containers, a persistent setup.

A common long-lived session for me is working on aetherlay, where I prefer using a dev container because it also lets me manage service dependencies like Redis, which I have to run in a "companion" container.

But enough talk, let's get to the code...

Here's a minimal devcontainer.json to mount your local .claude folder into your dev container so that Claude can keep and reuse its memory:

{
  "name": "Dev Container",
  "service": "dev",
  "workspaceFolder": "/workspace",
  "remoteUser": "root",
  "mounts": [
    "source=~/.claude,target=/root/.claude,type=bind,consistency=cached"
  ]
}
Enter fullscreen mode Exit fullscreen mode

For the corresponding Dockerfile, you can do something like this:

# Use whatever base image you want
FROM alpine:latest

# Install Node.js and npm (required by Claude Code)
RUN apk update && apk add --no-cache nodejs npm

# Install Claude Code
RUN npm install -g @anthropic-ai/claude-code

# Match the workspaceFolder set in devcontainer.json
WORKDIR /workspace
Enter fullscreen mode Exit fullscreen mode

Place these two files in a .devcontainer folder at your project root in order to have them automatically picked up by VS Code or compatible forks like Cursor.

For a more complete example, check out the config I have for aetherlay.

There's a lot of ways to do this, this one is simply meant as a starting point.

Happy coding 🖖

Top comments (0)