LLMs for grammar
UPDATE: There’s a more refined version of this in a new post.
Today, Dr. Drang asked on Mastodon about my setup to leverage LLMs to check my grammar.
My setup has a couple of assumptions, just like his:
- I have a native macOS app holding text1
- I write in markdown (although this one can be relaxed)
Tooling
- I use Keyboard Maestro
- I use the excellent llm command-line utility
For this post, I’m assuming you already set up llm, but if not and you have uv handy, it’s this simple:
uv tool install llm
llm keys set openai # if using OpenAI
# if using gemini
llm install llm-gemini
llm keys set gemini
# if using Claude
llm install llm-anthropic
llm keys set anthropic
The macro
Once this is in place, the macro is pretty straightforward, and I invoke it with the text I want to check selected. I then have to wait a bit, and the script will replace the text with a corrected version, each corrected item marked in bold (I don’t use bold much in my text, so that is OK).

The core of the macro is the (fish, but it will work on other shell unmodified, probably) script (pasted here to make it easier to copy and paste):
#!/opt/homebrew/bin/fish
pbpaste | llm -m gemini-3-flash-preview -s "
Given the following text, improve grammar and punctuations.
Once you're done, highlight the changes by using a double asterisk (bold, in Markdown). Only output the text, don't add commentary or summaries anywhere in the text"
Since the macro highlights clearly what has been changed, I can learn a bit as well! And if the window loses focus, everything will be in the clipboard.
-
Not all text might need to be checked, though. For example, in my mail client, most of the text I’m replying to doesn’t need a grammar check. ↩︎