MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / initialize

Function initialize

source code/utils/settings/changeDetector.ts:86–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84 * Initialize file watching
85 */
86export async function initialize(): Promise<void> {
87 if (getIsRemoteMode()) return
88 if (initialized || disposed) return
89 initialized = true
90
91 // Start MDM poll for registry/plist changes (independent of filesystem watching)
92 startMdmPoll()
93
94 // Register cleanup to properly dispose during graceful shutdown
95 registerCleanup(dispose)
96
97 const { dirs, settingsFiles, dropInDir } = await getWatchTargets()
98 if (disposed) return // dispose() ran during the await
99 if (dirs.length === 0) return
100
101 logForDebugging(
102 `Watching for changes in setting files ${[...settingsFiles].join(', ')}...${dropInDir ? ` and drop-in directory ${dropInDir}` : ''}`,
103 )
104
105 watcher = chokidar.watch(dirs, {
106 persistent: true,
107 ignoreInitial: true,
108 depth: 0, // Only watch immediate children, not subdirectories
109 awaitWriteFinish: {
110 stabilityThreshold:
111 testOverrides?.stabilityThreshold ?? FILE_STABILITY_THRESHOLD_MS,
112 pollInterval:
113 testOverrides?.pollInterval ?? FILE_STABILITY_POLL_INTERVAL_MS,
114 },
115 ignored: (path, stats) => {
116 // Ignore special file types (sockets, FIFOs, devices) - they cannot be watched
117 // and will error with EOPNOTSUPP on macOS.
118 if (stats && !stats.isFile() && !stats.isDirectory()) return true
119 // Ignore .git directories
120 if (path.split(platformPath.sep).some(dir => dir === '.git')) return true
121 // Allow directories (chokidar needs them for directory-level watching)
122 // and paths without stats (chokidar's initial check before stat)
123 if (!stats || stats.isDirectory()) return false
124 // Only watch known settings files, ignore everything else in the directory
125 // Note: chokidar normalizes paths to forward slashes on Windows, so we
126 // normalize back to native format for comparison
127 const normalized = platformPath.normalize(path)
128 if (settingsFiles.has(normalized)) return false
129 // Also accept .json files inside the managed-settings.d/ drop-in directory
130 if (
131 dropInDir &&
132 normalized.startsWith(dropInDir + platformPath.sep) &&
133 normalized.endsWith('.json')
134 ) {
135 return false
136 }
137 return true
138 },
139 // Additional options for stability
140 ignorePermissionErrors: true,
141 usePolling: false, // Use native file system events
142 atomic: true, // Handle atomic writes better
143 })

Callers

nothing calls this directly

Calls 6

getIsRemoteModeFunction · 0.85
startMdmPollFunction · 0.85
registerCleanupFunction · 0.85
getWatchTargetsFunction · 0.85
logForDebuggingFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected