Skip to content

Stop paying the multimodal tax. Your AI agent keeps every image it has seen but only sends the ones it needs: lighter chats, no endless reconnecting, no starting over. Works with Codex, Claude Code, Cline, Gemini CLI, OpenCode, WorkBuddy and more. Install once, forget it.

fix(mod): spell out env names so Claude Code 2.1.309 loads the mod

chipfighter8b4fe479b5b0
diff --git a/hooks/register.js b/hooks/register.js
index b894c7d..0009bbb 100644
--- a/hooks/register.js
+++ b/hooks/register.js
@@ -202,12 +202,11 @@ async function startRouting($, attempts = 60) {
async function restoreRouting($) {
const saved = await readRouting($)
if (!saved?.active) return
- const restore = async (name, managed, original) => {
- if (await $.env.get(name) === managed) await $.env.set(name, original ?? undefined)
- }
- await restore('ANTHROPIC_BASE_URL', saved.managedBaseUrl ?? `http://127.0.0.1:${saved.port}`, saved.originalBaseUrl)
- await restore('NO_PROXY', saved.managedNoProxy ?? loopbackAdded(saved.originalNoProxy), saved.originalNoProxy)
- await restore('no_proxy', saved.managedNoProxyLower ?? loopbackAdded(saved.originalNoProxyLower), saved.originalNoProxyLower)
+ // Each variable is put back only while it still has the value this mod set. The names are spelled out: Claude Code
+ // 2.1.309 refuses a module whose $.env calls take a name from a variable.
+ if (await $.env.get('ANTHROPIC_BASE_URL') === (saved.managedBaseUrl ?? `http://127.0.0.1:${saved.port}`)) await $.env.set('ANTHROPIC_BASE_URL', saved.originalBaseUrl ?? undefined)
+ if (await $.env.get('NO_PROXY') === (saved.managedNoProxy ?? loopbackAdded(saved.originalNoProxy))) await $.env.set('NO_PROXY', saved.originalNoProxy ?? undefined)
+ if (await $.env.get('no_proxy') === (saved.managedNoProxyLower ?? loopbackAdded(saved.originalNoProxyLower))) await $.env.set('no_proxy', saved.originalNoProxyLower ?? undefined)
routingState = { ...saved, active: false, reason: null }
await $.state.set(ROUTING, routingState)
}
diff --git a/spike/src/claude-routing.test.ts b/spike/src/claude-routing.test.ts
index 54b4ba0..11cc513 100644
--- a/spike/src/claude-routing.test.ts
+++ b/spike/src/claude-routing.test.ts
@@ -1,5 +1,6 @@
// The real Claude mod handlers, with only the host's process environment and HTTP API replaced.
import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
import test from "node:test";
let instance = 0;
@@ -171,3 +172,12 @@ test("a reloaded mod upgrades an earlier unscoped engine URL using its saved ori
await m.end();
assert.deepEqual(Object.fromEntries(m.env), original);
});
+
+// Claude Code 2.1.309 refuses the whole module otherwise ("$.env.get takes a literal name as its first argument"), and
+// the plugin then does nothing in that session: its requests no longer go through the engine.
+test("every $.env call in the mod names its variable literally", () => {
+ const source = readFileSync(new URL("../../hooks/register.js", import.meta.url), "utf8");
+ const names = [...source.matchAll(/\$\.env\.(?:get|set)\(\s*([^,)]+)/g)].map((match) => match[1].trim());
+ assert.ok(names.length >= 10);
+ assert.deepEqual(names.filter((name) => !/^'[A-Za-z_][A-Za-z0-9_]*'$/.test(name)), []);
+});