fix: 让 codex 自动配置遵循 $CODEX_HOME(本地 & ssh)#129
Merged
Conversation
之前 codex 的 hooks 安装与 config.toml 改写都直接拼 ~/.codex/,
对自定义了 CODEX_HOME 的用户来说,钩子被写到了 codex 根本不会读的目录里。
- ConfigInstaller: 新增 codexHome() 解析器,按 $CODEX_HOME → ~/.codex
顺序回退,并扩展 CLIConfig 让 codex 走自定义根目录,其他 CLI 不受影响。
- RemoteInstaller: 远端 Python 脚本同样读取 $CODEX_HOME;ssh 调用改走
登录 shell("${SHELL:-/bin/bash}" -lc),让远端 ~/.zprofile /
~/.bash_profile 里导出的环境变量能进到非交互会话。
- 补 8 个解析器单测:未设置 / 绝对路径 / ~ 展开 / 空串 / 纯空白 等。
senshinya
added a commit
to senshinya/CodeIsland
that referenced
this pull request
Apr 26, 2026
Two narrow fixes from upstream's v1.0.23 day, applied without the broader HookServer / Buddy work: - ConfigInstaller: honor $CODEX_HOME for hooks.json and config.toml writes instead of hardcoding ~/.codex/. Falls back to ~/.codex when the env var is unset, with `~`/`~/...` expansion. Codex CLIConfig now resolves configPath through a new optional rootOverride closure on CLIConfig (keeps the home-relative semantics for every other CLI). RemoteInstaller parts of the upstream commit are skipped — this fork has no SSH session feature. (upstream 9346ff3, wxtsky#129) - TerminalActivator: append a System Events Accessibility fallback to Ghostty and Terminal.app activation so a window minimized to the dock is restored even when the terminal's own AppleScript dictionary fails (Ghostty issue wxtsky#84) or its `windows` collection doesn't include the minimized window (Terminal.app issue wxtsky#124, some macOS 14 cases). The upstream `tty` variable-rename (`set tty to ...` → `set targetTty`) is not applicable here — this fork uses a string-literal interpolation so the AppleScript-shadowing bug never manifests. (upstream ed7cb7e) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
codex 自身解析配置目录的顺序是:先看
$CODEX_HOME,没有再退回~/.codex。但当前我们做 codex 自动配置时,无论本地还是 ssh,都直接拼了~/.codex/:ConfigInstaller把hooks.json写到~/.codex/hooks.json,并在~/.codex/config.toml里改codex_hooks = true。RemoteInstaller里嵌入的 Python 脚本同样硬编码home / ".codex"。对于把
CODEX_HOME指到别处的用户,钩子写入的目录 codex 根本不会读 —— 安装看起来成功,运行时一个事件都不会触发。改动
ConfigInstaller.swift
codexHome()解析器:读$CODEX_HOME,处理~/~/x展开,空串和纯空白都视为未设置,回退到~/.codex。displayCodexPath(filename:):UI/日志里显示\$CODEX_HOME/hooks.json或~/.codex/hooks.json,跟实际写入位置保持一致。CLIConfig加了两个可选闭包rootOverride/displayPathOverride,特例本地化在 codex 一条记录里,其它 CLI 完全不受影响。installAll/verifyAndRepair/enableCodexHooksConfig里原本拼NSHomeDirectory() + "/.codex"的三处都改成走codexHome()。RemoteInstaller.swift
_codex_home():同样的$CODEX_HOME→~/.codex回退逻辑,install_codex走它。\"\${SHELL:-/bin/bash}\" -lc \"...\",让远端~/.zprofile/~/.bash_profile里 export 的CODEX_HOME能进到非交互会话。Python 脚本用 base64 编码再喂给 stdin,避开嵌套 heredoc 的引号问题。测试
Tests/CodeIslandTests/CodexHomeTests.swift覆盖 8 种情况:未设置 / 绝对路径 /~/foo/ 裸~/ 空串 / 纯空白 / display 名走 env / display 名回退。swift test:197/197 通过,没有回归。验证步骤
CODEX_HOME,安装 hooks →~/.codex/hooks.json与config.toml正常更新。launchctl setenv CODEX_HOME ~/codex-custom后重启 app,再次安装 →~/codex-custom/下生成两个文件,~/.codex/没被碰过。~/.zprofile里export CODEX_HOME=$HOME/codex-custom,触发远端安装 →~/codex-custom/hooks.json写入成功。