opencode崩溃

opencode 崩溃现象的排查与修复

#status / growing #type / debug #resource / opencode

[!info] related notes

opencode 崩溃

opencode崩溃

现象

opencode CLI 工具在运行过程中突然崩溃退出,终端显示 panic 堆栈或进程直接消失。

常见原因

  1. Go 运行时 panic:空指针解引用、数组越界、并发竞态
  2. 配置文件损坏~/.config/opencode/config.json 格式错误或缺少必要字段
  3. API Key 失效或未配置:请求 LLM API 时未处理好 401/429 响应导致 panic
  4. 版本不兼容:opencode 版本与 Go runtime 或系统库版本冲突
  5. 内存不足:上下文过长或并发请求过多导致 OOM

排查

1. 查看崩溃日志

# Linux / macOS
cat ~/.local/share/opencode/crash.log 2>/dev/null || cat /tmp/opencode-crash*.log

# Windows
Get-Content "$env:LOCALAPPDATA\opencode\crash.log" -ErrorAction SilentlyContinue

2. 检查配置文件

cat ~/.config/opencode/config.json | jq .  # 验证 JSON 格式

3. 检查版本

opencode --version
go version  # 确认 Go 版本兼容

4. 复现问题

# 开启 debug 日志
OPENCODE_DEBUG=1 opencode

# 使用 verbose 模式运行
opencode --verbose

解决

配置问题

# 重置配置文件
mv ~/.config/opencode/config.json ~/.config/opencode/config.json.bak
opencode  # 重新生成默认配置

版本问题

# 更新到最新版
go install github.com/opencode-ai/opencode@latest

# 或使用包管理器
brew upgrade opencode

内存问题

  • 减少 --max-context-length 参数
  • 避免在大文件仓库根目录运行
创建于 2026/2/25 更新于 2026/5/27