claude-code - 💡(How to fix) Fix Session resume crashes with TypeError on H.addedBlocks.length after reboot (mcp_instructions_delta handler)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

After an unclean shutdown (reboot / power loss) while Claude Code CLI sessions are active, those sessions can no longer be continued. Any input returns:

undefined is not an object (evaluating 'H.addedBlocks.length')

The session becomes permanently unusable — every subsequent message reproduces the error, which also gets persisted into the transcript as isApiErrorMessage entries.

Error Message

The session becomes permanently unusable — every subsequent message reproduces the error, which also gets persisted into the transcript as isApiErrorMessage entries. Not rare. On one machine, 746 session transcripts contain this error, clustered around 3 reboot events (444 / 291 / 9 sessions) — each reboot bricks every active MCP-enabled session at once. Transcripts stay valid JSON; only the in-app resume path crashes, so context is recoverable manually but sessions can never be resumed in-app.

Root Cause

In the bundled CLI, the mcp_instructions_delta event handler reads addedBlocks with no null-guard:

case "mcp_instructions_delta": {
  let q = [];
  if (H.addedBlocks.length > 0)
    q.push(`# MCP Server Instructions\n\n...${H.addedBlocks.join("\n\n")}`);
  if (H.removedNames.length > 0) q.push(/* ... */);

When the delta object arrives without an addedBlocks field, .length throws TypeError. The sibling code path that constructs these deltas always returns {addedNames, addedBlocks, removedNames}, so addedBlocks is normally defined — but on the resume path it can be undefined.

Code Example

case "mcp_instructions_delta": {
  let q = [];
  if (H.addedBlocks.length > 0)
    q.push(`# MCP Server Instructions\n\n...${H.addedBlocks.join("\n\n")}`);
  if (H.removedNames.length > 0) q.push(/* ... */);

---

if ((H.addedBlocks?.length ?? 0) > 0) /* ... */;
if ((H.removedNames?.length ?? 0) > 0) /* ... */;
RAW_BUFFERClick to expand / collapse

Summary

After an unclean shutdown (reboot / power loss) while Claude Code CLI sessions are active, those sessions can no longer be continued. Any input returns:

undefined is not an object (evaluating 'H.addedBlocks.length')

The session becomes permanently unusable — every subsequent message reproduces the error, which also gets persisted into the transcript as isApiErrorMessage entries.

Environment

  • Claude Code CLI 2.1.143 (also observed on 2.1.141 / 2.1.142)
  • macOS (Darwin 25.3.0), arm64
  • Many MCP servers configured

Root cause

In the bundled CLI, the mcp_instructions_delta event handler reads addedBlocks with no null-guard:

case "mcp_instructions_delta": {
  let q = [];
  if (H.addedBlocks.length > 0)
    q.push(`# MCP Server Instructions\n\n...${H.addedBlocks.join("\n\n")}`);
  if (H.removedNames.length > 0) q.push(/* ... */);

When the delta object arrives without an addedBlocks field, .length throws TypeError. The sibling code path that constructs these deltas always returns {addedNames, addedBlocks, removedNames}, so addedBlocks is normally defined — but on the resume path it can be undefined.

Reproduction

  1. Start a CLI session with MCP servers configured.
  2. While the session is mid-turn (e.g. just after a tool call), kill the machine uncleanly (reboot / power loss).
  3. Relaunch Claude Code, resume that session.
  4. Send any message -> undefined is not an object (evaluating 'H.addedBlocks.length').

Trigger chain: reboot -> all MCP servers disconnect -> on resume the CLI replays queued operations and MCP servers reconnect -> a mcp_instructions_delta event is produced/replayed without addedBlocks -> the unguarded .length access throws.

Impact

Not rare. On one machine, 746 session transcripts contain this error, clustered around 3 reboot events (444 / 291 / 9 sessions) — each reboot bricks every active MCP-enabled session at once. Transcripts stay valid JSON; only the in-app resume path crashes, so context is recoverable manually but sessions can never be resumed in-app.

Suggested fix

Guard the access in the mcp_instructions_delta handler:

if ((H.addedBlocks?.length ?? 0) > 0) /* ... */;
if ((H.removedNames?.length ?? 0) > 0) /* ... */;

or ensure the delta object always carries addedBlocks / removedNames (defaulting to []) on the resume / replay path.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Session resume crashes with TypeError on H.addedBlocks.length after reboot (mcp_instructions_delta handler)