[BUG] Session resume crashes with "Cannot read properties of undefined (reading 'trim')"
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
## Description
When trying to resume a session from the session list, Claude Code crashes with:
Cannot read properties of undefined (reading 'trim')
file:///.../claude-code/cli.js:2722:6198
## Root Cause Analysis
Session .jsonl files are being created without proper summary header lines. They start with file-history-snapshot, progress, or user
type records instead of a summary record.
I wrote a repair script that adds missing summary headers, but the crash persists even after fixing all session files. This suggests the bug may
be in how session content is parsed for preview/display, not just the header.
Additionally, new sessions keep being created without proper headers - the bug is ongoing, not just affecting old sessions.
## Affected session first lines
{"type":"file-history-snapshot",...}❌{"type":"progress",...}❌{"type":"user",...}❌
## Expected first line
{"type":"summary","summary":"...","leafUuid":null,"cwd":"..."}✓
## Version
2.1.47+ (based on session metadata)
## Suggested Fix
Add null-safe handling when reading session data:
```javascript
const summary = sessionData?.summary?.trim?.() ?? 'Untitled Session';
Also ensure new sessions are always created with a proper summary header.
What Should Happen?
Claude should resume large session files from previously created sessions without errors.
Error Messages/Logs
ERROR Cannot read properties of undefined (reading 'trim')
file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2722:6198
- d15 (file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2722:6198)
- A9 (file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:601:21820)
- i2 (file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:601:38061)
- oT (file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:601:49007)
- _M (file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:601:85342)
- Li (file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:601:84348)
- qi (file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:601:84174)
- wh (file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:601:81067)
- g0 (file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:601:8914)
- hA (file:///Users/id/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:601:7651)
Steps to Reproduce
- Start Claude Code in a project that has session hooks configured (e.g., SessionStart hook)
- Have a conversation
- Exit and try to resume the session later
- Crash occurs - the session was created starting with a progress event instead of a summary header
The issue seems to be: When session hooks run at startup, the session file gets created with a progress record as the first line instead of a
proper summary header.
Additional context:
- Version: 2.0.64
- Platform: macOS (Darwin 22.6.0)
- The crash appears to be triggered by session files that are missing a summary header line
- New sessions are sometimes created without proper headers, causing future resume attempts to crash
- Manually adding summary headers to .jsonl files does not fix the issue - crash still occurs
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.0.64
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