Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dist/autofork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]
});
Expand Down
7 changes: 6 additions & 1 deletion src/autofork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Comment thread
AVGVSTVS96 marked this conversation as resolved.
Resolved

const codexHome = () => process.env.CODEX_HOME ?? join(homedir(), ".codex");

function agentCommand(config: Config, cap: number) {
Expand Down Expand Up @@ -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"],
});
Expand Down
17 changes: 15 additions & 2 deletions test/autofork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
Expand All @@ -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");
Comment thread
AVGVSTVS96 marked this conversation as resolved.
Resolved
const calls = file(home, "billed-site.log")
.trim()
.split("\n")
Expand Down Expand Up @@ -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"',
);
Expand Down
Loading