{"slug": "show-hn-claude-cli-run-claude-code-in-a-throwaway-docker-container", "title": "Show HN: Claude-CLI – Run Claude Code in a throwaway Docker container", "summary": "A developer released Claude-CLI, a shell wrapper that runs Anthropic's Claude Code inside a throwaway Docker container to keep the host system clean while persisting configuration across sessions. The tool supports multiple modes including single-directory, multi-directory, and no-directory operation, and allows users to pass flags through to Claude Code.", "body_md": "A lightweight shell wrapper that runs [Claude Code](https://github.com/anthropics/claude-code) inside a Docker container, keeping your host system clean while persisting your Claude configuration across sessions.\n\n[Docker](https://docs.docker.com/get-docker/)with[Buildx](https://docs.docker.com/reference/cli/docker/buildx/)plugin[dmenu](https://tools.suckless.org/dmenu/)— mode selection prompt (not required when using`-f`\n\n)[fzf](https://github.com/junegunn/fzf)— directory picker; also used for mode selection with`-f`\n\n- Current user must be a member of the\n`docker`\n\ngroup\n\n```\ngit clone https://github.com/shirozuki/claude-cli\nchmod +x claude-cli/claude-cli.sh\nln -s \"$PWD/claude-cli/claude-cli.sh\" ~/.local/bin/claude-cli\nclaude-cli [-b] [-c] [-f] [-h] [DIR...]\n```\n\n| Option | Description |\n|---|---|\n`-b` |\nBuild (or rebuild) the `claude-cli:latest` Docker image |\n`-c` |\nRemove all `claude-cli` containers; optionally remove the image |\n`-f` |\nUse `fzf` instead of `dmenu` for the mode selection prompt |\n`-h` |\nShow help |\n\nRunning without any option or argument launches a `dmenu`\n\nprompt to choose a mode. Pass `-f`\n\nto use `fzf`\n\ninstead — useful on setups without dmenu or when you prefer a terminal picker.\n\nYou can skip the menu and pickers entirely by passing directories directly on the command line:\n\n```\nclaude-cli ~/projects/app            # single-dir mode\nclaude-cli ~/projects/app ~/shared   # multi-dir mode (first arg is the working dir)\n```\n\n- One argument runs\n`single-dir`\n\nmode with that directory. - Two or more arguments run\n`multi-dir`\n\nmode, mounting every directory and using the**first** as the working directory.\n\nRelative paths are resolved against the current working directory, so `claude-cli .`\n\nmounts `$PWD`\n\n. When directories are passed this way, `dmenu`\n\nand `fzf`\n\nare not required.\n\nLaunches Claude without mounting any project directories. Useful for general questions, quick tasks, or exploring Claude's capabilities without exposing local files.\n\nMounts the current working directory $PWD directly.\n\nOpens an `fzf`\n\npicker to select one directory from your home tree (up to 3 levels deep). The selected directory is mounted and set as the working directory inside the container.\n\nOpens `fzf`\n\nin multi-select mode to pick several directories (use `Tab`\n\nto select), then asks you to designate one of them as the working directory. All selected directories are mounted simultaneously — useful when working across multiple repos or sharing common config directories.\n\nClaude's configuration (`~/.claude/`\n\nand `~/.claude.json`\n\n) is bind-mounted into the container on every run, so your account, settings, and session history survive container restarts.\n\nThe mount source is resolved in this order:\n\n`$XDG_CONFIG_HOME/claude/`\n\n— if`$XDG_CONFIG_HOME`\n\nis set`$HOME/`\n\n— fallback\n\nThe following environment variables can be set to override defaults without editing the script:\n\n| Variable | Default | Description |\n|---|---|---|\n`CLAUDE_IMAGE` |\n`claude-cli:latest` |\nDocker image name to use |\n`NOTIFY_ERROR_ICON` |\n`$XDG_CONFIG_HOME/dunst/critical.png` |\nIcon used in desktop error notifications |\n`CLAUDE_CLI_FLAGS` |\n(none) | Extra flags passed through to the `claude` binary inside the container |\n`CLAUDE_CLI_DOCKERFILE` |\n(see below) | Path to a custom Dockerfile used to build the image (highest precedence). |\n\nExamples:\n\n```\nCLAUDE_IMAGE=my-claude:dev claude-cli\n\n# Pass flags through to Claude Code itself\nCLAUDE_CLI_FLAGS=\"--resume $session_id --dangerously-skip-permissions\" claude-cli\n\n# Build the image from a custom Dockerfile\nCLAUDE_CLI_DOCKERFILE=~/my-claude.dockerfile claude-cli -b\n```\n\n`CLAUDE_CLI_FLAGS`\n\nis word-split, so each space-separated token becomes a\nseparate argument. Quote arguments that contain spaces is not supported — pass\nonly flags whose values have no spaces.\n\nOn first run (or after `-b`\n\n), the script builds a Docker image based on `node:lts`\n\nwith `@anthropic-ai/claude-code`\n\ninstalled globally. The container user is created with the same UID/GID as the host user to avoid file permission issues on bind-mounted volumes.\n\nThe Dockerfile is selected in order of precedence:\n\n- Custom Dockerfile path (\n`CLAUDE_CLI_DOCKERFILE`\n\n) - Dockerfile next to the script (\n`claude-cli-dockerfile`\n\n) - Inline Dockerfile baked into the script (the default)\n\nThe customization is purely additive: with none of the above set, the script writes its built-in Dockerfile to `/tmp`\n\nand builds from that, so `claude-cli.sh`\n\nstays self-contained and can be fetched and run entirely on its own.\n\nTo customize the image, drop a `claude-cli-dockerfile`\n\nnext to the script and it will be preferred when present:\n\n```\n# create claude-cli-dockerfile to taste, then rebuild\nclaude-cli -b\n```\n\nAlternatively, point `CLAUDE_CLI_DOCKERFILE`\n\nat a Dockerfile anywhere on disk.\n\nThe image is tagged `claude-cli:latest`\n\nand reused on subsequent runs until you explicitly rebuild with `-b`\n\n.", "url": "https://wpnews.pro/news/show-hn-claude-cli-run-claude-code-in-a-throwaway-docker-container", "canonical_source": "https://github.com/shirozuki/claude-cli", "published_at": "2026-06-27 21:51:56+00:00", "updated_at": "2026-06-27 22:05:01.932868+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "large-language-models"], "entities": ["Claude-CLI", "Anthropic", "Claude Code", "Docker", "Buildx", "dmenu", "fzf"], "alternates": {"html": "https://wpnews.pro/news/show-hn-claude-cli-run-claude-code-in-a-throwaway-docker-container", "markdown": "https://wpnews.pro/news/show-hn-claude-cli-run-claude-code-in-a-throwaway-docker-container.md", "text": "https://wpnews.pro/news/show-hn-claude-cli-run-claude-code-in-a-throwaway-docker-container.txt", "jsonld": "https://wpnews.pro/news/show-hn-claude-cli-run-claude-code-in-a-throwaway-docker-container.jsonld"}}