OpenCode 经常会唤起 Shell 执行命令,但其默认不走代理,比较麻烦。
如何令其默认走代理呢?个人分析得到两种比较好的实现方式:更新 Shell 配置文件和实现 OpenCode 插件。
实现 OpenCode 插件
我自己使用了这种方式,因为出于某些原因我不希望平时使用的 Shell 默认走代理。
OpenCode 插件文档:https://opencode.ai/docs/plugins/
-
创建文件:
/Users/[your_username]/.config/opencode/plugins/proxy.tsexport default (async () => { return { "shell.env": async (input, output) => { output.env = { ...output.env, https_proxy: "http://127.0.0.1:7890", http_proxy: "http://127.0.0.1:7890", all_proxy: "socks5://127.0.0.1:7890" } } } }) satisfies Plugin -
重启 OpenCode 使插件生效。
更新 Shell 配置文件
在 ~/.zshrc 中添加:
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890