> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trae.cn/llms.txt?lang=zh
> Use this file to discover all available pages before exploring further.

在会话中，使用斜杠命令执行快捷操作、管理会话状态，并自定义常用工作流。

## 内置斜杠命令 {#b6712d14}

TraeCode CLI 提供以下内置斜杠命令。

<!-- @cols-width: 153,398 -->
| **命令**  | **目的**  |
| --- | --- |
| /agent-new  | 创建一个新的自定义智能体。  |
| /clear 或 /reset  | 清空对话历史并释放上下文。  |
| /feedback  | 提交反馈或报告问题。  |
| /init  | 为当前目录初始化一个新的 AGENTS.md 文件。  |
| /login  | 登录 TraeCode CLI。  |
| /logout  | 登出 TraeCode CLI。  |
| /mcp  | 管理 MCP Server 和工具。  |
| /model  | 切换所使用的 AI 模型。  |
| /plugin 或 /plugins  | 管理插件。  |
| /status  | 展示 TRAE CLI 的状态信息。  |
| /terminal-setup  | 安装用于换行的 Shift+Enter 快捷键。  |
| /skills  | 展示可用的技能。  |

## 自定义斜杠命令 {#cf8d916c}

你可以将常用的提示词定义为 Markdown 文件，并由 TraeCode CLI 将其作为自定义斜杠命令来执行。

### 语法 {#3b25542e}

自定义斜杠命令的语法如下：

```Plain Text
/<command-name> [arguments]
```

参数说明如下：

<!-- @cols-width: 171,500 -->
| **参数**  | **描述**  |
| --- | --- |
| `<command-name>`  | 由 Markdown 文件名（不含 `.md` 扩展名）派生的名称。  |
| `[arguments]`  | 传递给该命令的可选参数。  |

### 创建自定义斜杠命令 {#e2cc6b52}

1. 使用 `mkdir -p .traecli/commands` 命令，在项目的根目录中创建 `.traecli/commands` 目录。
2. 使用 `cd .traecli/commands` 命令，进入 `.traecli/commands` 目录。
3. 在 `.traecli/commands` 目录下创建 Markdown 格式的自定义斜杠命令配置文件。
4. 配置自定义斜杠命令并保存。
   Frontmatter 字段说明如下：
   <!-- @cols-width: 117,326,398 -->
   | **Frontmatter**  | **描述**  | **示例**  |
   | --- | --- | --- |
   | description  | 该自定义斜杠命令的简介。  | `Review code changes with context`  |
   | argument-hint  | 斜杠命令（`/`）所需的参数。在用户进行斜杠命令自动补全时，会向用户显示这一提示。  | `argument-hint: add [tagId] | remove [tagId] | list`  |
   | tools  | 指定可使用的工具。多个工具间使用逗号分隔。  | `Read,Write,mcp__{$mcp_server_name}__{$tool_name}`  |
   | model  | 指定所使用的模型。  | `kimi-k2`  |
   示例如下：
   ```Markdown
   ---
   description: Review code changes with context
   argument-hint: <file-pattern>
   model: kimi-k2
   tools: Read
   ---
   
   ## Code Review Request
   
   Files to review: $1
   
   Current git diff: !`git diff HEAD -- $1`
   
   File structure: !`find . -name "$1" -type f | head -10`
   
   ## Your task
   
   Please perform a thorough code review of the specified files focusing on:
   
   1. **Code Quality**: Check for best practices, readability, and maintainability
   2. **Security**: Look for potential security vulnerabilities
   3. **Performance**: Identify potential performance issues
   4. **Testing**: Suggest areas that need test coverage
   5. **Documentation**: Check if code is properly documented
   
   Provide specific suggestions for improvement with line numbers where applicable.
   ```   


### 其他功能 {#eb52b5c6}

TraeCode CLI 提供了一系列特殊语法，用于在命令定义中动态引用参数、设定默认值以及插入系统命令执行结果，从而极大增强了自定义命令的灵活性和复用性。

#### `$ARGUMENTS` {#1241248b}

`$ARGUMENTS` 占位符会捕获传递给该命令的所有参数，多个参数之间使用空格分隔。示例如下：

```Bash
# 命令定义
echo 'Deploying service: $ARGUMENTS to the staging environment' > .traecli/commands/deploy-service.md

# 用法
> /deploy-service auth-api v2.3.1
# $ARGUMENTS 变成: "auth-api v2.3.1"
```

#### `$N` {#c71b1abb}

你可以像在 Shell 脚本中一样，通过位置参数 `$N` 来单独访问特定的参数。示例如下：

```Bash
# Command definition
echo 'Deploy service $1 to environment $2 with version $3' > .traecli/commands/deploy-service.md

# 用法
> /deploy-service auth staging v1.4.2
# $1 变成 "auth"，$2 变成 "staging"，$3 变成 "v1.4.2"
```

#### `!`command`` {#8203d060}

`!`command`` 用于执行指定命令，并将其标准输出结果作为文本内容直接插入到当前位置。

例如，在以下命令定义中，`!`cat VERSION` 会在 TRAE CLI 处理该文件时被执行。 TRAE CLI 会运行 `cat VERSION`，然后获取它的标准输出（例如 `1.4.0`），最后将 `!`cat VERSION` 这一段替换成输出内容。

```Bash
# 命令定义 
echo "Project version: !`cat VERSION`" > traecli/commands/show-version.md

# 替换后的文本
Project version: 1.4.0
```

#### `${N:-DefaultValue}` {#d5f1e587}

`${N:-DefaultValue}` 用来为变量提供默认值。

* 如果变量 `N` 没有被定义或值为空，使用 `DefaultValue` 作为替代值。
* 如果变量 `N` 已被定义且值非空，使用变量本身的值。

示例如下：

```Bash
# 命令定义
echo 'Deploying to environment: ${1:-staging}' > .traecli/commands/deploy.md

# 用法
# 情况一：用户提供了参数和定义 $1="production"
> /deploy production
# ${1:-staging} 变成 "production"

# 情况二：用户未提供参数，$1 未定义
> /deploy
# ${1:-staging} becomes "staging"
```
