diff --git a/dist/autofork.js b/dist/autofork.js index da979a6..e06a70d 100755 --- a/dist/autofork.js +++ b/dist/autofork.js @@ -292,6 +292,7 @@ Don't edit anything ${fresh || !config.verify ? "else " : ""}in ${DIR}/ or ${WOR If upstream already does what PATCH.md asks, or something close enough that building it would duplicate upstream's own version, write one line saying what upstream does to ${DIR}/${id}/UPSTREAM.md, and the sync leaves the patch out.`; } var installed = (bin) => run("sh", ["-c", `command -v ${bin}`], ".").ok; +var entrypoint = !process.env.CLAUDECODE && process.env.CLAUDE_CODE_ENTRYPOINT || "autofork"; var codexHome = () => process.env.CODEX_HOME ?? join(homedir(), ".codex"); function agentCommand(config, cap) { if (config.agent) @@ -422,7 +423,7 @@ async function agent(config, build, what, prompt, env) { const out = openSync(printed, "w"); const result = spawnSync("sh", ["-c", command], { cwd: dir, - env, + env: { ...env ?? process.env, CLAUDE_CODE_ENTRYPOINT: entrypoint }, input: prompt, stdio: ["pipe", agent === "custom" ? "inherit" : out, "inherit"] }); diff --git a/src/autofork.ts b/src/autofork.ts index 03a3c3a..bb105ae 100644 --- a/src/autofork.ts +++ b/src/autofork.ts @@ -419,6 +419,11 @@ If upstream already does what PATCH.md asks, or something close enough that buil const installed = (bin: string) => run("sh", ["-c", `command -v ${bin}`], ".").ok; +/* Claude's 5-hour limit drains faster for claude -p's own label than for interactive Claude Code, and + a run labeled autofork drains at the interactive rate (pingdotgg/t3code#24649). A label inherited + from a Claude Code session autofork runs in is that session's, not the user's */ +const entrypoint = (!process.env.CLAUDECODE && process.env.CLAUDE_CODE_ENTRYPOINT) || "autofork"; + const codexHome = () => process.env.CODEX_HOME ?? join(homedir(), ".codex"); function agentCommand(config: Config, cap: number) { @@ -588,7 +593,7 @@ async function agent( const out = openSync(printed, "w"); const result = spawnSync("sh", ["-c", command], { cwd: dir, - env, + env: { ...(env ?? process.env), CLAUDE_CODE_ENTRYPOINT: entrypoint }, input: prompt, stdio: ["pipe", agent === "custom" ? "inherit" : out, "inherit"], }); diff --git a/test/autofork.test.ts b/test/autofork.test.ts index 64e3ec6..f637a12 100644 --- a/test/autofork.test.ts +++ b/test/autofork.test.ts @@ -2331,7 +2331,12 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"built it", }; wish(mine, "five"); const { ok, log } = autoforkWith( - { ...site, SITE_TOTALS: '{"rebuilds":3,"spent":40}' }, + { + ...site, + SITE_TOTALS: '{"rebuilds":3,"spent":40}', + CLAUDECODE: "1", + CLAUDE_CODE_ENTRYPOINT: "sdk-cli", + }, mine, "sync", ); @@ -2341,6 +2346,7 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"built it", "-p --dangerously-skip-permissions --output-format json --max-budget-usd 20", ); expect(file(home, "claude-env")).not.toContain("ACTIONS_ID_TOKEN_REQUEST"); + expect(file(home, "claude-env")).toContain("CLAUDE_CODE_ENTRYPOINT=autofork\n"); const calls = file(home, "billed-site.log") .trim() .split("\n") @@ -2369,11 +2375,18 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"built it", wish(mine, "retried"); const retried = autoforkWith( - { ...site, SITE_TOTALS: '{"rebuilds":4,"spent":41.25}', SITE_FAIL_ONCE: "/api/ledger/close" }, + { + ...site, + SITE_TOTALS: '{"rebuilds":4,"spent":41.25}', + SITE_FAIL_ONCE: "/api/ledger/close", + CLAUDECODE: "", + CLAUDE_CODE_ENTRYPOINT: "mine", + }, mine, "sync", ); expect(retried.log).not.toContain("couldn't report"); + expect(file(home, "claude-env")).toContain("CLAUDE_CODE_ENTRYPOINT=mine\n"); expect(file(home, "billed-site.log")).toContain( '"path":"/api/ledger/close","auth":"Bearer oidc-autofork","body":{"id":"row-1","status":"done"', );