Skip to content

Commit d4ad4f4

Browse files
fix(provider-core): Chocolatey Claude installs stay manual-only and compare against choco
Claude Code installed with Chocolatey was compared against npm, and Update now ran claude update through the shim. That installs a native copy and leaves the Chocolatey install unchanged. Treat those installs as manual-only, compare them with choco search, and show choco upgrade claude-code without running it. Co-authored-by: Cursor <[email protected]>
1 parent 680152e commit d4ad4f4

5 files changed

Lines changed: 226 additions & 10 deletions

File tree

‎docs/internals/providers.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ manual-only because their version is pinned in mise's config. A Grok cask whose
9393
cannot be verified also stays manual-only: `grok update` would install a second copy. npm updates pin `--prefix` because the
9494
`npm` on `PATH` can belong to a different Node than the one that owns the provider. Homebrew
9595
compares against `brew info` since casks trail npm by hours; native installs share npm's version
96-
train, so the registry stays authoritative for them.
96+
train, so the registry stays authoritative for them. A Chocolatey install of Claude stays
97+
manual-only: its package directory is writable only by administrators, and `claude update` through
98+
the shim installs a native copy elsewhere. The latest version comes from `choco search`, and the
99+
card shows `choco upgrade claude-code` without running it.
97100
See the [resolver](../../apps/server/src/provider/providerMaintenance.ts).
98101

99102
Ownership is cached per instance and re-read immediately before an update runs. The

‎docs/user/install.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ When a provider CLI is behind its latest release, its provider card shows the
161161
available version. **Update now** runs the installer that owns the CLI
162162
(Homebrew, or a global npm, pnpm, Yarn, Bun, Volta, or Vite+ install), or the
163163
CLI's own update command when T3 Code cannot tell. Update a CLI installed with
164-
mise through mise. Cursor and Antigravity update with T3 Code. Homebrew installs
165-
compare against the version Homebrew offers, which can trail the npm release by
166-
a few hours.
164+
mise through mise. Cursor and Antigravity update with T3 Code. Homebrew and
165+
Chocolatey installs compare against the version their package manager offers,
166+
which can trail the npm release; update Claude installed with Chocolatey
167+
through Chocolatey.
167168

168169
Add another provider instance for a separate account or configuration. Each
169170
instance can have its own environment variables, such as API keys or a custom

‎packages/provider-core/src/server/maintenance.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export interface ProviderMaintenanceCapabilities {
2323
* install to update.
2424
*/
2525
readonly installPath?: string;
26+
/**
27+
* A command T3 Code shows but cannot run.
28+
*/
29+
readonly manualCommand?: string;
2630
}
2731

2832
export interface ProviderMaintenanceCommandAction {

‎packages/provider-core/src/server/maintenanceResolver.test.ts‎

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import {
2222
homebrewOwnershipFromCommandPath,
2323
invalidateLatestProviderVersion,
2424
makeCachedProviderMaintenanceResolution,
25+
makeManualOnlyProviderMaintenanceCapabilities,
2526
makePackageManagedProviderMaintenanceResolver,
2627
makeProviderMaintenanceCapabilities,
2728
normalizeCommandPath,
2829
npmGlobalPrefixFromCommandPath,
30+
parseChocolateyLatestVersion,
2931
parseHomebrewLatestVersion,
3032
resolveLatestProviderVersion,
3133
resolvePackageManagedProviderMaintenance,
@@ -254,6 +256,26 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
254256
});
255257
});
256258

259+
it("shows the Chocolatey upgrade command without offering to run it", () => {
260+
expect(
261+
createProviderVersionAdvisory({
262+
driver: driver("claudeAgent"),
263+
currentVersion: "2.1.304",
264+
latestVersion: "2.1.306",
265+
maintenanceCapabilities: makeManualOnlyProviderMaintenanceCapabilities({
266+
provider: driver("claudeAgent"),
267+
packageName: "@anthropic-ai/claude-code",
268+
installPath: "C:\\ProgramData\\chocolatey\\bin\\claude.exe",
269+
manualCommand: "choco upgrade claude-code",
270+
}),
271+
}),
272+
).toMatchObject({
273+
canUpdate: false,
274+
canInstallVersion: false,
275+
updateCommand: "choco upgrade claude-code",
276+
});
277+
});
278+
257279
it.effect("stays manual-only when the binary cannot be located", () =>
258280
resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
259281
binaryPath: "package-tool",
@@ -390,12 +412,13 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
390412
readonly resolved: string;
391413
readonly real: string;
392414
readonly platform?: NodeJS.Platform;
415+
readonly env?: NodeJS.ProcessEnv;
393416
}) =>
394417
resolvePackageManagedProviderMaintenance(input.definition, {
395418
binaryPath: "claude",
396419
resolvedCommandPath: input.resolved,
397420
realCommandPath: input.real,
398-
env: {},
421+
env: input.env ?? {},
399422
platform: input.platform ?? "win32",
400423
}).pipe(
401424
Effect.provideService(HostProcess.Platform, input.platform ?? "win32"),
@@ -428,6 +451,113 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
428451
}),
429452
);
430453

