@@ -64,55 +64,10 @@ function validate_claude_installation() {
6464 fi
6565}
6666
67- has_session_for_workdir () {
68- local workdir=" $1 "
69- local workdir_abs=$( realpath " $workdir " 2> /dev/null || echo " $workdir " )
70-
71- local project_dir_name=$( echo " $workdir_abs " | sed ' s|/|-|g' )
72- local project_sessions_dir=" $HOME /.claude/projects/$project_dir_name "
73-
74- if [ -d " $project_sessions_dir " ]; then
75- for file in " $project_sessions_dir " /* .jsonl; do
76- [ -f " $file " ] || continue
77- if grep -q ' "type":"user"' " $file " 2> /dev/null; then
78- if grep -q ' "isSidechain":false' " $file " 2> /dev/null; then
79- return 0
80- fi
81- fi
82- done
83- fi
84- return 1
85- }
86-
87- get_latest_session_id () {
88- local workdir=" $1 "
89- local workdir_abs=$( realpath " $workdir " 2> /dev/null || echo " $workdir " )
90- local project_dir_name=$( echo " $workdir_abs " | sed ' s|/|-|g' )
91- local project_sessions_dir=" $HOME /.claude/projects/$project_dir_name "
92-
93- if [ ! -d " $project_sessions_dir " ]; then
94- return 1
95- fi
96-
97- local latest_session_id=" "
98- local latest_time=0
99-
100- for file in " $project_sessions_dir " /* .jsonl; do
101- [ -f " $file " ] || continue
67+ TASK_SESSION_ID=" cd32e253-ca16-4fd3-9825-d837e74ae3c2"
10268
103- if grep -q ' "type":"user"' " $file " 2> /dev/null; then
104- if grep -q ' "isSidechain":false' " $file " 2> /dev/null; then
105- local file_time=$( stat -c %Y " $file " 2> /dev/null || stat -f %m " $file " 2> /dev/null || echo 0)
106- if [ " $file_time " -gt " $latest_time " ]; then
107- latest_time=$file_time
108- latest_session_id=$( grep ' "isSidechain":false' " $file " | grep ' "sessionId"' | head -1 | grep -o ' "sessionId":"[^"]*"' | cut -d' "' -f4)
109- fi
110- fi
111- fi
112- done
113-
114- if [ -n " $latest_session_id " ]; then
115- echo " $latest_session_id "
69+ task_session_exists () {
70+ if find " $HOME /.claude" -type f -name " *${TASK_SESSION_ID} *" 2> /dev/null | grep -q . ; then
11671 return 0
11772 else
11873 return 1
@@ -140,38 +95,24 @@ function start_agentapi() {
14095 ARGS+=(--dangerously-skip-permissions)
14196 fi
14297 elif [ " $ARG_CONTINUE " = " true" ]; then
143- if has_session_for_workdir " $ARG_WORKDIR " ; then
144- local session_id=$( get_latest_session_id " $ARG_WORKDIR " )
145- if [ -n " $session_id " ]; then
146- echo " Session detected for workdir: $ARG_WORKDIR "
147- echo " Latest session ID: $session_id "
148- ARGS+=(--resume " $session_id " )
149- if [ " $ARG_DANGEROUSLY_SKIP_PERMISSIONS " = " true" ]; then
150- ARGS+=(--dangerously-skip-permissions)
151- fi
152- echo " Resuming existing session with explicit session ID"
153- else
154- echo " Could not extract session ID, starting new session"
155- if [ -n " $ARG_AI_PROMPT " ]; then
156- ARGS+=(--dangerously-skip-permissions " $ARG_AI_PROMPT " )
157- echo " Starting new session with prompt"
158- else
159- if [ " $ARG_DANGEROUSLY_SKIP_PERMISSIONS " = " true" ]; then
160- ARGS+=(--dangerously-skip-permissions)
161- fi
162- echo " Starting claude code session"
163- fi
98+ if task_session_exists; then
99+ echo " Task session detected (ID: $TASK_SESSION_ID )"
100+ ARGS+=(--resume " $TASK_SESSION_ID " )
101+ if [ " $ARG_DANGEROUSLY_SKIP_PERMISSIONS " = " true" ]; then
102+ ARGS+=(--dangerously-skip-permissions)
164103 fi
104+ echo " Resuming existing task session"
165105 else
166- echo " No existing session for workdir: $ARG_WORKDIR "
106+ echo " No existing task session found"
107+ ARGS+=(--session-id " $TASK_SESSION_ID " )
167108 if [ -n " $ARG_AI_PROMPT " ]; then
168109 ARGS+=(--dangerously-skip-permissions " $ARG_AI_PROMPT " )
169- echo " Starting new session with prompt"
110+ echo " Starting new task session with prompt"
170111 else
171112 if [ " $ARG_DANGEROUSLY_SKIP_PERMISSIONS " = " true" ]; then
172113 ARGS+=(--dangerously-skip-permissions)
173114 fi
174- echo " Starting claude code session"
115+ echo " Starting new task session"
175116 fi
176117 fi
177118 else
0 commit comments