Overview
Concrete tool for reading and caching team configuration from the filesystem with generation-based invalidation, provided by the Agent Teams application.
Description
The TeamConfigReader class provides cached, concurrent-safe reads of team `config.json` files. It deduplicates in-flight reads (multiple IPC callers requesting the same config share a single disk read), uses generation counters to reject stale in-flight results after invalidation, and exposes both verified and snapshot read modes.
Usage
- Team launch: Call `getConfig()` to read the verified, latest configuration before spawning a team.
- UI display: Call `getConfigSnapshot()` for a best-effort read that retries on generation mismatch (up to 3 attempts).
- Cache invalidation: Call `TeamConfigReader.invalidateTeam(name)` when a config file watcher fires, or `invalidatePath(path)` for finer-grained control.
- List teams: The class also caches team listing scans with their own in-flight deduplication and generation tracking.
Code Reference
Source Location
- Repository: agent-teams
- File: src/main/services/team/TeamConfigReader.ts
Signature
export class TeamConfigReader {
// Static caches and in-flight tracking
private static readonly configCacheByPath: Map<string, CachedTeamConfig>;
private static readonly configReadInFlightByPath: Map<string, Promise<TeamConfig | null>>;
private static readonly configGenerationByPath: Map<string, number>;
// Static invalidation
static invalidateTeam(teamName: string): void;
static invalidatePath(configPath: string): void;
static invalidateListTeamsCache(): void;
static clearCacheForTests(): void;
// Public API
async getConfig(teamName: string): Promise<TeamConfig | null>;
async getConfigVerified(teamName: string): Promise<TeamConfig | null>;
async getConfigSnapshot(teamName: string): Promise<TeamConfig | null>;
}
Import
import { TeamConfigReader } from '@main/services/team/TeamConfigReader';
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| teamName |
string |
Yes |
Unique team identifier used to resolve config path under `~/.claude/teams/{teamName}/config.json`
|
Outputs
| Name |
Type |
Description
|
| return (getConfig) |
null> |
Verified team config with members, roles, provider, model settings; null if not found
|
| return (getConfigSnapshot) |
null> |
Best-effort snapshot with up to 3 retry attempts on generation mismatch
|
| TeamConfig.members |
MemberConfig[] |
Array of member definitions with name, role, provider config
|
| TeamConfig.provider |
TeamProviderId |
Runtime provider: 'claude', 'codex', or 'opencode'
|
Usage Examples
Reading Verified Config Before Launch
import { TeamConfigReader } from '@main/services/team/TeamConfigReader';
const reader = new TeamConfigReader();
// Read the latest, verified configuration
const config = await reader.getConfig('my-team');
if (!config) {
throw new Error('Team not found');
}
console.log(`Team has ${config.members.length} members`);
console.log(`Provider: ${config.provider}`);
Cache Invalidation on File Watch
import { TeamConfigReader } from '@main/services/team/TeamConfigReader';
// File watcher detects config.json change
watcher.on('change', (filePath) => {
TeamConfigReader.invalidatePath(filePath);
});
// Invalidate all caches for a specific team
TeamConfigReader.invalidateTeam('my-team');
// Invalidate the team listing cache (e.g., after team creation)
TeamConfigReader.invalidateListTeamsCache();
Snapshot Read with Retry
const reader = new TeamConfigReader();
// getConfigSnapshot retries up to 3 times if the generation
// changes between fingerprint check and read (handles race conditions
// where the file is written between check and read)
const snapshot = await reader.getConfigSnapshot('my-team');
Related Pages
Implements Principle
Requires Environment
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.