454+
const chocolateyShim = "C:\\ProgramData\\chocolatey\\bin\\claude.exe";
455+
const chocolateyPackage = "C:\\ProgramData\\chocolatey\\lib\\claude-code\\tools\\claude.exe";
456+
457+
it.effect.each([
458+
{ name: "the shimgen shim", resolved: chocolateyShim, real: chocolateyShim },
459+
{ name: "the package binary", resolved: chocolateyPackage, real: chocolateyPackage },
460+
{
461+
name: "a custom root",
462+
resolved: "D:\\Tools\\Choco\\bin\\claude.exe",
463+
real: "D:\\Tools\\Choco\\bin\\claude.exe",
464+
env: { ChocolateyInstall: "D:\\Tools\\Choco" },
465+
},
466+
] as const)("keeps a Chocolatey Claude install manual-only through $name", (fixture) =>
467+
Effect.gen(function* () {
468+
const capabilities = yield* resolveInstall({ definition: claudeUpdate, ...fixture });
469+
470+
expect(capabilities.update).toBeNull();
471+
expect(capabilities.installPath).toBe(fixture.real);
472+
expect(capabilities.latestVersion).toBeNull();
473+
expect(capabilities.lookupLatestVersion).toBeDefined();
474+
expect(capabilities.manualCommand).toBe("choco upgrade claude-code");
475+
}),
476+
);
477+
478+
it.effect("keeps a Chocolatey-shaped path off Windows on the native updater", () =>
479+
Effect.gen(function* () {
480+
const commandPath = "/home/me/chocolatey/bin/claude.exe";
481+
const capabilities = yield* resolveInstall({
482+
definition: claudeUpdate,
483+
resolved: commandPath,
484+
real: commandPath,
485+
platform: "linux",
486+
});
487+
488+
expect(capabilities.update).toMatchObject({ lockKey: "claudeAgent-native" });
489+
}),
490+
);
491+
492+
// Chocolatey publishes behind npm, so comparing against the registry would
493+
// report an update `choco upgrade` cannot install yet.
494+
it.effect("compares a Chocolatey Claude install against choco search", () =>
495+
Effect.gen(function* () {
496+
const probes: Array<string> = [];
497+
const capabilities = yield* resolvePackageManagedProviderMaintenance(claudeUpdate, {
498+
binaryPath: "claude",
499+
resolvedCommandPath: chocolateyShim,
500+
realCommandPath: chocolateyShim,
501+
env: {},
502+
platform: "win32",
503+
}).pipe(
504+
Effect.provideService(HostProcess.Platform, "win32"),
505+
Effect.provideService(
506+
ChildProcessSpawner.ChildProcessSpawner,
507+
stdoutSpawner((command) => {
508+
probes.push(command);
509+
return "claude-code|2.1.304\r\n";
510+
}),
511+
),
512+
);
513+
expect(probes).toEqual([]);
514+
515+
const latest = yield* resolveLatestProviderVersion(capabilities).pipe(
516+
Effect.provide(ProviderLatestVersions.layer),
517+
Effect.provideService(
518+
HttpClient.HttpClient,
519+
HttpClient.make(() => Effect.die("the installer's latest should not come from npm")),
520+
),
521+
);
522+
523+
expect(latest).toBe("2.1.304");
524+
expect(probes.map((command) => NodePath.basename(command).replace(/\.\w+$/, ""))).toEqual([
525+
"choco",
526+
]);
527+
}).pipe(Effect.provide(NodeServices.layer)),
528+
);
529+
530+
it.effect("stays unknown when choco search fails instead of asking npm", () =>
531+
Effect.gen(function* () {
532+
const capabilities = yield* resolvePackageManagedProviderMaintenance(claudeUpdate, {
533+
binaryPath: "claude",
534+
resolvedCommandPath: chocolateyShim,
535+
realCommandPath: chocolateyShim,
536+
env: {},
537+
platform: "win32",
538+
}).pipe(
539+
Effect.provideService(HostProcess.Platform, "win32"),
540+
Effect.provideService(
541+
ChildProcessSpawner.ChildProcessSpawner,
542+
stdoutSpawner(
543+
() => "",
544+
() => 1,
545+
),
546+
),
547+
);
548+
549+
const latest = yield* resolveLatestProviderVersion(capabilities).pipe(
550+
Effect.provide(ProviderLatestVersions.layer),
551+
Effect.provideService(
552+
HttpClient.HttpClient,
553+
HttpClient.make(() => Effect.die("a failed choco search should not fall back to npm")),
554+
),
555+
);
556+
557+
expect(latest).toBeNull();
558+
}).pipe(Effect.provide(NodeServices.layer)),
559+
);
560+
431561
it.effect.each([
432562
{
433563
name: "a native install",
@@ -863,6 +993,13 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
863993
}),
864994
);
865995

