davila7/claude-code-templates · error · Error

Invalid session file - missing conversation data

Error message

Invalid session file - missing conversation data

What it means

Thrown by validateSessionData() in cli-tool/src/session-sharing.js when the session object has no 'conversation' object or the conversation is missing its 'id'. cloneSession needs the conversation id to place the session into Claude Code's project directory structure, so a session without it cannot be installed.

Source

Thrown at cli-tool/src/session-sharing.js:338

      if (error.message.includes('Unexpected token')) {
        throw new Error('Invalid session file - corrupted or not a Claude Code session');
      }
      throw error;
    }
  }

  /**
   * Validate session data structure
   * @param {Object} sessionData - Session data to validate
   * @throws {Error} If validation fails
   */
  validateSessionData(sessionData) {
    if (!sessionData.version) {
      throw new Error('Invalid session file - missing version');
    }

    if (!sessionData.conversation || !sessionData.conversation.id) {
      throw new Error('Invalid session file - missing conversation data');
    }

    if (!sessionData.messages || !Array.isArray(sessionData.messages)) {
      throw new Error('Invalid session file - missing or invalid messages');
    }

    if (sessionData.messages.length === 0) {
      throw new Error('Invalid session file - no messages found');
    }
  }

  /**
   * Install session in Claude Code directory structure
   * @param {Object} sessionData - Session data to install
   * @param {Object} options - Installation options
   * @returns {Promise<Object>} Installation result
   */
  async installSession(sessionData, options = {}) {

View on GitHub (pinned to a0851ed10c)

Solutions

  1. Check sessionData.conversation in the downloaded file — if absent, re-export and re-share the session with a current CLI version
  2. Confirm the whole file downloaded (compare file size with the sender)
  3. If schema changed upstream, update session-sharing.js to map the new conversation field

Example fix

// before
if (!sessionData.conversation || !sessionData.conversation.id) {
  throw new Error('Invalid session file - missing conversation data');
}

// after
const convId = sessionData.conversation?.id || sessionData.conversationId;
if (!convId) {
  throw new Error('Invalid session file - missing conversation data');
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!data.conversation || !data.conversation.id) {
  throw new Error('Rejecting file: no conversation.id — cannot install session');
}

Type guard

function hasConversationId(d) {
  return Boolean(d && d.conversation && typeof d.conversation.id === 'string' && d.conversation.id.length > 0);
}

Try / catch

try {
  await cloner.cloneSession(data);
} catch (e) {
  if (e.message.includes('missing conversation data')) {
    // regenerate the export from the source session
    return reExport(originalSession);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling cloneSession()/validateSessionData() on a session export whose 'conversation' field is absent, null, or an object without 'id' — typically a truncated export, a different JSON file, or a schema drift after a Claude Code update.

Common situations: Session exports created by an older/newer Claude Code version with a changed schema; manually edited exports where the conversation block was removed; downloading a partial file that JSON-parses by luck.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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