Skip to content

Add Windows Claude Desktop credential helper - #6516

Merged
aponcedeleonch merged 2 commits into
stacklok:mainfrom
stantheman0128:fix/6507-claude-desktop-windows-helper
Oct 27, 2026
Merged

aponcedeleonch merged 2 commits into
stacklok:mainfrom
stantheman0128:fix/6507-claude-desktop-windows-helper

Conversation

@stantheman0128

Copy link
Copy Markdown
Contributor

Summary

thv llm setup --client claude-desktop detected Claude Desktop on Windows and then failed with claude-desktop LLM gateway setup is not supported on Windows yet. The helper it would have written is a POSIX /bin/sh script (claude-desktop-helper.sh).

The Windows early return is gone. Setup now writes claude-desktop-helper.cmd. The shim still execs the absolute thv path from os.Executable() (GUI-launched Claude Desktop has no useful PATH). It uses goto instead of a parenthesized if so a ) in the path cannot break the block, and call so a .cmd token helper returns. % and " in the path are escaped for cmd.exe.

Fixes #6507

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (go test ./pkg/client/ -count=1 -timeout 180s -run "CredentialHelper|QuoteFor|WriteCredential")
  • E2E tests (task test-e2e) (suite skips on Windows; POSIX fake-browser)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Isolated %USERPROFILE% on this Win11 box (real Claude store untouched):

thv llm setup --client claude-desktop --lazy --gateway-url https://127.0.0.1:9 --issuer https://127.0.0.1:9 --client-id dummy-self-found --tls-skip-verify

Setup exit 0. Wrote .toolhive\llm\claude-desktop-helper.cmd with call "<abs thv.exe>" llm token. Config document inferenceCredentialHelper pointed at that .cmd. thv llm teardown claude-desktop removed the shim and the config document.

Did not launch Claude Desktop itself, so the GUI helper invoke is untested here.

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

Does this introduce a user-facing change?

Yes. thv llm setup --client claude-desktop now configures Claude Desktop on Windows.

Special notes for reviewers

Assigned on #6507. Direct-mode clients still use the PATH-resolved thv llm token shell string; only Claude Desktop needs the absolute-path shim.

Assisted by Cursor.

Evidence

go test ./pkg/client/ -count=1 -timeout 180s -run "CredentialHelper|QuoteFor|WriteCredential"
ok  	github.com/stacklok/toolhive/pkg/client	1.560s

Live setup/teardown under a temp USERPROFILE: setup exit 0, .cmd present, teardown removed the shim. Real %LOCALAPPDATA%\Claude-3p file count stayed 0.

Setup on Windows used to write a POSIX .sh shim and then refuse. Write a .cmd shim and quote the thv path for cmd.exe instead.

Signed-off-by: Po-Han Shih <[email protected]>
@codecov

codecov Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.04%. Comparing base (7970d58) to head (8cbcf31).

Files with missing lines Patch % Lines
pkg/client/llm_gateway_credential_helper.go 25.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6516      +/-   ##
==========================================
+ Coverage   80.01%   80.04%   +0.03%     
==========================================
  Files         837      837              
  Lines       85215    85236      +21     
==========================================
+ Hits        68182    68228      +46     
+ Misses      17028    17003      -25     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aponcedeleonch aponcedeleonch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up, @stantheman0128, and sorry it took so long to get a review. The approach still fits main, and the goto trick to keep a ) in the path from breaking the script is a nice touch. A few things before we can merge:

  1. call re-runs percent expansion (pkg/client/llm_gateway_credential_helper.go:302 and :305). The %% from quoteForCmd collapses back to a single % and then gets stripped, so C:\100%\thv.exe turns into C:\100\thv.exe. call also doubles ^ inside quotes. Since os.Executable() always gives us thv.exe, could we drop call and run the exe directly?
  2. The Windows execution test uses a path without %, ^ or &, which is why this slipped through. Could you add those to the path, and use a real .exe as the fake thv (a tiny go build in the test works)? Heads up that CI has no Windows runner, so this test only runs locally.
  3. Has anyone confirmed that Claude Desktop actually runs a .cmd helper? Node refuses to spawn .cmd/.bat files without shell: true, so this is the part I'm least sure about. A quick end-to-end check on a Windows machine would settle it.
  4. It needs a rebase. The only conflict is quoteForCmd sitting next to the managedProfilePresent rewrite from #6883, so keeping main's version and adding quoteForCmd above it should do it. While you're there, the "POSIX-only" comment near quoteForPOSIXShell can go.

Small nit: the comment at :243 says Windows GUI apps don't get thv on PATH. They do get the user's PATH from the registry. Using the absolute path is still the right call, just for a different reason.

call re-expanded percent signs and doubled carets inside the quoted thv.exe path.
@stantheman0128

Copy link
Copy Markdown
Contributor Author

The Windows shim now runs thv.exe directly. call was expanding % a second time and doubling ^ inside the quotes. The Windows test builds a real exe and runs the shim from a directory named 100% ^ &. go test ./pkg/client -run TestWriteCredentialHelperShim passed on this machine. I have not launched Claude Desktop to watch it spawn the .cmd. This also merges current main. Head 8cbcf31.

@aponcedeleonch
aponcedeleonch merged commit f71ed5f into stacklok:main Oct 27, 2026
42 checks passed
aponcedeleonch added a commit that referenced this pull request Oct 27, 2026
#6516 dropped `call` from the Windows Claude Desktop shim, but
TestConfigureCredentialHelper_WritesConfigMetaAndShim still asserted
`call "<thv>" llm token` on Windows. That contradicts the NotContains
check in TestWriteCredentialHelperShim_UsesAbsolutePath, so the test
fails on Windows. CI has no Windows runner, so it went unnoticed.

Also correct the shim doc comment: explorer-launched apps on Windows
do get the user's PATH. The absolute path is still right because it
does not depend on thv being on PATH and pins the thv that ran setup.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot mentioned this pull request Oct 28, 2026
2 tasks
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.

thv llm setup --client claude-desktop fails on Windows (POSIX credential-helper shim)

2 participants