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

Function immediateFlushHistory

src/history.ts:292–327  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

290
291// Core flush logic - writes pending entries to disk
292async function immediateFlushHistory(): Promise<void> {
293 if (pendingEntries.length === 0) {
294 return
295 }
296
297 let release
298 try {
299 const historyPath = join(getClaudeConfigHomeDir(), 'history.jsonl')
300
301 // Ensure the file exists before acquiring lock (append mode creates if missing)
302 await writeFile(historyPath, '', {
303 encoding: 'utf8',
304 mode: 0o600,
305 flag: 'a',
306 })
307
308 release = await lock(historyPath, {
309 stale: 10000,
310 retries: {
311 retries: 3,
312 minTimeout: 50,
313 },
314 })
315
316 const jsonLines = pendingEntries.map(entry => jsonStringify(entry) + '\n')
317 pendingEntries = []
318
319 await appendFile(historyPath, jsonLines.join(''), { mode: 0o600 })
320 } catch (error) {
321 logForDebugging(`Failed to write prompt history: ${error}`)
322 } finally {
323 if (release) {
324 await release()
325 }
326 }
327}
328
329async function flushPromptHistory(retries: number): Promise<void> {
330 if (isWriting || pendingEntries.length === 0) {

Callers 2

flushPromptHistoryFunction · 0.85
addToHistoryFunction · 0.85

Calls 4

lockFunction · 0.85
jsonStringifyFunction · 0.85
logForDebuggingFunction · 0.85
releaseFunction · 0.50

Tested by

no test coverage detected