2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Claude Code] エージェントに並列で処理させる container-use

Posted at

Claude Codeのエージェントに並列で作業(処理)をさせようとすると、修正がバッディングしてまうことがあります…。サブタスクを切って、レポジトリを分けて作業させるの王道なのですが、めんどうくさい…。ということで、container-useを使って、並列で作業できるようにします。

container-use

container-useはコンテナを使うことで、独自の環境の中で作業をすることができるようになります。お陰で、複数のエージェントに作業させることが安全になります。container-useはMCPサーバで提供されるので、Calude Code以外の環境でも利用できます。

事前に、

  • Docker
  • Git

をインストールしてください。

インストール

brew install dagger/tap/container-use

※Macでインストールの場合

インストールの確認

container-use version
❯ container-use version
container-use version 0.3.1
commit: bfff9fc05e24a9d120d19b87d555a27e87d939cc
built: 2025-07-15T18:14:16Z

MCP設定の追加

container-useを使うレポジトリ(ディレクトリ)に移動します。もし、無い場合は作成してください。

cd /path/to/repository
claude mcp add container-use -- container-use stdio

CLAUDE.mdへ設定追加

公式サイトでは、オプションになっていますが、必須の設定です。

curl https://raw.githubusercontent.com/dagger/container-use/main/rules/agent.md >> CLAUDE.md

CLAUDE.mdに次のようなプロンプトが追記されます。

CLAUDE.md
ALWAYS use ONLY Environments for ANY and ALL file, code, or shell operations—NO EXCEPTIONS—even for simple or generic requests.

DO NOT install or use the git cli with the environment_run_cmd tool. All environment tools will handle git operations for you. Changing ".git" yourself will compromise the integrity of your environment.

You MUST inform the user how to view your work using `container-use log <env_id>` AND `container-use checkout <env_id>`. Failure to do this will make your work inaccessible to others.

レポジトリの初期化

container-useを使うには、コミットが一つ以上されているレポジトリが必要になります。

git init
touch README.md
git add .
git commit -m "initial commit"

MCP動作の確認

claudeを立ち上げて、次のコマンドを実行します

/mcp

container-useが無事にインストールされていると、次のように表示されます。

╭──────────────────────────────────────────────────────────────────────────────╮
│ Manage MCP servers                                                           │
│                                                                              │
│ ❯ 1. container-use  ✔ connected · Enter to view details                      │
╰──────────────────────────────────────────────────────────────────────────────╯
   Esc to exit

container-useを動かしてみる

公式サイトで紹介されているプロンプトを使って、エージェントに簡単なサンプルサイトをつくらせます。

Create a hello world app in python using flask

すると、作業が始まります。

⏺ Update Todos
  ⎿  ☒ Create development environment for Flask app
     ☒ Configure environment with Python and Flask dependencies
     ☒ Create Flask hello world application
     ☒ Test the Flask application runs correctly

⏺ Flask hello world app created successfully! The app is running and
  accessible at http://127.0.0.1:59903

  To view the work: container-use log live-impala and container-use
  checkout live-impala

  Note: Your repository has uncommitted changes (.claude/ directory). To
  include these in the environment, commit them first using git commands
  outside the environment.

  Configuration: To make the Python/Flask configuration persistent, run cu
  config import live-impala

作業完了後、Claude Codeが立ち上げたhttp://127.0.0.1:59903にアクセスすると、Hello, World!が表示されるはずです。

動作結果の確認

レポジトリの内容を確認すると、

❯ ls
CLAUDE.md README.md

となっていて、生成されたはずのpythonファイルがありません。実は、タスクで生成されたファイルは、各コンテナのブランチの中で生成されています。

gitのレポジトリを確認すると、
image.png
新しくコミットが生成されていることを確認できます。

各エージェントの作業は、個別のブランチ内で行われ、ローカルファイルや他のブランチには、影響を与えません。ブランチ名は自動的に付けられます。

作業で作成されたファイルを確認するには、コンテナのブランチをcheckoutをします。次のコマンドを実行します

container-use checkout [ID]
❯ container-use checkout [live-impala]
❯ ls
app.py    CLAUDE.md README.md

app.pyというファイルが生成されているのがわかります。

今、つくられているコンテナのリストは、次のコマンドで表示されます

container-use list

実行例

❯ container-use list
ID           TITLE                  CREATED         UPDATED
live-impala  Flask Hello World App  15 minutes ago  14 minutes ago

コミットを取り込むには、まず、対象となるブランチから出ます。

❯ git switch main
Switched to branch 'main'
container-use merge [ID]

実行例

❯ container-use merge live-impala
Merge made by the 'ort' strategy.
 app.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 app.py
Environment 'live-impala' merged successfully.

image.png
Mainブランチにマージされたことを確認できます。

コンテナを削除

コンテナは次のコマンドで削除できます。

container-use delete [ID]

その他のコマンドのリファレンスは、こちらから。
https://container-use.com/quickstart#essential-commands

並列作業

次のプロンプトを並列に実行します。

> aboutページを追加してください
> プロフィールページを追加してください
> サービス紹介ページを追加してください

タスクが完了すると、次のようなブランチが作成され、完全に独立した形で並行して作業ができたことを確認できます。

image.png

この後、適宜レビューし、マージしていきます。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?