Command Structure and Help

Understanding the go command syntax, getting help, and navigating the built-in documentation system

Every interaction with Go's toolchain begins with the same two characters, go. The command's syntax is simple on the surface, a single binary that dispatches to subcommands, but the way you ask it for help determines how fast you find answers. This page covers the structure of go invocations and the help system that makes the entire toolchain self-documenting.

The go Command Syntax

A go invocation has a fixed shape.

go <command> [arguments]

The first word after go is always a subcommand that tells the tool what to do. Everything that follows, flags, package names, file paths, supplies how and where to do it.

go build -o myapp ./cmd/server

Here build is the subcommand, -o myapp is a flag with a value, and ./cmd/server identifies the package to build. The subcommand is not optional. Running go with no arguments prints a short help overview but does not perform any work. Every meaningful operation, compiling, testing, formatting, managing dependencies, lives behind one of the subcommands the binary carries.

Subcommands are not flags:

A subcommand like build or run is a positional argument that selects an entire operation mode. It is not a flag. You do not write go -build. That would be a flag called -build which does not exist and will produce an error.

Getting Help from the go Command

Go ships its own documentation inside the tool. No internet connection is required, and you never need to leave the terminal. The help system is the fastest way to recall a flag you forgot or to discover what a subcommand does.

The top-level help overview

Running go help with no subcommand prints every available command and a list of additional help topics.

go help

The output on Go 1.27.4 looks like this.

Go is a tool for managing Go source code.

Usage:

        go <command> [arguments]

The commands are:

        bug         start a bug report
        build       compile packages and dependencies
        clean       remove object files and cached files
        doc         show documentation for package or symbol
        env         print Go environment information
        fix         apply fixes suggested by static checkers
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing source
        get         add dependencies to current module and install them
        install     compile and install packages and dependencies
        list        list packages or modules
        mod         module maintenance
        run         compile and run Go program
        telemetry   manage telemetry data and settings
        test        test packages
        tool        run specified go tool
        version     print Go version
        vet         report likely mistakes in packages
        work        workspace maintenance

Use "go help <command>" for more information about a command.

Additional help topics:

        buildconstraint build constraints
        buildjson       build -json encoding
        buildmode       build modes
        c               calling between Go and C
        cache           build and test caching
        environment     environment variables
        filetype        file types
        goauth          GOAUTH environment variable
        go.mod          the go.mod file
        gopath          GOPATH environment variable
        goproxy         module proxy protocol
        importpath      import path syntax
        modules         modules, module versions, and more
        module-auth     module authentication using go.sum
        packages        package lists and patterns
        private         configuration for downloading non-public code
        testflag        testing flags
        testfunc        testing functions
        vcs             controlling version control with GOVCS

Use "go help <topic>" for more information about that topic.

The commands are listed alphabetically, with work last. The top of the output gives you a choice, pick a command for operational tasks, or pick a topic for conceptual documentation. Both paths lead to further detailed help.

Your installation is working:

If this output appears after typing go help, your Go installation is correctly set up and the tool is accessible from your terminal. A missing or garbled output usually means the Go binary is not on your PATH.

Help for a specific subcommand

To learn everything about one subcommand, add its name after help.

go help build

This prints the subcommand's usage line, a description of what it does, and every flag it accepts. For example, go help build explains the -o flag, the handling of _test.go files, and how the output binary is named when you pass a list of .go source files. If you ever forget a flag that belongs to go test, you do not need to search the web, you run go help test and scroll to the flags part.

Help for a conceptual topic

The "Additional help topics" part covers subjects that are not subcommands but govern behaviour across multiple commands. Run the same syntax.

go help gopath
go help modules
go help packages

These pages define conventions and environment variables. They are especially useful when you encounter errors about module requirements or package resolution, because the explanation of what the tool expects is already on your machine.

Topic names are case-sensitive:

The help topic is gopath, not GOPATH. Typing go help GOPATH returns go help GOPATH: unknown help topic. Run 'go help'. Use the lowercase name exactly as it appears in the help overview.

The -h shortcut on subcommands

Most subcommands accept a -h or --help flag directly, without the help subcommand.

go build -h
go test -h

