@@ -75,13 +75,30 @@ func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any,
7575 if r .Dir != "" {
7676 cmd .Dir = r .Dir
7777 }
78- // Inherit the current environment (excluding SQLC_AUTH_TOKEN) and add SQLC_VERSION
79- for _ , env := range os .Environ () {
80- if ! strings .HasPrefix (env , "SQLC_AUTH_TOKEN=" ) {
81- cmd .Env = append (cmd .Env , env )
78+ // Pass only SQLC_VERSION and explicitly configured environment variables
79+ cmd .Env = []string {
80+ fmt .Sprintf ("SQLC_VERSION=%s" , info .Version ),
81+ }
82+ for _ , key := range r .Env {
83+ if key == "SQLC_AUTH_TOKEN" {
84+ continue
85+ }
86+ cmd .Env = append (cmd .Env , fmt .Sprintf ("%s=%s" , key , os .Getenv (key )))
87+ }
88+ // For "go run" commands, inherit PATH and Go-related environment
89+ if len (cmdParts ) > 1 && cmdParts [0 ] == "go" {
90+ for _ , env := range os .Environ () {
91+ if strings .HasPrefix (env , "PATH=" ) ||
92+ strings .HasPrefix (env , "GOPATH=" ) ||
93+ strings .HasPrefix (env , "GOROOT=" ) ||
94+ strings .HasPrefix (env , "GOWORK=" ) ||
95+ strings .HasPrefix (env , "HOME=" ) ||
96+ strings .HasPrefix (env , "GOCACHE=" ) ||
97+ strings .HasPrefix (env , "GOMODCACHE=" ) {
98+ cmd .Env = append (cmd .Env , env )
99+ }
82100 }
83101 }
84- cmd .Env = append (cmd .Env , fmt .Sprintf ("SQLC_VERSION=%s" , info .Version ))
85102
86103 out , err := cmd .Output ()
87104 if err != nil {
0 commit comments