Repository navigation
Description
Describe the bug
On Windows, gh extension upgrade, gh extension remove and gh extension install delete the installed extension's folder before doing anything else. If any file in it is in use, gh stops half-way and leaves an extension that gh extension upgrade can no longer repair.
The cause is in pkg/cmd/extension/manager.go. installBin, installGit, InstallLocal and Remove all call cleanExtensionUpdateDir(name) first:
func (m *Manager) cleanExtensionUpdateDir(name string) error {
if err := os.RemoveAll(m.UpdateDir(name)); err != nil {
return fmt.Errorf("failed to remove previous extension update state: %w", err)
}
return nil
}UpdateDir(name) is config.StateDir()/extensions/<name> and the install folder is config.DataDir()/extensions/<name>. On Linux and macOS these are different folders. On Windows, go-gh/pkg/config resolves both StateDir() and DataDir() to %LOCALAPPDATA%\GitHub CLI, so the "update state" folder is the installed extension itself.
os.RemoveAll deletes what it can, including manifest.yml, and then fails on whatever is locked. Windows locks the extension's .exe while it runs, and it locks a folder that is any process's working directory. Without manifest.yml the extension is listed with no repo or version, and every later gh extension upgrade fails with unable to retrieve latest version for extension "<name>". Only remove + install recovers.
This came in with #9934, which added the update-state folder. github/gh-aw ran into the same thing and traced it to the same lines (github/gh-aw#27269). They worked around it on their side, but this repo never got an issue.
Affected version
gh version 2.102.0 (2026-09-30)
Also reproduced with 2.92.0 and 2.103.3. cleanExtensionUpdateDir is unchanged on trunk.
Steps to reproduce the behavior
On Windows, with any binary extension (gh-foo below):
gh extension install owner/gh-foo- Keep the extension running, e.g. a long-running
gh foo <command>in one terminal. A terminal opened with%LOCALAPPDATA%\GitHub CLI\extensions\gh-fooas its working directory has the same effect. - In a second terminal:
gh extension remove foo.gh extension upgrade footakes the same path whenever an update is available. gh extension list
Expected vs actual behavior
Expected: gh only touches its own update state. An upgrade while the extension runs either succeeds (a running .exe can be renamed aside) or fails before changing the install, and the installed extension stays usable either way.
Actual (upgrade prints the same error after [foo]: and then some extensions failed to upgrade):
failed to remove previous extension update state: unlinkat C:\Users\<user>\AppData\Local\GitHub CLI\extensions\gh-foo: The process cannot access the file because it is being used by another process.
gh extension list then shows gh foo with no repo and no version, manifest.yml is gone, and gh extension upgrade foo fails from then on with unable to retrieve latest version until gh extension remove foo && gh extension install owner/gh-foo.
Possible fixes, in increasing scope:
- Delete only the state file inside
UpdateDir(name)instead of the folder, or skipcleanExtensionUpdateDirwhenUpdateDir(name)equals the install folder. - Use a separate state folder on Windows, e.g.
%LOCALAPPDATA%\GitHub CLI\state. Existing state would need a migration.
Logs
The error above is the only output. The command is local file handling, so GH_DEBUG=api adds nothing past the release lookup.
Activity
darshpatel1052 commentedon Nov 3, 2026
I’d like to take this on. I’d reproduce the Windows overlap between update-state and install directories, then make cleanup target only update state and add coverage for the shared-path case. I’d also check failure with a locked extension so its manifest remains usable. Would you prefer the narrow cleanup fix, or a separate state directory with migration?
cli-triage commentedon Nov 9, 2026
Unable to test: available builds run on Linux, which does not enforce Windows file and directory locks.
Source inspection confirms extension update cleanup removes the update directory before install or removal continues. The manager stores update state under
StateDir()and installed extensions underDataDir(). The dependency maps both roots to the same Windows directory, matching the reported destructive path. Linux can unlink open executables and current working directories, so it cannot produce the partial deletion that removesmanifest.ymlwhile leaving a locked file.Exit status:
0.Supporting reports
Duplicate analysis
Label reasoning
Reproduction log
Investigation notes
Generated by issue triage.