From 753837bff3f878e65c1de386e7f8657200000c38 Mon Sep 17 00:00:00 2001 From: Henry Gimenez da Costa Date: Sun, 5 Apr 2026 02:45:57 -0300 Subject: [PATCH] =?UTF-8?q?fix(windows):=20isMainModule=20CJS=20branch=20f?= =?UTF-8?q?ails=20on=20Bun=20=E2=80=94=20add=20CLAUDE=5FMEM=5FMANAGED=20fa?= =?UTF-8?q?llback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Bun/Windows, `require.main !== module` in CJS mode causes the worker to exit silently with code 0. The wrapper already sets CLAUDE_MEM_MANAGED=true when spawning the inner worker, so checking this env var is a safe fallback that doesn't affect standalone execution. Ref #1450 (incomplete fix in PR #1518 — ESM path fixed but CJS branch not). Co-Authored-By: Claude Opus 4.6 (1M context) --- src/services/worker-service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/services/worker-service.ts b/src/services/worker-service.ts index 43077394..29d6fcb2 100644 --- a/src/services/worker-service.ts +++ b/src/services/worker-service.ts @@ -1307,8 +1307,10 @@ async function main() { } // Check if running as main module in both ESM and CommonJS +// The CLAUDE_MEM_MANAGED check handles Bun on Windows where require.main !== module +// in CJS mode despite being the entry point (see #1450) const isMainModule = typeof require !== 'undefined' && typeof module !== 'undefined' - ? require.main === module || !module.parent + ? require.main === module || !module.parent || process.env.CLAUDE_MEM_MANAGED === 'true' : import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('worker-service') || process.argv[1]?.endsWith('worker-service.cjs')