@praeviso/code-env-switch 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +18 -0
- package/.vscode/settings.json +4 -0
- package/LICENSE +21 -0
- package/README.md +184 -32
- package/README_zh.md +241 -0
- package/bin/codenv.js +1289 -350
- package/code-env.example.json +25 -23
- package/package.json +13 -1
- package/src/codenv.ts +1478 -0
- package/tsconfig.json +12 -0
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: {
|
|
4
|
+
node: true,
|
|
5
|
+
es2021: true,
|
|
6
|
+
},
|
|
7
|
+
parser: "@typescript-eslint/parser",
|
|
8
|
+
parserOptions: {
|
|
9
|
+
ecmaVersion: 2021,
|
|
10
|
+
sourceType: "module",
|
|
11
|
+
},
|
|
12
|
+
plugins: ["@typescript-eslint"],
|
|
13
|
+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
|
14
|
+
ignorePatterns: ["bin/", "node_modules/"],
|
|
15
|
+
rules: {
|
|
16
|
+
"no-constant-condition": ["error", { "checkLoops": false }]
|
|
17
|
+
}
|
|
18
|
+
};
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Krito.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,19 +2,60 @@
|
|
|
2
2
|
|
|
3
3
|
A tiny CLI to switch between Claude Code and Codex environment variables.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[中文说明](README_zh.md)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Manage multiple profiles and switch by name or type
|
|
10
|
+
- `codenv use` prints shell commands for the current terminal
|
|
11
|
+
- Interactive profile creation and selection
|
|
12
|
+
- Optional cleanup via `removeFiles` and post-switch `commands`
|
|
13
|
+
- Config auto-discovery and type-based default `unset` keys
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
1) Install:
|
|
8
18
|
|
|
9
19
|
```bash
|
|
10
|
-
|
|
20
|
+
npm install -g @praeviso/code-env-switch
|
|
11
21
|
```
|
|
12
22
|
|
|
13
|
-
2)
|
|
23
|
+
2) Add profiles interactively (this creates `~/.config/code-env/config.json` if missing):
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
codenv add
|
|
27
|
+
# run it again to add the second type
|
|
28
|
+
codenv add
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Example session:
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
$ codenv add
|
|
35
|
+
Select type (1=codex, 2=claude): 1
|
|
36
|
+
Profile name (default: default): primary
|
|
37
|
+
Base URL (required): https://api.example.com/v1
|
|
38
|
+
API key (required): YOUR_API_KEY
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
3) Set defaults per type:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
codenv default codex primary
|
|
45
|
+
codenv default claude default
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
4) Enable auto-apply in your shell:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
codenv init
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Open a new terminal (or `source ~/.bashrc` / `source ~/.zshrc`) to auto-apply the defaults.
|
|
55
|
+
|
|
56
|
+
For local development install:
|
|
14
57
|
|
|
15
58
|
```bash
|
|
16
|
-
npm install -g code-env-switch
|
|
17
|
-
# or local dev
|
|
18
59
|
npm install -g .
|
|
19
60
|
# or
|
|
20
61
|
npm link
|
|
@@ -22,69 +63,180 @@ npm link
|
|
|
22
63
|
|
|
23
64
|
## Usage
|
|
24
65
|
|
|
25
|
-
|
|
66
|
+
> By default, `codenv use` only outputs shell commands. After running
|
|
67
|
+
> `codenv init`, the shell wrapper applies them automatically.
|
|
68
|
+
|
|
69
|
+
### Common commands
|
|
26
70
|
|
|
27
71
|
```bash
|
|
28
72
|
codenv list
|
|
73
|
+
codenv show codex primary
|
|
74
|
+
codenv default codex primary
|
|
75
|
+
codenv remove codex primary
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`codenv list` (or `codenv ls`) prints a table with `PROFILE`, `TYPE`, and `NOTE`. Default profiles are labeled in the `NOTE` column, and the active profile is shown in green.
|
|
79
|
+
If `profile.name` is set, it is shown in `PROFILE`. Otherwise the profile key is shown (with legacy `type-` prefixes stripped when possible).
|
|
80
|
+
|
|
81
|
+
### Add / update a profile
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
codenv add primary OPENAI_BASE_URL=https://api.example.com/v1 OPENAI_API_KEY=YOUR_API_KEY --note "Primary endpoint"
|
|
85
|
+
# with explicit type (codex/claude, claude also accepts cc)
|
|
86
|
+
codenv add --type codex primary OPENAI_BASE_URL=https://api.example.com/v1 OPENAI_API_KEY=YOUR_API_KEY
|
|
29
87
|
```
|
|
30
88
|
|
|
31
|
-
|
|
89
|
+
When `--type` is set, the profile name is kept as-is and `type` is stored separately.
|
|
90
|
+
Profiles are keyed by an internal id; the human-facing name lives in `profile.name`.
|
|
91
|
+
|
|
92
|
+
Interactive add (default):
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
codenv add
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Remove a profile
|
|
32
99
|
|
|
33
100
|
```bash
|
|
34
|
-
codenv
|
|
101
|
+
codenv remove primary
|
|
102
|
+
# or by type + name (recommended when names overlap)
|
|
103
|
+
codenv remove codex primary
|
|
104
|
+
# multiple at once
|
|
105
|
+
codenv remove codex primary claude default
|
|
106
|
+
# (legacy keys like codex-primary also work)
|
|
107
|
+
codenv remove codex-primary claude-default
|
|
108
|
+
# remove all
|
|
109
|
+
codenv remove --all
|
|
35
110
|
```
|
|
36
111
|
|
|
37
|
-
Switch in the current shell (bash/zsh)
|
|
112
|
+
### Switch in the current shell (bash/zsh)
|
|
38
113
|
|
|
39
114
|
```bash
|
|
40
|
-
|
|
115
|
+
codenv use
|
|
116
|
+
# use up/down then Enter (q to exit)
|
|
117
|
+
codenv use primary
|
|
118
|
+
# or by type + name (also matches legacy keys like codex-primary)
|
|
119
|
+
codenv use codex primary
|
|
120
|
+
codenv use cc primary
|
|
41
121
|
```
|
|
42
122
|
|
|
43
|
-
|
|
123
|
+
First run `codenv init` once to install the shell wrapper:
|
|
44
124
|
|
|
45
125
|
```bash
|
|
126
|
+
codenv init
|
|
127
|
+
# or target a specific shell
|
|
128
|
+
codenv init --shell zsh
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
This wrapper makes `codenv use` and `codenv unset` apply automatically in the
|
|
132
|
+
current shell. To print the snippet without writing to rc, use
|
|
133
|
+
`codenv init --print`.
|
|
134
|
+
|
|
135
|
+
### Auto-apply default profiles (per type)
|
|
136
|
+
|
|
137
|
+
Set a default per type (codex/claude) and re-run `codenv init`:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
codenv default codex primary
|
|
141
|
+
codenv default claude default
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"defaultProfiles": {
|
|
147
|
+
"codex": "primary",
|
|
148
|
+
"claude": "default"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
On new terminal sessions, `codenv` will auto-apply all defaults via `codenv auto`.
|
|
154
|
+
To clear all defaults, run `codenv default --clear` (with confirmation).
|
|
155
|
+
|
|
156
|
+
One-off without init:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
eval "$(codenv use codex primary)"
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Note: the change takes effect in new terminals. To apply immediately, run:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
source ~/.bashrc
|
|
166
|
+
# or for zsh
|
|
167
|
+
source ~/.zshrc
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Unset known keys
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
codenv unset
|
|
174
|
+
# or one-off without init
|
|
46
175
|
eval "$(codenv unset)"
|
|
47
176
|
```
|
|
48
177
|
|
|
49
|
-
###
|
|
178
|
+
### Fish shell
|
|
179
|
+
|
|
180
|
+
```fish
|
|
181
|
+
codenv use codex primary
|
|
182
|
+
# or one-off without init
|
|
183
|
+
codenv use codex primary | source
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Config lookup order
|
|
50
187
|
|
|
51
188
|
`codenv` searches in this order:
|
|
52
189
|
|
|
53
190
|
1) `--config <path>`
|
|
54
191
|
2) `CODE_ENV_CONFIG`
|
|
55
|
-
3)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
192
|
+
3) `~/.config/code-env/config.json`
|
|
193
|
+
|
|
194
|
+
Use `codenv config` to print the path selected for the current directory.
|
|
195
|
+
|
|
196
|
+
If nothing is found, `codenv add` writes to `~/.config/code-env/config.json`.
|
|
59
197
|
|
|
60
198
|
## Config format
|
|
61
199
|
|
|
62
200
|
```json
|
|
63
201
|
{
|
|
64
|
-
"unset": [
|
|
202
|
+
"unset": [],
|
|
203
|
+
"defaultProfiles": {
|
|
204
|
+
"codex": "primary",
|
|
205
|
+
"claude": "default"
|
|
206
|
+
},
|
|
65
207
|
"profiles": {
|
|
66
|
-
"
|
|
67
|
-
"
|
|
208
|
+
"p_a1b2c3": {
|
|
209
|
+
"name": "primary",
|
|
210
|
+
"type": "codex",
|
|
211
|
+
"note": "Primary endpoint",
|
|
68
212
|
"env": {
|
|
69
|
-
"OPENAI_BASE_URL": "https://api.
|
|
70
|
-
"OPENAI_API_KEY": "
|
|
71
|
-
"CODEX_PROVIDER": "OpenAI"
|
|
213
|
+
"OPENAI_BASE_URL": "https://api.example.com/v1",
|
|
214
|
+
"OPENAI_API_KEY": "YOUR_API_KEY"
|
|
72
215
|
},
|
|
73
|
-
"removeFiles": ["$HOME/.config/
|
|
74
|
-
"commands": ["echo \"Switched to codex
|
|
216
|
+
"removeFiles": ["$HOME/.config/example/auth.json"],
|
|
217
|
+
"commands": ["echo \"Switched to codex primary\""]
|
|
75
218
|
}
|
|
76
219
|
}
|
|
77
220
|
}
|
|
78
221
|
```
|
|
79
222
|
|
|
80
223
|
Notes:
|
|
81
|
-
- `
|
|
82
|
-
- `
|
|
83
|
-
- `
|
|
84
|
-
- `
|
|
224
|
+
- `unset`: global keys to clear. Type-specific defaults are applied only for the active type and won't clear the other type.
|
|
225
|
+
- `defaultProfiles`: optional; map of `codex`/`claude` to profile name or key used by `codenv auto`.
|
|
226
|
+
- `name`: human-facing profile name shown in `codenv list` and used by `codenv use <name>`.
|
|
227
|
+
- `type`: optional; `codex` or `claude` (alias `cc`) for `codenv use <type> <name>` matching.
|
|
228
|
+
- `note`: shown in `codenv list`.
|
|
229
|
+
- `removeFiles`: optional; `codenv use` emits `rm -f` for each path. Codex profiles also remove `~/.codex/auth.json`.
|
|
230
|
+
- `ANTHROPIC_AUTH_TOKEN`: when `ANTHROPIC_API_KEY` is set, `codenv use` also exports `ANTHROPIC_AUTH_TOKEN` with the same value.
|
|
231
|
+
- `commands`: optional; emitted as-is in the switch script.
|
|
85
232
|
|
|
86
|
-
##
|
|
233
|
+
## Security
|
|
87
234
|
|
|
88
|
-
|
|
89
|
-
|
|
235
|
+
Your config contains API keys. Keep it private and out of public repositories.
|
|
236
|
+
|
|
237
|
+
## Development
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
npm install
|
|
241
|
+
npm run build
|
|
90
242
|
```
|
package/README_zh.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# code-env-switch
|
|
2
|
+
|
|
3
|
+
一个轻量的 CLI,用于在 Claude Code 与 Codex 的环境变量之间快速切换。
|
|
4
|
+
|
|
5
|
+
[English](README.md)
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- 多 profile 管理,按名称或类型切换
|
|
10
|
+
- `codenv use` 输出可执行的 shell 命令,方便在当前终端生效
|
|
11
|
+
- 支持交互式添加与选择 profile
|
|
12
|
+
- 支持 `removeFiles` 与 `commands` 做清理与自动化
|
|
13
|
+
- 配置文件自动发现与按类型自动补充 `unset` 键
|
|
14
|
+
|
|
15
|
+
## 快速开始
|
|
16
|
+
|
|
17
|
+
1) 安装:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @praeviso/code-env-switch
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
2) 交互式添加 profile(若不存在会创建 `~/.config/code-env/config.json`):
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
codenv add
|
|
27
|
+
# 再执行一次,用来添加另一种 type
|
|
28
|
+
codenv add
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
交互示例:
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
$ codenv add
|
|
35
|
+
Select type (1=codex, 2=claude): 1
|
|
36
|
+
Profile name (default: default): primary
|
|
37
|
+
Base URL (required): https://api.example.com/v1
|
|
38
|
+
API key (required): YOUR_API_KEY
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
3) 按 type 设置默认项:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
codenv default codex primary
|
|
45
|
+
codenv default claude default
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
4) 启用自动应用:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
codenv init
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
新开终端(或执行 `source ~/.bashrc` / `source ~/.zshrc`)即可自动应用默认配置。
|
|
55
|
+
|
|
56
|
+
本地开发可用:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install -g .
|
|
60
|
+
# 或
|
|
61
|
+
npm link
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 使用方法
|
|
65
|
+
|
|
66
|
+
> 默认情况下,`codenv use` 仅输出 shell 命令;执行 `codenv init` 后,
|
|
67
|
+
> shell 包装函数会自动在当前终端生效。
|
|
68
|
+
|
|
69
|
+
### 常用命令
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
codenv list
|
|
73
|
+
codenv show codex primary
|
|
74
|
+
codenv default codex primary
|
|
75
|
+
codenv remove codex primary
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`codenv list`(或 `codenv ls`)会输出 `PROFILE` / `TYPE` / `NOTE` 的表格。默认项会标注在 `NOTE` 列,当前激活的配置会用绿色显示。
|
|
79
|
+
如果设置了 `profile.name`,`PROFILE` 列会显示该名称;否则显示 profile 的 key(会尽量去掉旧的 `type-` 前缀)。
|
|
80
|
+
|
|
81
|
+
### 添加 / 更新 profile
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
codenv add primary OPENAI_BASE_URL=https://api.example.com/v1 OPENAI_API_KEY=YOUR_API_KEY --note "Primary endpoint"
|
|
85
|
+
# 指定 type(codex/claude,claude 也可写 cc)
|
|
86
|
+
codenv add --type codex primary OPENAI_BASE_URL=https://api.example.com/v1 OPENAI_API_KEY=YOUR_API_KEY
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
当设置 `--type` 时,名称保持不变,`type` 会单独存储。
|
|
90
|
+
profiles 使用内部 key,展示名称存放在 `profile.name`。
|
|
91
|
+
|
|
92
|
+
交互式添加(默认):
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
codenv add
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 删除 profile
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
codenv remove primary
|
|
102
|
+
# 或按类型 + 名称(名称重复时推荐)
|
|
103
|
+
codenv remove codex primary
|
|
104
|
+
# 一次删多个
|
|
105
|
+
codenv remove codex primary claude default
|
|
106
|
+
# (也兼容形如 codex-primary 的旧 key)
|
|
107
|
+
codenv remove codex-primary claude-default
|
|
108
|
+
# 全部删除
|
|
109
|
+
codenv remove --all
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 切换并生效(bash/zsh)
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
codenv use
|
|
116
|
+
# 上下选择,回车确认(q 退出)
|
|
117
|
+
codenv use primary
|
|
118
|
+
# 或按类型 + 名称匹配(也兼容形如 codex-primary 的旧 key)
|
|
119
|
+
codenv use codex primary
|
|
120
|
+
codenv use cc primary
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
先执行一次 `codenv init` 安装 shell 包装函数:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
codenv init
|
|
127
|
+
# 或指定 shell
|
|
128
|
+
codenv init --shell zsh
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
该包装函数会让 `codenv use` 和 `codenv unset` 在当前终端自动生效。
|
|
132
|
+
如果只想打印片段而不写入,可用 `codenv init --print`。
|
|
133
|
+
|
|
134
|
+
### 默认 profile 自动生效(按 type)
|
|
135
|
+
|
|
136
|
+
为不同 type 设置默认 profile,并重新执行一次 `codenv init`:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
codenv default codex primary
|
|
140
|
+
codenv default claude default
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"defaultProfiles": {
|
|
146
|
+
"codex": "primary",
|
|
147
|
+
"claude": "default"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
之后每次新开终端都会自动执行 `codenv auto` 应用所有默认配置。
|
|
153
|
+
如需清除全部默认设置,可执行 `codenv default --clear`(需确认)。
|
|
154
|
+
|
|
155
|
+
如果不想安装,可一次性执行:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
eval "$(codenv use codex primary)"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
注意:写入后对新终端生效;如需立刻生效,可执行:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
source ~/.bashrc
|
|
165
|
+
# 或 zsh
|
|
166
|
+
source ~/.zshrc
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 清理已知键
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
codenv unset
|
|
173
|
+
# 或一次性执行
|
|
174
|
+
eval "$(codenv unset)"
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Fish shell
|
|
178
|
+
|
|
179
|
+
```fish
|
|
180
|
+
codenv use codex primary
|
|
181
|
+
# 或一次性执行
|
|
182
|
+
codenv use codex primary | source
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## 配置文件查找顺序
|
|
186
|
+
|
|
187
|
+
`codenv` 按以下顺序查找:
|
|
188
|
+
|
|
189
|
+
1) `--config <path>`
|
|
190
|
+
2) `CODE_ENV_CONFIG`
|
|
191
|
+
3) `~/.config/code-env/config.json`
|
|
192
|
+
|
|
193
|
+
可用 `codenv config` 输出当前目录会使用的配置路径。
|
|
194
|
+
|
|
195
|
+
`codenv add` 在找不到配置时,会默认写入 `~/.config/code-env/config.json`。
|
|
196
|
+
|
|
197
|
+
## 配置格式
|
|
198
|
+
|
|
199
|
+
```json
|
|
200
|
+
{
|
|
201
|
+
"unset": [],
|
|
202
|
+
"defaultProfiles": {
|
|
203
|
+
"codex": "primary",
|
|
204
|
+
"claude": "default"
|
|
205
|
+
},
|
|
206
|
+
"profiles": {
|
|
207
|
+
"p_a1b2c3": {
|
|
208
|
+
"name": "primary",
|
|
209
|
+
"type": "codex",
|
|
210
|
+
"note": "Primary endpoint",
|
|
211
|
+
"env": {
|
|
212
|
+
"OPENAI_BASE_URL": "https://api.example.com/v1",
|
|
213
|
+
"OPENAI_API_KEY": "YOUR_API_KEY"
|
|
214
|
+
},
|
|
215
|
+
"removeFiles": ["$HOME/.config/example/auth.json"],
|
|
216
|
+
"commands": ["echo \"Switched to codex primary\""]
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
说明:
|
|
223
|
+
- `unset`:全局需要清理的环境变量。按 type 的默认清理键只会对当前 type 生效,不会影响其他 type。
|
|
224
|
+
- `defaultProfiles`:可选;`codex`/`claude` 对应的默认 profile 名称或 key,供 `codenv auto` 使用。
|
|
225
|
+
- `name`:用于展示的 profile 名称,`codenv list` 与 `codenv use <name>` 会使用它。
|
|
226
|
+
- `type`:可选,`codex` 或 `claude`(别名 `cc`),便于用 `codenv use <type> <name>` 匹配。
|
|
227
|
+
- `note`:显示在 `codenv list` 输出中。
|
|
228
|
+
- `removeFiles`:可选;`codenv use` 会输出对应 `rm -f`。Codex profile 还会删除 `~/.codex/auth.json`。
|
|
229
|
+
- `ANTHROPIC_AUTH_TOKEN`:当设置了 `ANTHROPIC_API_KEY` 时,`codenv use` 会自动以同样的值导出 `ANTHROPIC_AUTH_TOKEN`。
|
|
230
|
+
- `commands`:可选;原样输出到切换脚本中。
|
|
231
|
+
|
|
232
|
+
## 安全提示
|
|
233
|
+
|
|
234
|
+
配置文件包含 API key,请妥善保存并避免提交到公共仓库。
|
|
235
|
+
|
|
236
|
+
## 开发
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
npm install
|
|
240
|
+
npm run build
|
|
241
|
+
```
|