MCPcopy
hub / github.com/codeaashu/claude-code / loadSettingsFromDisk

Function loadSettingsFromDisk

src/utils/settings/settings.ts:645–796  ·  view source on GitHub ↗

* Load settings from disk without using cache * This is the original implementation that actually reads from files

()

Source from the content-addressed store, hash-verified

643 * This is the original implementation that actually reads from files
644 */
645function loadSettingsFromDisk(): SettingsWithErrors {
646 // Prevent recursive calls to loadSettingsFromDisk
647 if (isLoadingSettings) {
648 return { settings: {}, errors: [] }
649 }
650
651 const startTime = Date.now()
652 profileCheckpoint('loadSettingsFromDisk_start')
653 logForDiagnosticsNoPII('info', 'settings_load_started')
654
655 isLoadingSettings = true
656 try {
657 // Start with plugin settings as the lowest priority base.
658 // All file-based sources (user, project, local, flag, policy) override these.
659 // Plugin settings only contain allowlisted keys (e.g., agent) that are valid SettingsJson fields.
660 const pluginSettings = getPluginSettingsBase()
661 let mergedSettings: SettingsJson = {}
662 if (pluginSettings) {
663 mergedSettings = mergeWith(
664 mergedSettings,
665 pluginSettings,
666 settingsMergeCustomizer,
667 )
668 }
669 const allErrors: ValidationError[] = []
670 const seenErrors = new Set<string>()
671 const seenFiles = new Set<string>()
672
673 // Merge settings from each source in priority order with deep merging
674 for (const source of getEnabledSettingSources()) {
675 // policySettings: "first source wins" — use the highest-priority source
676 // that has content. Priority: remote > HKLM/plist > managed-settings.json > HKCU
677 if (source === 'policySettings') {
678 let policySettings: SettingsJson | null = null
679 const policyErrors: ValidationError[] = []
680
681 // 1. Remote (highest priority)
682 const remoteSettings = getRemoteManagedSettingsSyncFromCache()
683 if (remoteSettings && Object.keys(remoteSettings).length > 0) {
684 const result = SettingsSchema().safeParse(remoteSettings)
685 if (result.success) {
686 policySettings = result.data
687 } else {
688 // Remote exists but is invalid — surface errors even as we fall through
689 policyErrors.push(
690 ...formatZodError(result.error, 'remote managed settings'),
691 )
692 }
693 }
694
695 // 2. Admin-only MDM (HKLM / macOS plist)
696 if (!policySettings) {
697 const mdmResult = getMdmSettings()
698 if (Object.keys(mdmResult.settings).length > 0) {
699 policySettings = mdmResult.settings
700 }
701 policyErrors.push(...mdmResult.errors)
702 }

Callers 1

getSettingsWithErrorsFunction · 0.85

Calls 15

profileCheckpointFunction · 0.85
logForDiagnosticsNoPIIFunction · 0.85
getPluginSettingsBaseFunction · 0.85
getEnabledSettingSourcesFunction · 0.85
formatZodErrorFunction · 0.85
getMdmSettingsFunction · 0.85
loadManagedFileSettingsFunction · 0.85
getHkcuSettingsFunction · 0.85
parseSettingsFileFunction · 0.85
getFlagSettingsInlineFunction · 0.85

Tested by

no test coverage detected