When running ./install.sh from a clone of the repo (rather than via curl | bash), the installer identifies the current working directory as an "old installation" and rm -rfs it after completing the install to ~/.claude-code-docs.
I discovered this while working on some contributions for a PR. There is a check for any uncommitted changes, but if everything has been committed but not yet pushed it still gets nuked.
Fix is probably, when checking if pwd == $INSTALL_DIR, also check against script's location.
Another possibility might be to evaluate if the migration logic has outlived its usefulness. At some point, any installations of the tool will be to the proper location and not need to be migrated. In theory, it should be okay to remove this logic completely at some point. It's quite complicated and could be the source of more issues.
Detailed analysis follows:
Root Cause
Three pieces of code combine to cause this:
-
find_existing_installations() (line 107-109) adds $(pwd) to the old installations list if ./docs/docs_manifest.json exists and the CWD isn't ~/.claude-code-docs:
if [[ -f "./docs/docs_manifest.json" && "$(pwd)" != "$INSTALL_DIR" ]]; then
paths+=("$(pwd)")
fi
-
That path gets saved into the OLD_INSTALLATIONS array (line 345).
-
After installing/updating to ~/.claude-code-docs, cleanup_old_installations() (line 498) iterates OLD_INSTALLATIONS and deletes any that are clean git repos:
if [[ -z "$(git status --porcelain 2>/dev/null)" ]]; then
cd - >/dev/null
rm -rf "$old_dir"
Steps to Reproduce
- Clone the repo to any location other than
~/.claude-code-docs (e.g., ~/work/claude-code-docs)
- Ensure the working tree is clean (
git status shows nothing)
- Run
./install.sh from that directory
- The directory you ran the script from is deleted
Suggested Fix
Exclude the script's own directory from the old installations list, or skip it during cleanup. For example:
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# In find_existing_installations(), change the CWD check:
if [[ -f "./docs/docs_manifest.json" && "$(pwd)" != "$INSTALL_DIR" && "$(pwd)" != "$SCRIPT_DIR" ]]; then
paths+=("$(pwd)")
fi
When running
./install.shfrom a clone of the repo (rather than viacurl | bash), the installer identifies the current working directory as an "old installation" andrm -rfs it after completing the install to~/.claude-code-docs.I discovered this while working on some contributions for a PR. There is a check for any uncommitted changes, but if everything has been committed but not yet pushed it still gets nuked.
Fix is probably, when checking if
pwd==$INSTALL_DIR, also check against script's location.Another possibility might be to evaluate if the migration logic has outlived its usefulness. At some point, any installations of the tool will be to the proper location and not need to be migrated. In theory, it should be okay to remove this logic completely at some point. It's quite complicated and could be the source of more issues.
Detailed analysis follows:
Root Cause
Three pieces of code combine to cause this:
find_existing_installations()(line 107-109) adds$(pwd)to the old installations list if./docs/docs_manifest.jsonexists and the CWD isn't~/.claude-code-docs:That path gets saved into the
OLD_INSTALLATIONSarray (line 345).After installing/updating to
~/.claude-code-docs,cleanup_old_installations()(line 498) iteratesOLD_INSTALLATIONSand deletes any that are clean git repos:Steps to Reproduce
~/.claude-code-docs(e.g.,~/work/claude-code-docs)git statusshows nothing)./install.shfrom that directorySuggested Fix
Exclude the script's own directory from the old installations list, or skip it during cleanup. For example: