We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Automatic Formatting

Without a strict formatter, your agent will spend tokens worrying about indentation, trailing commas, and line length. Not only will it waste tokens, but it will also (like any human) be inconsistent.

So, just like when working with humans, always add a code formatter to your workflow and put the problem to rest. For example:

  • oxfmt for JavaScript/TypeScript, HTML, CSS, Markdown, and more
  • ruff for Python
  • gofmt for Go

It's just one less thing for your agent to worry about.

I prompt my agent to make formatting changes only as a last step, after all the logic changes are done. If I don't, I've found it can really slow things down.

I think the models are pretty good now at realizing that they're approaching the end of their work, and they'll call things like type checking and formatting on their own. If they don't, steer them in AGENTS.md.

Assignment

Make formatting part of OpenCode's normal workflow, then try it out by adding some new unit tests for joining strings. This SlopLang code should print what's shown in the comments:

hallucinate(“” + “slop”)✨
— slop
hallucinate(“slop” + “”)✨
— slop

hallucinate(“café” + “✨”)✨
— café✨

Notably, adding empty strings doesn't change the original string, and adding a string with an emoji works as expected.

Tell OpenCode to run and submit the CLI tests from the project root.