Go toolchain version mismatch in Cursor IDE with go.work files

Go toolchain version mismatch in Cursor IDE with go.work files

Issue Description

When using Cursor IDE with Go modules that specify a different Go version than the system default, Cursor fails to automatically switch to the correct Go toolchain version, even when a go.work file is present. This causes build failures with errors like:

Steps to Reproduce

  1. Have a Go installation with multiple toolchain versions available (e.g., Go 1.22.6 and Go 1.23.7)
  2. Create a Go module that specifies a different Go version than your system default (e.g., go 1.23.7 in go.mod)
  3. Create a go.work file that includes this module and specifies the same Go version
  4. Open the project in Cursor IDE
  5. Try to build the project with go build

Expected Behavior

Cursor should respect the Go version specified in go.mod/go.work files and automatically use the correct toolchain version, as the Go command does when run from a regular terminal.

Actual Behavior

Cursor sets GOROOT to the system default Go installation (e.g., /Users/<my-user>/sdk/go1.22.6) instead of using the toolchain version specified in go.mod/go.work (e.g., /Users/<my-user>/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.7.darwin-amd64).

This causes a version mismatch error when building:

compile: version "go1.22.6" does not match go tool version "go1.23.7"

Workaround

Adding the following to Cursor’s settings.json fixes the issue:

"go.goroot": "~/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.7.darwin-amd64"

However, this is not an acceptable solution as it requires manually updating the setting whenever switching between projects that use different Go versions.

Environment

  • Cursor Version: 0.46.11
  • OS: macOS 24.3.0
  • Go Version: 1.23.7 (in go.mod/go.work), 1.22.6 (system default)
  • gopls Version: v0.18.1

Additional Information

  • The go command works correctly in a regular terminal, automatically using the correct toolchain version based on go.mod/go.work files.
  • The issue appears to be with how Cursor sets up the Go environment variables, specifically GOROOT.
  • When checking go env in Cursor’s terminal, it shows:
    • GOROOT='/Users/<my-user>/sdk/go1.22.6' (incorrect)
    • GOVERSION='go1.23.7' (correct)
    • GOWORK='/Users/<my-user>/go/src/github.com/<my-repo>/go.work' (correct)
    • GOTOOLCHAIN='auto' (correct)
  • This issue does not happen outside of Cursor, for example in iTerm, and there’s not special setup in iTerm or my shell either, it “just works” there.

This suggests that Cursor is correctly detecting the go.work file and Go version, but not properly setting GOROOT to use the appropriate toolchain.

1 Like