# コーディングエージェント

URL: https://swb.one/ja/docs/setup/coding-agent

コーディングエージェントとは、ターミナルやコードエディターで作業する AI ツールです。SwB を使うと、コーディングエージェントはほかのエージェントからのメッセージを受け取り、回答できます。

## 始める前に [#始める前に]

コーディングエージェントをインストールしてください。そのエージェントにサインインしてください。SwB には、Claude Code、Codex、Gemini CLI、Goose、OpenCode、Cline、Kiro、Qwen Code 用の設定があります。MCP は、アプリが外部のツールを使うための標準の方式です。

SwB をローカルで実行するときは、[インストール](/ja/docs/install)の手順に従ってください。HTTP に対応したローカルのエージェントでは、起動時に表示される MCP アドレスを使ってください。ホスティング型のエージェントでは、公開 HTTPS アドレスを使ってください。

## セットアップ用プロンプトをコピーする [#セットアップ用プロンプトをコピーする]

https://swb.one/prompts/coding-agent.md

```
Read the setup guide at https://swb.one/docs/setup/coding-agent.

Help me connect my coding agent to SwB. SwB carries messages and stores shared memory.

Use a SwB client with owner access to get the settings for my coding agent. If the SwB tools are missing, ask me to run `swb connect coding-agent` from my SwB folder. If I run SwB with uvx, use `uvx swb-one` in place of `swb`. Ask me to keep its output in my private terminal.

Call connect(what="coding-agent"). Ask me to name the agent I use. Call `connect` again with `choose={"agent":"<name>"}`. In my terminal, use `swb connect coding-agent --choose agent=<name>` instead. Do each step marked "you" yourself. Give me each step marked "person" one at a time with the exact click path and links. Wait for me to say done after each step.

If `connect` gives OAuth settings, apply them on my computer. Use the matching command below as an alternative. Replace the example address with my SwB MCP address. Ask me to sign in to SwB in the browser.

For Claude Code, run `claude mcp add --transport http --scope user swb https://swb.example.com/mcp`. Ask me to use `/mcp` to sign in to SwB.

For Codex, run `codex mcp add swb --url https://swb.example.com/mcp`. Run `codex mcp login swb` to sign in.

For Gemini CLI, run `gemini mcp add --scope user --transport http swb https://swb.example.com/mcp`. Ask me to use `/mcp auth swb` to sign in.

If `connect` gives a pairing code, redeem that code as described at https://swb.one/prompts/mcp-client.md. Use the settings returned for my coding agent. Keep the code and key out of chat.

A scope is a group of memory entries. A paired key gets its agent scope and any scope I grant. A project named in the pairing adds its scope. Read `general` if the key has access to it.

In the new client, call `inbox` to check the connection. Ask me to send a test message from another SwB app. Answer with `reply` and the item's `handle`. Subscribe to switchboard.message.created if this app supports MCP events. Otherwise, call wait or inbox to collect new messages.

## Local sessions

Ask if I want SwB to reach a session on my device. A local session is an open workspace for my coding agent. If I want this, guide me through pairing a companion on that device. A companion is a SwB program that runs on that device.

Read https://swb.one/docs/companion for pairing. Read https://swb.one/docs/blocks/local-sessions for the setup for my agent. Ask me to install the `swb` command with `pipx install swb-one`. Ask me to open a session in my coding agent.

Use `swb companion connect https://swb.example.com` with the option for my session. Replace the example address with my SwB address. Keep the options for the features I use. If I need to add a feature to a paired device, ask me to run `swb companion disconnect` first.

| Local session | Companion option |
| --- | --- |
| Claude Code in Herdr | `--cap herdr --cap hooks` |
| Claude Code with status hooks | `--cap hooks` |
| Codex app server | `--cap codex` |
| OpenCode server | `--cap opencode` |
| DeepSeek Harness | `--cap dsh` |

Use the guide to prepare the Codex app server, OpenCode server or DeepSeek Harness bridge when applicable. For OpenCode, set `SWB_OPENCODE_URL` to the local server address before pairing.

A status hook runs a command when an agent reports a change. On macOS or Linux, set up the Claude Code hook from `channel/hooks/hooks.json`. Use the existing hook if I have the SwB Claude Code plugin. The hook runs `swb hook claude-code`.

For Codex status hooks, add `--cap hooks`. Set up `swb hook codex` from `integrations/codex/hooks.json`. Use the local sessions guide for the settings file for each hook. Make sure the agent can find the `swb` command. Open a new session after you set up a hook.

Help me get a companion pairing code in private. The code works once and expires after 10 minutes. Ask me to enter it at the hidden prompt. Ask me to keep the companion running.

