Skip to content

When installed from local project clone, install.sh deletes project directory #121

@zcutlip

Description

@zcutlip

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:

  1. 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
  2. That path gets saved into the OLD_INSTALLATIONS array (line 345).

  3. 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

  1. Clone the repo to any location other than ~/.claude-code-docs (e.g., ~/work/claude-code-docs)
  2. Ensure the working tree is clean (git status shows nothing)
  3. Run ./install.sh from that directory
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions