Skip to content

proposal: cmd/go: tell tools they are being run via go tool #78673

Description

@dolmen

Proposal Details

Summary

go tool set environment variable(s) that allows a tool to identify being run from go tool.

Proposal

When go tool executes a tool, set the following variables:

As a tool being called by go tool might itself call another tool via go tool, all go tool specific environment variables of a parent tool execution must be overwritten or deleted.

Rationale

Tools can currently run in two modes:

  • stand-alone: when installed with go install <tool>@<version> and executed as normal commands from the shell
  • module tool: when declared in go.mod and executed through go tool <tool>

To improve integration of tools with the Go toolchain, I think that tools should be able to distinguish in which mode they are being executed: when running stand-alone, they should be able to detect if they are working in a Go module which has declared them, and then work just as a shim that delegate to go tool to the specific version selected for the project is executed.

The purpose of this proposal is to help the tool to distinguish if it is being executed via go tool (stand-alone vs module tool as defined above).

For example golang.org/x/tools/cmd/stringer installed with go install should be able to detect that it is executed from a Go module that has golang.org/x/tools/cmd/stringer declared (and so locked to a specific version), and then forward its arguments to go tool golang.org/x/tools/cmd/stringer. But to avoid infinite recursion, stringer should be able to discover if it is already running via go tool.

Update 2026-05-18: fixed Markdown for specification of environment variable values as <bla bla> was hidden

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions