-
Notifications
You must be signed in to change notification settings - Fork 88
Description
I lost my .claude/settings.json
ccstatusline/src/utils/claude-settings.ts
Lines 61 to 72 in 03d1969
| export async function loadClaudeSettings(): Promise<ClaudeSettings> { | |
| try { | |
| const settingsPath = getClaudeSettingsPath(); | |
| if (!fs.existsSync(settingsPath)) { | |
| return {}; | |
| } | |
| const content = await readFile(settingsPath, 'utf-8'); | |
| return JSON.parse(content) as ClaudeSettings; | |
| } catch { | |
| return {}; | |
| } | |
| } |
- If not exists, return empty.
- If it exists, and can't be read or parsed, you return empty. This is after acknowledging that the file exists. This truncates the file effectively. There's no logging/information.
You already have a mechanism for your ~/.config/ccstatusline/settings.json to be moved to ~/.config/ccstatusline/settings.bak
ccstatusline/src/utils/config.ts
Lines 24 to 36 in 03d1969
| const SETTINGS_BACKUP_PATH = path.join(CONFIG_DIR, 'settings.bak'); | |
| async function backupBadSettings(): Promise<void> { | |
| try { | |
| if (fs.existsSync(SETTINGS_PATH)) { | |
| const content = await readFile(SETTINGS_PATH, 'utf-8'); | |
| await writeFile(SETTINGS_BACKUP_PATH, content, 'utf-8'); | |
| console.error(`Bad settings backed up to ${SETTINGS_BACKUP_PATH}`); | |
| } | |
| } catch (error) { | |
| console.error('Failed to backup bad settings:', error); | |
| } | |
| } |
In 2 places, if there's issues with it, you back it up before setting defaults and have some logging at least,
ccstatusline/src/utils/config.ts
Lines 65 to 72 in 03d1969
| try { | |
| rawData = JSON.parse(content); | |
| } catch { | |
| // If we can't parse the JSON, backup and write defaults | |
| console.error('Failed to parse settings.json, backing up and using defaults'); | |
| await backupBadSettings(); | |
| return await writeDefaultSettings(); | |
| } |
ccstatusline/src/utils/config.ts
Lines 104 to 109 in 03d1969
| } catch (error) { | |
| // Any other error, backup and write defaults | |
| console.error('Error loading settings:', error); | |
| await backupBadSettings(); | |
| return await writeDefaultSettings(); | |
| } |
I also run multiple claude instances. It could also be a race condition or something else modifying things on the fly and timing could have sucked. Something that implements file locking could be good too.