This produces the same detailed output as go help build or go help test. The shortcut exists because many developers are used to -h from other tools, and the go command accommodates that habit.

What go -h really does at the top level

A common beginner belief is that go -h fails with a flag error at the top level. That is not what happens. Running go -h prints the full help overview, the same text go help prints, and then exits with status 2. The same is true for go --help and go -help. The help goes to standard error rather than standard output, and the non-zero exit status is what marks the difference. So go -h works as a way to read the help, but go help is the clean way to do it, because it prints the same text to standard output and exits with status 0.

go -h

The output is the full command list shown above, followed by exit status 2. There is no message like flag provided but not defined: -h. If you write go -h inside a script, remember that the exit status is non-zero, so a script that stops on errors would treat it as a failure even though the help printed fine.

go -h exits non-zero:

go -h prints the help overview but exits with status 2. Use go help when you want the help text with a successful exit status, for example inside a script or when piping the output.

How the Help Output Is Structured

Each help page follows a consistent layout that makes scanning for information predictable.

  1. Header line - a one-sentence description, for example "Build compiles the packages named by the import paths...".
  2. Usage line - the exact syntax, with brackets for optional parts.
  3. Description - paragraphs explaining what the command does and any important default behaviours.
  4. Flags - a list of every accepted flag, grouped by shared flags first, then command-specific ones.

The flag list is especially thorough. Flags that appear across multiple commands, like -v for verbose output or -x to print executed commands, are documented once and identified as shared. This avoids duplication in the tool's internal documentation and helps you recognise patterns across different subcommands.

When a flag accepts a value, the help output shows the syntax inline, for example -o output tells you that -o expects a following argument. Flags that are boolean toggles do not take a value, -v simply means verbose mode is on.

The help system is hierarchical, and the fastest way to navigate it is to treat it as a tree.

  • Start with go help to see the top-level commands and topic list.
  • For a command, run go help <command>.
  • If a concept appears in the output that you do not understand, like "build constraints", use go help buildconstraint to read its dedicated page.

You rarely need to memorise more than a handful of commands because the tree itself serves as a live reference. Many experienced Go developers keep a terminal open and run go help as their first instinct when they encounter an unfamiliar subcommand.

Common Mistakes When Using Help

Mistakes with the go help system are easy to make but equally easy to fix once you know the rules.

Confusing the help subcommand with a help flag

The go binary has a help subcommand, and subcommands accept a -h flag. go help build and go build -h both work. At the top level, go help is the clean form, while go -h prints the same overview but exits with status 2.

Assuming go help covers everything

The output of go help lists subcommands and additional help topics, but it does not show every possible flag for every command. You must drill down with go help <command> to see those. A developer who only ever runs go help and skims the summary will miss flags like -race or -cover that only appear in the detailed help for go test and go build.

Trying to get help for a non-existent command

Running go help nonexistent produces go help nonexistent: unknown help topic. Run 'go help'. The error message tells you exactly what went wrong, but it can be confusing if you expected the tool to guess or offer suggestions. There is no fuzzy matching. You need the exact subcommand or topic name from the go help listing.

How This Fits Into Daily Work

The go command's self-documenting nature means the terminal becomes a self-contained learning environment. When you are writing a build script or debugging a CI pipeline, the fastest answer is often go help <command> rather than a web search. Because the help is versioned with the Go toolchain itself, the information always matches the exact binary you are using, with no risk of reading documentation for a newer or older version.

The help system also reflects the design philosophy of the go command, conventions over configuration. You cannot add custom help topics or flags to the built-in system, and that constraint keeps the documentation predictable. You learn the pattern once, and it applies across every subcommand.

Summary

The go command is a single binary that dispatches to subcommands, and its help system is the fastest way to discover what each subcommand can do. The syntax go help opens the top-level index, go help <command> and go help <topic> give detailed, version-accurate documentation, and go -h prints the same overview with a non-zero exit status. The built-in help replaces external man pages and web searches for most day-to-day questions about the Go toolchain.

The habit worth building is to run go help <command> before using a subcommand for the first time. The answer you need is almost certainly already on your machine, structured in a consistent format, and matched to the exact Go version you have installed.