Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(openai-codex): leave cache_control out of code-mode history hashes

Jack Rudenkoa681ca1708bc
diff --git a/packages/cli/src/code-mode/hashes.ts b/packages/cli/src/code-mode/hashes.ts
index 16c1ab76..49db8b27 100644
--- a/packages/cli/src/code-mode/hashes.ts
+++ b/packages/cli/src/code-mode/hashes.ts
@@ -23,7 +23,19 @@ export interface BatchResultEntry {
result?: { isError: boolean; content: unknown };
}
-/** JSON with object keys sorted at every depth: a stable serialisation for hashing. */
+/**
+ * Per-request transport fields a key must not depend on. `cache_control` is a
+ * prompt-cache breakpoint Claude Code moves between requests: the message that
+ * carried it when a record was written no longer does when history is
+ * rendered, so a hash over it never matched again.
+ */
+const TRANSPORT_KEYS = new Set(["cache_control"]);
+
+/**
+ * JSON with object keys sorted at every depth, transport fields left out: a
+ * stable serialisation for hashing (`batchHash`, `turnAnchorFor`, replay's
+ * input comparison), never for sending.
+ */
export function canonicalJson(value: unknown): string {
if (value === null || typeof value !== "object") {
return JSON.stringify(value) ?? "null";
@@ -32,7 +44,7 @@ export function canonicalJson(value: unknown): string {
return `[${value.map((v) => canonicalJson(v)).join(",")}]`;
}
const keys = Object.keys(value as Record<string, unknown>)
- .filter((k) => (value as Record<string, unknown>)[k] !== undefined)
+ .filter((k) => (value as Record<string, unknown>)[k] !== undefined && !TRANSPORT_KEYS.has(k))
.sort();
const body = keys
.map((k) => `${JSON.stringify(k)}:${canonicalJson((value as Record<string, unknown>)[k])}`)