Fix nested Claude Code session detection and centralize provider availability checks

Strip parent Claude Code session env vars (CLAUDECODE, CLAUDE_CODE_ENTRYPOINT, etc.)
from child agent environments so spawned agents don't fail with "cannot be launched
inside another Claude Code session". Centralize isProviderAvailable to check both
binary and credential availability. Add red e2e test for send-during-tool-call bug
and force-cancel stale foreground turns in cancelAgentRun.
This commit is contained in:
Mohamed Boudra
2026-03-25 16:00:24 +07:00
parent 81ee887d03
commit c4782ec71c
14 changed files with 321 additions and 45 deletions
@@ -111,6 +111,26 @@ describe("applyProviderEnv", () => {
expect(env.PATH).toBe("/custom/path");
});
test("strips parent Claude Code session env vars", () => {
const base = {
PATH: "/usr/bin",
CLAUDECODE: "1",
CLAUDE_CODE_ENTRYPOINT: "sdk-ts",
CLAUDE_CODE_SSE_PORT: "11803",
CLAUDE_AGENT_SDK_VERSION: "0.2.71",
CLAUDE_CODE_ENABLE_SDK_FILE_CHECKPOINTING: "true",
};
const env = applyProviderEnv(base, undefined, {});
expect(env.PATH).toBe("/usr/bin");
expect(env.CLAUDECODE).toBeUndefined();
expect(env.CLAUDE_CODE_ENTRYPOINT).toBeUndefined();
expect(env.CLAUDE_CODE_SSE_PORT).toBeUndefined();
expect(env.CLAUDE_AGENT_SDK_VERSION).toBeUndefined();
expect(env.CLAUDE_CODE_ENABLE_SDK_FILE_CHECKPOINTING).toBeUndefined();
});
});
describe("findExecutable", () => {