@qqq123456789/codex-doctor 0.2.0

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.
@@ -0,0 +1,74 @@
1
+ English | [中文](06-sandbox-windows.md)
2
+
3
+ # 06 · Approvals, Sandbox & Windows
4
+
5
+ > Keywords: `sandbox`, `exec denied`, writes refused, commands intercepted, sandbox quirks on Windows
6
+
7
+ ## Two core concepts
8
+
9
+ | Setting | Values | Meaning |
10
+ |---|---|---|
11
+ | `approval_policy` | `untrusted` / `on-failure` / `on-request` / `never` | When you get asked to confirm |
12
+ | `sandbox_mode` | `read-only` / `workspace-write` / `danger-full-access` | Which files the model may touch |
13
+
14
+ Common presets:
15
+
16
+ ```bash
17
+ codex # default: conservative, safety first
18
+ codex --full-auto # workspace-write + fewer interruptions — the daily-driver balance
19
+ codex --dangerously-bypass-approvals-and-sandbox # everything off — see the risk note below
20
+ ```
21
+
22
+ > ⚠️ **Risk note**: bypassing approvals and sandbox lets the model run arbitrary commands and read/write arbitrary files with your user privileges. Reserve it for disposable containers / VMs — don't run it long-term on your daily machine.
23
+
24
+ ## Common problems
25
+
26
+ ### Writes refused / commands intercepted
27
+
28
+ The sandbox is working, not broken. In order:
29
+
30
+ 1. `/status` to confirm the current `approval_policy` and `sandbox_mode`;
31
+ 2. `read-only` refuses all writes — switch to `workspace-write` for daily development;
32
+ 3. Writes **outside** the project directory (system dirs, your home dir) are refused too — keep projects in a normal user directory, not system-protected locations;
33
+ 4. Dependency installs / builds that keep getting intercepted: approve them in the prompt; for recurring commands, adjust the policy instead of clicking every time.
34
+
35
+ ### "Trust this folder" prompt on every launch
36
+
37
+ Newer versions no longer trust directories by default and ask on first use. If the prompt keeps coming back:
38
+
39
+ 1. Choose to trust the directory, then **restart the session**;
40
+ 2. `/status` to confirm trust state and the approval/sandbox settings took effect;
41
+ 3. VS Code users: also mark the folder as a Trusted Workspace in VS Code and reload the window — **both** sides must trust it;
42
+ 4. Still prompting on every launch: upgrade to the latest version — the prompt's persistence has been fixed repeatedly across versions (see [openai/codex #14547](https://github.com/openai/codex/issues/14547), [#14345](https://github.com/openai/codex/issues/14345)).
43
+
44
+ > Don't reach for `--dangerously-bypass-approvals-and-sandbox` just to skip the prompt — that's a different, bigger risk (see above).
45
+
46
+ ### Sandbox quirks on native Windows
47
+
48
+ Native Windows support is still maturing; most reported issues concentrate in the sandbox implementation:
49
+
50
+ - Upgrade to the latest version first (sandbox fixes land frequently);
51
+ - Make sure PowerShell execution policy isn't blocking scripts (see [01](01-installation.md));
52
+ - Stably reproducible even after upgrading → use the WSL2 route below, the most compatible path;
53
+ - Sharing projects between Windows and WSL causes "corrupted files / line-ending warnings": add a `.gitattributes` to pin line endings (e.g. `* text=auto eol=lf`) and stop the CRLF/LF ping-pong;
54
+ - Scripts and CI that need a fixed shell: specify the shell explicitly instead of relying on "the default shell" — on Windows it differs by terminal (PowerShell / cmd / Git Bash).
55
+
56
+ ## WSL2 route (the most reliable path)
57
+
58
+ ```powershell
59
+ # Admin PowerShell (installs Ubuntu by default)
60
+ wsl --install
61
+ ```
62
+
63
+ Then install Node and Codex inside Ubuntu per [01](01-installation.md). Key points:
64
+
65
+ 1. **Keep project files inside the WSL filesystem** (e.g. `~/projects/...`), not `/mnt/c/...` — cross-filesystem I/O is several times slower and permission behavior gets weird;
66
+ 2. VS Code: install the "WSL" extension, connect into WSL, then install the CLI and extension inside WSL — behaves like native Linux;
67
+ 3. Proxy must be configured separately inside WSL ([03](03-network-proxy.md)) — inside WSL, `127.0.0.1` points to WSL itself. Newer WSL2 offers a mirrored networking mode that shares the Windows-side proxy; alternatively enable "allow LAN connections" in your proxy client and point WSL at the Windows host gateway IP. Login-callback problems (browser authorized but credentials never arrive in WSL) are covered in [02's WSL section](02-login-auth.en.md).
68
+
69
+ ## When do you actually need danger-full-access
70
+
71
+ - Automation inside Docker / VMs / disposable cloud boxes;
72
+ - You know exactly what the model will do, and the task genuinely requires broad system access.
73
+
74
+ Even then, try `workspace-write` first — it covers most development work.
@@ -0,0 +1,74 @@
1
+ # 06 · 审批、沙箱与 Windows
2
+
3
+ > 报错关键词:`sandbox`、`exec denied`、写入文件被拒、命令被拦截、Windows 下各种沙箱异常
4
+ >
5
+ > English version: [06-sandbox-windows.en.md](06-sandbox-windows.en.md)
6
+
7
+ ## 两个核心概念
8
+
9
+ | 配置 | 可选值 | 含义 |
10
+ |---|---|---|
11
+ | `approval_policy` | `untrusted` / `on-failure` / `on-request` / `never` | 什么时候要你点确认 |
12
+ | `sandbox_mode` | `read-only` / `workspace-write` / `danger-full-access` | 模型能碰哪些文件、能不能联网 |
13
+
14
+ 常用组合:
15
+
16
+ ```bash
17
+ codex # 默认:较保守,安全优先
18
+ codex --full-auto # workspace-write + 少打扰,日常开发的平衡点
19
+ codex --dangerously-bypass-approvals-and-sandbox # 全关,见下方风险提示
20
+ ```
21
+
22
+ > ⚠️ **风险提示**:完全绕过审批与沙箱等于让模型直接以你的用户权限执行任意命令、读写任意文件。只应在**一次性容器 / 虚拟机**里使用,不要在日常工作机上长期使用。
23
+
24
+ ## 常见问题
25
+
26
+ ### 模型想写文件被拒 / 命令被拦截
27
+
28
+ 这是沙箱在正常工作,不是 bug。处理顺序:
29
+
30
+ 1. 用 `/status` 确认当前 `approval_policy` 和 `sandbox_mode`;
31
+ 2. `read-only` 模式下所有写操作都会被拒——日常开发切到 `workspace-write`;
32
+ 3. 写入目标在项目目录**外**(比如系统目录、用户主目录)也会被拒——把项目放到普通用户目录下,别放在受系统保护的位置;
33
+ 4. 需要装依赖、跑构建这类被拦的命令,在审批弹窗里批准即可;总是被拦的固定命令考虑调整策略而不是次次手点。
34
+
35
+ ### 每次启动都弹「信任此目录」(Trust this folder)
36
+
37
+ 新版本出于安全考虑不再默认信任目录,首次在某个目录使用会询问。弹窗反复出现的处理:
38
+
39
+ 1. 在提示里选择信任该目录,然后**重启会话**;
40
+ 2. 用 `/status` 确认信任状态与审批/沙箱模式已生效;
41
+ 3. VS Code 用户:同时把该文件夹在 VS Code 里设为 Trusted Workspace 并重载窗口——两边都信任后才不再重复询问;
42
+ 4. 仍每次都弹:升级到最新版,这个提示的持久化在不同版本间反复修过(参考 [openai/codex #14547](https://github.com/openai/codex/issues/14547)、[#14345](https://github.com/openai/codex/issues/14345))。
43
+
44
+ > 不要为了跳过提示就长期使用 `--dangerously-bypass-approvals-and-sandbox`——那是另一层风险(见上文)。
45
+
46
+ ### Windows 原生版沙箱异常
47
+
48
+ Windows 原生支持仍在持续完善,社区常见问题集中在沙箱实现上:
49
+
50
+ - 升级到最新版再试(沙箱相关修复很频繁);
51
+ - 确认 PowerShell 执行策略没拦脚本(见 [01](01-installation.md));
52
+ - 报错稳定复现且升级无效 → 走 WSL2 方案,兼容性最好;
53
+ - 项目在 Windows 与 WSL 间共享时大量「文件被改坏 / 行尾报警」:加 `.gitattributes` 统一行尾(如 `* text=auto eol=lf`),避免 CRLF/LF 反复横跳;
54
+ - 脚本、CI 里需要固定 shell 的:显式指定 shell,别依赖「默认 shell」——Windows 上默认 shell 随终端(PowerShell / cmd / Git Bash)不同而不同。
55
+
56
+ ## WSL2 方案(社区最稳路径)
57
+
58
+ ```powershell
59
+ # 管理员 PowerShell 里安装 WSL2(默认装 Ubuntu)
60
+ wsl --install
61
+ ```
62
+
63
+ 然后在 Ubuntu 里按 [01](01-installation.md) 正常安装 Node 和 Codex。要点:
64
+
65
+ 1. **项目文件放在 WSL 文件系统里**(如 `~/projects/...`),不要放在 `/mnt/c/...`——跨文件系统 I/O 慢好几倍,权限行为也容易出怪问题;
66
+ 2. VS Code 用「WSL」扩展连入 WSL,再在 WSL 内运行 Codex,体验和原生一致;
67
+ 3. WSL 里的代理要单独配置([03 网络与代理](03-network-proxy.md)),`127.0.0.1` 指向的是 WSL 自己;新版 WSL2 可用 mirrored 网络模式共享 Windows 侧代理,或在代理客户端里开启「允许局域网连接」并写 Windows 主机在 WSL 里的网关 IP。登录回调类问题(浏览器授权后凭据回不到 WSL)见 [02 的 WSL 小节](02-login-auth.md)。
68
+
69
+ ## 什么时候才需要 `danger-full-access`
70
+
71
+ - 在 Docker / VM / 一次性云主机里跑自动化任务;
72
+ - 明确知道模型要做什么,且任务本身需要大范围系统访问。
73
+
74
+ 即使在这些场景,也建议先试 `workspace-write`——大部分开发任务它就够了。
@@ -0,0 +1,55 @@
1
+ English | [中文](07-mcp.md)
2
+
3
+ # 07 · MCP Configuration & Troubleshooting
4
+
5
+ > Keywords: MCP tools missing, MCP server fails to start, tool call timeouts
6
+
7
+ ## Basic configuration
8
+
9
+ MCP servers are configured in `~/.codex/config.toml` (remember [04](04-config.en.md): tables go below root keys):
10
+
11
+ ```toml
12
+ [mcp_servers.context7]
13
+ command = "npx"
14
+ args = ["-y", "@upstash/context7-mcp"]
15
+
16
+ [mcp_servers.filesystem]
17
+ command = "npx"
18
+ args = ["-y", "@modelcontextprotocol/server-filesystem", "D:/projects"]
19
+ env = { "SOME_VAR" = "value" }
20
+ ```
21
+
22
+ **Restart the Codex session** after config changes — servers are launched per session.
23
+
24
+ ## Gotcha #1 on Windows: wrap `npx` with `cmd`
25
+
26
+ On Windows, `command = "npx"` directly often fails to start (`.cmd` resolution). Wrap it:
27
+
28
+ ```toml
29
+ [mcp_servers.context7]
30
+ command = "cmd"
31
+ args = ["/c", "npx", "-y", "@upstash/context7-mcp"]
32
+ ```
33
+
34
+ Check this first whenever tools don't show up on Windows — it resolves most "configured MCP but nothing happens" cases.
35
+
36
+ ## Tools not showing up: ordered checklist
37
+
38
+ 1. **Restart the session** — config only applies to new sessions;
39
+ 2. **Verify the server actually starts**: run `command + args` manually in a terminal — a stdio server should start and wait for input (Ctrl+C to quit);
40
+ - "command not found" → `npx`/`node` not on PATH;
41
+ - "module not found" → wrong package name, or `npm i -g` needed first;
42
+ 3. **Windows** → check whether the `cmd /c` wrapper is needed (see above);
43
+ 4. **Confirm the section name** is `[mcp_servers.<name>]`, not some variant like `[mcp.<name>]`;
44
+ 5. Try renaming the server — duplicate names or special characters can break loading;
45
+ 6. Still failing: search `~/.codex/log/` for MCP-related errors.
46
+
47
+ ## Call errors / timeouts
48
+
49
+ - **Timeouts**: the server itself is slow (e.g. fetches remote data) — use a faster source or increase timeouts if your version supports it;
50
+ - **Auth failures**: for HTTP-based servers, put required headers/tokens into `env` or per the server's docs;
51
+ - **One broken server slows startup**: comment out the servers you don't use and bisect to find the culprit.
52
+
53
+ ## Environment variables note
54
+
55
+ If `env = { ... }` depends on variables from your shell, remember Codex may be launched from a different environment than your terminal (e.g. IDE-launched processes don't read `.bashrc`). Putting the value directly into `env` is more reliable — but **never commit sensitive keys to any repository**.
package/docs/07-mcp.md ADDED
@@ -0,0 +1,57 @@
1
+ # 07 · MCP 配置与排障
2
+
3
+ > 报错关键词:MCP 工具不出现、`mcp server` 启动失败、工具调用超时
4
+ >
5
+ > English version: [07-mcp.en.md](07-mcp.en.md)
6
+
7
+ ## 基本配置
8
+
9
+ MCP server 配置在 `~/.codex/config.toml`(注意 [04](04-config.md) 说的:表要放在根级键之后):
10
+
11
+ ```toml
12
+ [mcp_servers.context7]
13
+ command = "npx"
14
+ args = ["-y", "@upstash/context7-mcp"]
15
+
16
+ [mcp_servers.filesystem]
17
+ command = "npx"
18
+ args = ["-y", "@modelcontextprotocol/server-filesystem", "D:/projects"]
19
+ env = { "SOME_VAR" = "value" }
20
+ ```
21
+
22
+ 修改配置后**重启 Codex 会话**才会重新拉起 MCP server。
23
+
24
+ ## Windows 上的第一大坑:npx 需要 cmd 包装
25
+
26
+ Windows 下直接 `command = "npx"` 经常起不来(`.cmd` 解析问题)。用 cmd 包一层:
27
+
28
+ ```toml
29
+ [mcp_servers.context7]
30
+ command = "cmd"
31
+ args = ["/c", "npx", "-y", "@upstash/context7-mcp"]
32
+ ```
33
+
34
+ 工具不出现先查这一条,能解决 Windows 下的大多数「MCP 配置了但没反应」。
35
+
36
+ ## 工具不出现的排查步骤
37
+
38
+ 按顺序:
39
+
40
+ 1. **重启会话**——配置只在新会话生效;
41
+ 2. **手动验证 server 能不能启动**:把 `command + args` 拼起来在终端直接跑,看是否正常输出/挂起等待(stdio 型 server 正常时会等待输入,Ctrl+C 退出);
42
+ - 报「命令不存在」→ `npx`/`node` 不在 PATH 里;
43
+ - 报模块找不到 → 包名写错,或需要先 `npm i -g`;
44
+ 3. **Windows** → 检查是否需要 `cmd /c` 包装(见上);
45
+ 4. **确认配置段落名**是 `[mcp_servers.<name>]`,不是 `[mcp.<name>]` 之类的变体;
46
+ 5. 换个名字试试——server 名重复或含特殊字符可能导致加载失败;
47
+ 6. 仍不行,看 `~/.codex/log/` 日志里 MCP 相关报错。
48
+
49
+ ## 调用报错 / 超时
50
+
51
+ - **超时**:server 本身响应慢(比如联网拉数据的),换更快的源或加大超时(如版本支持相应配置项);
52
+ - **认证失败**:HTTP 型 MCP 需要的 header/token 配进 `env` 或按 server 文档配置;
53
+ - **一个 server 崩了拖慢启动**:把不常用的 server 注释掉,二分定位是哪一个的问题。
54
+
55
+ ## 环境变量注意
56
+
57
+ `env = { ... }` 里引用的 Key 如果依赖你 shell 里的环境变量,注意 Codex 启动环境可能和你当前终端不同(比如从 IDE 启动时读不到 `.bashrc` 里的变量)——直接把值写进 `env` 更可靠,但注意**别把敏感 Key 提交进任何仓库**。
@@ -0,0 +1,53 @@
1
+ # 08 · Error Quick Reference (English)
2
+
3
+ > Usage: Ctrl+F for the keyword from your terminal → follow the row to the full guide. The full guides are in Chinese; commands and error strings are universal.
4
+ >
5
+ > 中文版见 [08-errors-quickref.md](08-errors-quickref.md)。
6
+
7
+ ## Status codes first
8
+
9
+ | Code | Meaning | Details |
10
+ |---|---|---|
11
+ | `401` | Authentication failed — invalid/expired credentials, or credentials sent to the wrong endpoint | [02 Login & auth](02-login-auth.md) |
12
+ | `403` | Authorization failed — authenticated but not permitted (model access / region / org policy) | [02 Login & auth](02-login-auth.md) |
13
+ | `429` | Usage — quota exhausted or rate limited | [05 Models & limits](05-models-limits.md) |
14
+ | `5xx` | Server / relay outage | Retry later; relay users check relay status first |
15
+
16
+ ## Error keyword → fix
17
+
18
+ | Error / symptom | Likely cause | Guide |
19
+ |---|---|---|
20
+ | `Exceeded retry limit, last error: 401 Unauthorized` | Expired/broken login state, or credential↔endpoint mismatch | [02 decision tree](02-login-auth.md) |
21
+ | ChatGPT login succeeds but 401 persists | Config conflict: leftover third-party provider / env vars | [02 steps ②⑤](02-login-auth.md), [04 checklist](04-config.md) |
22
+ | `403 Forbidden` | Model permission / region / org policy | [02](02-login-auth.md) |
23
+ | `You've hit your usage limit` (429) | Subscription quota window exhausted | [05](05-models-limits.md) |
24
+ | `insufficient_quota` | API account out of credit | [05](05-models-limits.md) |
25
+ | `model_not_found` | Wrong model name / no access / relay doesn't serve it | [05](05-models-limits.md) |
26
+ | `stream error` / `stream disconnected` | Unstable network path | [03 Network & proxy](03-network-proxy.md) |
27
+ | `ETIMEDOUT` / endless spinner | Direct connection blocked or proxy not applied | [03](03-network-proxy.md) |
28
+ | `ECONNREFUSED` | Proxy port closed or wrong | [03](03-network-proxy.md) |
29
+ | TLS / certificate errors | Corporate MITM proxy replacing certs | [03](03-network-proxy.md) |
30
+ | `failed to parse config` / `TOML parse error` | config.toml syntax error | [04](04-config.md) |
31
+ | Config written but **not taking effect** | Root keys placed after a `[table]` / session not restarted | [04 gotcha](04-config.md) |
32
+ | `codex: command not found` | PATH problem | [01 Installation](01-installation.md) |
33
+ | `EACCES` / `EPERM` (during install) | npm global directory permissions | [01](01-installation.md) |
34
+ | PowerShell "running scripts is disabled" | Execution policy blocking `codex.ps1` | [01](01-installation.md) |
35
+ | Writes denied / commands intercepted | Sandbox working as intended, policy too strict | [06 Sandbox & Windows](06-sandbox-windows.md) |
36
+ | Sandbox issues on Windows | Native support still maturing | [06](06-sandbox-windows.md), or use WSL2 |
37
+ | MCP tools missing | Server failed to start (Windows `cmd /c` wrapper) | [07 MCP](07-mcp.md) |
38
+ | 401 / config drift **inside VS Code / Cursor** | Shared `~/.codex` but stale IDE caches / env | [10 IDE](10-ide-vscode.md) |
39
+ | Device-code login fails / `token exchange failed` | Device-code auth disabled by default | [02 device code](02-login-auth.md) |
40
+ | WSL login credentials never arrive back | WSL ↔ Windows localhost isolation | [02 WSL section](02-login-auth.md) |
41
+ | `stream disconnected before completion` | Network / OneDrive folder / very long session | [03 deep dive](03-network-proxy.md) |
42
+ | "Trust this folder" prompt on every launch | Directory not trusted / version behavior | [06](06-sandbox-windows.md) |
43
+ | Weekly limit reset date keeps moving | Rolling 7-day window, by design | [05](05-models-limits.md) |
44
+
45
+ ## The five-step triage (cheat sheet)
46
+
47
+ ```
48
+ 1. codex --version ← version; upgrade first if old
49
+ 2. /status ← current model / provider / sandbox as expected?
50
+ 3. run the doctor script ← scripts/codex-doctor.sh or .ps1
51
+ 4. check ~/.codex/log/ ← far more context than the terminal line
52
+ 5. minimal repro ← empty dir + move config.toml aside + re-login
53
+ ```
@@ -0,0 +1,55 @@
1
+ # 08 · 常见报错速查表
2
+
3
+ > 用法:Ctrl+F 搜你终端里的报错关键词 → 按表跳详细文档。
4
+ >
5
+ > English version: [08-errors-quickref.en.md](08-errors-quickref.en.md)
6
+ >
7
+ > 先跑一次 [环境自检脚本](../scripts/codex-doctor.ps1),它覆盖了本表里一半以上的检查项。
8
+
9
+ ## 状态码先分清
10
+
11
+ | 状态码 | 含义 | 详细文档 |
12
+ |---|---|---|
13
+ | `401` | 认证失败——没认出你是谁(凭据无效/过期/发错端点) | [02 登录与认证](02-login-auth.md) |
14
+ | `403` | 授权失败——认出你了,但你没权限(模型权限/地区/组织策略) | [02 登录与认证](02-login-auth.md) |
15
+ | `429` | 用量问题——额度用完或速率超限 | [05 模型与限额](05-models-limits.md) |
16
+ | `5xx` | 服务端/中转站故障 | 稍后重试;中转站用户先确认中转站状态 |
17
+
18
+ ## 报错关键词 → 处理
19
+
20
+ | 报错/症状 | 大概率原因 | 去哪看 |
21
+ |---|---|---|
22
+ | `Exceeded retry limit, last error: 401 Unauthorized` | 登录态过期/损坏,或凭据与端点不匹配 | [02](02-login-auth.md) 决策树 |
23
+ | ChatGPT 登录成功但一直 401 | 配置冲突:第三方 provider / 环境变量残留 | [02](02-login-auth.md) 第②⑤步、[04](04-config.md) 清单 |
24
+ | `403 Forbidden` | 模型权限 / 地区 / 组织策略 | [02](02-login-auth.md) |
25
+ | `You've hit your usage limit`(429) | 订阅额度窗口用完 | [05](05-models-limits.md) |
26
+ | `insufficient_quota` | API 账户欠费 | [05](05-models-limits.md) |
27
+ | `model_not_found` | 模型名错误 / 无权限 / 中转站不支持 | [05](05-models-limits.md) |
28
+ | `stream error` / `stream disconnected` | 网络路径抖动(国内直连高发) | [03 网络与代理](03-network-proxy.md) |
29
+ | `ETIMEDOUT` / 长时间转圈 | 直连被阻断或代理没生效 | [03](03-network-proxy.md) |
30
+ | `ECONNREFUSED` | 代理端口没开/写错 | [03](03-network-proxy.md) |
31
+ | TLS / 证书类报错 | 企业 MITM 代理替换证书 | [03](03-network-proxy.md) |
32
+ | `failed to parse config` / `TOML parse error` | config.toml 语法错误 | [04](04-config.md) |
33
+ | 配置写了但**不生效** | 根级键写在 `[表]` 之后 / 忘了重启会话 | [04](04-config.md) 第一大坑 |
34
+ | `codex: command not found` | PATH 问题 | [01](01-installation.md) |
35
+ | `EACCES` / `EPERM`(安装时) | npm 全局目录权限 | [01](01-installation.md) |
36
+ | PowerShell「禁止运行脚本」 | 执行策略拦截 `codex.ps1` | [01](01-installation.md) |
37
+ | 写文件被拒 / 命令被拦截 | 沙箱正常工作,策略太严 | [06 沙箱与 Windows](06-sandbox-windows.md) |
38
+ | Windows 沙箱异常 | 原生支持不完善 | [06](06-sandbox-windows.md),或改用 WSL2 |
39
+ | MCP 工具不出现 | server 没起来(Windows `cmd /c` 坑) | [07 MCP](07-mcp.md) |
40
+ | 设备码登录失败 / `token exchange failed` | 设备码授权默认未开启 | [02](02-login-auth.md) 设备码小节 |
41
+ | WSL 登录后凭据传不回去 | WSL 与 Windows localhost 隔离 | [02](02-login-auth.md) WSL 小节 |
42
+ | `stream disconnected before completion` | 网络 / OneDrive 同步盘 / 超长会话 | [03](03-network-proxy.md) 深挖小节 |
43
+ | 每次启动都弹「信任此目录」 | 目录未信任 / 版本行为 | [06](06-sandbox-windows.md) |
44
+ | 每周限额重置时间一直变 | 滚动 7 天窗口,设计如此 | [05](05-models-limits.md) |
45
+ | VS Code 选 WSL agent 后进不去 / 崩溃 | 全局状态文件 | [10](10-ide-vscode.md) |
46
+
47
+ ## 通用排查五步法(速记)
48
+
49
+ ```
50
+ 1. codex --version ← 版本,旧版先升级
51
+ 2. /status ← 当前 model / provider / 沙箱模式是否符合预期
52
+ 3. 跑自检脚本 ← scripts/codex-doctor
53
+ 4. 看日志 ~/.codex/log/ ← 报错上下文比终端一句话详细
54
+ 5. 最小化复现 ← 空目录 + 移走 config.toml 重登测试
55
+ ```
@@ -0,0 +1,77 @@
1
+ English | [中文](09-maintenance.md)
2
+
3
+ # 09 · Maintenance: Upgrade, Cleanup, Backup, Migration, Reset
4
+
5
+ > For long-term Codex users: turning these routines into habits means fast recovery when things break.
6
+
7
+ ## A tour of `~/.codex`
8
+
9
+ ```
10
+ ~/.codex/
11
+ ├── config.toml # your configuration (created/edited by you)
12
+ ├── auth.json # login credentials (treat as a password, never share)
13
+ ├── log/ # runtime logs — the first place to look when troubleshooting
14
+ └── sessions/ # session history (grows with usage)
15
+ ```
16
+
17
+ Directory contents vary slightly between versions; trust what you actually see.
18
+
19
+ ## Version strategy & upgrading
20
+
21
+ - **Stability first**: don't upgrade mid-sprint; upgrade between tasks and keep rollback time in reserve.
22
+ - **Upgrade routine**:
23
+ ```bash
24
+ codex --version # 1. note the current version
25
+ npm install -g @openai/codex@latest # 2. upgrade (brew: brew upgrade codex)
26
+ codex --version # 3. confirm the new version
27
+ ```
28
+ - **Rollback**:
29
+ ```bash
30
+ npm install -g @openai/codex@<old-version>
31
+ ```
32
+ - After a major upgrade, use `/status` on first run to confirm model and config behave as before — major versions occasionally change config keys.
33
+
34
+ ## Routine cleanup
35
+
36
+ | Target | Action | Frequency |
37
+ |---|---|---|
38
+ | Session history `~/.codex/sessions/` | Archive or delete once you don't need to revisit them | As needed |
39
+ | Logs `~/.codex/log/` | Safe to clear | Keep them until a problem is diagnosed first |
40
+ | npm cache | `npm cache clean --force` | When npm misbehaves |
41
+
42
+ > 💡 You don't need to stop Codex, but in-flight sessions are affected — never clean in the middle of an important task.
43
+
44
+ ## Backup & machine migration
45
+
46
+ **Only two things need backing up**:
47
+
48
+ ```bash
49
+ cp ~/.codex/config.toml ~/codex-backup-config.toml
50
+ cp ~/.codex/auth.json ~/codex-backup-auth.json
51
+ ```
52
+
53
+ 1. `config.toml` is plain text — back it up freely, read it freely;
54
+ 2. `auth.json` is a credential — **treat the backup itself as a password**: no plaintext cloud drives, never into git, delete after migrating.
55
+
56
+ Restore on a new machine: install Codex, put both files back into `~/.codex/`. If an older `auth.json` causes 401, just `codex login` once more.
57
+
58
+ ## Full reset (the last resort)
59
+
60
+ Use when: config changes never take effect, 401s with no identifiable cause, or starting from scratch. **Wipes all session history — back up first.**
61
+
62
+ ```bash
63
+ # 1. back up (see above)
64
+ # 2. log out and clear
65
+ codex logout
66
+ rm -rf ~/.codex
67
+ # 3. log in again (credentials back to a pristine state)
68
+ codex login
69
+ # 4. rebuild config.toml against 04 — add only what you know you need, verify item by item
70
+ ```
71
+
72
+ If the problem **disappears** afterwards, it was stale config/credentials; if it **persists**, follow the network & version routes in [08](08-errors-quickref.md).
73
+
74
+ ## Logs
75
+
76
+ - Logs live in `~/.codex/log/` — the error context (full URL, status code, retries) is far richer than the terminal's one-liner; **read the log before filing an issue or asking anywhere**;
77
+ - Redact before submitting: URLs and account info inside logs can be sensitive.
@@ -0,0 +1,78 @@
1
+ # 09 · 日常维护:升级、清理、备份、迁移、重置
2
+
3
+ > 面向长期使用 Codex 的用户:把这几件例行操作流程化,出问题时能快速恢复。
4
+ >
5
+ > English version: [09-maintenance.en.md](09-maintenance.en.md)
6
+
7
+ ## `~/.codex` 目录导览
8
+
9
+ ```
10
+ ~/.codex/
11
+ ├── config.toml # 你的配置(自建/修改)
12
+ ├── auth.json # 登录凭据(等同密码,勿外传)
13
+ ├── log/ # 运行日志,排障重点看这里
14
+ └── sessions/ # 会话历史记录(占用会随使用增长)
15
+ ```
16
+
17
+ 不同版本目录内容略有差异,以实际为准。
18
+
19
+ ## 版本策略与升级
20
+
21
+ - **稳定优先**:正在赶工期就别升级;升级放在任务间隙,并预留回滚时间。
22
+ - **查最新版本**:官方 Releases 一览见 [版本追踪](releases.md)(每周自动更新)。
23
+ - **升级流程**:
24
+ ```bash
25
+ codex --version # 1. 记下当前版本
26
+ npm install -g @openai/codex@latest # 2. 升级(brew 用户:brew upgrade codex)
27
+ codex --version # 3. 确认新版本
28
+ ```
29
+ - **回滚**:
30
+ ```bash
31
+ npm install -g @openai/codex@<旧版本号>
32
+ ```
33
+ - 升级后首次使用,用 `/status` 核对模型与配置是否如常——大版本偶尔伴随配置键变更。
34
+
35
+ ## 例行清理
36
+
37
+ | 对象 | 操作 | 频率 |
38
+ |---|---|---|
39
+ | 会话历史 `~/.codex/sessions/` | 确认不需要回溯后按需删除/归档 | 按需 |
40
+ | 日志 `~/.codex/log/` | 可直接清空 | 出问题前先留档 |
41
+ | npm 缓存 | `npm cache clean --force` | npm 异常时 |
42
+
43
+ > 💡 清理前不需要停 Codex,但正在进行的会话记录会被影响,别在重要任务进行中清。
44
+
45
+ ## 备份与迁移机器
46
+
47
+ **需要备份的只有两样**:
48
+
49
+ ```bash
50
+ cp ~/.codex/config.toml ~/codex-backup-config.toml
51
+ cp ~/.codex/auth.json ~/codex-backup-auth.json
52
+ ```
53
+
54
+ 1. `config.toml` 是纯文本配置,随便备份、随便看;
55
+ 2. `auth.json` 是凭据——**备份文件本身要当作密码对待**:不要进网盘明文、不要进 git、迁移完就删。
56
+
57
+ 新机器恢复:装好 Codex 后把两个文件放回 `~/.codex/` 即可。如果 auth.json 较旧导致 401,重新 `codex login` 一次。
58
+
59
+ ## 完全重置(终极大招)
60
+
61
+ 适用:配置怎么改都不生效、401 查不出原因、想从零开始。**会清掉所有会话历史,先备份。**
62
+
63
+ ```bash
64
+ # 1. 备份(见上节)
65
+ # 2. 登出并清理
66
+ codex logout
67
+ rm -rf ~/.codex
68
+ # 3. 重新登录(凭据回到初始状态)
69
+ codex login
70
+ # 4. 对照 04 篇重建 config.toml —— 建议只加你确认需要的配置,逐项验证
71
+ ```
72
+
73
+ 重置后如果问题**消失**,说明是旧配置/凭据残留;如果**还在**,按 [08 速查表](08-errors-quickref.md) 走网络与版本路线。
74
+
75
+ ## 排障日志
76
+
77
+ - 日志在 `~/.codex/log/`,报错上下文(完整 URL、状态码、重试过程)通常比终端一行话详细得多,提 Issue / 求助时**先翻日志**;
78
+ - 提交日志前脱敏:里面的 URL、账号信息可能含敏感内容。
@@ -0,0 +1,63 @@
1
+ English | [中文](10-ide-vscode.md)
2
+
3
+ # 10 · IDE Integration (VS Code / Cursor)
4
+
5
+ > Keywords: extension won't install, 401 inside the extension, extension config not taking effect, extension behaves differently from the terminal
6
+
7
+ ## Understand the architecture first — it saves half the detour
8
+
9
+ - The IDE extension and the CLI **share the same** `~/.codex` (`config.toml`, `auth.json`) — so the troubleshooting in [02 Login & auth](02-login-auth.en.md) and [04 config.toml](04-config.en.md) applies to the extension too;
10
+ - The extension and the CLI are **two independently released artifacts**: upgrading one doesn't necessarily upgrade the other;
11
+ - Step one is always recording both versions: `codex --version` in the terminal + the version shown in the extension panel.
12
+
13
+ ## Common problems
14
+
15
+ ### The extension keeps asking to log in / 401 after login
16
+
17
+ 1. Credentials are shared: run the [02 401 decision tree](02-login-auth.en.md) in the terminal first — if the CLI side is broken, the extension can't work;
18
+ 2. CLI fine, only the extension broken: run "Developer: Reload Window" so the extension refreshes its cached credentials;
19
+ 3. Still failing: delete `~/.codex/auth.json`, then re-login **from the extension's own login entry** (not the terminal);
20
+ 4. Multiple IDEs (VS Code + Cursor) on the same account: one side refreshing tokens can invalidate the other's session — re-login in whichever IDE shows the 401.
21
+
22
+ ### Changed config, the extension doesn't pick it up
23
+
24
+ - `config.toml` is shared, but **already-open sessions don't hot-reload** — start a new conversation in the extension;
25
+ - Big trap: an IDE launched from the GUI cannot read environment variables from shell profiles (`.bashrc` / PowerShell `$PROFILE`). Anything env-dependent — `OPENAI_BASE_URL`, proxy, MCP `env` — must be configured in `config.toml` / the extension settings, or injected by the IDE launcher. Hoping your terminal `export` carries over will not work.
26
+
27
+ ### The extension behaves differently from the terminal
28
+
29
+ - Confirm which environment the IDE actually runs in: native Windows or WSL Remote (see [06](06-sandbox-windows.en.md)) — they can have **different CLI versions** and different default shells;
30
+ - WSL users, recommended path: install the "WSL" extension → connect VS Code into WSL → install the CLI and extension inside WSL — behaves like native Linux;
31
+ - Run `/status` in the extension and diff it against the terminal's `/status` — the difference is the problem.
32
+
33
+ ### Proxy: terminal works, extension doesn't
34
+
35
+ The codex process launched by the IDE inherits **the IDE's environment**, not your terminal's:
36
+
37
+ 1. Run the [03 connectivity test](03-network-proxy.en.md) in the VS Code integrated terminal — terminal OK + extension failing = environment difference;
38
+ 2. Fix: configure the proxy at the system level (affects GUI apps), or in IDE settings, or launch the IDE from a login shell;
39
+ 3. Restart the whole IDE afterwards (not just the window).
40
+
41
+ ### Where are the logs
42
+
43
+ - VS Code: Output panel → select the Codex output channel;
44
+ - CLI side: `~/.codex/log/` (see [09](09-maintenance.en.md));
45
+ - Read both before filing an issue — many "extension bugs" are CLI errors swallowed by the extension.
46
+
47
+ ### Update & downgrade
48
+
49
+ - Extension: update from the extensions panel; "Install Another Version…" to roll back;
50
+ - CLI: `npm install -g @openai/codex@<version>` (see [01](01-installation.en.md));
51
+ - When something breaks after an upgrade, pin one side's version to bisect whether the extension or the CLI introduced it.
52
+
53
+ ### Windows: can't enter after choosing the WSL agent / crashes
54
+
55
+ The "run in WSL" toggle lives in `C:\Users\<you>\.codex\codex-global-state.json`:
56
+
57
+ 1. Fully quit Codex / the IDE;
58
+ 2. Edit the file and set `runCodexInWindowsSubsystemForLinux` back to `false` (or delete the file to rebuild defaults);
59
+ 3. Update the WSL components/extensions from the Microsoft Store and restart — old version combinations have crash cases (see [openai/codex #13699](https://github.com/openai/codex/issues/13699)).
60
+
61
+ ## Cursor and other forks
62
+
63
+ The same logic applies (shared `~/.codex`, shared credentials and config). Some IDE versions have extension-API compatibility quirks: retest in **vanilla VS Code** first to rule out IDE differences before digging deeper.