Fix: Unset CLAUDECODE env var za child claude procese

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
djuka 2026-02-20 14:55:13 +00:00
parent 80cf1d73ce
commit 695bd24d1d
2 changed files with 16 additions and 0 deletions

View File

@ -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 {

View File

@ -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 {