Skip to main content

Fixed: "route: bad keyword" When uv run route Runs the System Command

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A Python project's command, named route, worked inside the project but answered route: bad keyword: I lost my card when I ran it from another folder. That message came from the operating system's network tool, also called route, which uv run ran instead. Giving the project's command a name no system tool uses fixed it.

What I Was Doing​

A Python project, built with uv 0.13.10, has one command declared in its pyproject.toml:

pyproject.toml (excerpt)
[project.scripts]
route = "support_intent_router.cli:main"

route takes a customer's message and prints the topic it's about. Inside the project folder it worked:

Terminal
uv run route --help
Output
usage: route [-h] message

Route a customer support message to its intent.

positional arguments:
message the customer's message, in quotes

options:
-h, --help show this help message and exit

The terminal after uv run route --help inside the project: the project's own usage, route [-h] message, and its description, Route a customer support message to its intent.

Then I ran the same command from a different folder.

What I Expected​

Either the project's command, or an error saying there's no such command here.

What I Got​

Terminal
uv run route "I lost my card"
Output
route: bad keyword: I lost my card
usage: route [-dnqtv] command [[modifiers] args]

The terminal after uv run route "I lost my card" outside the project: route: bad keyword: I lost my card, then usage: route [-dnqtv] command [[modifiers] args], the usage of a different program.

That usage line, route [-dnqtv] command [[modifiers] args], isn't my program's. My route only takes a message.

What I Checked​

I asked the shell which route it finds:

Terminal
which route
Output
/sbin/route

/sbin/route is macOS's tool for viewing and changing network routes. Linux has a route command too, and so does Windows.

The uv reference explains what uv run does in each place: "When used in a project, the project environment will be created and updated before invoking the command. When used outside a project, if a virtual environment can be found in the current directory or a parent directory, the command will be run in that environment. Otherwise, the command will be run in the environment of the discovered interpreter."

Why It Happens​

Inside the project, uv run puts the project's environment first, so its route wins. Outside it, there's no project environment, so the name is looked up like any other command, and the system's route is found. The same happens to anyone who installs the project and types route directly. A command name shares one space with every program already on the computer.

The Fix​

Give the command a name no system tool uses. In pyproject.toml:

pyproject.toml (excerpt)
[project.scripts]
route-message = "support_intent_router.cli:main"

Inside the project, the next uv run rebuilds the project and installs the new name:

Terminal
uv run route-message --help
Output
Built support-intent-router @ file:///Users/you/source/dewiride-support-intent-router
Uninstalled 1 package in 1ms
Installed 1 package in 2ms
usage: route-message [-h] message

Route a customer support message to its intent.

positional arguments:
message the customer's message, in quotes

options:
-h, --help show this help message and exit

The terminal after uv run route-message --help inside the project: uv rebuilt the project, then usage: route-message [-h] message with its description.

After the Fix​

Outside the project, the new name no longer reaches a stranger's program:

Terminal
uv run route-message "I lost my card"
Output
error: Failed to spawn: route-message
cause: No such file or directory (os error 2)

The terminal after uv run route-message outside the project: error: Failed to spawn: route-message, caused by No such file or directory (os error 2).

That's the right answer: there's no route-message here, and uv says so instead of running something else. The commands work the same in PowerShell, apart from which, whose PowerShell counterpart is Get-Command route.

Common Mistakes​

MistakeWhat happensDo this instead
Naming a command after a common tool, such as route, test, time or openOutside the project, or for anyone who installs it, the other program runsCheck first with which <name>, or Get-Command <name> in PowerShell; pick a name that finds nothing
Renaming the command but not the instructionsPeople keep typing the old nameUpdate the README and any scripts in the same change

FAQ​

Is it safe inside the project?​

Yes: uv run puts the project's environment first there. The trouble starts anywhere else, which is why a unique name is the real fix.

Does Python warn about the clash?​

No. Nothing checks your command names against the system's.

Conclusion​

route: bad keyword: I lost my card came from macOS's /sbin/route, which uv run ran because there was no project in that folder. Renaming the project's command to route-message made it unmistakable, and running it in the wrong place now gives a clear Failed to spawn instead.

Additional Resources​