
VS CodeのCodex履歴をWorkspaceごとに分離するSeparating VS Code Codex History by Workspace
匿名の公開いいねです。記事の保存・お気に入りではなく、Featured、Top 3、重要度、掲載順位には影響しません。仕組みとプライバシーAnonymous public likes are reactions, not saved articles or bookmarks. They do not affect Featured, Top 3, importance, or listing order.How it works and privacy
- VS CodeのCodex拡張で、chatgpt.cliExecutableに独自ラッパーを指定し、CODEX_HOMEを各Workspaceの「.codex」へ切り替える手順を解説。
- 履歴と設定を案件別に分離でき、複数案件の管理が容易になります。
VS Code's Codex extension is wrapped through chatgpt.cliExecutable to set CODEX_HOME to each workspace's .codex directory, isolating sessions and settings across projects.
本ページの本文と要約は AI による自動生成です。日本語版と英語版は言語ごとに独立して生成されるため、表現や詳しさが異なる場合があります。正確性は元記事 (qiita.com) をご確認ください。The body and summaries are AI-generated independently for each language, so wording and detail may differ. Verify accuracy at the original source (qiita.com).
要約と収集メタデータに基づく AI 解説。元記事全文の転載・翻訳ではありません。AI explainer based on the summaries and collected metadata, not a copy or translation of the full source article.
VS CodeのCodex拡張で、セッション履歴と設定の保存先をWorkspaceごとに分離する方法が示されている。chatgpt.cliExecutableに独自ラッパーを指定し、Codex起動時にCODEX_HOMEを切り替える仕組みだ。
セッション履歴
OpenAI Codex extension 26.928.31416では、セッションが「~/.codex」に保存されるため、作業中のWorkspaceにかかわらず、すべてのセッションが表示される。Codexの設定やセッション履歴などの状態保存先はCODEX_HOMEで指定できるが、VS Code拡張では「~/.codex」が固定で指定されていると説明されている。
codeの起動時にCODEX_HOMEを上書きする方法も考えられるものの、それではWorkspaceごとに専用のショートカットが必要になる。この方法では、ショートカットを個別に用意せず、Codexの起動時に保存先を変更する。
独自ラッパー
VS Code側のchatgpt.cliExecutableには、Codexを直接指定するのではなく、独自に用意したラッパーを設定する。ラッパー内では「CODEX_HOME="$PWD/.codex"」を設定し、現在のWorkspace直下にある「.codex」をCodexの状態保存先として扱う。
構成例には「chatgpt.runCodexInWindowsSubsystemForLinux」をtrueにする設定も含まれている。ラッパーは、VS Code拡張内にあるCodexの実行ファイルを対象として起動処理を挟む形になる。
Workspace分離
この切り替えにより、セッション履歴だけでなく、Codexの設定もWorkspaceごとの「.codex」に置ける。複数のWorkspaceで作業しても履歴と設定が混在せず、案件単位で分離して管理できる構成となる。
Codex History by Workspace
The approach separates VS Code Codex session history and settings by workspace. This matters because the Codex extension stores every session in ~/.codex, causing sessions from all workspaces to appear together regardless of which workspace is currently open.
The setup was described for OpenAI Codex extension 26.928.31416. Instead of keeping the extension’s default shared state location, it gives each workspace its own .codex directory. That isolates session history and other Codex settings across projects, making multiple projects easier to manage independently.
CODEX_HOME
Codex’s state location, including settings and session history, can be specified with CODEX_HOME. In the VS Code extension, CODEX_HOME points to ~/.codex, which creates a single shared location for all sessions.
Overriding CODEX_HOME when starting code would change that location, but the described approach avoids creating a dedicated shortcut for every workspace. Instead, CODEX_HOME is set when Codex starts, using the current workspace directory as the base.
The resulting value is $PWD/.codex. Because $PWD represents the current location, each workspace receives a separate .codex directory directly beneath its root. Codex then uses that directory for its state rather than combining everything under ~/.codex.
chatgpt.cliExecutable
The extension is configured through chatgpt.cliExecutable to use a custom wrapper. Inside that wrapper, the environment variable is set with CODEX_HOME="$PWD/.codex" before Codex is launched.
The configuration also shows "chatgpt.runCodexInWindowsSubsystemForLinux": true. With the wrapper placed between the VS Code extension and the Codex executable, the state location can be changed according to the active workspace without maintaining workspace-specific launch shortcuts.
The practical result is that each project keeps its Codex sessions and settings in its own .codex directory. Sessions from unrelated workspaces therefore remain separated instead of appearing together in the extension’s shared history.
ポコとTECHガイドPoko & TECH Guide
ポコと当サイトのTECHガイドが、記事の要約と収集した情報から読みどころを語るAI生成の対話です。Poko and TECH Dashboard's own TECH Guide discuss the article's highlights in an AI-generated conversation based on its summary and collected source details.
- ポコPoko複数の案件を行き来するとき、Codexの履歴はどう変わるの?When I switch between projects, what changes about my Codex history?
- TECHガイドTECH GuideWorkspaceごとの「.codex」に履歴や設定を分けられるので、別案件のセッションが混ざりにくくなるよ。Sessions and settings can live in each workspace’s .codex folder, so different projects don’t get mixed together.
- ポコPoko前はWorkspaceごとに分かれていなかったの?Weren’t they already separated by workspace?
- TECHガイドTECH Guide以前は作業中のWorkspaceに関係なく、全セッションが「~/.codex」に保存されて表示されていたんだ。Before, all sessions were stored in ~/.codex and displayed regardless of which workspace you were using.
- ポコPokoなるほど。専用ショートカットを増やさず、案件ごとにCodexの履歴と設定を整理できるのが収穫だね。Got it. The key benefit is keeping Codex history and settings organized per project without creating separate shortcuts.
- TECHガイドTECH Guideうん。次はchatgpt.cliExecutableのラッパーで、CODEX_HOMEを現在のWorkspace直下へ切り替える部分に注目だね。Right. Next, focus on the chatgpt.cliExecutable wrapper that points CODEX_HOME to the current workspace.


