Skip to content

File Watching

Lucerna uses chokidar for debounced incremental re-indexing. Only changed files are re-processed — no full DB scan on each file change.

await indexer.startWatching();
await indexer.stopWatching();

Pass watch: true to the constructor to start watching automatically when initialize() is called:

const indexer = new CodeIndexer({
projectRoot: '/path/to/project',
watch: true,
watchDebounce: 500, // ms, default
onIndexed: (event) => {
if (event.type === 'indexed') {
console.log(`[indexed] ${event.filePath} (${event.chunksAffected} chunks)`);
} else if (event.type === 'removed') {
console.log(`[removed] ${event.filePath}`);
} else if (event.type === 'error') {
console.error(`[error] ${event.filePath}:`, event.error);
}
},
});
await indexer.initialize(); // starts watching immediately