fix(coder/modules/claude-code): check existing session-ids when using --session-id flag (#557)

This commit is contained in:
35C4n0r 2025-11-21 14:54:01 +05:30 committed by GitHub
parent 143656017e
commit f3c24af1db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 9 deletions

View File

@ -13,7 +13,7 @@ Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude
```tf ```tf
module "claude-code" { module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder" source = "registry.coder.com/coder/claude-code/coder"
version = "4.2.0" version = "4.2.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
workdir = "/home/coder/project" workdir = "/home/coder/project"
claude_api_key = "xxxx-xxxxx-xxxx" claude_api_key = "xxxx-xxxxx-xxxx"
@ -51,7 +51,7 @@ module "claude-code" {
boundary_log_level = "WARN" boundary_log_level = "WARN"
boundary_additional_allowed_urls = ["GET *google.com"] boundary_additional_allowed_urls = ["GET *google.com"]
boundary_proxy_port = "8087" boundary_proxy_port = "8087"
version = "3.4.3" version = "4.2.1"
} }
``` ```
@ -70,7 +70,7 @@ data "coder_parameter" "ai_prompt" {
module "claude-code" { module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder" source = "registry.coder.com/coder/claude-code/coder"
version = "4.2.0" version = "4.2.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
workdir = "/home/coder/project" workdir = "/home/coder/project"
@ -106,7 +106,7 @@ Run and configure Claude Code as a standalone CLI in your workspace.
```tf ```tf
module "claude-code" { module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder" source = "registry.coder.com/coder/claude-code/coder"
version = "4.2.0" version = "4.2.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
workdir = "/home/coder" workdir = "/home/coder"
install_claude_code = true install_claude_code = true
@ -129,7 +129,7 @@ variable "claude_code_oauth_token" {
module "claude-code" { module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder" source = "registry.coder.com/coder/claude-code/coder"
version = "4.2.0" version = "4.2.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
workdir = "/home/coder/project" workdir = "/home/coder/project"
claude_code_oauth_token = var.claude_code_oauth_token claude_code_oauth_token = var.claude_code_oauth_token
@ -202,7 +202,7 @@ resource "coder_env" "bedrock_api_key" {
module "claude-code" { module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder" source = "registry.coder.com/coder/claude-code/coder"
version = "4.2.0" version = "4.2.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
workdir = "/home/coder/project" workdir = "/home/coder/project"
model = "global.anthropic.claude-sonnet-4-5-20250929-v1:0" model = "global.anthropic.claude-sonnet-4-5-20250929-v1:0"
@ -259,7 +259,7 @@ resource "coder_env" "google_application_credentials" {
module "claude-code" { module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder" source = "registry.coder.com/coder/claude-code/coder"
version = "4.2.0" version = "4.2.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
workdir = "/home/coder/project" workdir = "/home/coder/project"
model = "claude-sonnet-4@20250514" model = "claude-sonnet-4@20250514"

View File

@ -103,9 +103,13 @@ task_session_exists() {
local workdir_normalized=$(echo "$ARG_WORKDIR" | tr '/' '-') local workdir_normalized=$(echo "$ARG_WORKDIR" | tr '/' '-')
local project_dir="$HOME/.claude/projects/${workdir_normalized}" local project_dir="$HOME/.claude/projects/${workdir_normalized}"
printf "PROJECT_DIR: %s, workdir_normalized: %s\n" "$project_dir" "$workdir_normalized"
if [ -d "$project_dir" ] && find "$project_dir" -type f -name "*${TASK_SESSION_ID}*" 2> /dev/null | grep -q .; then if [ -d "$project_dir" ] && find "$project_dir" -type f -name "*${TASK_SESSION_ID}*" 2> /dev/null | grep -q .; then
printf "TASK_SESSION_ID: %s file found\n" "$TASK_SESSION_ID"
return 0 return 0
else else
printf "TASK_SESSION_ID: %s file not found\n" "$TASK_SESSION_ID"
return 1 return 1
fi fi
} }
@ -149,7 +153,11 @@ function start_agentapi() {
else else
echo "No existing session found" echo "No existing session found"
if [ "$ARG_REPORT_TASKS" = "true" ]; then if [ "$ARG_REPORT_TASKS" = "true" ]; then
ARGS+=(--session-id "$TASK_SESSION_ID") if task_session_exists; then
ARGS+=(--resume "$TASK_SESSION_ID")
else
ARGS+=(--session-id "$TASK_SESSION_ID")
fi
fi fi
if [ -n "$ARG_AI_PROMPT" ]; then if [ -n "$ARG_AI_PROMPT" ]; then
if [ "$ARG_REPORT_TASKS" = "true" ]; then if [ "$ARG_REPORT_TASKS" = "true" ]; then
@ -171,7 +179,11 @@ function start_agentapi() {
else else
echo "Continue disabled, starting fresh session" echo "Continue disabled, starting fresh session"
if [ "$ARG_REPORT_TASKS" = "true" ]; then if [ "$ARG_REPORT_TASKS" = "true" ]; then
ARGS+=(--session-id "$TASK_SESSION_ID") if task_session_exists; then
ARGS+=(--resume "$TASK_SESSION_ID")
else
ARGS+=(--session-id "$TASK_SESSION_ID")
fi
fi fi
if [ -n "$ARG_AI_PROMPT" ]; then if [ -n "$ARG_AI_PROMPT" ]; then
if [ "$ARG_REPORT_TASKS" = "true" ]; then if [ "$ARG_REPORT_TASKS" = "true" ]; then