Add safe cleanup of older direct-install copilot binaries#2887
Closed
meagancojocar wants to merge 1 commit intogithub:mainfrom
Closed
Add safe cleanup of older direct-install copilot binaries#2887meagancojocar wants to merge 1 commit intogithub:mainfrom
meagancojocar wants to merge 1 commit intogithub:mainfrom
Conversation
Extend install.sh so that every successful install automatically removes older install-script copies of copilot, while preserving: - The currently selected CLI (command -v copilot or just-installed binary) - Any binary backing an active session (via lock-file and process-table scan) - Package-managed installs (Homebrew, npm, nix, snap, etc.) - Runtime caches (copilot-sdk-* directories) Cleanup runs by default after install. Set NO_CLEANUP=true or pass --no-cleanup to opt out. A standalone CLEANUP_ONLY=true / --cleanup-only mode is also available for cleanup without a fresh download. Safety model: - Only standalone executables named 'copilot' in bin/ directories are eligible for deletion (classified as direct-install candidates) - Symlinks, node_modules paths, Homebrew Cellar/Caskroom paths, and copilot-sdk-* cache paths are classified as managed and skipped - Version comparison requires the candidate to be strictly older than the keep target; ambiguous or unparseable versions are skipped - Active-session detection inspects lock file PIDs and scans the process table for running copilot processes (covering pre-lock-era CLI versions) - Post-install cleanup is non-fatal: failures produce a warning but do not prevent the install from completing - Permission failures are surfaced clearly and are non-fatal Update README.md with cleanup usage, dry-run guidance, scope limits, and package-manager uninstall guidance. Add changelog entry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
When users reinstall the CLI via
install.shinto a different prefix, or when multiple direct-install copies accumulate over time, stale older binaries are left behind with no built-in way to clean them up. This PR makes cleanup automatic and has an opt out for the cleanup.Approach
The install script now automatically removes older direct-install copies of
copilotafter every successful install. The cleanup is conservative by design -- it only deletes candidates that pass every safety check:copilotinbin/directories are eligible. Symlinks,node_modulespaths, Homebrew Cellar/Caskroom paths,copilot-sdk-*cache dirs, nix/snap/flatpak paths are all classified as managed and skipped.command -v copilot(cleanup-only flow) is never deleted.~/.copilot/session-state/*/inuse.<pid>.lock) for recent CLI versionsps -axww) that catches any runningcopilotprocess, covering pre-lock-era CLI versions that never created lock filesUsage
Cleanup runs by default. Opt out with:
curl -fsSL https://gh.io/copilot-install | NO_CLEANUP=true bashStandalone cleanup without installing:
curl -fsSL https://gh.io/copilot-install | CLEANUP_ONLY=true bashPreview mode:
curl -fsSL https://gh.io/copilot-install | CLEANUP_ONLY=true DRY_RUN=true VERBOSE=true bashFiles changed
install.shREADME.mdchangelog.mdOut of scope
copilot-sdk-*) > I just didnt know what to do with this