fix(executor): unset CLAUDECODE env to prevent nested session rejection

Claude Code v2.1.41+ sets CLAUDECODE=1 in all child Bash processes and
rejects startup when the variable is present. When codeagent-wrapper
spawns `claude -p` as a subprocess, it inherits this variable and gets
blocked with "cannot be launched inside another Claude Code session".

Add UnsetEnv method to commandRunner interface and strip CLAUDECODE
before spawning the claude backend.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
lza
2026-02-18 07:56:25 +08:00
parent 1dd7b23942
commit 5fe8c24f55
4 changed files with 58 additions and 0 deletions

View File

@@ -41,6 +41,11 @@ func (f *fakeCmd) SetEnv(env map[string]string) {
}
}
func (f *fakeCmd) Process() processHandle { return nil }
func (f *fakeCmd) UnsetEnv(keys ...string) {
for _, k := range keys {
delete(f.env, k)
}
}
func TestEnvInjection_LogsToStderrAndMasksKey(t *testing.T) {
// Arrange ~/.codeagent/models.json via HOME override.