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

Function getAllSessionFiles

src/utils/stats.ts:374–435  ·  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

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

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