davila7/claude-code-templates · info
Error parsing message line:
Error message
Error parsing message line:
What it means
A per-line warning while parsing a Claude Code conversation .jsonl file: one line failed JSON.parse, so it's skipped (mapped to null and filtered out). Non-fatal by design; malformed/truncated lines are dropped.
Source
Thrown at cli-tool/src/analytics.js:919
error: 'Conversation file path not found',
conversationId: conversationId,
conversationKeys: Object.keys(conversation),
hasFilePath: !!conversation.filePath,
hasFileName: !!conversation.filename
});
}
if (!await fs.pathExists(conversationFile)) {
return res.status(404).json({ error: 'Conversation file not found', path: conversationFile });
}
const content = await fs.readFile(conversationFile, 'utf8');
const lines = content.trim().split('\n').filter(line => line.trim());
const rawMessages = lines.map(line => {
try {
return JSON.parse(line);
} catch (error) {
console.warn('Error parsing message line:', error);
return null;
}
}).filter(Boolean);
// Extract actual messages from Claude Code format
const messages = rawMessages.map(item => {
if (item.message && item.message.role) {
let content = '';
if (typeof item.message.content === 'string') {
content = item.message.content;
} else if (Array.isArray(item.message.content)) {
content = item.message.content
.map(block => {
if (block.type === 'text') return block.text;
if (block.type === 'tool_use') return `[Tool: ${block.name}]`;
if (block.type === 'tool_result') return '[Tool Result]';
return block.content || '';View on GitHub (pinned to a0851ed10c)
Solutions
- Close the active Claude Code session writing to that file, or exclude recently-modified files from the scan
- Ignore the warning — the line is skipped and analytics continue
- Re-validate the file with `jq -c . file.jsonl > /dev/null` to see which lines are corrupt
- Restore the file from backup if many lines fail
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validate a conversation file cheaply
async function isValidJsonl(file) {
const text = await fs.readFile(file, 'utf8').catch(() => null);
return !!text && text.split('\n').filter(Boolean).every(l => { try { JSON.parse(l); return true; } catch { return false; } });
} Try / catch
const rawMessages = lines.map(line => {
try { return JSON.parse(line); }
catch { return null; } // skip-and-continue is the intended pattern
}).filter(Boolean); Prevention
- Exclude files modified in the last few seconds from scans (still being written)
- Never assume every .jsonl line parses — always null-filter
- Keep backups of ~/.claude/projects if analytics fidelity matters
When it happens
Trigger: A partially-written last line in a .jsonl conversation file (Claude Code still writing), embedded NUL bytes, or an empty/truncated line that survived the filter. Fires for each bad line during message loading.
Common situations: Scanning conversations while Claude Code is actively writing to them; crash-truncated files; files synced/edited by other tools corrupting line boundaries.
Related errors
- Warning: Could not parse ${filename}:
- Failed to update states
- Failed to get system health
- Failed to get Claude session info
- Failed to get performance metrics
AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28).
Data as JSON: /api/errors/c558cfd7f5885402.
Report an issue: GitHub.