claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[Bug] Resumable agents fork from checkpoint instead of accumulating context

Open yannbam opened this issue 2 months ago • 6 comments

Bug Description

Bug Report: Resumable Agents Don't Accumulate Context

Summary

Resumable agents (introduced in v2.0.28) do not accumulate context across resume operations. Each resume loads only the original conversation from the agent JSONL checkpoint, not any previous resume interactions. This makes agents "forkable" rather than truly "resumable."

Expected Behavior

When resuming an agent multiple times, it should maintain a continuous conversation thread:

Agent Created (Message #1)
    ↓
Resume #1 (Message #2) - sees: #1, #2
    ↓
Resume #2 (Message #3) - sees: #1, #2, #3  ✓ Expected
    ↓
Resume #3 (Message #4) - sees: #1, #2, #3, #4  ✓ Expected

Actual Behavior

Each resume creates an independent branch from the original checkpoint:

Agent Created (Message #1) ← saved to JSONL
    ↓
    ├─→ Resume #1 (Message #2) - sees: #1, #2
    ├─→ Resume #2 (Message #3) - sees: #1, #3  ✗ Missing #2
    └─→ Resume #3 (Message #4) - sees: #1, #4  ✗ Missing #2, #3

Reproduction Steps

Test 1: Simple Multi-Resume

# 1. Create an agent with initial message
Task(subagent_type="general-purpose", model="haiku", prompt="MESSAGE #1: Remember ALPHA-100")
# Agent ID: 03f6525d (example)

# 2. First resume
Task(resume="03f6525d", prompt="MESSAGE #2: Remember BETA-200. Quote all messages you see.")
# Output: Sees MESSAGE #1 (ALPHA-100) and MESSAGE #2 (BETA-200) ✓

# 3. Second resume
Task(resume="03f6525d", prompt="MESSAGE #3: Remember GAMMA-300. Quote all messages you see.")
# Output: Sees MESSAGE #1 (ALPHA-100) and MESSAGE #3 (GAMMA-300)
# Missing: MESSAGE #2 (BETA-200) ✗

Test 2: File System Evidence

# Create agent
ls -lt ~/.claude/projects/*/agent-*.jsonl | head -1
# Output: agent-03f6525d.jsonl created at 13:51:23

# Resume agent twice
# ... perform resumes ...

# Check file modification time
stat ~/.claude/projects/*/agent-03f6525d.jsonl | grep Modify
# Output: Modify: 2025-11-02 13:51:23 (unchanged!)

# Check line count
wc -l ~/.claude/projects/*/agent-03f6525d.jsonl
# Output: 8 lines (unchanged after resumes!)

Evidence

Agent's Own Observation

When asked to quote visible messages on Resume #2, the agent responded:

"Based on my conversation history, here are the user messages I can see:

MESSAGE #1: "This is the first message. Remember this number: ALPHA-100."

MESSAGE #3: "This is the third message. Remember this number: GAMMA-300."

What I cannot see:

  • MESSAGE #2 and any BETA number (there is a gap in the visible conversation history)

I do not have access to MESSAGE #2, so I cannot see the BETA number, even though the sequence suggests one existed."

The agent itself detected the gap in conversation history!

File System Evidence

  • Agent JSONL files never updated after initial creation
  • Modification timestamps frozen at creation time
  • Line counts unchanged despite multiple resume operations
  • view-cc-transcript agent-<id> shows only original conversation

Impact

This bug breaks several expected use cases:

  1. Multi-turn agent conversations: Cannot have ongoing dialogue with resumed agents
  2. Iterative refinement: Cannot build on previous agent responses across resumes
  3. Agent collaboration: Cannot chain agent conversations meaningfully
  4. Context accumulation: Agents lose all intermediate conversation history

Additional Notes

The release notes for v2.0.28 described this as:

"Subagents: claude can now choose to resume subagents"

This implies agents should maintain continuity across resumes, not fork from a checkpoint.

Test Agents Used

  • agent-03f6525d - ALPHA/BETA/GAMMA test
  • agent-977bef0e - Simple "Hi!" test
  • agent-fad96168 - Penguin fact / number 42 test

All exhibited the same forking behavior.

Suggested Fix

Agent JSONL files should be appended with new messages when resumed, similar to how the main session JSONL file grows during conversation. Each resume should load the complete agent conversation history, not just the original checkpoint. Or fork with a new session id for each resume if you can't get your session resume code work properly.

Environment

  • Claude Code Version: 2.0.31
  • OS: Linux (Ubuntu/Debian) - Linux 6.11.0-28-generic
  • Terminal: Kitty
  • Model Tested: Haiku 4.5 (claude-haiku-4-5-20251001)
  • Session ID: 8cb86e85-6130-4db5-a754-8188e91f8423

Environment Info

  • Platform: linux
  • Terminal: ghostty
  • Version: 2.0.31
  • Feedback ID: 482e664c-b72c-4dc8-b43e-69f7848ec0aa

yannbam avatar Nov 02 '25 13:11 yannbam

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/7317
  2. https://github.com/anthropics/claude-code/issues/10063
  3. https://github.com/anthropics/claude-code/issues/8462

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Nov 02 '25 13:11 github-actions[bot]

● 🎉 FOUND THE BUG!!!

Look at this line in the Task tool (around line 3629 in cli.js):

let D;
if (G) {  // G = resume parameter
  let L = await If2(G);  // Loads agent transcript
  if (!L) throw Error(`No transcript found for agent ID: ${G}`);
  D = L
}
// ... later ...
recordMessagesToSessionStorage: !G,  // ⚠️ THIS IS THE BUG!

THE BUG: recordMessagesToSessionStorage: !G

When resuming (G is the agent ID), this sets recordMessagesToSessionStorage to false, which means the resume conversation is NEVER saved to the agent JSONL file!

THE FIX: Change !G to true:

recordMessagesToSessionStorage: true, // Always record, even when resuming

Or if they want to preserve the original intent but fix the bug: recordMessagesToSessionStorage: true, // Changed from !G to always record

This single character change (!G → true) will fix the entire resumable agents feature!

Want me to create a patch file? 🔧

yannbam avatar Nov 02 '25 14:11 yannbam

What was the outcome here ?

As a workaround I'm contemplating keeping my own conversation log and then saving the history when interrupted - then when resume() pass the new instructions and also point it to the log files for additional context.

Something like that -- OR could modify the cli.js but that is not sustainable.

cbleroibeukes avatar Nov 06 '25 03:11 cbleroibeukes

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 12 '25 10:12 github-actions[bot]