Skip to content

feat(devcontainer): ビルド時に完全なClaude設定をイメージに組み込み - #327

Merged
keito4 merged 2 commits into
mainfrom
feat/embed-claude-setup-in-image
Jan 11, 2026
Merged

feat(devcontainer): ビルド時に完全なClaude設定をイメージに組み込み#327
keito4 merged 2 commits into
mainfrom
feat/embed-claude-setup-in-image

Conversation

@keito4

@keito4 keito4 commented Jan 11, 2026

Copy link
Copy Markdown
Owner

Summary

新しいリポジトリでconfig-baseイメージを使用する際、ファイルのコピーや手動設定なしでClaude Code環境をすぐに利用できるようにしました。

Changes

  • setup-claude-build.sh: ビルド時専用セットアップスクリプトを追加
    • hookifyプラグインのパッチ適用
    • known_marketplaces.jsonの生成
  • Dockerfile: プラグインインストール後にビルド時セットアップを実行
    • 必要なライブラリファイルをCOPY
    • setup-claude-build.shをUSER vscodeで実行
  • docs/using-config-base-image.md: 使用方法ドキュメントを追加
    • 最小構成、推奨構成、プロジェクト固有設定の3パターンを記載

Implementation

Dockerビルド時に以下を実行:

  1. Claude設定ファイル、コマンド、エージェント、hooksをCOPY
  2. プラグインをインストール(install-claude-plugins.sh)
  3. hookifyパッチ適用とknown_marketplaces.json生成(setup-claude-build.sh)

Result

新しいリポジトリでは devcontainer.json でイメージを指定するだけで、すべてのClaude設定が利用可能になります。

最小構成例

```json
{
"name": "My Project",
"image": "ghcr.io/keito4/config-base:1.43.0",
"remoteEnv": {
"TMPDIR": "/home/vscode/.claude/tmp"
}
}
```

Test plan

  • setup-claude-build.sh のスクリプトが正しく動作することを確認
  • Dockerfile の構文が正しいことを確認
  • ドキュメントのフォーマットが正しいことを確認
  • すべてのテストが通過することを確認
  • 新しいイメージのビルドが成功することを確認(CI後)

Risks

  • イメージサイズが若干増加(設定ファイルとライブラリの追加)
  • ビルド時間が若干増加(setup-claude-build.shの実行)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Added a comprehensive guide for the Claude Config Base image covering contents, usage examples, plugin management, persistence recommendations, build/release steps, and troubleshooting.
  • Chores

    • Enhanced the container build to perform build-time Claude setup and plugin installation with resilient failure handling and correct ownership, improving out-of-the-box development environment consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

## Why(なぜ)
新しいリポジトリでconfig-baseイメージを使用する際、ファイルのコピーや
手動設定なしでClaude Code環境をすぐに利用できるようにするため。

## What(何を)
- setup-claude-build.sh: ビルド時専用セットアップスクリプトを追加
  - hookifyプラグインのパッチ適用
  - known_marketplaces.jsonの生成
- Dockerfile: プラグインインストール後にビルド時セットアップを実行
  - 必要なライブラリファイルをCOPY
  - setup-claude-build.shをUSER vscodeで実行
- docs/using-config-base-image.md: 使用方法ドキュメントを追加
  - 最小構成、推奨構成、プロジェクト固有設定の3パターンを記載

## How(どのように)
Dockerビルド時に以下を実行:
1. Claude設定ファイル、コマンド、エージェント、hooksをCOPY
2. プラグインをインストール(install-claude-plugins.sh)
3. hookifyパッチ適用とknown_marketplaces.json生成(setup-claude-build.sh)

これにより、新しいリポジトリでは devcontainer.json で
イメージを指定するだけで、すべてのClaude設定が利用可能になります。

## Risk(リスク)
- イメージサイズが若干増加(設定ファイルとライブラリの追加)
- ビルド時間が若干増加(setup-claude-build.shの実行)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the size/M PR サイズ Medium label Jan 11, 2026
@coderabbitai

coderabbitai Bot commented Jan 11, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds a build-time Claude setup flow: copies templates and scripts into the devcontainer image, runs a new script/setup-claude-build.sh during Docker build (as user vscode) to install/patch plugins and generate known_marketplaces.json, and adds documentation for the Claude Config Base image.

Changes

Cohort / File(s) Summary
Build configuration
\.devcontainer/Dockerfile
Copies known_marketplaces.json.template, script/setup-claude-build.sh, and script/lib/* into the image; makes scripts executable; adds BuildKit secret-driven plugin install block with warning-and-continue fallback; runs /tmp/setup-claude-build.sh as vscode then reverts to root; adjusts ownership.
Build script
script/setup-claude-build.sh
New build-time setup script: locates script/lib paths, sources output.sh and claude_plugins.sh, checks for Claude CLI and plugins, applies hookify patch via plugins helper, generates known_marketplaces.json from template (substituting HOME), and fixes ownership; logs guarded warnings if prerequisites missing.
Documentation
docs/using-config-base-image.md
New comprehensive guide for the Claude Config Base image: image contents, minimal and persistent-host examples, available commands/plugins, project-specific settings, build/release steps, and troubleshooting tips (includes devcontainer.json and Docker build examples).

Sequence Diagram(s)

sequenceDiagram
    participant DockerBuild as Docker Build
    participant SetupScript as /tmp/setup-claude-build.sh
    participant Libs as script/lib
    participant ClaudeCLI as Claude CLI
    participant FileSystem as File System

    DockerBuild->>SetupScript: Copy scripts/libs and make executable
    DockerBuild->>SetupScript: Run as user vscode
    SetupScript->>Libs: Source output.sh & claude_plugins.sh
    SetupScript->>ClaudeCLI: Check presence
    alt Claude CLI and plugins present
        SetupScript->>ClaudeCLI: Run plugin install / apply hookify
        SetupScript->>FileSystem: Generate known_marketplaces.json from template
        SetupScript->>FileSystem: chown files to vscode
        SetupScript->>DockerBuild: Exit success
    else Missing CLI or plugins
        SetupScript->>DockerBuild: Log warning and exit early (continue build)
    end
    DockerBuild->>DockerBuild: Revert to root user
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped into the build today,
Copied scripts and plugins on my way,
Marketplaces formed from a template bright,
Hookify patched by soft moonlight,
Container warmed — the rabbit's delight. 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title is in Japanese and uses non-ASCII characters, making it difficult for English-speaking teammates to understand the primary change when scanning history. Use English for the pull request title to ensure clarity and accessibility for all team members. Example: 'feat(devcontainer): Embed complete Claude setup in image during build'
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3a2093 and 353b2c7.

📒 Files selected for processing (1)
  • script/setup-claude-build.sh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

ShellCheckのwarning SC2034を修正。
setup-claude-build.shではプラグインリストは不要なため削除。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@github-actions github-actions Bot added size/M PR サイズ Medium and removed size/M PR サイズ Medium labels Jan 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In @.devcontainer/Dockerfile:
- Around line 101-104: The Dockerfile currently swallows errors from RUN bash
/tmp/setup-claude-build.sh via "|| echo ..." which hides failures (e.g., the
chown permission error in setup-claude-build.sh); update the Dockerfile to run
the setup script without silent failure and move any filesystem ownership
operations (the chown referenced in setup-claude-build.sh) to run as root after
USER vscode returns to USER root so permission changes succeed, or alternatively
have the script itself exit successfully only when allowable errors occur and
explicitly log warnings; specifically, remove the "|| echo" suppression, ensure
setup-claude-build.sh either handles expected missing-credential cases and exits
0 or propagate failure, and perform chown as root after switching back to USER
root to fix permission errors.

In @script/setup-claude-build.sh:
- Around line 23-24: The script defines an unused variable PLUGINS_FILE; remove
the PLUGINS_FILE assignment line (the
PLUGINS_FILE="${CLAUDE_DIR}/plugins/plugins.txt" statement) so only CLAUDE_DIR
remains, and ensure no other code in the file references PLUGINS_FILE (delete or
update any references if present).
- Around line 54-56: The chown invocation in setup-claude-build.sh (the chown -R
vscode:vscode "$CLAUDE_DIR" line) fails because the script runs as USER vscode
and requires root; remove that chown from setup-claude-build.sh and instead
perform the ownership change in the Dockerfile after the script completes (i.e.,
run chown -R vscode:vscode "$CLAUDE_DIR" as root in the Dockerfile), or if you
prefer the alternative, run the script itself as root and switch to vscode
inside the script—prefer the Dockerfile-change approach.
🧹 Nitpick comments (1)
script/setup-claude-build.sh (1)

45-52: Consider using $CLAUDE_DIR for consistency.

The hardcoded /home/vscode path should be derived from the $CLAUDE_DIR variable to maintain a single source of truth. This improves maintainability if the user home directory ever changes.

♻️ Proposed refactor
     # known_marketplaces.json の生成
     if [[ -f "${CLAUDE_DIR}/plugins/known_marketplaces.json.template" ]]; then
         log_info "known_marketplaces.json を生成中..."
+        HOME_DIR="${CLAUDE_DIR%/.claude}"
-        sed "s|{{HOME}}|/home/vscode|g" \
+        sed "s|{{HOME}}|${HOME_DIR}|g" \
             "${CLAUDE_DIR}/plugins/known_marketplaces.json.template" \
             > "${CLAUDE_DIR}/plugins/known_marketplaces.json"
         log_success "known_marketplaces.json を生成しました"
     fi
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5446aeb and a3a2093.

📒 Files selected for processing (3)
  • .devcontainer/Dockerfile
  • docs/using-config-base-image.md
  • script/setup-claude-build.sh
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Publish DevContainer images to ghcr.io/keito4/config-base with semantic versioning
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/docker-image.yml : Build DevContainer images automatically with semantic versioning and multi-platform support in .github/workflows/docker-image.yml
Learnt from: CR
Repo: keito4/config PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-04T04:05:56.913Z
Learning: Use automated Claude commands from `.claude/commands/` directory for maintenance, Git workflows, code analysis, quality checks, dependency management, security reviews, and tool configuration
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/claude.yml : Trigger automatic AI assistance on claude mentions in issues, PRs, and comments using .github/workflows/claude.yml
📚 Learning: 2026-01-04T04:05:56.913Z
Learnt from: CR
Repo: keito4/config PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-04T04:05:56.913Z
Learning: Use automated Claude commands from `.claude/commands/` directory for maintenance, Git workflows, code analysis, quality checks, dependency management, security reviews, and tool configuration

Applied to files:

  • script/setup-claude-build.sh
  • docs/using-config-base-image.md
  • .devcontainer/Dockerfile
📚 Learning: 2026-01-04T04:05:56.913Z
Learnt from: CR
Repo: keito4/config PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-04T04:05:56.913Z
Learning: Refer to `CLAUDE.md` for quality standards, AI prompt design guidelines, and CI integration

Applied to files:

  • docs/using-config-base-image.md
📚 Learning: 2025-12-01T03:45:17.253Z
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Publish DevContainer images to ghcr.io/keito4/config-base with semantic versioning

Applied to files:

  • docs/using-config-base-image.md
📚 Learning: 2025-12-01T03:45:17.253Z
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/docker-image.yml : Build DevContainer images automatically with semantic versioning and multi-platform support in .github/workflows/docker-image.yml

Applied to files:

  • docs/using-config-base-image.md
  • .devcontainer/Dockerfile
📚 Learning: 2026-01-04T04:05:56.913Z
Learnt from: CR
Repo: keito4/config PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-04T04:05:56.913Z
Learning: Use specialized Claude Code agents from `.claude/agents/` directory for architecture validation, performance analysis, concurrency safety, and testability analysis

Applied to files:

  • .devcontainer/Dockerfile
🧬 Code graph analysis (1)
script/setup-claude-build.sh (1)
script/lib/claude_plugins.sh (1)
  • plugins::apply_hookify_patch (237-272)
🪛 GitHub Actions: CI
script/setup-claude-build.sh

[warning] 24-24: SC2034: PLUGINS_FILE appears unused. Verify use (or export if used externally).

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Generate SBOM
  • GitHub Check: Trivy Container Scan
🔇 Additional comments (5)
.devcontainer/Dockerfile (1)

84-84: LGTM!

The new COPY instructions properly set ownership and permissions for the build-time setup artifacts. The addition of script/lib and the template file supports the new build-time configuration flow.

Also applies to: 87-89

docs/using-config-base-image.md (4)

1-45: LGTM!

The overview and minimal configuration sections are clear, accurate, and provide helpful guidance for users starting with the config-base image. The minimal example correctly demonstrates the simplest usage pattern.


46-85: LGTM!

The plugin list and recommended configuration section clearly explains the trade-offs between minimal and persistent configurations. The mount setup and postCreateCommand usage are correctly documented.


86-134: LGTM!

The project-specific settings section provides clear, actionable guidance for customizing the base image. The explanation of setup-claude.sh behavior correctly describes the runtime setup responsibilities.


135-178: LGTM!

The build instructions correctly document the BuildKit secret usage, and the troubleshooting section addresses the most likely user issues. The reference links provide appropriate additional resources.

Comment thread .devcontainer/Dockerfile
Comment on lines +101 to +104
# ビルド時にClaude設定を完全にセットアップ
USER vscode
RUN bash /tmp/setup-claude-build.sh || echo "[WARN] ビルド時セットアップに失敗しました"
USER root

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Improve error handling for the build-time setup.

The error suppression with || echo "[WARN]..." will silently hide failures in the setup script, including the permission error from the chown command identified in setup-claude-build.sh. This makes debugging difficult.

If the setup script is expected to fail gracefully during builds without credentials, consider more explicit error handling:

🔧 Suggested improvements
 # ビルド時にClaude設定を完全にセットアップ
 USER vscode
-RUN bash /tmp/setup-claude-build.sh || echo "[WARN] ビルド時セットアップに失敗しました"
+RUN bash /tmp/setup-claude-build.sh || ( \
+    echo "[WARN] ビルド時セットアップに失敗しました" && \
+    echo "[INFO] コンテナ起動後に setup-claude.sh を実行してください" \
+)
 USER root
+RUN chown -R vscode:vscode /home/vscode/.claude

This moves the chown operation to run as root after the vscode-user script completes, fixing the permission issue while maintaining graceful degradation.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# ビルド時にClaude設定を完全にセットアップ
USER vscode
RUN bash /tmp/setup-claude-build.sh || echo "[WARN] ビルド時セットアップに失敗しました"
USER root
# ビルド時にClaude設定を完全にセットアップ
USER vscode
RUN bash /tmp/setup-claude-build.sh || ( \
echo "[WARN] ビルド時セットアップに失敗しました" && \
echo "[INFO] コンテナ起動後に setup-claude.sh を実行してください" \
)
USER root
RUN chown -R vscode:vscode /home/vscode/.claude
🤖 Prompt for AI Agents
In @.devcontainer/Dockerfile around lines 101 - 104, The Dockerfile currently
swallows errors from RUN bash /tmp/setup-claude-build.sh via "|| echo ..." which
hides failures (e.g., the chown permission error in setup-claude-build.sh);
update the Dockerfile to run the setup script without silent failure and move
any filesystem ownership operations (the chown referenced in
setup-claude-build.sh) to run as root after USER vscode returns to USER root so
permission changes succeed, or alternatively have the script itself exit
successfully only when allowable errors occur and explicitly log warnings;
specifically, remove the "|| echo" suppression, ensure setup-claude-build.sh
either handles expected missing-credential cases and exits 0 or propagate
failure, and perform chown as root after switching back to USER root to fix
permission errors.

Comment thread script/setup-claude-build.sh Outdated
Comment on lines +54 to +56
# 設定ファイルのパーミッション確認
chown -R vscode:vscode "$CLAUDE_DIR"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Permission error: chown requires root privileges.

This script runs as USER vscode (Dockerfile line 102), but the chown command requires root privileges. This operation will fail silently due to the || echo "[WARN]..." error suppression in the Dockerfile.

🔧 Recommended fix

Option 1 (Recommended): Remove the chown from this script and handle it in the Dockerfile after the script completes:

-    # 設定ファイルのパーミッション確認
-    chown -R vscode:vscode "$CLAUDE_DIR"
-
     log_success "Claude Code ビルド時セットアップが完了しました!"

Then in .devcontainer/Dockerfile line 103-104:

 USER vscode
-RUN bash /tmp/setup-claude-build.sh || echo "[WARN] ビルド時セットアップに失敗しました"
+RUN bash /tmp/setup-claude-build.sh
 USER root
+RUN chown -R vscode:vscode /home/vscode/.claude

Option 2: Run the entire script as root and handle user switching internally, but this is less clean.

🤖 Prompt for AI Agents
In @script/setup-claude-build.sh around lines 54 - 56, The chown invocation in
setup-claude-build.sh (the chown -R vscode:vscode "$CLAUDE_DIR" line) fails
because the script runs as USER vscode and requires root; remove that chown from
setup-claude-build.sh and instead perform the ownership change in the Dockerfile
after the script completes (i.e., run chown -R vscode:vscode "$CLAUDE_DIR" as
root in the Dockerfile), or if you prefer the alternative, run the script itself
as root and switch to vscode inside the script—prefer the Dockerfile-change
approach.

@keito4
keito4 merged commit 6f73076 into main Jan 11, 2026
20 of 21 checks passed
@claude

claude Bot commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

PR Review: config-baseイメージへのClaude設定の組み込み

このPRは、config-baseイメージに完全なClaude Code環境を組み込むための重要な改善です。全体的に良く設計されていますが、いくつかの改善点と懸念事項があります。

良い点

  1. 明確な責任分離 - setup-claude-build.sh(ビルド時)とsetup-claude.sh(ランタイム時)の役割が明確
  2. エラーハンドリング - set -euo pipefail で堅牢なエラーハンドリング
  3. 包括的なドキュメント - 3つの使用パターン(最小構成・推奨構成・プロジェクト固有)を明確に記載
  4. 既存コードの再利用 - script/lib/claude_plugins.sh と script/lib/output.sh を効果的に活用

改善が必要な点

1. 重大な問題: setup-claude-build.shのパーミッション操作

script/setup-claude-build.sh:54 で chown -R vscode:vscode を実行していますが、このスクリプトは USER vscode で実行されており、vscode ユーザーは chown を実行する権限がありません。

推奨修正: この chown 行を削除する(既にDockerfileで適切な所有権が設定されています)

2. Dockerfileの論理的な問題

.devcontainer/Dockerfile:101-104 で、エラーが発生しても警告メッセージだけで続行します。これにより、セットアップが不完全なイメージが作成される可能性があります。

3. テストカバレッジの不足

実際のDockerビルドでテストされていない可能性があります。ローカルでのDockerビルドテストとCI結果の確認を推奨します。

4. スクリプトのロバスト性

script/setup-claude-build.sh:13-16 で SCRIPT_DIR が計算されますが、Dockerビルド時は常に /tmp/script-lib を使用するため、最初の計算が無駄になっています。

その他の観察事項

  • セキュリティ: 機密情報の漏洩リスクなし、BuildKit secretsを適切に使用
  • パフォーマンス: イメージサイズとビルド時間が若干増加(許容範囲内)
  • コード品質: shellcheck指令が適切、関数とライブラリの再利用が適切

推奨アクション

マージ前に必須:

  1. chown の問題を修正(削除または適切なユーザーコンテキストで実行)
  2. Dockerfileの USER 切り替えロジックを見直し
  3. ローカルでDockerビルドをテストし、実際に動作することを確認

推奨(オプション):

  1. エラーハンドリングのメッセージを改善
  2. スクリプトの条件分岐を最適化

総評

このPRは、config-baseイメージの利便性を大幅に向上させる優れた機能追加です。しかし、上記の問題(特に chown とUSER切り替え)を修正してからマージすることを強く推奨します。

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.45.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み size/M PR サイズ Medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant