Back to News & Insights
Artificial Intelligence August 27, 2026 · 20 min read

[Go in Practice] Writing Modern Go with AI: Testing JetBrains go-modern-guidelines and Refactoring a 1,039-line main.go

Background In the AI era, even I delegate most of my code optimization or writing tasks...

[Go in Practice] Writing Modern Go with AI: Testing JetBrains go-modern-guidelines and Refactoring a 1,039-line main.go

In the AI era, even I delegate most of my code optimization or writing tasks to AI. However, due to factors in model training data, too many writing styles are outdated. This results in code that cannot utilize features of the latest Go versions, which is quite a pity.

Fortunately, JetBrains released go-modern-guidelines, a very useful plugin. It makes your AI Agent smarter and teaches it how to use the latest syntax to optimize your Golang code.

The positioning of this project is very straightforward: Provide contemporary Go writing specifications for AI agents so they don't write outdated Go due to knowledge cutoffs.

The problem has two layers. The first layer is easy to understand: training data has a cutoff. Anything added to the standard library after that cutoff won't be used because the model hasn't seen it. The project's own example is errors.AsType[T] (Go 1.26); if the model hasn't seen it, it naturally won't write it.

The second layer is more subtle, which the project calls frequency bias: even if the model "knows" the new way, the old way appears overwhelmingly more often in the training data. In ten years of Go code on the internet, interface{} appears far more than any, and sort.Slice far more than slices.SortFunc. Models perform probabilistic prediction; the one that wins by majority vote is usually the old one.

I really saw this second point in this refactoring. The original project had this snippet:

A hand-rolled string search, with a comment specifically explaining "to avoid importing strings". strings is in the standard library; the cost of importing it is zero. What this code actually needed was just one line: strings.Contains(err.Error(), "invalidgrant").

The key point of list is that it provides different answers based on the Go version. You can pass a file path directly, and it will look up for go.mod, go.work, or fall back to the local Go toolchain:

My project's go.mod specifies go 1.24.0, so it returned 45 guidelines. Change the version number, and the count changes:

| Go Version | Guideline Count | | --- | --- | | 1.21 | 32 | | 1.22 | 37 | | 1.23 | 41 | | 1.24 | 45 | | 1.25 | 46 | | 1.26 | 48 | | 1.27 | 54 |

This design is intentional: it only suggests syntax that your project version can actually use. This is crucial for AI agents; otherwise, it might happily suggest errors.AsType[T], and your CI would fail because it's running on Go 1.24.

Looking at the differences between versions, it's essentially a condensed list of Go's recent features:

list provides a one-line summary; use explain for detailed instructions when you're ready to work. Output looks like this:

Note the last sentence in the Details section: "all arguments are evaluated before the call." This is the real trap of cmp.Or—if your fallback source is an expensive function call, writing cmp.Or(a(), b()) will execute both. This kind of "you can use it, but know the cost" reminder is much more useful than just telling you to change the syntax.

This list/explain layering might look like just interface design, but it's actually for the AI agent's context window. 45 guidelines, each with a one-line summary, take about 1000 tokens; but if every guideline included full explanations and before/after examples, just stuffing this list would burn tens of thousands of tokens.

So the workflow is: first list to scan everything, determine which guidelines are relevant to the current code, and then only call explain for those. In this case, I actually only explained six guidelines.

There's one rule in the skill documentation written with particular emphasis: Do not pipe the output of list to head, tail, or grep, as you might miss important guidelines. I violated this rule on my first try, which I'll discuss in the "Pitfalls" section.

Once installed, it triggers automatically for Go-related tasks, or you can call it manually: /modern-go-guidelines:use-modern-go. Cursor, Junie, and Codex have their own installation methods; other agents can use npx skills add JetBrains/go-modern-guidelines. The project is licensed under Apache 2.0.

Want to discuss this further?

Book a free strategy call with our team to see how these insights apply to your specific business goals.

Book a consultation