Go version

go version go1.25-devel_4d1c255f15 Thu Jun 5 11:44:48 2025 -0700 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN='/usr/w/bin'
GOCACHE='/tmp/go'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/w/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2397608331=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/tmp/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/w/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/w/g/lang/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/w/.config/go/telemetry'
GOTMPDIR='/tmp'
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/w/g/lang/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25-devel_4d1c255f15 Thu Jun 5 11:44:48 2025 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

$ mkdir -p /tmp/x/{a,b} && cd /tmp/x
$ echo 'pacakge main; func main() {}' | tee a/a.go b/b.go
$ go mod init x
$ go get -tool x/a x/b

What did you see happen?

$ cat go.mod
module x

go 1.25

tool x/b

What did you expect to see?

Only the very last package is tracked, I expected to have x/a and x/b in go.mod.

Comment From: wgrr

here's the bug. (note the argument in append)

https://github.com/golang/go/blob/d184f8dc020ac635cea02c046ab1d0b87dfd624d/src/cmd/go/internal/modget/get.go#L456

Comment From: gopherbot

Change https://go.dev/cl/679975 mentions this issue: cmd/go: fix get -tool when multiple packages are provided

Comment From: dolmen

Note however that a package pattern that matches multiple package works.

For the given test case:

$ go get -tool ./...
$ cat go.mod
module x

go 1.25

tool (
    x/a
    x/b
)

(but (not demonstrated here) it works beyond what is expected, as even non-main packages are registered as tools)