> ## Documentation Index
> Fetch the complete documentation index at: https://dify-6c0370d8-docs-agent-app-service-api.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 工作空间

> 显示你的工作空间，并了解 difyctl 如何决定命令使用哪个工作空间

> 本文档由 AI 自动翻译。如有任何不准确之处，请参考 [英文原版](/en/cli/reference/workspaces)。

登录后，`difyctl` 会保存你的工作空间，并对它执行每一条命令。完整的解析顺序参见 [difyctl 如何选择工作空间](#difyctl-如何选择工作空间)。

[`difyctl get workspace`](#显示工作空间) 会显示你所属的工作空间，并接受 [全局标志](/zh/cli/reference/global-flags)。

## 显示工作空间

```text theme={null}
difyctl get workspace [flags]
```

### 标志

| 标志            | 类型     | 默认值  | 说明                                               |
| :------------ | :----- | :--- | :----------------------------------------------- |
| `-o <format>` | string | none | 输出格式：`json`、`yaml`、`name` 或 `wide`。省略此标志则使用默认表格。 |

### 示例

查看你的工作空间：

```bash theme={null}
difyctl get workspace
```

获取 JSON 格式，便于脚本处理：

```bash theme={null}
difyctl get workspace -o json
```

仅打印工作空间 ID：

```bash theme={null}
difyctl get workspace -o name
```

### 输出

| 格式                  | stdout 输出内容                                                        |
| :------------------ | :----------------------------------------------------------------- |
| default             | 对齐的表格。`CURRENT` 列以 `*` 标记当前激活的工作空间，`ROLE` 列为你的角色。                  |
| `-o wide`           | 相同的列。工作空间没有仅在 wide 格式下显示的列。                                        |
| `-o json`、`-o yaml` | 一个 `workspaces` 数组，每个条目包含 `id`、`name`、`role`、`status` 和 `current`。 |
| `-o name`           | 工作空间 ID。                                                           |

默认表格：

```text theme={null}
ID                                    NAME       ROLE    STATUS  CURRENT
b4e8d2a6-7c3f-4a1e-9d5b-8f2c6e0a4d7b  Acme Team  owner   normal  *
```

`-o json`：

```json theme={null}
{
  "workspaces": [
    {
      "id": "b4e8d2a6-7c3f-4a1e-9d5b-8f2c6e0a4d7b",
      "name": "Acme Team",
      "role": "owner",
      "status": "normal",
      "current": true
    }
  ]
}
```

### 退出码

| 退出码 | 含义                 |
| :-- | :----------------- |
| `0` | 成功                 |
| `1` | 网络或服务器错误           |
| `2` | 用法错误，例如不支持的 `-o` 值 |
| `4` | 认证失败               |
| `7` | 触发限流（HTTP 429）     |

完整方案参见 [输出格式与退出码](/zh/cli/reference/output-formats-and-exit-codes)。

## difyctl 如何选择工作空间

应用只属于一个工作空间，因此每条命令都对某一个工作空间执行。通常就是你登录时保存的那个。`difyctl` 按以下顺序解析，取首个找到的值：

1. [`DIFY_WORKSPACE_ID`](/zh/cli/reference/environment-variables) 环境变量，一个可选的覆盖项。
2. 你存储的默认值，登录时写入配置目录下的 `hosts.yml`。

如果两者都未指定工作空间，命令以退出码 `2` 失败。

工作空间 ID 是 UUID，因此请使用 [`get workspace`](#显示工作空间) 返回的 ID，而非工作空间名称。非 UUID 的值会作为用法错误失败。
