Lexa: A System-Wide AI English Corrector and Explainer
I write English every day in emails, Slack messages, code comments and terminal commit notes, and English is not my first language. Most grammar tools live inside one app or one browser tab. Lexa is my attempt to fix that: select text anywhere, right-click, and get a corrected version or a plain-English explanation, powered by an LLM through OpenRouter.
Why I built it
The problem was friction. Copying a sentence into a separate grammar site, reading the result and pasting it back is enough effort that I often skipped it and sent the message as written. I wanted the correction step to be as cheap as a copy and paste, and to work in every app, not only the ones with a plugin.
I also wanted it to cost nothing to try. OpenRouter offers free-tier models, so Lexa can run at $0 with no credit card needed for those models. Paid models are available if you prefer them.
What it does
Lexa has two actions:
- Correct English fixes grammar, spelling and clarity. The corrected text is copied to your clipboard, so you press paste to replace the original.
- Explain Text opens a popup that explains jargon, idioms or complex sentences in plain English.
On macOS the actions appear under right-click, then Services, as Correct English (Lexa) and Explain Text (Lexa). There is also a Stop Lexa Services entry that kills any running Lexa process, which is useful when a slow free model hangs. Keyboard shortcuts are Cmd+Shift+E and Cmd+Shift+X on macOS, and Ctrl+Shift+E and Ctrl+Shift+X on Linux.
It also works from the terminal:
python3 assistant.py --correctcorrects text from the clipboard.python3 assistant.py --explainexplains it.- You can pipe text in, for example
echo "I didn't went there yesterday" | python3 assistant.py --correct.
How it works
The project is mostly Python, with Shell scripts for installation. The core is a small set of files:
assistant.pyis the CLI entry point and handles the--correctand--explainflags.openrouter_client.pytalks to the OpenRouter API and includes a fallback chain.prompts.pyholds the prompt templates for both modes.popup_ui.pydraws the explanation popup and a loading indicator.config.pyreads environment variables.
One engine, thin OS wrappers
The main design choice was keeping all the logic in one Python CLI and letting each operating system provide only a trigger. On macOS, the setup script registers Automator Quick Actions in ~/Library/Services/ and refreshes the services cache. On Linux, the setup script installs xclip, libnotify-bin and python3-tk through apt-get and registers GNOME keyboard shortcuts. Both end up calling the same script. This is reusable: if your tool is a command that reads text and writes text, the OS integration is just glue.
Clipboard as the interface
Using the clipboard as input and output avoids needing accessibility permissions or app-specific plugins. On Linux, selected text is already in the X11 selection, and after correction the result sits in the clipboard for Ctrl+V. The trade-off is that Lexa does not replace text in place; you paste it yourself.
Configuration through .env
Settings live in a .env file, or in ~/Library/Application Support/Lexa/.env for the macOS app install:
OPENROUTER_API_KEYis required.CORRECTOR_MODELdefaults toopenrouter/free, which auto-picks an available free model.CORRECTOR_TIMEOUTdefaults to 30 seconds, because free models can be slow.CORRECTOR_MAX_CHARSdefaults to 2000, with a hard cap of 5000.CORRECTOR_QUIETset to1suppresses desktop notifications.
The input cap matters. Since every selection goes to a remote model, a limit stops an accidental select-all from sending a huge document.
Model choice
Because OpenRouter exposes many models behind one API, switching is a one-line change to CORRECTOR_MODEL. The README lists free options such as Llama 3.3 70B, Gemini 2.0 Flash, DeepSeek R1 and V3, Mistral 7B, Qwen 2.5 72B and Gemma 3 12B, plus paid ones like GPT-4o Mini and Claude Haiku.
Installing it
On macOS, the recommended route is the DMG: drag Lexa.app into Applications, open it, enter your OpenRouter key, choose a model, and enable the three services under System Settings, Keyboard, Shortcuts, Services, Text. Opening the app again re-runs setup. Developers can clone the repository and run bash mac/setup_mac.sh instead, which needs Python 3.9 or newer. On Linux, run bash linux/setup_linux.sh on a GNOME desktop, then add your key to .env.
What I learned
- Free models are slow and uneven. That is why the timeout is configurable, a fallback chain exists in the client, and the default is an auto-picking model rather than a fixed one.
- Keep the core portable. Separating the engine from the OS triggers made adding Linux a matter of a different setup script rather than a rewrite.
- Prompts are a feature. Correcting and explaining need different instructions, so each mode has its own template in
prompts.py. - Feedback matters for background tools. With no visible window, a loading indicator, notifications and a stop action make the tool feel predictable.
Conclusion
Lexa is a small tool with a narrow job: make checking my English cost one right-click. A single Python CLI, a clipboard-based workflow and an OpenRouter model of your choice are enough to make that work across apps on macOS and Linux. If you try it, start with the free default model and adjust the timeout before anything else.