Skip to content

claude's settings.json deleted / lost #122

@rubenvarela

Description

@rubenvarela

I lost my .claude/settings.json

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

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,

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();
}

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

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