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

Function getAllSessionFiles

source code/utils/stats.ts:376–437  ·  view source on GitHub ↗

* Get all session files from all project directories. * Includes both main session files and subagent transcript files.

()

Source from the content-addressed store, hash-verified

374 * Includes both main session files and subagent transcript files.
375 */
376async function getAllSessionFiles(): Promise<string[]> {
377 const projectsDir = getProjectsDir()
378 const fs = getFsImplementation()
379
380 // Get all project directories
381 let allEntries
382 try {
383 allEntries = await fs.readdir(projectsDir)
384 } catch (e) {
385 if (isENOENT(e)) return []
386 throw e
387 }
388 const projectDirs = allEntries
389 .filter(dirent => dirent.isDirectory())
390 .map(dirent => join(projectsDir, dirent.name))
391
392 // Collect all session files from all projects in parallel
393 const projectResults = await Promise.all(
394 projectDirs.map(async projectDir => {
395 try {
396 const entries = await fs.readdir(projectDir)
397
398 // Collect main session files (*.jsonl directly in project dir)
399 const mainFiles = entries
400 .filter(dirent => dirent.isFile() && dirent.name.endsWith('.jsonl'))
401 .map(dirent => join(projectDir, dirent.name))
402
403 // Collect subagent files from session subdirectories in parallel
404 // Structure: {projectDir}/{sessionId}/subagents/agent-{agentId}.jsonl
405 const sessionDirs = entries.filter(dirent => dirent.isDirectory())
406 const subagentResults = await Promise.all(
407 sessionDirs.map(async sessionDir => {
408 const subagentsDir = join(projectDir, sessionDir.name, 'subagents')
409 try {
410 const subagentEntries = await fs.readdir(subagentsDir)
411 return subagentEntries
412 .filter(
413 dirent =>
414 dirent.isFile() &&
415 dirent.name.endsWith('.jsonl') &&
416 dirent.name.startsWith('agent-'),
417 )
418 .map(dirent => join(subagentsDir, dirent.name))
419 } catch {
420 // subagents directory doesn't exist for this session, skip
421 return []
422 }
423 }),
424 )
425
426 return [...mainFiles, ...subagentResults.flat()]
427 } catch (error) {
428 logForDebugging(
429 `Failed to read project directory ${projectDir}: ${errorMessage(error)}`,
430 )
431 return []
432 }
433 }),

Callers 2

aggregateClaudeCodeStatsFunction · 0.85

Calls 5

getFsImplementationFunction · 0.85
isENOENTFunction · 0.85
logForDebuggingFunction · 0.85
getProjectsDirFunction · 0.70
errorMessageFunction · 0.70

Tested by

no test coverage detected