996+
it("reads the Chocolatey package version from choco search --limit-output", () => {
997+
expect(parseChocolateyLatestVersion("claude-code|2.1.304\r\n", "claude-code")).toBe("2.1.304");
998+
expect(parseChocolateyLatestVersion("Claude-Code|2.1.304\r\n", "claude-code")).toBe("2.1.304");
999+
expect(parseChocolateyLatestVersion("claude-code-other|9.9.9\r\n", "claude-code")).toBeNull();
1000+
expect(parseChocolateyLatestVersion("", "claude-code")).toBeNull();
1001+
});
1002+
8661003
it("recognizes Homebrew kegs and casks from the real executable path", () => {
8671004
expect(
8681005
homebrewOwnershipFromCommandPath("/opt/homebrew/Cellar/claude-code@latest/2.1.0/bin/claude"),

‎packages/provider-core/src/server/maintenanceResolver.ts‎

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ export function makeManualOnlyProviderMaintenanceCapabilities(input: {
194194
readonly provider: ProviderDriverKind;
195195
readonly packageName: string | null;
196196
readonly installPath?: string;
197+
/**
198+
* The owning installer's own release, when it publishes behind npm. Without
199+
* it the npm registry is authoritative, and the advisory would keep asking
200+
* for a version the installer cannot provide yet.
201+
*/
202+
readonly lookupLatestVersion?: Effect.Effect<string | null>;
203+
readonly manualCommand?: string;
197204
}): ProviderMaintenanceCapabilities {
198205
return {
199206
...makeProviderMaintenanceCapabilities({
@@ -202,8 +209,12 @@ export function makeManualOnlyProviderMaintenanceCapabilities(input: {
202209
updateExecutable: null,
203210
updateArgs: [],
204211
updateLockKey: null,
212+
...(input.lookupLatestVersion
213+
? { latestVersion: null, lookupLatestVersion: input.lookupLatestVersion }
214+
: {}),
205215
}),
206216
...(input.installPath ? { installPath: input.installPath } : {}),
217+
...(input.manualCommand ? { manualCommand: input.manualCommand } : {}),
207218
};
208219
}
209220

@@ -248,6 +259,34 @@ function isWinGetClaudeCommandPath(commandPath: string): boolean {
248259
return winGetClaudeCommandPath.test(normalizeCommandPath(commandPath));
249260
}
250261

262+
const CHOCOLATEY_CLAUDE_PACKAGE_ID = "claude-code";
263+
264+
/**
265+
* Chocolatey's Claude Code package: the shimgen shim in `<ChocolateyInstall>\bin`
266+
* (default `chocolatey\bin`) or the binary it launches from `lib\claude-code\tools`.
267+
* The shim is a real executable rather than a link, so following symlinks never
268+
* reaches the package directory. A custom root is not in that path shape, so it is
269+
* also compared with `ChocolateyInstall`.
270+
*/
271+
const chocolateyClaudeCommandPath = /\/(?:chocolatey\/bin|lib\/claude-code\/tools)\/claude\.exe$/;
272+
273+
function isChocolateyClaudeCommandPath(commandPath: string, env: NodeJS.ProcessEnv): boolean {
274+
if (chocolateyClaudeCommandPath.test(normalizeCommandPath(commandPath))) return true;
275+
const root = nonEmptyString(env.ChocolateyInstall);
276+
if (!root) return false;
277+
const shim = normalizeCommandPath(`${root.replace(/[\\/]+$/, "")}/bin/claude.exe`);
278+
return normalizeCommandPath(commandPath) === shim;
279+
}
280+
281+
/** `choco search --exact --limit-output` prints `<id>|<version>` for a match and nothing otherwise. */
282+
export function parseChocolateyLatestVersion(output: string, packageId: string): string | null {
283+
for (const line of output.split(/\r?\n/)) {
284+
const [id, version] = line.trim().split("|", 2);
285+
if (id?.toLowerCase() === packageId.toLowerCase()) return nonEmptyString(version);
286+
}
287+
return null;
288+
}
289+
251290
function isPnpmGlobalCommandPath(commandPath: string): boolean {
252291
const normalized = normalizeCommandPath(commandPath);
253292
return (
@@ -450,6 +489,32 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
450489
) {
451490
return manual;
452491
}
492+
// Chocolatey's package directory is writable only by administrators, so an
493+
// unelevated server cannot run `choco upgrade`; `claude update` through the
494+
// shim installs a native copy elsewhere and leaves the shim's version alone.
495+
if (
496+
definition.provider === "claudeAgent" &&
497+
context.platform === "win32" &&
498+
commandPaths.some((commandPath) => isChocolateyClaudeCommandPath(commandPath, context.env))
499+
) {
500+
const services = yield* Effect.context<ProviderMaintenanceResolverServices>();
501+
return makeManualOnlyProviderMaintenanceCapabilities({
502+
provider: definition.provider,
503+
packageName,
504+
installPath: context.realCommandPath,
505+
manualCommand: "choco upgrade claude-code",
506+
lookupLatestVersion: runProbe(
507+
"choco",
508+
["search", CHOCOLATEY_CLAUDE_PACKAGE_ID, "--exact", "--limit-output"],
509+
context.env,
510+
).pipe(
511+
Effect.map((output) =>
512+
output ? parseChocolateyLatestVersion(output, CHOCOLATEY_CLAUDE_PACKAGE_ID) : null,
513+
),
514+
Effect.provideContext(services),
515+
),
516+
});
517+
}
453518

454519
const nativeUpdate = definition.nativeUpdate;
455520
const native = nativeUpdate
@@ -839,7 +904,10 @@ export function createProviderVersionAdvisory(input: {
839904
status: advisory.status,
840905
currentVersion: input.currentVersion,
841906
latestVersion,
842-
updateCommand: resolveLatestProviderUpdateAction(capabilities, latestVersion)?.command ?? null,
907+
updateCommand:
908+
resolveLatestProviderUpdateAction(capabilities, latestVersion)?.command ??
909+
capabilities.manualCommand ??
910+
null,
843911
canUpdate: capabilities.update !== null,
844912
canInstallVersion: makeTargetedProviderUpdateAction(capabilities, "0.0.0") !== null,
845913
checkedAt: input.checkedAt ?? null,
@@ -870,12 +938,15 @@ const fetchNpmLatestVersion = Effect.fn("fetchNpmLatestVersion")(function* (pack
870938
return payload ? nonEmptyString(payload.version) : null;
871939
});
872940

873-
/** The installer's own answer is cached apart from the npm registry entry. */
941+
/**
942+
* The installer's own answer is cached apart from the npm registry entry. A
943+
* manual-only install has no command to key on, so its executable stands in.
944+
*/
874945
function installerLatestVersionKey(capabilities: ProviderMaintenanceCapabilities) {
946+
if (!capabilities.lookupLatestVersion) return null;
875947
const update = capabilities.update;
876-
return capabilities.lookupLatestVersion && update
877-
? [update.lockKey, update.executable, ...update.args].join("\0")
878-
: null;
948+
if (update) return [update.lockKey, update.executable, ...update.args].join("\0");
949+
return capabilities.installPath ? ["manual", capabilities.installPath].join("\0") : null;
879950
}
880951

881952
export function latestProviderVersionCacheKeys(

0 commit comments

Comments
 (0)