> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/shi-yong-dai-ma-kuo-zhan/ai-assistant.md).

# AI 助手

在 Creator Hub 内通过与 AI 助手聊天来构建和修改你的场景。

Creator Hub 可以运行一个 AI 助手，它能看到你打开的场景并为你编辑。你可以让它放置物品、连接行为、编写脚本，或运行预览并检查结果。

该助手是一个实验性功能，默认关闭。

{% hint style="warning" %}
**📔 注意**：该助手运行的是一个你需要安装并登录的编码 CLI，它可完全访问你的机器，权限与它在终端中的权限相同。只有在你信任自己交给它的操作时才启用它。
{% endhint %}

## 将其打开

1. 打开设置（右上角的齿轮图标）。
2. 前往 **实验性** 选项卡中。
3. 开启 **启用 AI 助手**.

启用后， **AI 助手** 按钮会出现在编辑器顶部栏中。点击它可在场景旁打开聊天面板。

## 连接一个编码 CLI

该助手不使用自己的 API 密钥。它运行的是你安装并登录的编码 CLI，因此费用会计入该工具自己的订阅。

目前支持两个：

| CLI         | 安装                                   | 登录            |
| ----------- | ------------------------------------ | ------------- |
| Claude Code | `npm i -g @anthropic-ai/claude-code` | `claude`      |
| Codex       | `npm i -g @openai/codex`             | `codex login` |

你可以在 Creator Hub 内完成此操作。在设置中，位于 **连接**下，每个检测到的 CLI 都会显示其状态以及一个 **登录** 链接，它会为你运行登录并打开浏览器。绿色圆点和 **已连接** 表示它已准备就绪。 **退出登录** 会断开它。

如果你想自己操作，请打开 **通过终端** CLI 下的部分。它会提供准确的 **安装** 和 **登录** 命令供你复制。

首次在未连接 CLI 的情况下打开聊天面板时，会显示同样的设置卡片。

{% hint style="info" %}
**💡 提示**：如果你登录了多个 CLI，聊天面板中的下拉菜单可让你在它们之间切换。
{% endhint %}

### 改为计入 API 密钥

如果你更愿意按 token 付费而不是使用 CLI 订阅，请开启 **改为计入 API 密钥** 在设置中。它会读取 `ANTHROPIC_API_KEY` 或 `OPENAI_API_KEY` 来自你的环境变量。默认关闭。

## 它可以做什么

该助手会在你当前打开的场景中工作。它可以：

* **编辑场景**：创建和删除实体，更改组件，放置 [智能物品](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items.md)，附加 [脚本](/creator/content-creator-zh/chang-jing-bian-ji-qi/shi-yong-dai-ma-kuo-zhan/script-component.md)，以及读取和写入 `scene.json`.
* **编写代码** 到你场景的文件中。
* **运行预览** 并操作它：截屏、四处走动、点击对象、读取日志并检查性能。
* **读取你的所选内容**，这样你就可以选中一个实体并说“让这个更高一些”。

更改会在发生时自动保存，并进入常规撤销历史。若要一次撤回整轮对话，请使用 **撤销 AI 更改** 在助手回复中的选项。

## 使用聊天功能

* **新聊天** 会开始一个新的对话。
* **聊天记录** 列出更早的对话以及它们运行于多久之前。对话会按项目保存，因此重新打开某个场景时会恢复其聊天记录。
* **在单独窗口中打开** 会将助手弹出到它自己的窗口中，在第二台显示器上很方便。 **重新停靠到编辑器中** 会将其返回。
* 面板可以拖宽或拖窄。

一个 **关于 AI 使用情况** 卡片会提醒你，助手会消耗你已连接账户中的 token。请留意该账户的使用情况。

如果你的 Claude CLI 版本过旧，面板会显示警告。运行 `claude update` 在终端中修复它。

## Decentraland 技能会自动为你安装

当助手运行时，Creator Hub 会下载官方的 [Decentraland SDK 技能](/creator/content-creator-zh/chang-jing-sdk7/ru-men/vibe-coding.md) 并将它们链接到你的项目中，这样助手就会遵循经过验证的 SDK7 模式，而不是靠猜测。

它们会链接在 `.claude/skills` 和 `.agents/skills` ，位于你的项目文件夹内，并且两者都会被添加到 `.gitignore` 中，因此它们不会进入你的仓库。

## 改用你自己的 AI 工具

如果你已经在使用 Claude Code、Cursor、Codex，或其他支持 MCP 的工具，你可以让它指向当前打开的场景，而不是使用内置面板。MCP（模型上下文协议，Model Context Protocol）是一种让 AI 工具调用另一个程序的标准方式。

1. 在设置中，位于 **实验性** 选项卡下，展开 **公开 AI 助手 MCP 服务器**.
2. 点击 **复制配置**.
3. 将其粘贴到你的工具的 MCP 配置中。

复制的配置如下所示，其中已填入真实的端口和令牌：

```json
{
  "mcpServers": {
    "creator-hub": {
      "type": "http",
      "url": "http://127.0.0.1:<PORT>/mcp",
      "headers": { "Authorization": "Bearer <TOKEN>" }
    }
  }
}
```

对于 Claude Code，你也可以在场景文件夹中的终端里添加它：

```bash
claude mcp add --transport http --scope local creator-hub http://127.0.0.1:<PORT>/mcp \\
  --header "Authorization: Bearer <TOKEN>"
```

{% hint style="warning" %}
**📔 注意**：每次 Creator Hub 启动时，端口和令牌都会重新生成。如果你的工具突然出现 `401` 错误，请重新复制配置。该服务器只监听你自己的机器，并且只会对你当前打开的场景生效。
{% endhint %}

## 相关页面

* [使用 AI 进行 Vibe Coding](/creator/content-creator-zh/chang-jing-sdk7/ru-men/vibe-coding.md)：关于 SDK 技能和良好提示的完整指南。
* [与代码结合使用](/creator/content-creator-zh/chang-jing-bian-ji-qi/shi-yong-dai-ma-kuo-zhan/overview.md)：在代码编辑器中打开你的场景。
* [使用脚本组件](/creator/content-creator-zh/chang-jing-bian-ji-qi/shi-yong-dai-ma-kuo-zhan/script-component.md)：从文件中为实体附加行为。


---

# 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://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/shi-yong-dai-ma-kuo-zhan/ai-assistant.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.
