-
Notifications
You must be signed in to change notification settings - Fork 76
fix: resolve issues with claude-code session resumption #496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…messages are prioritized over warmup messages
…mentation in Claude Code module README
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the session resumption logic in the Claude Code module by implementing proper detection of existing sessions before attempting to resume them. The key change is adding a has_session_for_workdir() function that checks for valid user messages in session history, and modifying the startup logic to use the continue flag to intelligently decide whether to resume an existing session or start fresh.
Key changes:
- Adds session detection logic that validates actual user interaction history before attempting to resume
- Updates the
continuevariable default fromfalsetotruewith improved documentation - Refactors startup script to handle three scenarios: explicit resume, conditional continue based on session existence, and fresh start
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| registry/coder/modules/claude-code/scripts/start.sh | Adds has_session_for_workdir() function and implements conditional session resumption logic in start_agentapi() |
| registry/coder/modules/claude-code/main.tf | Updates continue variable default to true and improves its description to reflect new behavior |
| registry/coder/modules/claude-code/main.test.ts | Corrects test variable names from task_prompt to ai_prompt |
| registry/coder/modules/claude-code/README.md | Updates version references to v3.1.2 and adds documentation section explaining session resumption behavior |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…chain checks and consolidating functions to build args
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the logic is tightly coupled with the internal file structure of claude. I think it'd be more robust to rely on claude --session-id <uuid> and claude -r <uuid>.
You could choose a predefined uuid such as cd32e253-ca16-4fd3-9825-d837e74ae3c2 for the task session. Before starting claude, first run
find "$HOME/.claude" -type f -name "*cd32e253-ca16-4fd3-9825-d837e74ae3c2*"to see if there are any sessions with this id in the workspace. If there are, use claude -r, if there are none, use --session-id.
This approach also avoids buggy behavior with user-spawned claude sessions in the workspace. --continue opens the last-used session, --session-id and -r would always open the same task session.
… to validate session resumption
I ironically just had the same thought and switched over to extracting the latest session with actual user messages in it, but defining the session id is a much better solution. I will make the change now. |
|
Everything works well with session resumption now. |
Description
Fixes session resumption logic by having the continue flag decide whether to continue a workspace based on session history
Type of Change
Module Information
Path:
registry/coder/modules/claude-codeNew version:
v3.2.2Breaking change: [ ] Yes [X] No
Testing & Validation
bun test)bun fmt)Related Issues