ChatGPT Appからローカルのcodex-cliへ接続するためにCodexを入れ直す
概要
スマホアプリのChatGPT Appから、ローカルにインストールしたcodex-cliへ接続するために、Codexを入れ直す。
通常npm版でcodex-cliをインストールすると思うが、
codex remote-controlを使う場合、npm版の@openai/codexではなく、Codexインストーラで管理されるstandalone版が必要になる。
インストール手順
npm版をアンインストールする
standalone版を入れる。
npm版のままcodex remote-controlを実行すると、以下のような表示になる。
user@user:~/workspace$ codex remote-control
Error: managed standalone Codex install not found at /home/user/.codex/packages/standalone/current/codex
This command requires the standalone install managed by the Codex installer, because the daemon starts and updates app-server from that fixed path.
Install it with:
curl -fsSL https://chatgpt.com/codex/install.sh | sh
npm版を消す。
npm uninstall -g @openai/codex
hash -r
standalone版をインストールする
インストールスクリプトを実行する。
curl -fsSL https://chatgpt.com/codex/install.sh | sh
現在のターミナルでパスを設定する。
export PATH="$HOME/.local/bin:$PATH"
パスを確認する。
which codex
readlink -f "$(which codex)"
ls -l ~/.codex/packages/standalone/current/codex
~/.codex/packages/standalone/current/codexが存在し、which codexの向き先がstandalone版になっていればよい。
起動する
codex remote-control
起動後
起動後は、codex-cliと同じアカウントでログインしているスマートフォン側のChatGPT AppからCodexを選択すると、PCへ接続するかどうかの確認が表示される。
その後は、画面へ表示される手順に従うだけで、特別な設定なしに接続できた。
なお、おそらく事前に2FAの設定が必要である。
おまけ: default_permissions設定を効かせる
default_permissionsは必須でない。
ただし、自分の環境ではgitのcommitができないため、権限設定を編集している。
しかし、Codex 0.131.0では、0.131.0対応の書き方にしても.gitがread-onlyでマウントされてしまう。そのため、0.130.0の入れ方も記載しておく。
standalone版もバージョン指定で入れられる。0.130.0を入れる場合は以下の通り。
curl -fsSL https://chatgpt.com/codex/install.sh | sh -s -- --release 0.130.0
権限設定は以下のようにする。
[permissions.workspace-git.filesystem]
":tmpdir" = "write"
":root" = "read"
"/tmp" = "write"
"~/workspace/**" = "write"
# ":workspace_roots" = { "." = "write", ".git" = "write", ".git/**" = "write", ".agents" = "read", ".codex" = "read" } # for v0.131
[permissions.workspace-git.filesystem.":project_roots"] # for v0.130
"." = "write"
".git" = "write"
".git/**" = "write"
".agents" = "read"
".codex" = "read"
編集後は、以下のようにdefault_permissionsを指定して起動する。
codex remote-control -c default_permissions=workspace-git