# fix(agent): skip full-transcript subagent scan when subagentsDir is empty

`9e4217c`→[main](/content/gh/entireio/cli/commits/main/index.html)·

suhaanthayyil·4d ago·2 files·+19 added/-9 removed

## Changes

- cmd/entire/cli/agent

- claudecode

- Mtranscript.go+10/-5

- factoryaidroid

- Mtranscript.go+9/-4

```
394 unmodified lines

395
396
397
398
399
400
401
402
403
404
4 unmodified lines

409
410
411
408
412
413
414
415
4 unmodified lines

420
421
422
419
423
424
425
426
43 unmodified lines

470
471
472
473
474
475
476
477
478
479
3 unmodified lines

483
484
485
478
479
480
486
487
488

394 unmodified lines

// Calculate token usage from parsed transcript
	mainUsage := CalculateTokenUsage(parsed)

if subagentsDir == "" {
		return mainUsage, nil
	}

// Extract spawned agent IDs from the FULL transcript (startLine=0), not the
	// sliced portion. A subagent spawned before this checkpoint's startLine can
	// keep writing to its transcript in later turns; scanning only the slice
4 unmodified lines

}
	agentIDs := ExtractSpawnedAgentIDs(fullParsed)

// Calculate subagent token usage (skip when subagentsDir is empty to avoid reading from cwd).
	// Calculate subagent token usage.
	// NOTE: each subagent transcript is re-read from line 0 on every call, so
	// mainUsage.SubagentTokens below is a CUMULATIVE-since-session-start total,
	// not a delta scoped to [startLine, end) like mainUsage's own fields.\
4 unmodified lines
\
	// checkpoint-window delta by subtracting a previously captured baseline.\
	// See accumulateTokenUsage and SessionState.SubagentTokensBaseline in\
	// cmd/entire/cli/strategy for the caller-side fix.\
	if len(agentIDs) > 0 && subagentsDir != "" {\
	if len(agentIDs) > 0 {\
		subagentUsage := &agent.TokenUsage{}\
		for agentID := range agentIDs {\
			agentPath := filepath.Join(subagentsDir, fmt.Sprintf("agent-%s.jsonl", agentID))\
43 unmodified lines
\
		}\
	}\

if subagentsDir == "" {\
		return files, nil\
	}\
\
	// Find spawned subagents from the FULL transcript (startLine=0): a subagent\
	// spawned before this checkpoint's startLine may keep modifying files in\
	// later turns, and scanning only the slice would miss it (#329). Main-agent\
3 unmodified lines\
\
		return nil, fmt.Errorf("failed to parse full transcript: %w", err)\
	}\
	agentIDs := ExtractSpawnedAgentIDs(fullParsed)\
	if subagentsDir == "" {\
		return files, nil\
	}\
	for agentID := range agentIDs {\
		agentPath := filepath.Join(subagentsDir, fmt.Sprintf("agent-%s.jsonl", agentID))\
		agentLines, agentErr := transcript.ParseFromFileAtLine(agentPath, 0)\
```
\
Mcmd/entire/cli/agent/claudecode/transcript.go+10/-5\
\
```
365 unmodified lines\
\
366\
367\
368\
369\
370\
371\
372\
373\
374\
375\
11 unmodified lines\
\
387\
388\
389\
386\
390\
391\
392\
393\
35 unmodified lines\
\
429\
430\
431\
432\
433\
434\
435\
436\
437\
438\
3 unmodified lines\
\
442\
443\
444\
437\
438\
439\
445\
446\
447\
\
365 unmodified lines\
\
	mainUsage := CalculateTokenUsage(parsed)\
\
	if subagentsDir == "" {\
		return mainUsage, nil\
	}\
\
	// Extract spawned agent IDs from the FULL transcript (startLine=0): a\
	// subagent spawned before this checkpoint's startLine can keep writing to\
	// its transcript, so scanning only the slice would undercount it (#329).\
11 unmodified lines\
\
	// delta by subtracting a previously captured baseline. See\
	// accumulateTokenUsage and SessionState.SubagentTokensBaseline in\
	// cmd/entire/cli/strategy for the caller-side fix (shared with Claude Code).\
	if len(agentIDs) > 0 && subagentsDir != "" {\
	if len(agentIDs) > 0 {\
		subagentUsage := &agent.TokenUsage{}\
		for agentID := range agentIDs {\
			agentPath := filepath.Join(subagentsDir, fmt.Sprintf("agent-%s.jsonl", agentID))\
35 unmodified lines\
\
		fileSet[f] = true\
	}\
\
	if subagentsDir == "" {\
		return files, nil\
	}\
\
	// Find spawned subagents from the FULL transcript (startLine=0): a subagent\
	// spawned before this checkpoint's startLine may keep modifying files in\
	// later turns, and scanning only the slice would miss it (#329). Main-agent\
3 unmodified lines\
\
		return nil, fmt.Errorf("failed to parse full transcript: %w", err)\
	}\
	agentIDs := ExtractSpawnedAgentIDs(fullParsed)\
	if subagentsDir == "" {\
		return files, nil\
	}\
	for agentID := range agentIDs {\
		agentPath := filepath.Join(subagentsDir, fmt.Sprintf("agent-%s.jsonl", agentID))\
		agentLines, _, agentErr := ParseDroidTranscript(agentPath, 0)\
```\
\
Mcmd/entire/cli/agent/factoryaidroid/transcript.go+9/-4
