Generated banner for Golang Gopls
Generated logo for Golang Gopls

Golang Gopls

Samuel BertheCommunityCreated by samberDistributed by Samuel Berthe

  • Skill
  • Tool integration
  • Software development
  • MIT
  • No issues found

From the author

Golang semantic code intelligence via `gopls`, the official Go language server — go-to-definition, find references, call/implementation hierarchy, workspace symbol search, package API discovery, diagnostics, safe rename, refactors (extract/inline/fill/rewrite code actions), formatting, and generated tests. Reaches an agent via gopls's own MCP server (`go_*` tools), Claude Code's native `LSP` tool, or the `gopls` CLI. Use when navigating or refactoring Go code — jumping to a definition, finding call sites before a rename, understanding a file's or package's dependencies, running diagnostics after an edit, or extracting/inlining/renaming. Not for the published ecosystem — packages not in your `go.mod`, versions, licenses, importers — → See `samber/cc-skills-golang@golang-pkg-go-dev` skill (`godig`). Not for a whole-tree vulnerability audit → See `samber/cc-skills-golang@golang-security` skill (`govulncheck`).
— the description by samber

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

The golang-gopls skill provides an agent with deep semantic understanding of Go codebases by leveraging gopls, the official Go language server. Unlike text-based search tools, gopls understands the resolved build, including dependencies, build tags, and interface relationships. It supports three integration modes: a dedicated MCP server for agent-friendly interactions, a native LSP tool for editor-like diagnostics, and a CLI for one-shot tasks. This skill is essential for precise navigation, automated refactoring, and maintaining code quality within a locally resolved Go workspace.

What it does

  • Performs semantic navigation like go-to-definition, implementation lookups, and call hierarchy analysis.
  • Provides fuzzy workspace symbol searching to locate types, functions, and variables.
  • Executes safe refactoring actions including renaming, extracting, and inlining code.
  • Generates compiler diagnostics and vulnerability reports based on the local build configuration.
  • Handles code formatting and import organization to maintain canonical Go style.
  • Offers documentation hovers and signature help for APIs within the workspace.

When to use it

  • When you need to understand the structure or dependencies of a local Go project.
  • Before performing refactors to ensure interface satisfaction and safe renaming.
  • To identify and fix compiler errors or linting issues after modifying code.
  • When you need to trace call sites or implementation relationships across a codebase.
  • To quickly locate symbols or package APIs within your current workspace.

Advantages

  • Provides build-aware intelligence that accounts for build tags and dependency pinning.
  • Supports automated, safe refactoring actions that preserve code integrity.
  • Offers multiple integration paths to suit different agent workflows and environments.
  • Reduces manual verification by providing immediate feedback on code changes via diagnostics.
  • Enables deep exploration of internal packages and local dependencies.

Usage examples

“Find all implementations of the Logger interface in this project.”
The agent uses the implementation tool to return a list of concrete types that satisfy the Logger interface, allowing for targeted code analysis.
“Rename the User struct to Account and update all references.”
The agent executes a safe rename refactor, ensuring that all imports and usages across the workspace are updated without breaking the build.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/samber/golang-gopls/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip golang-gopls.zip -d .agents/skills

Documentation by samber

Persona: You are a Go engineer who reaches for semantic code intelligence instead of grep whenever a question is about the resolved build — grep finds text, gopls finds meaning (types, call graphs, shadowing, implementation relationships).

Dependencies: gopls — go install golang.org/x/tools/gopls@latest (v0.20+). The native LSP tool additionally needs ENABLE_LSP_TOOL=1 and the gopls-lsp@claude-plugins-official marketplace plugin (see references/mcp.md).

gopls is the official Go language server. It only answers questions about your specific, locally resolved build — your workspace plus every dependency exactly as pinned in go.sum, including replace directives. For a package that isn't part of that build (versions, docs, licenses, CVEs of something you haven't added yet), → See samber/cc-skills-golang@golang-pkg-go-dev skill (godig) instead.

Three ways to reach gopls

Not interchangeable — pick by what you already know and what you need back:

  • gopls's own MCP server (preferred for most tasks) — purpose-built for agents: tools take names, file paths, and fuzzy queries instead of raw cursor positions. Register once per machine: claude mcp add gopls -- gopls mcp. Runs headless over stdio, no editor attached, only sees files saved to disk — the right default for an agent-only workflow. See references/mcp.md for every tool.

  • The native LSP tool — Claude Code's built-in editor-style integration. Off by default: set ENABLE_LSP_TOOL=1, install gopls, and install the official gopls-lsp@claude-plugins-official marketplace plugin to wire it as the Go language server. Operations (goToDefinition, findReferences, hover, documentSymbol, workspaceSymbol, goToImplementation, call hierarchy) are keyed by line/character, so they're most useful once you already have a location — typically right after a grep or a read. Unique value: compiler diagnostics are pushed into context automatically after every edit, no explicit call needed.

  • The gopls CLI — same engine, invoked as gopls <command> <file:line:col>. The Go team documents it as experimental and debugging-only — "not efficient, complete, flexible, or officially supported." Use it when neither MCP nor the native tool is wired up, or for a one-shot scripted check. Positions are file:line:col (1-indexed, UTF-8 bytes) or file:#offset (0-indexed). See references/cli.md.

Preference order: MCP → native LSP → CLI. MCP tools match how an agent thinks (by name/path, not cursor position); the native tool adds free automatic diagnostics; the CLI is the documented fallback of last resort. Wire as many as are available and let the task pick the tool — a query you already have a line:col for is cheap via LSP, a "where is X" query is cheap via go_search, a quick unattended check is cheap via the CLI.

Capability → CLI → MCP → native LSP

Full mapping of every capability to its CLI command, MCP tool, and native LSP op: references/matrix.md.

Use cases

  • Navigation — jump to a definition, an implementation, or trace a call graph before touching code you didn't write. Details: references/features.md.

  • Code discovery — learn a workspace's shape (go_workspace), fuzzy-search a symbol you can't place exactly (go_search), or read a dependency's public surface (go_package_api) before using it.

  • Documentation — hover for type/doc/size info, signature help while calling a function, or browse rendered package docs (source.doc, including internal packages pkg.go.dev never sees).

  • Diagnostics & safety — compiler and analyzer errors after every edit (go_diagnostics / automatic with LSP), plus a lightweight go_vulncheck reachability check: once as a baseline right after detecting the workspace, and again after any go.mod change.

  • Formatting — canonical gofmt-equivalent formatting and import organization, both scriptable and code-action-driven.

  • Refactoring — safe rename (blocks a change that would break interface satisfaction), extract/inline, and the full refactor.rewrite.* family (fill struct/switch, invert if, split/join lines, remove unused parameter, add struct tags, implement interface). Full catalog with gotchas: references/features.md.

Efficient workflows

These Read/Edit workflows encode the order that avoids redundant queries and half-applied edits — treat every step as required, not optional, even to save a round trip.

  • Session start — call go_workspace once to detect whether this is a Go workspace at all; if it is, immediately follow with a baseline go_vulncheck to surface vulnerabilities the workspace already carries. This is unconditional, separate from the edit workflow's later check after a dependency change.

Read workflow (understand before touching anything):

  1. go_workspace — layout (module/workspace/GOPATH); same call as the session-start check above if it hasn't run yet.

  2. go_search — fuzzy-locate a type/function/variable by name.

  3. go_file_context — right after reading any Go file for the first time, see what it pulls in from the rest of its package; re-run if that file's dependencies change.

  4. go_package_api — a third-party dependency's or sibling package's public surface, without reading every file.

Edit workflow (iterate until diagnostics are clean):

  1. Read first (workflow above).

  2. go_symbol_references before modifying any definition — judge the blast radius, then read every referencing file that needs a matching edit.

  3. Make all planned edits, including the reference-site edits, before moving on.

  4. go_diagnostics on every changed file — mandatory after each modification, not an optional cleanup pass.

  5. Fix reported errors: review any suggested quick-fix diff before applying, then re-run diagnostics to confirm the fix landed. Ignore hint/info diagnostics unrelated to the task. A diagnostic message can paraphrase the surrounding source rather than quote it verbatim.

  6. Only if go.mod dependencies changed, run go_vulncheck on the whole workspace — after diagnostics are clean, not before.

  7. Run go test <changed-package-paths> — not ./... unless explicitly asked, since a full-repo run slows the iteration loop.

Gotchas worth knowing before you rely on a result:

  • references results only reflect the build configuration of the queried file — a query on foo_windows.go will not surface matches in bar_linux.go; re-run under the relevant GOOS/build tags if a cross-platform result is missing.

  • call_hierarchy only shows static calls — calls through function values or interface methods are invisible to it; corroborate with references when the call site matters.

  • Extract/inline refactors are less rigorous than rename: comments are sometimes dropped, and generated files marked DO NOT EDIT receive no code actions at all.

  • refactor.rewrite.fillStruct searches only the current file above the cursor and needs the struct's package already imported — run source.organizeImports first if the type was just typed in.

gopls vs godig vs Context7 vs govulncheck

gopls only reasons about code present and resolvable in the local build:

  • For anything not tied to that build (version history, license, ecosystem-wide importers, CVEs of a package not yet added) → See samber/cc-skills-golang@golang-pkg-go-dev skill (godig) — it queries pkg.go.dev directly, no local checkout needed.

  • For a comprehensive, whole-tree vulnerability audit (CI gates, periodic sweeps) rather than gopls's lightweight on-demand go_vulncheck → See samber/cc-skills-golang@golang-security skill (govulncheck).

  • Context7 remains a fallback for non-Go docs or a Go module not indexed on pkg.go.dev.

The full task-to-tool matrix lives in the samber/cc-skills-golang@golang-how-to skill's "godig vs gopls vs Context7 vs govulncheck" section.

Files

references/cli.md

gopls CLI reference

The Go team documents this interface as experimental — "not efficient, complete, flexible, or officially supported." Treat it as a debugging and one-shot-scripting fallback, not the primary way to drive gopls; prefer the MCP tools or the native LSP tool when either is available (see mcp.md).

Table of contents

  • Position syntax

  • Global flags

  • Shared write flags

  • Navigation commands

  • Diagnostics

  • Transformation commands

  • Code actions and code lenses

  • Introspection

  • CodeAction kind reference

Position syntax

Two interchangeable formats locate a point in a file:

  • file.go:line:column — both 1-indexed; columns count UTF-8 bytes, not runes or UTF-16 code units. Non-ASCII lines can disagree with what an editor reports if the editor counts differently.

  • file.go:#1234 — a 0-indexed byte offset from the start of the file.

gopls definition internal/cmd/definition.go:44:47
gopls definition internal/cmd/definition.go:#1270

Global flags

Flags accepted by gopls itself, before the subcommand:

FlagValuePurpose
-logfile=<path>a file path, or the literal string autoLog destination; auto picks a default output file instead of stderr
-profile.cpu=<path>a file pathWrite a CPU profile to this file
-profile.mem=<path>a file pathWrite a memory profile to this file
-profile.alloc=<path>a file pathWrite an allocation profile to this file
-profile.block=<path>a file pathWrite a blocking-profile to this file
-profile.trace=<path>a file pathWrite an execution trace to this file
-v, -verboseboolean flag, no valueVerbose output
-vv, -veryverboseboolean flag, no valueVery verbose output

gopls mcp accepts its own, narrower flag set: -listen=<addr> (run over SSE/HTTP instead of stdio), -logfile=<path> (defaults to stderr), and -rpc.trace (cannot be combined with -listen).

Shared write flags

Every command that can modify source (format, imports, rename, codeaction, codelens, execute) accepts this same set — each is a boolean flag, no value:

FlagPurpose
-w, -writeWrite the edited content back to the source file(s)
-d, -diffPrint a unified diff instead of writing
-l, -listPrint only the names of the files that would be/were edited
-preserveCombined with -w: keep a copy of each original file before overwriting

None of these are mutually exclusive with each other; passing none of them just computes the edit without printing or writing it.

Navigation commands

CommandFlagsExampleNotes
definition-json (boolean), -markdown (boolean)gopls definition helper/helper.go:8:6-json for structured output, -markdown to render doc comments as Markdown
references-d, -declaration (boolean)gopls references helper/helper.go:8:6Includes the declaration itself in the results when set
implementationnonegopls implementation helper/helper.go:8:6—
call_hierarchynonegopls call_hierarchy helper/helper.go:8:6Static calls only
symbolsnonegopls symbols helper/helper.goFile-scoped outline
workspace_symbol-matcher=<value> — one of fuzzy, fastfuzzy, casesensitive, caseinsensitive (default caseinsensitive)gopls workspace_symbol -matcher fuzzy 'wsymbols'Matching algorithm for the query
signaturenonegopls signature helper/helper.go:8:6Function signature at position
highlightnonegopls highlight helper/helper.go:8:6Same-symbol identifier highlights
folding_rangesnonegopls folding_ranges helper/helper.goCollapsible regions
links-json (boolean)gopls links internal/cmd/check.goStructured output when set
prepare_renamenonegopls prepare_rename helper/helper.go:8:6Validates a rename is possible at this position before attempting it
semtoknonegopls semtok internal/cmd/semtok.goSemantic token dump

Diagnostics

CommandFlagsExample
check-severity=<value> — one of hint, info, warning, error (default warning); reports diagnostics at or above this severitygopls check -severity=error internal/cmd/check.go

