affaan-m/ECC · error · Error

Claude session not found

Error message

Claude session not found: ${explicitTarget}

What it means

resolveSessionRecord throws this when parseClaudeTarget returns an explicit target (a session id/filename) but sessionManager.getSessionById(explicitTarget, true) returns null. The requested Claude session does not exist in the local history store.

Solutions

  1. Print sessionManager.getAllSessions() and copy the exact filename/id from the list.
  2. Confirm the session belongs to the current project (lookup is cwd-scoped).
  3. Trim the target string of whitespace; pass a path to the session .jsonl file as a fallback.
  4. Recreate the session if history was deleted — there is no remote restore.
  5. Check for version drift: session filenames changed shape across Claude Code versions.

Example fix

// before
adapter.resolveSessionRecord('a1b2c3d4-e5f6'); // typo'd id -> throws
// after
const id = process.env.CLAUDE_SESSION_ID.trim();
const known = sessionManager.getAllSessions().sessions.find(s => s.filename === id);
if (!known) throw new Error(`Unknown session; available: ${sessionManager.getAllSessions().sessions.map(s => s.filename).join(', ')}`);
Defensive patterns

Strategy: validation

Validate before calling

const all = sessionManager.getAllSessions().sessions;
if (!all.some(s => s.filename === targetId)) throw new Error(`Unknown session id: ${targetId}; valid ids: ${all.map(s => s.filename).join(', ')}`);

Type guard

function isKnownSession(id, sessions) { return typeof id === 'string' && sessions.some(s => s.filename === id); }

Try / catch

try { return adapter.resolveSessionRecord(id); } catch (e) { if (/^Claude session not found:/.test(e.message)) throw new Error(`Pick a session from getAllSessions(); '${id}' not found`); throw e; }

Prevention

When it happens

Trigger: Calling resolveSessionRecord with a specific Claude session identifier (not 'latest', not a file path) that getSessionById cannot find — misspelled id, session from another project, or session deleted from disk.

Common situations: Pasting a session id from another machine or project; referencing a session after ~/.claude history cleanup; typo in a UUID or trailing whitespace/newline in a CI variable holding the id.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/8766db73d1e02a27. Report an issue: GitHub.

Appendix: source

Thrown at scripts/lib/session-adapters/claude-history.js:89

          value: 'latest'
        }
      };
    }

    const alias = sessionAliases.resolveAlias(explicitTarget);
    if (alias) {
      return {
        session: hydrateSessionFromPath(alias.sessionPath),
        sourceTarget: {
          type: 'claude-alias',
          value: explicitTarget
        }
      };
    }

    const session = sessionManager.getSessionById(explicitTarget, true);
    if (!session) {
      throw new Error(`Claude session not found: ${explicitTarget}`);
    }

    return {
      session,
      sourceTarget: {
        type: 'claude-history',
        value: explicitTarget
      }
    };
  }

  if (isSessionFileTarget(target, cwd)) {
    return {
      session: hydrateSessionFromPath(path.resolve(cwd, target)),
      sourceTarget: {
        type: 'session-file',
        value: path.resolve(cwd, target)
      }

View on GitHub (pinned to 8321021c54)