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

[BUG] Restarting claude with --resume clears out context and allows sessions to continue longer

Open ejc3 opened this issue 6 months ago • 8 comments

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?

I can consistently extend claude's context window by existing out of claude and using --resume. This happens on the latest production claude version.

Here's what a session looks like before the ctl-c, claude --resume: Image

Here's after: Image

What Should Happen?

Claude seems no dumber after the ctl-c loop, so claude should drop whatever context that is lost by doing ctl-c instead of jumping to /compact.

Error Messages/Logs


Steps to Reproduce

  1. Use claude a lot
  2. See a few percent left of context
  3. Run /context
  4. ctl -c
  5. claude --resume
  6. Run /context

The second time of running /context, the context will be way lower.

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.0.25

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

ejc3 avatar Oct 23 '25 03:10 ejc3

Image

Another example. After a restart, you can see 1% context but really 30% is available.

ejc3 avatar Nov 11 '25 05:11 ejc3

https://github.com/user-attachments/assets/c2a8e2ce-c896-4fc7-8508-e046f8b02e0a please fix this. it seems so easy given --continue just always clears out enough context to make much more progress!

ejc3 avatar Nov 15 '25 17:11 ejc3

https://github.com/user-attachments/assets/092818a9-7691-40b7-8923-211ae8cc01de so easy to reproduce!

ejc3 avatar Nov 16 '25 17:11 ejc3

@ejc3 has your "before" state gone through a round of compaction already?

sid374 avatar Nov 17 '25 00:11 sid374

Yes, most likely it has gone through one round

ejc3 avatar Nov 19 '25 04:11 ejc3

At least in one case the difference was due to the CLAUDE.md not being in the trajectory after the restart loop:

⏺ Based on the diff output, here's a summary of the key differences between the two files:

  Summary: Differences Between the Two Requests

  | Aspect        | 04-36-02 (newer) | 04-34-03 (older)                           |
  |---------------|------------------|--------------------------------------------|
  | Input Tokens  | 122,063          | 140,283                                    |
  | Output Tokens | 6                | 5                                          |
  | File size     | 1004 lines       | 973 lines (larger due to embedded content) |

  Key Differences:

  1. Git Status: The older request (04-34-03) shows src/firecracker/vm.rs as modified, while the newer one doesn't
  2. Recent Commits:
    - Newer (04-36-02) includes commit 3cf50ad ("Remove duplicate vm_name/vm_id from Firecracker log output")
    - Older (04-34-03) includes commit ad08893 ("Replace RwLock with DashMap in PassthroughFs") which is missing from the newer
  3. System Context: The older request (04-34-03) includes embedded CLAUDE.md content from the fcvm project (a Firecracker VM manager), showing that a Read tool was called to read
  /Users/ejcampbell/src/fcvm/.claude/CLAUDE.md. This adds ~200+ lines of escaped documentation about the fcvm project.
  4. Token Count: The older request has ~18,000 more input tokens, likely due to the embedded CLAUDE.md content

  In short: The newer request is a simpler/cleaner API call with fewer tokens, while the older one includes extensive project documentation that was read during the conversation.

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> 
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ? for shortcuts

ejc3 avatar Nov 28 '25 05:11 ejc3

Additional analysis: https://ejc3.github.io/claude-restart-trajectory-analysis/

ejc3 avatar Nov 28 '25 06:11 ejc3

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 28 '25 10:12 github-actions[bot]

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Jan 12 '26 14:01 github-actions[bot]