Transformation commands

All of these additionally accept the shared write flags above.

CommandPositional argsExampleNotes
formatone or more <filerange> (a file, or a range within one)gopls format -w internal/cmd/check.goCanonical gofmt-equivalent; ignores client formatting options
imports<filename>gopls imports -w internal/cmd/check.goAdds/removes/sorts imports
rename<position> <new-name>gopls rename helper/helper.go:8:6 Foo<new-name> is a plain identifier — validate first with prepare_rename if unsure

Code actions and code lenses

codeaction and codelens additionally accept the shared write flags.

CommandExtra flagsNotes
codeaction-kind=<value> — comma-separated list of kinds, see CodeAction kind reference below; -title=<regex> — filter actions by title; -exec (boolean) — execute the first match instead of only listing-kind=refactor matches every kind nested under it (kinds are hierarchical); only one action executes per invocation — there is no conflict resolution for applying more than one; actions of kind source.test are excluded unless explicitly requested via -kind
codelens-exec (boolean) — run the first matching lens instead of only listingTakes <file>, <file:line>, or <file> <title> as positional args
executenone beyond the shared write flagsTakes <command> <json-argument> — sends a raw LSP ExecuteCommand request; gopls's command set (command.Interface) is unstable and may change between versions
# List available code actions for a range
gopls codeaction -kind=quickfix ./gopls/main.go

# Execute the first matching action and show a diff
gopls codeaction -kind=quickfix -exec -diff ./gopls/main.go

# Filter by title (regex) in addition to kind
gopls codeaction -kind=refactor.rewrite -title 'Fill struct' -exec -w file.go:12:3

# Code lenses: list, or run a specific one
gopls codelens a_test.go                     # list lenses in a file
gopls codelens a_test.go:10                  # list lenses on line 10
gopls codelens a_test.go "run test"          # list gopls.run_tests commands
gopls codelens -exec a_test.go:10 "run test" # run a specific test

# Execute a raw LSP ExecuteCommand
gopls execute gopls.add_import '{"ImportPath": "fmt", "URI": "file:///hello.go"}'
gopls execute gopls.run_tests '{"URI": "file:///a_test.go", "Tests": ["Test"]}'
gopls execute gopls.list_known_packages '{"URI": "file:///hello.go"}'

Introspection

CommandFlagsNotes
stats-anon (boolean)JSON summary of workspace info relevant to performance; populates the file cache as a side effect. -anon redacts fields that could leak user/file names or source text
versionnonePrint gopls version info
api-jsonnonePrint gopls' full API surface as JSON
bugnoneReport a bug in gopls
licensesnonePrint licenses of bundled software
gopls stats
gopls stats -anon
gopls version
gopls api-json
gopls bug
gopls licenses

CodeAction kind reference

Passed to -kind on codeaction (comma-separated, hierarchical — refactor matches all refactor.*):

gopls.doc.features
quickfix
refactor
refactor.extract
refactor.extract.constant
refactor.extract.function
refactor.extract.method
refactor.extract.toNewFile
refactor.extract.variable
refactor.inline
refactor.inline.call
refactor.rewrite
refactor.rewrite.changeQuote
refactor.rewrite.fillStruct
refactor.rewrite.fillSwitch
refactor.rewrite.invertIf
refactor.rewrite.joinLines
refactor.rewrite.removeUnusedParam
refactor.rewrite.splitLines
source
source.assembly
source.doc
source.fixAll
source.freesymbols
source.organizeImports
source.test

A few additional kinds exist beyond this -kind-documented set but are reachable only through editor UI or execute/code lens, not by name filter: refactor.extract.variable-all, refactor.extract.constant-all, refactor.inline.variable, refactor.rewrite.moveParamLeft, refactor.rewrite.moveParamRight, refactor.rewrite.eliminateDotImport, refactor.rewrite.addTags, refactor.rewrite.removeTags, refactor.rewrite.implementInterface, source.addTest, source.splitPackage, source.toggleCompilerOptDetails. See features.md for what each one does.

Requirements and compatibility

Written for: Claude Code, OpenAI Codex

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Declares allowed tools, Claude Code frontmatter, Needs an MCP server

The author says: Designed for Claude Code, Codex or similar harness. Requires the gopls binary (go install golang.org/x/tools/gopls@latest) v0.20+ on PATH.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
samber
Publisher
Samuel Berthe (Community)
Distributed by
Samuel Berthe
Source
samber/cc-skills-golang · skills/golang-gopls · commit bb1d43d
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by samber or Samuel Berthe.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download golang-gopls.zip