| name | go-deps |
| description | Manage Go module dependencies: tidy, update, vendor, audit, and analyze dependency trees with go mod and govulncheck. Trigger: when managing Go dependencies, go mod tidy, go get update, go module graph, govulncheck, vendor dependencies, go module audit |
| version | 1 |
| argument-hint | [tidy|update|vendor|audit|graph|why <module>] |
| allowed-tools | ["bash","read","write","grep","glob"] |
Go Dependency Management
You are now operating in Go module dependency management mode.
Installation Check
go version
cat go.mod
Core Module Commands
go mod tidy
go mod download
go mod verify
go mod graph
go mod graph | head -50
Updating Dependencies
go list -m -u all
go list -m -u -json all 2>/dev/null | jq -r 'select(.Update != null) | "\(.Path) \(.Version) -> \(.Update.Version)"'
go get -u ./...
go get -u=patch ./...
go get -u github.com/some/module@latest
go get github.com/some/module@v1.2.3
go get github.com/some/module@v1.1.0
go get github.com/some/module@none
Conservative vs Aggressive Update Strategy
Conservative (patch-level only — lowest risk)
go get -u=patch ./...
go mod tidy
go test ./...
Moderate (minor + patch — safe for semver-compliant modules)
go get -u ./...
go mod tidy
go test ./...
Aggressive (includes major versions — may require code changes)
go list -m -u -json all 2>/dev/null | jq -r 'select(.Update != null) | .Path + " " + .Update.Version'
go get github.com/some/module/v2@latest
Dependency Analysis
go mod why github.com/some/module
go mod why -m github.com/some/module
go mod graph | grep github.com/some/module
go list -m -json all | jq -r 'select(.Indirect == null or .Indirect == false) | .Path + " " + .Version'
go list -m -json all | jq -r 'select(.Indirect == true) | .Path + " " + .Version'
go mod why -m golang.org/x/net
Vendoring
go mod vendor
go mod verify
go build -mod=vendor ./...
go test -mod=vendor ./...
rm -rf vendor/
Security Audit with govulncheck
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
govulncheck github.com/your/module/pkg/...
govulncheck -json ./...
govulncheck -mode=module ./...
go.sum Management
rm go.sum
go mod download
go mod verify
go mod download all
go mod verify
Replacing Modules (Local Development)
go mod edit -replace github.com/some/module=../local-fork
go mod edit -dropreplace github.com/some/module
go mod edit -replace github.com/some/module=github.com/your-fork/module@v0.0.0-timestamp-hash
Workspace Mode (Go 1.18+)
go work init ./moduleA ./moduleB
go work use ./moduleC
go build ./...
go work sync
GOWORK=off go build ./...
Common Workflows
Post-Clone Setup
go mod download
go mod verify
go mod tidy
go build ./...
Weekly Dependency Update
go list -m -u all
go get -u=patch ./...
go mod tidy
go test ./... -race
govulncheck ./...
Adding a New Dependency
go mod tidy
go get github.com/new/module@v1.2.3
go mod tidy
go.mod Directives Reference
module github.com/your/project // module path
go 1.22 // minimum Go version
require (
github.com/some/dep v1.2.3
github.com/other/dep v2.0.0+incompatible
)
replace github.com/some/dep => ../local-fork // local replacement
exclude github.com/bad/dep v1.0.0 // exclude problematic version
Best Practices
- Run
go mod tidy before every commit to keep go.mod and go.sum clean.
- Pin major version updates explicitly — do not use
go get -u blindly across major versions.
- Run
govulncheck ./... in CI to catch known vulnerabilities early.
- Use
-mod=vendor in CI builds for reproducibility without network access.
- Store
go.sum in version control — it provides supply-chain security.
- Prefer patch updates (
-u=patch) for production dependencies; review minor/major changes manually.