[BUG] Marketplace add fails - cleanup deletes cloned directory before rename can complete
Bug Description
When adding a marketplace with /plugin marketplace add METR/claude-code, the command fails with an ENOENT error during the rename step. The root cause is that the cleanup step deletes the freshly cloned directory before the rename can complete.
Steps to Reproduce
- Run
/plugin marketplace add METR/claude-code(or any marketplace where the repo owner name is uppercase) - Observe the error:
````
Failed to finalize marketplace cache. Please manually delete the directory at /Users/user/.claude/plugins/marketplaces/metr-claude-code if it exists and try again.
Technical details: ENOENT: no such file or directory, rename '/Users/user/.claude/plugins/marketplaces/METR-claude-code' -> '/Users/user/.claude/plugins/marketplaces/metr-claude-code'
Root Cause Analysis
I monitored the filesystem during the command execution and found:
- Clone step: Creates
/Users/user/.claude/plugins/marketplaces/METR-claude-code(preserving the uppercase from the GitHub org name "METR") - Validation step: Reads
marketplace.jsonwhich has"name": "metr-claude-code"(lowercase) - Cleanup step ("Cleaning up old marketplace cache…"): Deletes
METR-claude-codebecause it doesn't match the expected final name - Rename step: Tries to rename
METR-claude-codetometr-claude-code, fails with ENOENT because the source was just deleted
The cleanup logic appears to delete any directory that doesn't match the expected final marketplace name, not realizing that METR-claude-code is the just-cloned source that needs to be renamed.
Filesystem Evidence
# During clone:
drwxr-xr-x - mish 4 Feb 15:33 METR-claude-code # <-- Created
# After "Cleaning up old marketplace cache…":
(METR-claude-code is gone!)
# Then rename fails because source doesn't exist
Environment
- OS: macOS (case-insensitive filesystem)
- Claude Code Version: Latest
Workaround
Manually clone the marketplace repo:
git clone https://github.com/METR/claude-code.git ~/.claude/plugins/marketplaces/metr-claude-code
Suggested Fix
The cleanup logic should:
- Not delete the source directory before the rename, OR
- Perform the rename before the cleanup, OR
- Skip cleanup of directories that match the source pattern (original case from clone)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