chore(devcontainer): add Dev Container config for Claude Code isolated execution#686
Merged
Merged
Conversation
…d execution Claude Code をホスト直接実行するのではなく、devcontainer 内で動かすための設定を 追加する。社内ガイドライン (NaCl Claude Code 利用ガイドライン v0.2) の階層 B (OSS / 自社開発) の隔離環境推奨に準拠する。 ## 設計方針 - 既存の `docker-compose.yml` の `app` サービスを再利用する override 構成 - 物理的にアクセスできる範囲をホワイトリスト方式で制限: - `<repo>` → `/app` (既存通り) - `~/ghq` → `/ghq` (submodule の origin/upstream、関連 OSS 参照) - `~/.gitconfig` → `/root/.gitconfig` (ro) - `~/.config/gh` → `/root/.config/gh` (fine-grained PAT) - 以下は意図的にマウントしない: `~/.ssh`, `~/.aws`, `~/Documents`, `~/Downloads`, `~/Desktop`, `~/Library` - VS Code Dev Containers / devpod / docker compose のいずれからでも起動可能 ## ファイル - `.devcontainer/devcontainer.json` — devcontainer 設定本体。claude-code feature と github-cli feature を追加 - `.devcontainer/docker-compose.devcontainer.yml` — 既存 compose への override (sleep infinity で長寿命化 + 追加マウント) - `.devcontainer/README.md` — 起動方法、設計方針、トラブルシューティング 既存の `docker compose run --rm app ...` ワークフローには影響しない。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/feature/devcontainer-claude-code/ |
macOS の `gh` は PAT を Keychain に保存するため、~/.config/gh を
bind mount しても oauth_token がコンテナに渡らない。実機検証で発覚した
問題への対処。
- devcontainer.json の remoteEnv に GH_TOKEN: ${localEnv:GH_TOKEN} を追加
- initialize.sh を新設し、GH_TOKEN 未設定時に警告を出す
- README に「ホスト側で `export GH_TOKEN=$(gh auth token)` してから起動」
の手順を明記
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Author
実機検証結果と追加修正main checkout で ✅ OK だった項目
❌ 発見した問題と修正macOS の 修正内容 (963896a)
実機で ⏳ 残りの実機検証
|
…Command VS Code Reopen in Container を main checkout で実行したとき、 postCreateCommand の `bin/setup-worktree || true` が "this script is for worktrees, not the main checkout" を stderr に出力し、 VS Code のターミナルに "error" として表示されていた (exit code 0 だが UX 上は失敗に見える)。 post-create.sh を新設し、git-common-dir と git-dir を比較して worktree のときだけ bin/setup-worktree を実行するように修正。 main checkout では何もしない (env / node_modules / dist は既に揃っているため)。 加えて、Dev Containers CLI が `--experimental-lockfile` で生成した devcontainer-lock.json をコミット (features の digest を固定してサプライチェーンを保護)。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
devcontainer 内で claude を起動するとログイン状態・設定・skills・memory が リセットされてしまう問題への対応。素朴に ~/.claude 全体をマウントすると 他プロジェクトの transcripts/sessions/history が container から見えてしまうため、 選択的マウントを採用。 ## マウントするもの (グローバルかつ共有して安全なもの) - ~/.claude.json — 認証 - ~/.claude/settings.json (ro) — グローバル設定 - ~/.claude/skills/ (ro) — 自作スキル - ~/.claude/plugins/ (ro) — プラグイン - ~/.claude/statusline-command.sh (ro) — カスタム statusline ## マウントしないもの (他プロジェクト漏れ防止) - ~/.claude/projects/ 全体, ~/.claude/sessions/, ~/.claude/history.jsonl - ~/.claude/file-history/, ~/.claude/shell-snapshots/, ~/.claude/session-env/ ## このプロジェクトの memory だけ共有する仕組み ホスト側の per-project ディレクトリ名はユーザーのパスに依存。 コンテナ内では workspaceFolder=/app 固定なので slug は常に `-app`。 initialize.sh がホスト側に `-app` シンボリックリンクを作成し、 ホスト本来の slug を指すようにする。compose は `~/.claude/projects/-app` を マウントし、コンテナの claude は透過的に同じ memory を読み書きできる。 他のユーザー / worktree / マシンに切り替えても、initialize.sh がそのときの host slug を計算してリンクを張り直す。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
これまで docker-compose.devcontainer.yml に詰め込んでいた個人依存のマウント (ghq, ~/.claude*) を docker-compose.local.yml に分離。本ファイルは gitignore 対象で、各自が .example からコピーして自分の環境に合わせる。 ## ファイル構成 - docker-compose.devcontainer.yml (commit): 全員共通 (gitconfig, gh config) - docker-compose.local.yml.example (commit): テンプレート (ghq, ~/.claude*) - docker-compose.local.yml (gitignore): 各自カスタマイズ - initialize.sh: ファイル無ければ空の services スタブを自動生成 ## 理由 ghq の有無、Claude Code 利用の有無、~/ がどう構成されているかは開発者ごとに 異なる。共有 compose ファイルに個人依存のパスが残ると、他開発者の Reopen in Container が起動失敗する (bind mount のソース不在で fail)。 ## 動作 - Claude Code を使わない人: 何もしなくても起動する (空 stub だけが生成される) - 個人 mount を有効化したい人: cp .example → .local.yml で開始 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
github-actions Bot
pushed a commit
that referenced
this pull request
May 11, 2026
…ntainer-claude-code chore(devcontainer): add Dev Container config for Claude Code isolated execution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Claude Code をホスト直接実行するのではなく、devcontainer 内で動かすための設定を追加します。社内ガイドライン (NaCl Claude Code 利用ガイドライン v0.2) の 階層 B (OSS / 自社開発) の隔離環境推奨 に準拠することが目的です。
Why
ホスト直接実行では Claude Code が
~/.ssh,~/.aws, 他案件ディレクトリなどに物理アクセスできてしまう。本プロジェクトの作業範囲は明確 (<repo>+ 関連 OSS =~/ghq配下) なので、コンテナ内に限定することで「物理的にアクセスできる範囲」をホワイトリスト化する。Changes Made
.devcontainer/devcontainer.jsondocker-compose.ymlのappサービスを再利用する構成ghcr.io/anthropics/devcontainer-features/claude-code:1.0で Claude Code をインストールghcr.io/devcontainers/features/github-cli:1で gh CLI を導入forwardPorts: [8601]で dev server をホストに公開postCreateCommandでbin/setup-worktreeを自動実行.devcontainer/docker-compose.devcontainer.yml既存 compose への override:
command: sleep infinityで devcontainer を長寿命化~/ghq/ghq~/.gitconfig/root/.gitconfig(ro)~/.config/gh/root/.config/ghマウントしない:
~/.ssh,~/.aws,~/Documents,~/Downloads,~/Desktop,~/Library.devcontainer/README.md起動方法 (VS Code Dev Containers / devpod / docker compose 直接実行)、設計方針、AWS CDK deploy の運用方針 (ホスト側で実行)、トラブルシューティングを記載。
Compatibility
既存の
docker compose run --rm app .../bin/dx/git worktreeワークフローには影響しません。devcontainer は 追加 であり、既存ユーザーは従来通り作業可能です。Test Coverage
docker compose -f docker-compose.yml -f .devcontainer/docker-compose.devcontainer.yml config --quietでマージ後の compose 設定が有効であることを確認済みappサービスに既存 4 volume + 追加 3 mount が正しく合成されることを確認済みManual Verification (これから)
実機での
Reopen in Container動作確認は別途実施します:gh auth statusが成功すること/ghq配下が見えることnpm run lintが動くことbrew install devpod→devpod up .)Follow-up
bin/dxの devcontainer 内分岐CLAUDE.md/.claude/rules/git-workflow.mdにホスト直接 Claude Code 禁止を明記Test plan
gh auth status成功ls /ghqで OSS リポジトリ群が見えるnpm run lintが動く