最近用 Codex,经常看到一句: “不好意思,又被 PowerShell 坑了一下。”😅 很多问题其实是 Windows 工具和语法混用了。 先分清: - `powershell.exe`:系统自带的 PowerShell 5.1 - `pwsh.exe`:新版 PowerShell 7 - Windows Terminal:终端窗口,不是 PowerShell 升级 Terminal ≠ 安装 PowerShell 7。 ① 安装 PowerShell 7 ``` winget install --id Microsoft.PowerShell pwsh $PSVersionTable.PSVersion ``` 看到 7.x 就成功了。 ② 更新 Terminal,安装搜索工具 `rg` ``` winget upgrade --id Microsoft.WindowsTerminal winget install --id BurntSushi.ripgrep.MSVC rg --version ``` ③ 设置 Codex 集成终端选 PowerShell;Linux 项目再选 WSL。集成终端和智能体环境相互独立,智能体切到 WSL 后要重启。“跟进行为”建议选“引导”。 📌 自定义指令: ``` Windows 默认使用 PowerShell 7(pwsh)。 遵循 PowerShell 语法;未进 WSL 时不用 Bash 语法。 搜索文件和源码时优先使用 rg。 失败后分析原始报错,检查 Shell、路径、编码和权限,不要原样重试。 完成前实际验证,只报告执行过的结果。 ``` 只有出现“running scripts is disabled”时,才考虑: ``` Set-ExecutionPolicy -Scope CurrentUser RemoteSigned ``` PowerShell 7 不能解决权限、沙箱和依赖问题,但能减少很多兼容问题。 #howto入门codex #howto用好AI#Codex #PowerShell #Windows #AI编程 #新手教程 #避坑指南