diff --git a/code/internal/server/console.go b/code/internal/server/console.go index 235e112..8cf9076 100644 --- a/code/internal/server/console.go +++ b/code/internal/server/console.go @@ -6,8 +6,10 @@ import ( "fmt" "io" "net/http" + "os" "os/exec" "strconv" + "strings" "sync" "time" @@ -140,11 +142,24 @@ func (s *Server) handleConsoleExec(c *gin.Context) { }) } +// cleanEnv returns the current environment with CLAUDECODE removed, +// so child claude processes don't inherit the parent's session. +func cleanEnv() []string { + var env []string + for _, e := range os.Environ() { + if !strings.HasPrefix(e, "CLAUDECODE=") { + env = append(env, e) + } + } + return env +} + // runCommand executes a command and streams output to listeners. func (s *Server) runCommand(session *sessionState, command, execID string) { // Build the claude command cmd := exec.Command("claude", "--dangerously-skip-permissions", "-p", command) cmd.Dir = s.projectRoot() + cmd.Env = cleanEnv() stdout, err := cmd.StdoutPipe() if err != nil { diff --git a/code/internal/server/submit.go b/code/internal/server/submit.go index bf73692..23041df 100644 --- a/code/internal/server/submit.go +++ b/code/internal/server/submit.go @@ -158,6 +158,7 @@ func (s *Server) handleChatSubmit(c *gin.Context) { func (s *Server) runChatCommand(chat *chatState, prompt string) { cmd := exec.Command("claude", "--dangerously-skip-permissions", "-p", prompt) cmd.Dir = s.projectRoot() + cmd.Env = cleanEnv() stdout, err := cmd.StdoutPipe() if err != nil {