fix(executor): isolate CLAUDE_CODE_TMPDIR for nested claude to fix (no output) (#154)

* fix(executor): isolate CLAUDE_CODE_TMPDIR for nested claude to fix (no output)

Claude 2.1.45+ calls Nz7() in preAction to clean its tasks directory on
startup. When claude runs as a nested subprocess, it deletes the parent
session's *.output files, causing the parent to read an empty string and
display "(no output)".

Fix: assign each nested claude process its own unique CLAUDE_CODE_TMPDIR
(os.TempDir()/cc-nested-<pid>-<ns>) so it only cleans its own tasks
directory and never touches the parent's output files.

* fix(executor): use MkdirTemp for nested tmpdir

---------

Co-authored-by: cexll <evanxian9@gmail.com>
This commit is contained in:
cnzgray
2026-02-27 22:15:19 +08:00
committed by GitHub
parent b204ca94e2
commit 33a94d2bc4
2 changed files with 22 additions and 3 deletions

View File

@@ -1154,10 +1154,23 @@ func RunCodexTaskWithContext(parentCtx context.Context, taskSpec TaskSpec, backe
injectTempEnv(cmd)
// Claude Code sets CLAUDECODE=1 in its child processes. If we don't
// remove it, the spawned `claude -p` detects the variable and refuses
// to start ("cannot be launched inside another Claude Code session").
if commandName == "claude" {
// Claude 2.1.45+ calls Nz7() on startup to clean its tasks directory,
// which deletes the parent session's *.output files and causes "(no output)".
// Assign each nested claude its own isolated tmpdir so it only cleans its own files.
nestedTmpDir, err := os.MkdirTemp("", fmt.Sprintf("cc-nested-%d-", os.Getpid()))
if err != nil {
logWarnFn("Failed to create isolated CLAUDE_CODE_TMPDIR: " + err.Error())
} else {
cmd.SetEnv(map[string]string{"CLAUDE_CODE_TMPDIR": nestedTmpDir})
defer os.RemoveAll(nestedTmpDir) //nolint:errcheck
logInfoFn("CLAUDE_CODE_TMPDIR: " + nestedTmpDir)
fmt.Fprintln(os.Stderr, " CLAUDE_CODE_TMPDIR: "+nestedTmpDir)
}
// Claude Code sets CLAUDECODE=1 in its child processes. If we don't
// remove it, the spawned `claude -p` detects the variable and refuses
// to start ("cannot be launched inside another Claude Code session").
cmd.UnsetEnv("CLAUDECODE")
}