作者:互联网 时间: 2026-07-03 09:14:05
Codex 客户端下载地址:https://codexdown.cc/
不少 Windows 用户在使用 Codex 客户端 时,会遇到终端输出中文乱码的问题,例如:
���其实,大多数情况下并不是 Codex 的问题,而是 Windows PowerShell 默认编码不是 UTF-8 导致的。
下面介绍一种比较通用的解决方案,不需要修改 Codex 提示词,也不用每次启动都执行命令,只需要配置一次即可。

PowerShell 每次启动都会自动加载一个 Profile(配置文件)。
我们只需要把 UTF-8 编码配置写入 Profile,以后所有 PowerShell 会话都会默认使用 UTF-8,包括 Codex 调用 PowerShell 时也会自动生效。
打开 PowerShell,执行:
if (!(Test-Path -Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE -Force
}
如果 Profile 不存在,它会自动创建。
继续输入:
$PROFILE
PowerShell 会输出你的 Profile 文件位置。
例如:
C:UsersCloudGFXDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1
不同电脑用户名会有所不同。
打开刚刚输出的 .ps1 文件,在里面加入下面内容:
$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding $PSDefaultParameterValues['Get-Content:Encoding'] = 'UTF8' $PSDefaultParameterValues['Set-Content:Encoding'] = 'UTF8' $PSDefaultParameterValues['Add-Content:Encoding'] = 'UTF8'
保存即可。
关闭所有 PowerShell 窗口。
重新打开之后,新的编码配置就已经生效。
以后无论是:
都会默认采用 UTF-8 编码。
配置完成后,可以解决大量编码相关问题,例如:
基本可以作为 Windows 开发环境的通用配置。
很多人在网上会看到各种临时命令,例如:
chcp 65001
或者:
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
这些方法都有一个共同的问题:
关闭 PowerShell 后配置就失效了。
而 Profile 的方式属于永久配置,只需要设置一次,以后每次打开 PowerShell 都会自动加载,更适合作为开发环境的长期方案。
如果你在使用 Codex 客户端 时遇到终端乱码,不必修改提示词,也不用每次手动切换编码。
推荐直接配置 PowerShell 的 Profile,让系统默认使用 UTF-8 编码:
整个过程只需要几分钟,之后所有 PowerShell 会话都会默认使用 UTF-8,对于 Codex、VS Code、Windows Terminal 等工具都有帮助。