> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/jp/tong-he/opencode.md).

# OpenCode でローカル AI モデルを実行する方法

このガイドでは、接続の手順を順に説明します **OpenCode Desktop** 〜に [Unsloth](https://github.com/unslothai/unsloth) オープンLLMを実行するために **すべてローカルで。** OpenCodeは **オープンソースのAIコーディングエージェントです** 接続されたモデルを使ってプロジェクト全体のコードを読み取り、変更し、実行します。\
\
これは、任意の **ローカルモデル** Unslothの **OpenAI互換API**などを含みます: DeepSeek、Qwen、Gemma など。OpenCodeはクライアントとして動作し、UnslothはローカルAPI経由でモデルを読み込み、提供します。

セットアップ後、OpenCodeはUnslothに接続し、読み込まれたモデルを選択して、 **コーディングエージェント**.

<a href="https://sites.gitbook.com/preview/site_mXXTe/~/revisions/S6OVzFPYN3gcF4rziUb5/integrations/opencode?theme=light#installing-opencode-desktop" class="button primary">OpenCodeのセットアップ</a><a href="/pages/3864bcb37ba6a47277fdce43a7f1d4bc977d7edb#quickstart" class="button primary">クイックスタート</a>

{% hint style="info" %}
このチュートリアルでは、 `unsloth/Qwen3.6-27B-GGUF` をUnslothで読み込み、OpenCode内から直接アクセスします。別のモデルを使いたいですか？ Unslothで読み込めば、ほかのモデルに置き換えられます。
{% endhint %}

### OpenCode Desktopのインストール

{% tabs %}
{% tab title="MacOS" %}

#### **手順1: Mac用のOpenCodeインストーラをダウンロードする**

開く `opencode.ai/download` をお使いのブラウザで開きます。下までスクロールして **OpenCode Desktop (Beta) に移動し、** そして `ダウンロード` ボタンをクリックします。Macのアーキテクチャ（Apple Silicon または Intel）に対応するmacOSイメージ名の横にあります。

#### 手順2: OpenCodeをインストールする

ダウンロードフォルダで `OpenCode Desktop.dmg` インストーラファイルを見つけ、ダブルクリックします。

インストーラウィンドウが開きます。マウスで **OpenCode** アプリアイコンを **Applications** アイコンの上までドラッグします。

#### 手順3: OpenCodeを起動する

ダウンロードフォルダで **OpenCode** の下にあるアイコンを **Applications** フォルダ。

その **OpenCode** デスクトップアプリが開き、次の操作を行える状態になります。

<div data-with-frame="true"><figure><img src="/files/f9bb4f3eef10281460c019c427bb6880ed1af78c" alt="" width="563"><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

### ⚡ クイックスタート

OpenCodeをインストールしたら、OpenCodeがローカルモデルを提供し推論を実行できるようにするため、Unsloth Studioをインストールする必要があります。

1. **Unsloth Studioをインストールまたは更新します。** 以前のバージョンでは外部APIが公開されません。インストールを参照してください。
2. **Unslothを起動します。** 起動時のポートは通常 `8000` または `8888`です。これはターミナル出力とブラウザのURL（`http://localhost:PORT`).
3. **モデルを読み込みます。** クリックします。 **New Chat**をクリックし、モデル（GGUF）を選択または検索して、読み込みが完了するまで待ちます。
4. **APIキーを作成します。** Unslothで、左下の **Unsloth** アバターをクリック → **設定** → **API** → キー名を入力 → **作成**をクリックします。次に `sk-unsloth-…` と表示される値をコピーします。Unslothでは一度しか表示されません。
5. **クライアントをUnslothに向けます。** 使います `http://localhost:PORT` をベースURLとして、 `sk-unsloth-…` 認証用のキーを使います。以下のツールの手順に進んでください。

### 🔑 APIキーの作成

1. サイドバーを開き、左下の **Unsloth** アバターをクリックします。
2. 移動先: **設定** → **API**.
3. わかりやすい名前を入力します（例: `claude-code-macbook`).
4. *(任意)* 有効期限を設定します。
5. クリックします。 **作成**.
6. **キーをすぐにコピーします。** Unslothにはハッシュのみが保存され、再度表示することはできません。

<figure><img src="/files/56897ad32966d1081797ea8ccf97a7df82f0a550" alt="" width="375"><figcaption></figcaption></figure>

すべてのキーは次で始まります: `sk-unsloth-` というプレフィックスです。同じページからいつでもキーを取り消せます。取り消されたキーで行われたリクエストは次のエラーで失敗します `401 Unauthorized`.

{% hint style="warning" %}
APIキーはパスワードのように扱ってください。キーを持ち、Unslothインスタンスへネットワークアクセスできる人は、読み込まれたモデルにリクエストを送信できます。
{% endhint %}

## 🖇️ UnslothをOpenCode Desktopに接続する

**OpenCode** はOpenAI互換のプロバイダをサポートしているため、Unslothを **カスタム** プロバイダとして組み込めます。設定はopencodeの **プロバイダを接続** ダイアログ内で一度だけ行います。

**1. プロバイダ選択を開きます。** opencodeで `/model` と入力するか、入力欄の下部にあるモデルセレクタをクリックします。

<div data-with-frame="true"><figure><img src="/files/64dc1680e765673bbd10b5333da71ae819405b8b" alt="" width="563"><figcaption></figcaption></figure></div>

次に **プロバイダを接続** をクリックします（モデル選択ダイアログの右上）。

<div data-with-frame="true"><figure><img src="/files/ea04495ff1b7f0aba3c12b9c25624a6d011546d0" alt="" width="375"><figcaption></figcaption></figure></div>

**2. 「カスタム」を選びます。** プロバイダ一覧で **その他** までスクロールし、 **カスタム**.

<div data-with-frame="true"><figure><img src="/files/b96ecf4b991c2c0c1c3b2e552e70c9b3085ce8ad" alt="" width="375"><figcaption></figcaption></figure></div>

**3. カスタムプロバイダのフォームに入力します:**

| 項目          | 値                                                                              |
| ----------- | ------------------------------------------------------------------------------ |
| **プロバイダID** | `unsloth-studio` *（小文字、ハイフン可）*                                                 |
| **表示名**     | `Unsloth Studio`                                                               |
| **ベースURL**  | `http://localhost:8888/v1/` *（置き換え `8888` あなたの* Unsloth *ポートに置き換え、末尾の `/v1/`)* |
| **APIキー**   | あなたの `sk-unsloth-…` キー                                                         |

の **モデル** セクションで、公開したいモデルごとに1行追加します。左の項目はUnslothが提供するモデルID、右の項目はopencodeに表示される内容です:

| モデルID（左）                                             | 表示名（右）                                      |
| ---------------------------------------------------- | ------------------------------------------- |
| `unsloth/Qwen3.6-27B-GGUF` *（Studioに表示されるモデルの正確な名前）* | `unsloth/Qwen3.6-27B-GGUF` *（opencode内に表示）* |

空欄のままにします **ヘッダー** 。ただし、カスタムヘッダーを必要とする認証レイヤー経由でUnslothをプロキシしている場合は別です。

<div data-with-frame="true"><figure><img src="/files/eae09e6a7d3cf864f60b120c9daa15e0461ea066" alt="" width="375"><figcaption></figcaption></figure></div>

**4. 送信をクリックします。** 次の *「Unsloth Studio に接続しました。Unsloth のモデルが使用可能になりました」* というトースト通知が表示されるはずです。

<figure><img src="/files/76b1046f86f21d02062e9412d800191bdc2cd4e1" alt="" width="375"><figcaption></figcaption></figure>

{% hint style="warning" %}
**プロバイダを追加したらopencodeを再起動します。** 新しいプロバイダは再起動後にのみ選択可能になります。
{% endhint %}

**5. Unslothのモデルを選択します。** opencodeが再起動したら、 `/model`と入力して検索し、 `unsloth`を検索し、 **Unsloth Studio** グループの下にあるモデルを選びます。次のメッセージから有効になります。

<div data-with-frame="true"><figure><img src="/files/55d552c4ba0889a3dc3ee69f60efe59ba53d5647" alt="" width="375"><figcaption></figcaption></figure></div>

UnslothはOpenAIとAnthropicのPython SDKの両方をサポートしています。

### 任意: サーバーアクセスを設定する

`unsloth run` はローカルAPIサーバーを起動し、OpenCodeが接続するためのモデルを読み込みます。起動時のサーバーの動作もカスタマイズできます。

```bash
# APIをポート8888で実行（--disable-toolsはOpenCode独自のツールをそのまま通します）
unsloth run \\
  --model unsloth/gemma-4-26B-A4B-it-GGUF \\
  --disable-tools \\
  -p 8888
```

{% hint style="warning" %}
使います `--disable-tools` OpenCode（または他の外部コーディングエージェント）を操作するときに使用します。デフォルトではUnsloth Studioが独自のサーバー側ツールを実行し、エージェントのツール呼び出しを取り込んでしまうため、OpenCodeは応答しますがファイルは編集されません。 `--disable-tools` パススルーに切り替わり、OpenCode独自のツールが使用されます。
{% endhint %}

使います `-p` で、サーバーが実行するポートを変更します。

```bash
# ネットワーク上の他のデバイスからの接続を許可する
unsloth run \\
  --model unsloth/gemma-4-26B-A4B-it-GGUF \\
  -H 0.0.0.0 \\
  --disable-tools \\
  -p 8888
```

これによりサーバーは `0.0.0.0:8888`で起動し、ローカルネットワーク上の他のデバイスが接続できるようになります。

より高度な実行時設定については、メインの [APIチューニング](https://unsloth.ai/docs/basics/api#unsloth-run-command) セクションを参照してください。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://unsloth.ai/docs/jp/tong-he/opencode.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
