Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:777genius Agent teams ai ProjectScanner scan

From Leeroopedia
Knowledge Sources
Domains Session_Analysis, File_Discovery
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for discovering and cataloging Claude CLI session files from the filesystem with multi-layer caching and platform-aware batching, provided by the Agent Teams application.

Description

The ProjectScanner.scan() method scans the `~/.claude/projects/` directory and returns a list of all projects with their sessions, metadata, and file stats. It uses a short-lived scan cache (2-second TTL) to deduplicate concurrent scans, in-flight promise sharing, and platform-aware batch sizes to prevent thread pool saturation.

Key behaviors:

  • Short-lived scan cache: 2-second TTL deduplicates calls from `getProjects()` and `getRepositoryGroups()` that fire in `Promise.all()` on startup.
  • In-flight deduplication: A `scanInFlight` promise is shared between concurrent callers.
  • Generation tracking: A `scanGeneration` counter prevents stale in-flight results from being cached after invalidation.
  • Platform-aware batching: Windows: 16 sessions/batch, 4 projects/batch, 8 concurrent IO. Unix: 64, 12, 16.
  • Scan budget: 24-second default budget with 1-second minimum batch budget.
  • Multi-layer cache: Content presence cache, session metadata cache, session preview cache.
  • SessionMetadataIndex: Optional persisted index for accelerated session lookup.
  • File IO queue: Limits concurrent file IO operations via a queue with configurable concurrency.

Usage

  • App startup: Call `scan()` to populate the project list for the session browser UI.
  • Context switch: Call `scan()` when the user switches projects to refresh the session list.
  • Search: The scanner also caches a project list for `SessionSearcher` to avoid re-scanning for each query.

Code Reference

Source Location

  • Repository: agent-teams
  • File: src/main/services/discovery/ProjectScanner.ts

Signature

export class ProjectScanner {
  constructor(
    projectsDir?: string,
    todosDir?: string,
    fsProvider?: FileSystemProvider,
    options?: ProjectScannerOptions
  );

  async scan(): Promise<Project[]>;
}

Import

import { ProjectScanner } from '@main/services/discovery/ProjectScanner';

I/O Contract

Inputs

Name Type Required Description
(constructor) projectsDir string No (default ~/.claude/projects/) Directory to scan for session files
(constructor) todosDir string No (default ~/.claude/todos/) Directory for todo files
(constructor) fsProvider FileSystemProvider No (default LocalFileSystemProvider) Filesystem abstraction

Outputs

Name Type Description
return Promise<Project[]> Projects sorted by most recent activity
Project.path string Project filesystem path
Project.sessions SessionInfo[] Session list with metadata
Project.encodedPath string Encoded path for directory name

Usage Examples

Basic Scan

import { ProjectScanner } from '@main/services/discovery/ProjectScanner';

const scanner = new ProjectScanner();
const projects = await scanner.scan();

for (const project of projects) {
  console.log(`${project.path}: ${project.sessions.length} sessions`);
}

With Custom Filesystem Provider

const scanner = new ProjectScanner(
  undefined,
  undefined,
  new RemoteFileSystemProvider(),
  {
    scanFileIoConcurrency: 32,
    scanBudgetMs: 60_000,
  sessionIndexPersistDelayMs: 5000,
  sessionIndexDir: '/custom/index/path',
  scanBudgetMs: 60_000,
  sessionIndexPersistDelayMs: 5000,
  sessionIndexDir: '/custom/index/path',
  }
);

const projects = await scanner.scan();

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment