Devcontainer for using O(x)Caml and Claude in your projects / Jan 2026
I got a few questions about the dev setup I used for my
Using the OCaml/Claude devcontainers
A devcontainer can either be used in an editor that supports it like VSCode, or directly from the CLI (which is what I do for Claude Code). Adding it to your project is as simple as:
$ mkdir .devcontainer
$ cd .devcontainer
$ curl -OL https://raw.githubusercontent.com/avsm/claude-ocaml-devcontainer/refs/heads/main/.devcontainer/devcontainer.json
Edit the JSON file to add any other post-installation or extensions that you might need for that project. It's intended to be customisable.
To spin the devcontainer up, I use the npx CLI:
$ npx @devcontainers/cli up --workspace-folder .
$ npx @devcontainers/cli exec --workspace-folder . bash -l
This will mount your current project into /workspace in the dev container. The set of network domains that can be accessed are limited to a select few, but I'll parameterise this into the project metadata in the future.
When you're in the workspace container, you have two preinstalled OCaml switches:
$ opam switch
# switch compiler description
5.2.0+ox ocaml-variants.5.2.0+ox 5.2.0+ox
→ default ocaml.5.4.0 default
And claude maps its config from your home directory, so you can start up sessions once you've authenticated as normal, and everything runs in the container reasonably sandboxed.
Customising the devcontainers
Since compiling up O[x]Caml can take a while, it's a prebuilt image, but you can also clone the repository and customise the Dockerfile in .devcontainer to your heart's content.
The default disk space in a GitHub Action wasn't sufficient, but it turns out that the default ubuntu-latest has a ton of pre-installed packages that you can just delete to double your disk space.
One pretty cool thing about the action is that it doesn't use qemu to build the multiarch images. Instead, the multibuild.yml dispatches separate builds to the native arm64 and amd64 hosts, and then combines them together. This is faster and more reliable than the conventional path of going through CPU emulation for the non-native host.
I also modify my own devcontainer to mount some limited SSH keys and a
.gitconfig so I can commit from within the container, which allows for more
unattended feedback loops.