Skip to content

Commit 512692c

Browse files
fix: resolve session handling bug
1 parent c4c1694 commit 512692c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

registry/coder/modules/claude-code/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ variable "resume_session_id" {
134134

135135
variable "continue" {
136136
type = bool
137-
description = "Load the most recent conversation in the current directory. Task will fail in a new workspace with no conversation/session to continue"
138-
default = false
137+
description = "Automatically continue existing sessions when workspace restarts. When true, resumes existing conversation if found, otherwise runs prompt or starts new session. When false, always starts fresh (ignores existing sessions)."
138+
default = true
139139
}
140140

141141
variable "dangerously_skip_permissions" {

registry/coder/modules/claude-code/scripts/start.sh

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,30 @@ function start_agentapi() {
9595
ARGS+=(--dangerously-skip-permissions)
9696
fi
9797
elif [ "$ARG_CONTINUE" = "true" ]; then
98-
echo "Using explicit continue flag"
99-
if [ -n "$ARG_DANGEROUSLY_SKIP_PERMISSIONS" ]; then
100-
ARGS+=(--dangerously-skip-permissions)
101-
fi
102-
else
103-
local has_existing_session=false
10498
if has_session_for_workdir "$ARG_WORKDIR"; then
105-
has_existing_session=true
10699
echo "Session detected for workdir: $ARG_WORKDIR"
107-
else
108-
echo "No existing session for workdir: $ARG_WORKDIR"
109-
fi
110-
111-
if [ -n "$ARG_AI_PROMPT" ] && [ "$has_existing_session" = "false" ]; then
112-
ARGS+=(--dangerously-skip-permissions "$ARG_AI_PROMPT")
113-
echo "Starting new session with prompt"
114-
elif [ "$has_existing_session" = "true" ]; then
115100
ARGS+=(--continue)
116101
if [ -n "$ARG_DANGEROUSLY_SKIP_PERMISSIONS" ]; then
117102
ARGS+=(--dangerously-skip-permissions)
118103
fi
119104
echo "Resuming existing session"
105+
else
106+
echo "No existing session for workdir: $ARG_WORKDIR"
107+
if [ -n "$ARG_AI_PROMPT" ]; then
108+
ARGS+=(--dangerously-skip-permissions "$ARG_AI_PROMPT")
109+
echo "Starting new session with prompt"
110+
else
111+
if [ -n "$ARG_DANGEROUSLY_SKIP_PERMISSIONS" ]; then
112+
ARGS+=(--dangerously-skip-permissions)
113+
fi
114+
echo "Starting claude code session"
115+
fi
116+
fi
117+
else
118+
echo "Continue disabled, starting fresh session"
119+
if [ -n "$ARG_AI_PROMPT" ]; then
120+
ARGS+=(--dangerously-skip-permissions "$ARG_AI_PROMPT")
121+
echo "Starting new session with prompt"
120122
else
121123
if [ -n "$ARG_DANGEROUSLY_SKIP_PERMISSIONS" ]; then
122124
ARGS+=(--dangerously-skip-permissions)

0 commit comments

Comments
 (0)