davila7/claude-code-templates · warning

Could not analyze commands:

Error message

Could not analyze commands:

What it means

YearInReview2025 command analysis caught an error and returns an empty result ({commands: [], total: 0, events: []}). The commands section of the year-in-review will simply show no data.

Source

Thrown at cli-tool/src/analytics/core/YearInReview2025.js:708

              }
            }
          }
        } catch (e) {
          // Skip invalid lines
        }
      });

      const commands = Array.from(commandCounts.entries())
        .map(([name, count]) => ({ name, count }))
        .sort((a, b) => b.count - a.count);

      return {
        commands: commands.slice(0, 20), // Top 20 commands
        total: commands.reduce((sum, cmd) => sum + cmd.count, 0),
        events: commandEvents.sort((a, b) => a.timestamp - b.timestamp) // Sort by date
      };
    } catch (error) {
      console.warn('Could not analyze commands:', error.message);
      return { commands: [], total: 0, events: [] };
    }
  }

  /**
   * Analyze installed skills
   * @returns {Promise<Object>} Skills data
   */
  async analyzeSkills() {
    const fs = require('fs-extra');
    const os = require('os');
    const path = require('path');

    try {
      const skillsPath = path.join(os.homedir(), '.claude', 'skills');
      if (!await fs.pathExists(skillsPath)) {
        return { skills: [], total: 0, events: [] };
      }

View on GitHub (pinned to a0851ed10c)

Solutions

  1. Ignore if you don't need command stats — other sections still render
  2. Verify ~/.claude/history (or equivalent) parses: jq . per line
  3. Update the CLI so the history format matches the analyzer
  4. Delete corrupt history entries if jq pinpoints them
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check history file shape
const hist = await fs.readFile(histPath, 'utf8').catch(() => null);
const ok = !!hist && hist.trim().split('\n').every(l => { try { JSON.parse(l); return true; } catch { return false; } });

Try / catch

try { return analyzeCommands(events); }
catch (error) { console.warn('Could not analyze commands:', error.message); return { commands: [], total: 0, events: [] }; }

Prevention

When it happens

Trigger: Reading/parsing ~/.claude history or command log files for slash-command usage stats fails — malformed entries, missing files, unexpected JSON shape in history entries.

Common situations: History file format changed between CLI versions; large or corrupted history.jsonl; no history exists and an unexpected code path throws on undefined.

Related errors


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