Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions bin/claude-code-proxy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
//
// Conversations are keyed like commandcode-proxy keys them (explicit
// session headers / body ids, else a hash of the first user message), and
// the key -> CLI session map persists to sessions.json in the proxy dir,
// the key -> CLI session map persists to sessions.json in the shared
// CLI-proxy state root (~/.local/state/cli-proxies, #3067),
// so a proxy restart re-attaches with `--resume <sessionId>` instead of
// re-bootstrapping. A request whose history no longer matches the mapped
// session (diverged prefix, extra mid-history user turns, lost session)
Expand Down Expand Up @@ -49,7 +50,19 @@ const PROXY_DIR = path.dirname(fileURLToPath(import.meta.url));
const WORKROOT = process.env.CLAUDE_CODE_PROXY_WORKDIR || path.join(PROXY_DIR, 'work');
fs.mkdirSync(WORKROOT, { recursive: true });

const SESSION_FILE = process.env.CLAUDE_CODE_PROXY_SESSION_FILE || path.join(PROXY_DIR, 'sessions.json');
// Session map: SHARED with commandcode-proxy (mirrored key space), so
// both proxies must resolve to the SAME path -- the shared CLI-proxy
// state root, not the script's directory: bin/ is the tracked checkout,
// and every write there dirtied the primary clone and blocked
// pm-git-sync (#3067; missed by the #2782 workdir move).
const SESSION_FILE =
process.env.CLAUDE_CODE_PROXY_SESSION_FILE ||
path.join(
process.env.XDG_STATE_HOME || path.join(os.homedir(), '.local', 'state'),
'cli-proxies',
'sessions.json'
);
fs.mkdirSync(path.dirname(SESSION_FILE), { recursive: true });
const MAX_LIVE_SESSIONS = 32;
const IDLE_TTL_MS = 2 * 60 * 60 * 1000;
const TURN_TIMEOUT_MS = 300 * 1000;
Expand Down
15 changes: 14 additions & 1 deletion bin/commandcode-proxy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,20 @@ const childEnv = () => {
// change: the automatic multi-turn key hashes the first USER message,
// not messages[0] — OpenCode's messages[0] is its identical system
// prompt for every session, which would collide all conversations.
const SESSION_FILE = path.join(PROXY_DIR, 'sessions.json');
// Session map: SHARED with claude-code-proxy (mirrored key space), so
// both proxies must resolve to the SAME path. It lives in the shared
// CLI-proxy state root, not beside the script: bin/ is the tracked
// checkout, and every write there dirtied the primary clone and blocked
// pm-git-sync. #3067 completes the state-dir move of #2782, which
// covered the WORKDIR state (bin/work) but missed this PROXY_DIR anchor.
const SESSION_FILE =
process.env.COMMANDCODE_PROXY_SESSION_FILE ||
path.join(
process.env.XDG_STATE_HOME || path.join(os.homedir(), '.local', 'state'),
'cli-proxies',
'sessions.json'
);
fs.mkdirSync(path.dirname(SESSION_FILE), { recursive: true });
const MAX_SESSIONS = 200;
const sessionStore = new Map();

Expand Down
10 changes: 10 additions & 0 deletions home/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,14 @@ in
# (warm-session maps, per-conversation workdirs) lives outside the
# checkout. The scripts' default (bin/work inside ~/code) dirtied
# the primary checkout with every session and blocked pm-git-sync.
#
# The commandcode + claude-code units additionally pin their shared
# key->session map via *_PROXY_SESSION_FILE to
# ~/.local/state/cli-proxies/sessions.json (#3067): that map was
# anchored to the scripts' own directory (bin/sessions.json) rather
# than the workroot, so the #2782 move missed it and the primary
# checkout kept dirtying. Both units MUST name the same file -- the
# two proxies share one map (mirrored key space).

# Command Code CLI Local Proxy Bridge for OpenCode (Go plan: the hosted
# Provider API rejects the Go plan, so OpenCode talks to the CLI via
Expand Down Expand Up @@ -750,6 +758,7 @@ in
"COMMANDCODE_PROXY_PORT=${toString commandcodeProxyPort}"
"COMMANDCODE_PROXY_HOST=127.0.0.1"
"COMMANDCODE_PROXY_WORKDIR=%h/.local/state/cli-proxies"
"COMMANDCODE_PROXY_SESSION_FILE=%h/.local/state/cli-proxies/sessions.json"
"COMMANDCODE_PROXY_MAX_TURNS=1"
"COMMANDCODE_PROXY_AGENCY_MAX_TURNS=8"
];
Expand Down Expand Up @@ -779,6 +788,7 @@ in
"CLAUDE_CODE_PROXY_PORT=${toString claudeCodeProxyPort}"
"CLAUDE_CODE_PROXY_HOST=127.0.0.1"
"CLAUDE_CODE_PROXY_WORKDIR=%h/.local/state/cli-proxies"
"CLAUDE_CODE_PROXY_SESSION_FILE=%h/.local/state/cli-proxies/sessions.json"
];
};
Install.WantedBy = [ "default.target" ];
Expand Down