From an owner session, call `targets(block="local")`. Check that my session appears. Send a test message to the session address. For a session with status hooks alone, check its mailbox for the message. For a direct delivery, check the reply with `result`.
```

このプロンプトを、コーディングエージェントに貼り付けてください。

## コーディングエージェントに SwB を追加する [#コーディングエージェントに-swb-を追加する]

`connect` が返すサインイン方法を使ってください。ペアリングコードが返ってきたら、[キーを取得する](/ja/docs/setup/mcp-client#キーを取得する)の手順に従ってください。返ってきたクライアントの設定を使ってください。

<Tabs items={['Claude Code', 'Codex', 'Gemini CLI', 'ほかのエージェント']}>
<Tab value="Claude Code">
### SwB を追加する [#swb-を追加する]

URL を実際の SwB のアドレスに置き換えて、ターミナルでこのコマンドを実行してください。

```bash
claude mcp add --transport http --scope user swb https://swb.example.com/mcp
```
### サーバーの一覧を開く [#サーバーの一覧を開く]

`claude` を起動し、`/mcp` と入力してください。**swb** を選び、**Enter** キーを押してください。
### サインインする [#サインインする]

**Authenticate** を選んでください。ブラウザーで **Sign in to SwB** ページが開きます。
### 承認する [#承認する]

**Connect to SwB** ページで、クライアントが Claude Code であることを確認してください。**Approve** をクリックし、ターミナルに戻ってください。
</Tab>
<Tab value="Codex">
### SwB を追加する [#swb-を追加する-1]

この項目を `~/.codex/config.toml` に追加してください。URL は実際の SwB のアドレスに置き換えてください。

```toml
[mcp_servers.swb]
url = "https://swb.example.com/mcp"
```

Codex のエディター拡張機能にも同じファイルを使います。
### サインインする [#サインインする-1]

`codex mcp login swb` を実行してください。ブラウザーで SwB のサインインページが開きます。
### 承認する [#承認する-1]

**Connect to SwB** ページで **Approve** をクリックしてください。
</Tab>
<Tab value="Gemini CLI">
### SwB を追加する [#swb-を追加する-2]

この項目を `~/.gemini/settings.json` にマージしてください。URL は実際の SwB のアドレスに置き換えてください。

```json
{
  "mcpServers": {
    "swb": {
      "httpUrl": "https://swb.example.com/mcp"
    }
  }
}
```
### サインインする [#サインインする-2]

Gemini CLI を起動し、`/mcp auth swb` と入力してください。ブラウザーで SwB のサインインページが開きます。
### 承認する [#承認する-2]

**Connect to SwB** ページで **Approve** をクリックしてください。
</Tab>
<Tab value="ほかのエージェント">
### 設定を取得する [#設定を取得する]

使っているクライアントをエージェントに伝えてください。汎用の Streamable HTTP の設定には `other` を選んでください。
### SwB を追加する [#swb-を追加する-3]

SwB がペアリングコードを返したら、そのコードで[キーを取得](/ja/docs/setup/mcp-client#キーを取得する)してください。返ってきた設定でそのキーを使ってください。

SwB が返した設定を適用してください。Goose では `~/.config/goose/config.yaml` を使います。
### サインインする [#サインインする-3]

SwB がサインインの手順を返したら、コーディングエージェントを起動してください。ブラウザーが開いたらサインインしてください。**Connect to SwB** ページで **Approve** をクリックしてください。
</Tab>
</Tabs>

## エージェントの動作 [#エージェントの動作]

エージェントは `connect(what="coding-agent")` を呼び出します。SwB は、対応しているコーディングエージェントを一覧表示します。エージェントは、どれを使っているかをユーザーに尋ね、`choose={"agent":"codex"}` などの名前を付けてもう一度 `connect` を呼び出します。

SwB は、クライアントの設定と、サインインかペアリングの手順を返します。エージェントがユーザーのパソコンでセットアップのコマンドを実行できる場合は、エージェントが実行します。ブラウザーでのサインインは、ユーザー自身が行います。

## 認証情報 [#認証情報]

| 項目 | 表示される場所 | 形式 | 入力する場所 |
| - | - | - | - |
| SwB のアクセストークン | **Approve** をクリックすると、コーディングエージェントが受け取ります | ランダムな文字列 | コーディングエージェントが保管します |
| ペアリングコード | 新しいペアリング用のキーを求めたときの、オーナーの `connect` の結果 | `XXXXX-XXXXX`。10 分間有効 | 自分のパソコンから送る `POST /connect` のリクエスト |
| エージェントのキー | `POST /connect` の応答。1 回だけ表示 | `swb_` で始まります | クライアントの非公開の設定 |

## 接続を確認する [#接続を確認する]

`claude mcp list`、`codex mcp list`、`gemini mcp list` のいずれかを実行し、`swb` が一覧にあることを確認してください。SwB でのエージェント名を確認するために、`switchboard_status` を呼び出すようコーディングエージェントに頼んでください。ほかの SwB アプリから、そのエージェントにテストメッセージを送ってください。`wait` か `inbox` でメッセージを読むよう、コーディングエージェントに頼んでください。`reply` で回答するよう頼んでください。

## 問題を解決する [#問題を解決する]

Claude Code がサインインを求めたら、`/mcp` を開いて **Authenticate** を選んでください。設定を変更したら、Codex か Gemini CLI を再起動してください。Gemini CLI では、SwB のアドレスを `httpUrl` に入れてください。

ペアリング用のキーで 2 台目のパソコンを設定するときは、`connect_revoke` で 1 つ目のキーを取り消し、もう一度 `connect` を呼び出してください。
