davila7/claude-code-templates · warning

Warning: Could not extract project from conversation ${fileP

Error message

Warning: Could not extract project from conversation ${filePath}:

What it means

A warning emitted by extractProjectFromPath in cli-tool/src/analytics.js when reading/parsing a conversation .jsonl file throws unexpectedly (outer catch around the whole read loop). The function then falls back to parsing the project name from the directory path structure (~/.claude/projects/-Users-user-Projects-MyProject).

Source

Thrown at cli-tool/src/analytics.js:302

        try {
          const item = JSON.parse(line);
          
          // Look for cwd field in the message
          if (item.cwd) {
            return path.basename(item.cwd);
          }
          
          // Also check if it's in nested objects
          if (item.message && item.message.cwd) {
            return path.basename(item.message.cwd);
          }
        } catch (parseError) {
          // Skip invalid JSON lines
          continue;
        }
      }
    } catch (error) {
      console.warn(chalk.yellow(`Warning: Could not extract project from conversation ${filePath}:`, error.message));
    }

    // Fallback: Extract project name from file path like:
    // /Users/user/.claude/projects/-Users-user-Projects-MyProject/conversation.jsonl
    const pathParts = filePath.split('/');
    const projectIndex = pathParts.findIndex(part => part === 'projects');

    if (projectIndex !== -1 && projectIndex + 1 < pathParts.length) {
      const projectDir = pathParts[projectIndex + 1];
      // Clean up the project directory name
      const cleanName = projectDir
        .replace(/^-/, '')
        .replace(/-/g, '/')
        .split('/')
        .pop() || 'Unknown';

      return cleanName;
    }

View on GitHub (pinned to a0851ed10c)

Solutions

  1. Check file permissions on the file in the warning message (ls -la)
  2. Verify the path is a regular file (stat) before scanning
  3. Ignore the warning — the function has a documented fallback via path parsing
  4. Update to the latest CLI version if this fires on every scan (parsing bug)
Defensive patterns

Strategy: try-catch

Validate before calling

// Skip non-files before analyzing
const stat = await fs.stat(filePath).catch(() => null);
if (!stat?.isFile()) return fallbackFromPath(filePath);

Try / catch

try { /* parse loop */ } catch (error) {
  console.warn(`Could not extract project from ${filePath}:`, error.message);
  return fallbackFromPath(filePath); // documented path-based fallback
}

Prevention

When it happens

Trigger: A conversation file under ~/.claude/projects/ that cannot be read (permissions, deleted mid-scan) or whose contents cause readFile/JSON handling to reject; e.g. EACCES or EISDIR when the path points at a directory.

Common situations: Analytics scan hitting a file with odd permissions, a partially-written conversation file, or a path collision where a directory sits where a .jsonl file is expected.

Related errors


AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28). Data as JSON: /api/errors/2ddbd9b7f95ef7f9. Report an issue: GitHub.