详情

首页手游攻略 Codex客户端终端乱码的解决方式

Codex客户端终端乱码的解决方式

佚名 2026-07-03 09:14:05

Codex 客户端下载地址:https://codexdown.cc/

不少 Windows 用户在使用 Codex 客户端 时,会遇到终端输出中文乱码的问题,例如:

  • AI 输出中文变成 ���
  • Git 日志显示乱码
  • npm、pnpm 输出乱码
  • Python 程序中文乱码
  • PowerShell 中文显示异常
  • 文件读写编码不一致

其实,大多数情况下并不是 Codex 的问题,而是 Windows PowerShell 默认编码不是 UTF-8 导致的。

下面介绍一种比较通用的解决方案,不需要修改 Codex 提示词,也不用每次启动都执行命令,只需要配置一次即可。

原理

PowerShell 每次启动都会自动加载一个 Profile(配置文件)

我们只需要把 UTF-8 编码配置写入 Profile,以后所有 PowerShell 会话都会默认使用 UTF-8,包括 Codex 调用 PowerShell 时也会自动生效。

第一步:创建 PowerShell Profile

打开 PowerShell,执行:

if (!(Test-Path -Path $PROFILE)) {
  New-Item -ItemType File -Path $PROFILE -Force
}

如果 Profile 不存在,它会自动创建。

第二步:查看 Profile 路径

继续输入:

$PROFILE

PowerShell 会输出你的 Profile 文件位置。

例如:

C:UsersCloudGFXDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1

不同电脑用户名会有所不同。

第三步:编辑 Profile 文件

打开刚刚输出的 .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

关闭所有 PowerShell 窗口。

重新打开之后,新的编码配置就已经生效。

以后无论是:

  • Codex Client
  • Windows Terminal
  • PowerShell
  • VS Code Terminal

都会默认采用 UTF-8 编码。

配置后的效果

配置完成后,可以解决大量编码相关问题,例如:

  • ✅ Codex 输出中文正常
  • ✅ AI 生成内容不再乱码
  • ✅ Python 输出中文正常
  • ✅ Git 日志正常显示中文
  • ✅ npm、pnpm 输出中文正常
  • ✅ Get-Content 默认 UTF-8
  • ✅ Set-Content 默认 UTF-8
  • ✅ Add-Content 默认 UTF-8

基本可以作为 Windows 开发环境的通用配置。

为什么推荐这种方法?

很多人在网上会看到各种临时命令,例如:

chcp 65001

或者:

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

这些方法都有一个共同的问题:

关闭 PowerShell 后配置就失效了。

而 Profile 的方式属于永久配置,只需要设置一次,以后每次打开 PowerShell 都会自动加载,更适合作为开发环境的长期方案。

总结

如果你在使用 Codex 客户端 时遇到终端乱码,不必修改提示词,也不用每次手动切换编码。

推荐直接配置 PowerShell 的 Profile,让系统默认使用 UTF-8 编码:

  1. 创建 Profile 文件
  2. 查看 Profile 路径
  3. 写入 UTF-8 配置
  4. 保存并重新打开 PowerShell

整个过程只需要几分钟,之后所有 PowerShell 会话都会默认使用 UTF-8,对于 Codex、VS Code、Windows Terminal 等工具都有帮助。

点击查看更多
推荐专题
热门阅读