lk-autocorrect
Fuzzy autocorrect for mistyped shell commands. Works in zsh and bash on Linux and macOS, and PowerShell on Windows.
When you mistype a command, instead of a dead error you get a suggestion:
$ gti status
[lk-autocorrect] Did you mean: git status?
[lk-autocorrect] Run it? [y/N] y
$ dockr ps
[lk-autocorrect] Did you mean: docker ps?
[lk-autocorrect] Run it? [y/N] y
$ terrafrom plan
[lk-autocorrect] Did you mean: terraform plan?
[lk-autocorrect] Run it? [y/N] y
Requirements
- macOS or Linux (zsh or bash) — check with
echo $SHELL - Python 3.11+ — check with
python3 --version - Windows — PowerShell 5 or PowerShell 7
Install
macOS / Linux
Step 1 — Install lk-autocorrect
pip install lk-autocorrect
macOS users: if you see an
externally-managed-environmenterror, use:pip install lk-autocorrect --user --break-system-packages
Step 2 — Add lk-autocorrect to PATH (if needed)
If lk-autocorrect is not found after installing, run the command to add it to PATH:
export PATH="$HOME/Library/Python/3.13/bin:$PATH"
Add that line to your ~/.zshrc or ~/.bashrc to make it permanent, then restart your shell.
Step 3 — Run the installer
lk-autocorrect install
This automatically adds the source line to your ~/.zshrc or ~/.bashrc.
Step 4 — Reload your shell
source ~/.zshrc # zsh
source ~/.bashrc # bash
Step 5 — Test it
gti status # → Did you mean: git status?
dockr ps # → Did you mean: docker ps?
kubctl get pods # → Did you mean: kubectl get pods?
Windows (PowerShell)
Step 1 — Install lk-autocorrect
pip install lk-autocorrect
Step 2 — Add lk-autocorrect to PATH
After installing, if PowerShell cannot find lk-autocorrect run the following commands.
This will find where pip installed it and add it to your PATH permanently:
# find where pip installed lk-autocorrect
pip show lk-autocorrect
# add Scripts folder to PATH permanently
$scriptsPath = (pip show lk-autocorrect | Select-String "Location").Line.Split(" ")[1] + "\..\..\Scripts"
$env:PATH += ";$scriptsPath"
This adds the Python Scripts folder to your PATH so
lk-autocorrectcan be found. Open a new PowerShell window or restart Powershell after running this.
Step 3 — Run the installer
lk-autocorrect install
This automatically adds the source line to your PowerShell profile ($PROFILE).
After install you will see the PATH commands printed — run them if lk-autocorrect is not found.
Step 4 — Reload your profile
. $PROFILE
Step 5 — Test it
gti status # → Did you mean: git status?
dockr ps # → Did you mean: docker ps?
kubctl get pods # → Did you mean: kubectl get pods?
Note: if you see a script execution error on first run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Shell compatibility
| Shell | Platform | Support | Notes |
|---|---|---|---|
| zsh | macOS / Linux | Full | Automatic — fires on any mistyped command |
| bash 4+ | macOS / Linux | Full | Automatic — fires on any mistyped command |
| bash 3.2 | macOS | Partial | Use lk <command> as fallback |
| PowerShell 5 | Windows | Full | Automatic via CommandNotFoundAction |
| PowerShell 7 | Windows | Full | Automatic via CommandNotFoundAction |
| Git Bash | Windows | Full | Treated as bash — works automatically |
| WSL | Windows | Full | Treated as Linux — works automatically |
| CMD | Windows | ❌ | No hook mechanism available |
bash 3.2 on macOS
This version does not support the command_not_found_handle hook that lk-autocorrect relies on for automatic correction.
When you source the script in bash 3.2 you will see:
[lk-autocorrect] bash 3.2 detected — automatic correction unavailable.
[lk-autocorrect] Use: lk <command> e.g. lk gti status
[lk-autocorrect] Or switch to zsh: chsh -s /bin/zsh
Option 1 — use the lk fallback:
lk gti status # → Did you mean: git status?
lk dockr ps # → Did you mean: docker ps?
Option 2 — switch to zsh (recommended):
chsh -s /bin/zsh
# open a new terminal — autocorrect works automatically
Option 3 — upgrade bash:
brew install bash
echo '/opt/homebrew/bin/bash' | sudo tee -a /etc/shells
chsh -s /opt/homebrew/bin/bash
Python version
lk-autocorrect requires Python 3.11+ and is supported on older versions, but upgrading to 3.13+ is recommended since older versions no longer receive security patches.
Check your version:
python3 --version
Upgrade on macOS:
brew install python@3.13
Upgrade on Linux:
sudo apt install python3.13
Upgrade on Windows:
Download from python.org or:
winget install Python.Python.3.13
Usage
Once installed, autocorrect fires automatically whenever you mistype a command:
$ gti commit -m "fix bug"
[lk-autocorrect] Did you mean: git commit -m "fix bug"?
[lk-autocorrect] Run it? [y/N] y
Shell commands
| Command | Description |
|---|---|
ac-add <cmd> |
Add a command to the store |
ac-remove <cmd> |
Remove a command from the store |
ac-list |
List all commands in the store |
ac-test <typo> |
Preview what a typo would correct to |
ac-off |
Disable autocorrect for the current session |
ac-on |
Re-enable autocorrect |
ac-help |
Show in-shell help, including current on/off status |
# add your own commands
ac-add "mycli"
ac-add "my-test-command"
# preview a correction
ac-test "dockr"
# [lk-autocorrect] 'dockr' → 'docker' (distance: 1)
# list everything in the store
ac-list
CLI commands
| Command | Description |
|---|---|
lk-autocorrect install |
Install and set up shell hook |
lk-autocorrect uninstall |
Remove from system |
lk-autocorrect upgrade |
Upgrade to the latest stable version |
lk-autocorrect upgrade --pre |
Upgrade to the latest beta/alpha |
lk-autocorrect upgrade [version] |
Upgrade to a specific version |
lk-autocorrect status |
Show installation status |
lk-autocorrect verify |
Check file integrity and print checksums |
lk-autocorrect help |
Show help |
Configuration
macOS / Linux
Set these in your ~/.zshrc or ~/.bashrc before the source line:
# how forgiving the matcher is (1 = strict, 5 = loose) — default: 2
# words of 8+ characters automatically get +1 extra tolerance
export AUTOCORRECT_THRESHOLD=2
# auto-run the correction without asking — default: false
export AUTOCORRECT_AUTO=true
# turn off colours — default: true
export AUTOCORRECT_COLOR=false
# turn autocorrect on or off — default: true
export AUTOCORRECT_ENABLED=true
To turn autocorrect off temporarily without uninstalling, just run ac-off in your shell (and ac-on to bring it back). To disable it permanently, set AUTOCORRECT_ENABLED=false in your rc file as shown above.
Windows (PowerShell)
Set these in your $PROFILE before the source line:
$env:AUTOCORRECT_THRESHOLD = "2"
$env:AUTOCORRECT_AUTO = "true"
Command store
macOS / Linux
The store lives at ~/.config/lk-autocorrect/commands.txt — one command per line, # lines are comments.
Windows
The store lives at %USERPROFILE%\.config\lk-autocorrect\commands.txt.
Ships with 150+ popular commands and subcommands across git, docker, kubectl, terraform, AWS CLI, Azure CLI and more. Your store is preserved across updates and uninstalls (you are asked before it is deleted).
# add a command
ac-add "mycli"
# remove a command
ac-remove "mycli"
# or edit directly
nano ~/.config/lk-autocorrect/commands.txt or vim ~/.config/lk-autocorrect/commands.txt # macOS / Linux
notepad $env:USERPROFILE\.config\lk-autocorrect\commands.txt # Windows
How it works
- The shell hook (
command_not_found_handlerin zsh,command_not_found_handlein bash 4+,CommandNotFoundActionin PowerShell) fires when a command is not found. - The typo is passed to
matcher.pywhich compares it against every command in the store using Damerau-Levenshtein distance — an algorithm that counts insertions, deletions, substitutions, and transpositions. This meansgti→gitscores as distance 1 (one transposition) not 2. - If the closest match is within
AUTOCORRECT_THRESHOLDedits, the suggestion is shown. - You confirm with
yor it runs automatically ifAUTOCORRECT_AUTO=true.
Subcommand correction
git, terraform, kubectl, docker, aws, az, and helm also get their subcommands corrected, not just the base command:
$ git psuh
[lk-autocorrect] Did you mean: git push?
[lk-autocorrect] Run it? [y/N] y
$ trafform fmt
[lk-autocorrect] Did you mean: terraform fmt?
[lk-autocorrect] Run it? [y/N] y
This works even when both the base command and the subcommand are mistyped at once — both are corrected together and you only get asked once:
$ gti statsu
[lk-autocorrect] Did you mean: git status?
[lk-autocorrect] Run it? [y/N] y
Length-aware matching
Longer words get one extra edit of tolerance. A 3-edit difference on an 8+ letter word (like trafform → terraform) is a much smaller relative change than the same 3 edits on a short word — so short words are matched more strictly to avoid false positives, while longer words allow slightly looser matching.
Upgrade
lk-autocorrect detects whether you installed via pip or pipx and runs the correct upgrade command automatically, then refreshes your shell files in one step.
# upgrade to the latest stable release
lk-autocorrect upgrade
# upgrade to the latest beta/alpha (pre-release)
lk-autocorrect upgrade --pre
# upgrade to a specific version
lk-autocorrect upgrade [version]
# example: lk-autocorrect upgrade 1.3.0b4
This works the same way on macOS, Linux, and Windows.
other upgrade commands (alternative)
Instead of using
lk-autocorrect upgrade:
macOS / Linux (pipx):
pipx upgrade lk-autocorrect
macOS / Linux (pip):
pip install --upgrade lk-autocorrect
Windows (PowerShell):
pip install --upgrade lk-autocorrect
After a manual upgrade, run lk-autocorrect install once to refresh your shell files with the new version.
Uninstall
lk-autocorrect uninstall
pip uninstall lk-autocorrect
Verify integrity
lk-autocorrect verify
Prints the SHA256 checksums of the installed files so you can verify them against the GitHub release.
Contributing
Pull requests welcome.
- Fork the repo
- Create a branch:
git checkout -b my-feature - Make changes to
src/autocorrect.sh,src/autocorrect.ps1orsrc/matcher.py - Test in zsh, bash, and PowerShell
- Open a PR
License
MIT — see LICENSE
Metadata
Release files for lk-autocorrect 1.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lk_autocorrect-1.4.2.tar.gz | 21.6 kB | With provenance | Details for lk_autocorrect-1.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lk_autocorrect-1.4.2-py3-none-any.whl | Python 3 | none | any | Details for lk_autocorrect-1.4.2-py3-none-any.whl |
Total release size: 47.0 kB
Release files / lk_autocorrect-1.4.2.tar.gz
| Download URL | lk_autocorrect-1.4.2.tar.gz |
|---|---|
| Size | 21.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd4040a66aee17fa1b29e6c67307568fc97cc47339473bac4de9db9e72047c05
|
|
BLAKE2b-256 checksum How to use checksums |
17bbb489f690e67036d962e1dd015303a43f4c252f74c8be7e81773ffc6e01c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 17, 2026.
Transparency logRelease files / lk_autocorrect-1.4.2-py3-none-any.whl
| Download URL | lk_autocorrect-1.4.2-py3-none-any.whl |
|---|---|
| Size | 25.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2e11c84feca8cd986a9315d8104653df5a35b1b2ddecb8b25fc7a01e3103774
|
|
BLAKE2b-256 checksum How to use checksums |
a1f7f654e9c803b2f5ab518ef240af3f635122876282362f224e786ac5faa45f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 17, 2026.
Transparency logSecurity for lk-autocorrect 1.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for lk_autocorrect-1.4.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.