Skip to content

Fix: run the cargo-installed trodden from the plugin when PATH lacks cargo bin - #199

Open
aayank13 wants to merge 1 commit into
mainfrom
fix/plugin-cargo-bin-path
Open

aayank13 wants to merge 1 commit into
mainfrom
fix/plugin-cargo-bin-path

Conversation

@aayank13

Copy link
Copy Markdown
Owner

Fixes #170

The plugin's hooks added the cargo bin directory to the end of PATH, so any other trodden already on the agent's PATH won. When Claude Code runs with a PATH that lacks ~/.cargo/bin (started from a GUI, an IDE or a shell that never sourced ~/.cargo/env) and an older trodden sits in, say, /usr/local/bin, every hook ran the old binary. After cargo install, the user's terminal ran the new one while the plugin kept running the old one, and its errors only showed up in the hook log.

Moving the cargo bin directory to the front every time would just flip the problem: someone who installed a prebuilt binary or used Homebrew, and still has an old cargo install lying around, would then get the stale cargo copy even though their PATH says otherwise. So the hooks now do what rustup's ~/.cargo/env does. If ${CARGO_HOME:-$HOME/.cargo}/bin is already on PATH, PATH is left alone and its order decides, the same as in the user's shell. If it is missing, it is added at the front, which is where the user's shell setup would have put it. A trodden that is only found on PATH, whatever installed it, still runs, and with no trodden anywhere the hooks still exit quietly.

What this does not cover on purpose: if the user's own PATH lists an older trodden ahead of the cargo bin directory, that one runs, because that is also what trodden runs in their terminal. trodden doctor already prints which trodden is on PATH.

To reproduce, I put a fresh build in a scratch CARGO_HOME/bin, a fake old trodden that fails with "unrecognized subcommand 'hook'" in another directory, and ran each plugin hook command with sh -c and a UserPromptSubmit payload, with only the fake's directory on PATH. Before, every hook ran the fake and exited 2. After, every hook runs the cargo build and exits 0. With both directories on PATH and the fake first, the fake still runs, as intended.

The new test in crates/trodden/tests/claude_code_plugin.rs reads the plugin's hooks.json and runs every hook command against fake binaries. It checks that the cargo install wins when PATH lacks the cargo bin directory (this one fails on main), that a PATH listing the cargo bin directory keeps its order, that a trodden found only on PATH runs, and that the hooks stay quiet when there is no trodden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Claude Code plugin puts ~/.cargo/bin last on PATH, so an older trodden wins

1 participant