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

# 环境变量

> 通过环境变量为当前 Shell 会话设置 difyctl 的默认值

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

环境变量为当前 Shell 会话设置默认值：会话中运行的每条 `difyctl` 命令都会读取它们。优先级上，命令行参数高于环境变量。环境变量的作用域限于当前 Shell，仅在会话期间有效。

## difyctl 读取的变量

| 变量                   | 作用                                                                                                      | 默认值                                                                                                  |
| :------------------- | :------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------------------------- |
| `DIFY_CONFIG_DIR`    | `difyctl` 存放配置文件（`hosts.yml`）的位置。                                                                       | macOS 和 Linux：`~/.config/difyctl`（Linux 遵循 `XDG_CONFIG_HOME`）<br /><br />Windows：`%APPDATA%\difyctl` |
| `DIFY_LIMIT`         | 列表命令（`get app`、`auth devices list`）的默认页大小，取值 1 到 200。优先级上，`--limit` 参数高于该变量。                            | `20`                                                                                                 |
| `DIFY_WORKSPACE_ID`  | `difyctl` 命令所针对的工作空间，必须为 UUID。解析顺序详见 [difyctl 如何选择工作空间](/zh/cli/reference/workspaces#difyctl-如何选择工作空间)。 | 无                                                                                                    |
| `DIFYCTL_HTTP_RETRY` | 幂等请求遇到瞬时故障时的重试次数（`0` 表示禁用重试）。[`--http-retry`](/zh/cli/reference/global-flags#http-重试) 会覆盖它。             | `3`                                                                                                  |

无效的值会作为用法错误失败（退出码 `2`），而不会被静默忽略，例如非 UUID 的 `DIFY_WORKSPACE_ID`。

<Info>
  只有上表中的变量会影响 `difyctl` 的行为。`env list` 命令列出的其他变量虽被识别，但目前不起作用。
</Info>

## 查看已设置的变量

```text theme={null}
difyctl env list [flags]
```

`env list` 显示当前 Shell 中每个 `difyctl` 环境变量的值。它只读取本地环境，从不调用服务器，因此登录前也能使用。

### 标志

| 标志       | 类型      | 默认值     | 说明                    |
| :------- | :------ | :------ | :-------------------- |
| `--json` | boolean | `false` | 将清单以 JSON 数组而非表格形式输出。 |

<Note>
  `env list` 接受的是 `--json`，而非 [`-o` 全局参数](/zh/cli/reference/global-flags)。
</Note>

### 示例

查看当前 Shell 中设置了哪些变量：

```bash theme={null}
difyctl env list
```

以 JSON 形式获取同一份清单：

```bash theme={null}
difyctl env list --json
```

### 输出

未设置的变量显示为 `<unset>`，敏感变量从不输出其值（只显示 `<set>` 或 `<unset>`）。当 `DIFY_LIMIT=50` 已导出时：

```text theme={null}
NAME                VALUE    DESCRIPTION
DIFY_CONFIG_DIR     <unset>  Override the config-dir resolution (precedes XDG_CONFIG_HOME on Linux).
DIFY_FORMAT         <unset>  Default output format for list commands (table | json | yaml | wide | name).
DIFY_HOST           <unset>  Default Dify host (overridden by --host).
DIFY_LIMIT          50       Default page size for list commands (1..200).
DIFY_NO_PROGRESS    <unset>  Suppress progress spinners. Truthy values: 1, true, yes.
DIFY_PLAIN          <unset>  Disable ANSI colors and decorative output. Truthy values: 1, true, yes.
DIFY_TOKEN          <unset>  Bearer token for non-interactive auth.
DIFY_WORKSPACE_ID   <unset>  Workspace ID used for difyctl commands.
DIFYCTL_HTTP_RETRY  <unset>  HTTP retry count for GET/PUT/DELETE. 0 disables. Overrides --http-retry flag.
```

`--json` 输出一个 JSON 数组，每个变量一项，掩码方式与上面相同：

```json theme={null}
[
  {
    "name": "DIFY_CONFIG_DIR",
    "description": "Override the config-dir resolution (precedes XDG_CONFIG_HOME on Linux).",
    "sensitive": false,
    "value": "<unset>"
  }
]
```

### 退出码

| 退出码 | 含义 |
| :-- | :- |
| `0` | 成功 |

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