|
1 | | -# Codex Context Proxy |
| 1 | +<p align="center"> |
| 2 | + <img src="electron/assets/hash-icon.ico" alt="Codex Context Studio icon" width="128" height="128"> |
| 3 | +</p> |
2 | 4 |
|
3 | | -A visual, editable context layer for Codex. Let AI edit AI's context with surgical precision, giving you more control and freedom over what Codex sees. |
| 5 | +<h1 align="center">Codex Context Studio</h1> |
4 | 6 |
|
5 | | -## What We Built |
| 7 | +<p align="center"> |
| 8 | + <strong>🧠 Context Control Panel for Codex</strong> |
| 9 | + <br> |
| 10 | + <sub>Make Codex's context visible, locatable, and precisely manageable — like memory.</sub> |
| 11 | +</p> |
6 | 12 |
|
7 | | -Codex Context Proxy gives the official Codex CLI a visual and editable context layer. |
| 13 | +<p align="center"> |
| 14 | + <a href="#-core-features">Features</a> · |
| 15 | + <a href="#-architecture">Architecture</a> · |
| 16 | + <a href="#-quick-start">Install</a> · |
| 17 | + <a href="#-faq">FAQ</a> |
| 18 | +</p> |
8 | 19 |
|
9 | | -Codex is powerful in long coding sessions, but its context can become hard to inspect and harder to maintain. Tool logs, failed attempts, outdated assumptions, and repeated transcript fragments can keep accumulating. When that happens, you usually cannot see exactly what Codex is about to read or selectively remove noisy context before the next response. |
| 20 | +<p align="center"> |
| 21 | + <a href="README.md">English</a> · |
| 22 | + <a href="README.zh-CN.md">中文</a> |
| 23 | +</p> |
10 | 24 |
|
11 | | -This project adds a local context editor in front of Codex. You keep using the normal Codex workflow, while the proxy captures Codex's live context and opens a workbench where you can visualize, edit, compress, and delete context before future responses. |
| 25 | +<p align="center"> |
| 26 | + <img alt="Electron" src="https://img.shields.io/badge/electron-37-2f7f8f?style=flat-square&logo=electron&logoColor=white"> |
| 27 | + <img alt="Python" src="https://img.shields.io/badge/python-3.10%2B-3776ab?style=flat-square&logo=python&logoColor=white"> |
| 28 | + <img alt="React" src="https://img.shields.io/badge/react-19-149eca?style=flat-square&logo=react&logoColor=white"> |
| 29 | + <img alt="TypeScript" src="https://img.shields.io/badge/typescript-5.9-3178c6?style=flat-square&logo=typescript&logoColor=white"> |
| 30 | + <img alt="License" src="https://img.shields.io/badge/license-GPL--3.0-555?style=flat-square"> |
| 31 | + <img alt="Status" src="https://img.shields.io/badge/status-alpha-ff7a1a?style=flat-square"> |
| 32 | +</p> |
12 | 33 |
|
13 | | -In short: |
14 | 34 |
|
15 | | -```text |
16 | | -Codex writes code. |
17 | | -Codex Context Proxy helps maintain Codex's context. |
18 | | -``` |
19 | | - |
20 | | -## What Codex Gets |
| 35 | +--- |
21 | 36 |
|
22 | | -- Context visualization: see the conversation, tool history, and context nodes Codex is about to use. |
23 | | -- Editable context: compress, delete, or rewrite selected context items. |
24 | | -- AI context editing: use a second AI pass to maintain the main AI's context. |
25 | | -- Precise compaction: replace blunt auto-compact with targeted context surgery. |
26 | | -- CLI and Desktop support: use it with Codex CLI, with experimental support for Codex Desktop. |
27 | | -- Normal workflow: continue using Codex from the terminal or desktop app. |
| 37 | +## ⚡ In One Line |
28 | 38 |
|
29 | | -The context editing workbench is adapted from HashCode. The original project explains the broader "AI edits AI's context" idea in more detail: |
| 39 | +This project lets you see Codex's context consumption, what's retained after compression, and edit it yourself. It also lets you replace Codex's system prompt to break through Codex's limitations, and replace Codex's compression prompt for better compressed output. |
30 | 40 |
|
31 | | -https://github.com/HaShiShark/context-editor-agent |
| 41 | +--- |
32 | 42 |
|
33 | | -## Screenshots |
| 43 | +## 🎯 Core Features |
34 | 44 |
|
35 | | -### Visualize Codex Context and Token Usage |
| 45 | +### 🔬 Context Visualization — See Inside Codex's Brain |
36 | 46 |
|
37 | | - |
| 47 | +> View Codex's context by role, check token usage per turn, and see when prompts are injected. |
38 | 48 |
|
39 | | -### Ask AI to Inspect the Current Context |
| 49 | +### ✂️ Context Management — Take Over Codex's Memory |
40 | 50 |
|
41 | | - |
| 51 | +> Chat with a dedicated secondary model to analyze, edit, compress, and manage the main Codex's context. You can plug in a cheap secondary model. |
42 | 52 |
|
43 | | -### Compress Noisy Tool Context |
| 53 | +### 📈 Usage Panel — How Much Did This Session Cost? |
44 | 54 |
|
45 | | - |
| 55 | +> View token consumption, cache hit rate, and estimated cost across your Codex session. |
46 | 56 |
|
47 | | -## Features |
| 57 | +### 🔀 Prompt Replacement — Rewrite Codex's Default Prompts |
48 | 58 |
|
49 | | -### Live Context Map |
| 59 | +> Replace Codex's system prompt and native compression prompt for jailbreaking and better compression quality. |
50 | 60 |
|
51 | | -Codex Context Proxy converts a Codex session into a structured context map. Instead of treating the transcript as one long wall of text, it shows user turns, assistant turns, tool calls, tool results, and edited context nodes as separate items. |
| 61 | +### 🔌 Local Proxy — Transparent, Non-Invasive |
52 | 62 |
|
53 | | -### AI-Assisted Context Editing |
| 63 | +> No Codex source code changes, no official tools replaced. Sits in the middle as a local proxy, compatible with all native features. |
54 | 64 |
|
55 | | -You can select noisy or outdated context and ask an editor model to compress, rewrite, or clean it up. This makes it possible to preserve useful intent while removing bulk from logs, failed attempts, or repeated information. |
| 65 | +--- |
56 | 66 |
|
57 | | -### Manual Context Control |
| 67 | +## 📸 Screenshots |
58 | 68 |
|
59 | | -Not every context edit needs AI. You can also remove selected nodes or inspect raw content manually. |
| 69 | +### Context Map & Secondary Model Chat |
60 | 70 |
|
61 | | -### Codex CLI and Desktop |
| 71 | + |
62 | 72 |
|
63 | | -Codex CLI support is the main path. Once enabled, the normal `codex` command starts the local proxy and context window before launching the real Codex CLI. |
| 73 | +### Context Compression Result |
64 | 74 |
|
65 | | -Codex Desktop support is also included. It can point Codex Desktop's model provider configuration at the local proxy so desktop conversations can use the same editable context layer. Desktop support touches local Codex configuration, so it is controlled separately from the CLI switch. |
| 75 | + |
66 | 76 |
|
67 | | -### Transparent Workflow |
| 77 | +### Prompt Replacement |
68 | 78 |
|
69 | | -When the proxy is off, `codex` passes through to the official Codex CLI. When the proxy is on, the same `codex` command starts the local proxy, opens the context window, and then launches the real Codex CLI. |
| 79 | + |
70 | 80 |
|
71 | | -## How It Works |
| 81 | +### Usage Panel |
72 | 82 |
|
73 | | -Codex Context Proxy runs a local Responses API compatible proxy. |
| 83 | + |
74 | 84 |
|
75 | | -When Codex sends a request, the proxy captures the request body and response stream, then builds a canonical transcript for the context workbench. If you do not edit anything, requests are forwarded transparently and Codex behaves like normal. |
| 85 | +--- |
76 | 86 |
|
77 | | -When you edit the context, the proxy replaces that session's canonical transcript. On the next Codex turn, it diffs Codex's new raw `input` against the cursor, appends the new tail, and rebuilds the upstream Responses `input` from the edited transcript. |
| 87 | +## 🏗️ Architecture |
78 | 88 |
|
79 | | -High-level flow: |
| 89 | +```mermaid |
| 90 | +flowchart LR |
| 91 | + CD["Codex CLI / Desktop"] |
| 92 | + PX["Responses Proxy\n:8787"] |
| 93 | + WEB["Web Backend\n:8765"] |
| 94 | + FE["React Workbench"] |
| 95 | + OAI["OpenAI API / Upstream Model"] |
80 | 96 |
|
81 | | -```text |
82 | | -codex |
83 | | - -> local shim |
84 | | - -> Codex Context Proxy |
85 | | - -> official Codex request |
86 | | - -> OpenAI / ChatGPT Codex backend |
| 97 | + CD -- "POST /v1/responses" --> PX |
| 98 | + PX -- "Rebuilt request" --> OAI |
| 99 | + OAI -- "SSE stream" --> PX |
| 100 | + PX -- "SSE stream" --> CD |
87 | 101 |
|
88 | | -context window |
89 | | - -> visualize transcript |
90 | | - -> edit selected nodes |
91 | | - -> save edited context |
92 | | - -> next Codex turn uses edited context |
| 102 | + FE -- "HTTP edit/settings" --> WEB |
| 103 | + WEB -- "HTTP proxy control" --> PX |
| 104 | + PX -. "WebSocket realtime events" .-> FE |
93 | 105 | ``` |
94 | 106 |
|
95 | | -## Quick Start |
| 107 | +**How It Works:** |
96 | 108 |
|
97 | | -Download and run the Windows installer: |
| 109 | +Every Codex request follows the same path — there is no "pass-through if unedited" branch: |
98 | 110 |
|
99 | | -```text |
100 | | -Codex Context Proxy Setup 1.0.0.exe |
| 111 | +```mermaid |
| 112 | +flowchart LR |
| 113 | + A["Codex sends request"] --> B["cursor diff"] --> C["Update transcript"] --> D["Rebuild input"] --> E["Forward upstream"] |
101 | 114 | ``` |
102 | 115 |
|
103 | | -After installation, open a new terminal and enable the proxy: |
104 | | - |
105 | | -```powershell |
106 | | -codex ctx proxy on |
107 | | -``` |
| 116 | +- **Transcript** is the single source of truth: what users see in the workbench, edit, and what ultimately gets sent upstream |
| 117 | +- **Without edits**, the rebuilt input is naturally equivalent to the original Codex input |
| 118 | +- **With edits**, upstream receives the edited transcript + new content from the current turn |
| 119 | +- **During compression**, Codex's native compression prompt is replaced with a custom version, and the result is written back to the transcript |
108 | 120 |
|
109 | | -Use Codex normally: |
| 121 | +--- |
110 | 122 |
|
111 | | -```powershell |
112 | | -codex |
113 | | -``` |
| 123 | +## 🚀 Quick Start |
114 | 124 |
|
115 | | -Disable the proxy anytime: |
| 125 | +**1. Install** |
116 | 126 |
|
117 | | -```powershell |
118 | | -codex ctx proxy off |
119 | | -``` |
| 127 | +Download and run the latest Windows installer from [Releases](https://github.com/nicobailon/codex-context-studio/releases). |
120 | 128 |
|
121 | | -Check status: |
| 129 | +**2. Enable CLI Proxy** |
122 | 130 |
|
123 | 131 | ```powershell |
124 | | -codex ctx proxy status |
| 132 | +codex ctx proxy on # Enable proxy |
| 133 | +codex # Use Codex normally |
| 134 | +codex ctx proxy status # Check status |
| 135 | +codex ctx proxy off # Disable proxy |
125 | 136 | ``` |
126 | 137 |
|
127 | | -Remove the shim: |
| 138 | +**3. Desktop Support** |
128 | 139 |
|
129 | 140 | ```powershell |
130 | | -codex ctx proxy uninstall |
| 141 | +codex ctx desktop on # Enable Desktop mode |
| 142 | +codex ctx desktop status # Check status |
| 143 | +codex ctx desktop off # Disable |
131 | 144 | ``` |
132 | 145 |
|
133 | | -### Codex Desktop |
| 146 | +> [!NOTE] |
| 147 | +> Desktop mode modifies local Codex provider configuration. CLI mode only adds a shim and does not affect any config files. |
| 148 | +
|
| 149 | +--- |
134 | 150 |
|
135 | | -Desktop support is controlled separately: |
| 151 | +## 🛠️ Development |
136 | 152 |
|
137 | 153 | ```powershell |
138 | | -codex ctx desktop on |
139 | | -``` |
| 154 | +# Install dependencies |
| 155 | +npm install |
| 156 | +npm run setup:python |
140 | 157 |
|
141 | | -Check Desktop proxy status: |
| 158 | +# Run the full local flow |
| 159 | +npm run codex |
142 | 160 |
|
143 | | -```powershell |
144 | | -codex ctx desktop status |
145 | | -``` |
| 161 | +# Run only the context window |
| 162 | +npm run window |
146 | 163 |
|
147 | | -Disable Desktop proxying: |
| 164 | +# Run checks |
| 165 | +npm run typecheck |
| 166 | +npm test |
148 | 167 |
|
149 | | -```powershell |
150 | | -codex ctx desktop off |
| 168 | +# Build Windows installer |
| 169 | +npm run dist:win |
151 | 170 | ``` |
152 | 171 |
|
153 | | -Desktop support is more experimental than CLI support because it modifies local Codex configuration instead of only adding a command shim. |
| 172 | +--- |
154 | 173 |
|
155 | | -## Development |
| 174 | +## ❓ FAQ |
156 | 175 |
|
157 | | -Install dependencies: |
| 176 | +<details> |
| 177 | +<summary><strong>Is this a Codex plugin?</strong></summary> |
158 | 178 |
|
159 | | -```powershell |
160 | | -npm install |
161 | | -npm run setup:python |
162 | | -``` |
| 179 | +No. Codex Context Studio is a local context layer around Codex, implemented through proxy technology. |
163 | 180 |
|
164 | | -Run the local Codex flow: |
| 181 | +</details> |
165 | 182 |
|
166 | | -```powershell |
167 | | -npm run codex |
168 | | -``` |
| 183 | +<details> |
| 184 | +<summary><strong>Will it break the cache?</strong></summary> |
169 | 185 |
|
170 | | -Run only the context window: |
| 186 | +Compression is not a frequent event. After compression, it only recalculates once, which is more cost-efficient than carrying useless context. In practice, cache hit rate only drops by 5–10%. |
171 | 187 |
|
172 | | -```powershell |
173 | | -npm run window |
174 | | -``` |
| 188 | +</details> |
175 | 189 |
|
176 | | -Run type checks: |
| 190 | +<details> |
| 191 | +<summary><strong>Why not just rely on auto-compaction?</strong></summary> |
177 | 192 |
|
178 | | -```powershell |
179 | | -npm run typecheck |
180 | | -``` |
| 193 | +Compatible with native compression. The project also helps replace compression prompts — we've built more precise, targeted compression features. |
181 | 194 |
|
182 | | -Build the Windows installer: |
| 195 | +</details> |
183 | 196 |
|
184 | | -```powershell |
185 | | -npm run dist:win |
186 | | -``` |
| 197 | +<details> |
| 198 | +<summary><strong>Who is this for?</strong></summary> |
187 | 199 |
|
188 | | -The installer is generated at: |
| 200 | +People who want better control over context, have their own ideas about compression, or want to modify Codex's prompts. |
189 | 201 |
|
190 | | -```text |
191 | | -release/Codex Context Proxy Setup 1.0.0.exe |
192 | | -``` |
| 202 | +</details> |
193 | 203 |
|
194 | | -## Notes |
| 204 | +--- |
195 | 205 |
|
196 | | -- This project does not replace Codex. |
197 | | -- It does not require modifying the official Codex CLI source code. |
198 | | -- It works by adding a local editable context layer in front of Codex. |
199 | | -- Codex Desktop support is more experimental than Codex CLI support. |
| 206 | +<p align="center"> |
| 207 | + <sub>GPL-3.0 · Made with ❤️ for Codex power users</sub> |
| 208 | +</p> |
0 commit comments