Skip to content

fix: resolve issues with claude-code session resumption - #496

Merged
DevelopmentCats merged 14 commits into
mainfrom
cat/claude-resume-fix
Oct 22, 2025
Merged

DevelopmentCats merged 14 commits into
mainfrom
cat/claude-resume-fix

Conversation

@DevelopmentCats

@DevelopmentCats DevelopmentCats commented Oct 20, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Fixes session resumption logic by having the continue flag decide whether to continue a workspace based on session history

Type of Change

  • New module
  • New template
  • Bug fix
  • Feature/enhancement
  • Documentation
  • Other

Module Information

Path: registry/coder/modules/claude-code
New version: v3.2.2
Breaking change: [ ] Yes [X] No

Testing & Validation

  • Tests pass (bun test)
  • Code formatted (bun fmt)
  • Changes tested locally

Related Issues

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 continue variable default from false to true with 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

@DevelopmentCats DevelopmentCats changed the title Cat/claude resume fix fix: resolve issues with claude-code session resumption Oct 21, 2025
…chain checks and consolidating functions to build args

@hugodutka hugodutka left a comment

Copy link
Copy Markdown
Contributor

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.

@DevelopmentCats

DevelopmentCats commented Oct 21, 2025 •

Copy link
Copy Markdown
Collaborator Author

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.

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.

@DevelopmentCats

Copy link
Copy Markdown
Collaborator Author

Everything works well with session resumption now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants