Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(setup): detect existing statusline, create backup, and prompt before overwriting#546

Open
tenondecrpc wants to merge 1 commit into
jarrodwatts:mainfrom
tenondecrpc:fix/setup-detect-existing-statusline
Open

fix(setup): detect existing statusline, create backup, and prompt before overwriting#546
tenondecrpc wants to merge 1 commit into
jarrodwatts:mainfrom
tenondecrpc:fix/setup-detect-existing-statusline

Conversation

@tenondecrpc
Copy link
Copy Markdown

@tenondecrpc tenondecrpc commented May 14, 2026

Problem

/claude-hud:setup unconditionally overwrites the statusLine key in settings.json without detecting, warning about, or backing up any existing statusline configuration. If a user has another plugin (claude-pace, cc-statusline, etc.) or a custom script configured, it is silently destroyed with no recovery path.

This also means that if setup writes invalid JSON (as happened in #315), there is no backup to restore from.

Fix

Adds Step 2.5 between Test Command and Apply Configuration:

  • 2.5.1 — Read existing statusLine.command from settings.json (bash + PowerShell)
  • 2.5.2 — Classify the existing statusline: claude-hud (reinstall), known project (claude-pace, cc-statusline), statusline script, or custom
  • 2.5.3Always create a timestamped backup (settings.json.bak.YYYYMMDD-HHMMSS) before any modification
  • 2.5.4 — If a non-claude-hud statusline exists, prompt the user via AskUserQuestion: Replace / Keep / Cancel
  • 2.5.5 — Save the previous command to ~/.claude/plugins/claude-hud/previous-statusline.txt for easy restoration

Step 3 now references the backup and notes that setup exits early if the user chose Keep or Cancel. A restoration section is added after Step 3.

Test plan

  • All 576 existing tests pass (0 fail, 1 skip)
  • Manual: install claude-hud over an existing claude-pace statusline → should prompt
  • Manual: reinstall claude-hud over itself → should skip prompt (idempotent)
  • Manual: clean install with no statusline → should skip prompt
  • Manual: verify settings.json.bak.* backup is created before any write
  • Manual: verify previous-statusline.txt is saved when replacing another statusline
  • Manual: verify "Keep" option exits without modifying settings.json

…ore overwriting

Before this change, /claude-hud:setup unconditionally overwrote the
statusLine key in settings.json without warning, backup, or recovery.
If a user had another statusline plugin (claude-pace, cc-statusline,
etc.) or a custom script configured, it was silently destroyed.

Add Step 2.5 between Test Command and Apply Configuration:

- 2.5.1: Read existing statusLine.command from settings.json
- 2.5.2: Classify the existing statusline (claude-hud reinstall,
  known project, statusline script, or custom) to choose the right
  prompt tone
- 2.5.3: Always create a timestamped backup of settings.json before
  any modification (also protects against corruption like jarrodwatts#315)
- 2.5.4: If a non-claude-hud statusline exists, prompt the user with
  Replace / Keep / Cancel options via AskUserQuestion
- 2.5.5: Save the previous command to
  ~/.claude/plugins/claude-hud/previous-statusline.txt for easy
  restoration

Step 3 now references the backup and notes that setup exits early
if the user chose Keep or Cancel. A restoration section is added
after Step 3 with instructions to recover from the backup.

Closes jarrodwatts#545
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant