@@ -118,10 +118,11 @@ pub async fn handle_stop() -> anyhow::Result<ClaudeHookOutput> {
118
118
let prompt = transcript. prompt ( ) . unwrap_or_default ( ) ;
119
119
120
120
let ctx = & mut CommandContext :: open ( & project, AppSettings :: load_from_default_path_creating ( ) ?) ?;
121
+ let session_id = original_session_id ( ctx, input. session_id . clone ( ) ) ?;
121
122
122
123
let defer = ClearLocksGuard {
123
124
ctx,
124
- session_id : input . session_id . clone ( ) ,
125
+ session_id : session_id. clone ( ) ,
125
126
file_path : None ,
126
127
} ;
127
128
@@ -131,14 +132,14 @@ pub async fn handle_stop() -> anyhow::Result<ClaudeHookOutput> {
131
132
132
133
// If the session stopped, but there's no session persisted in the database, we create a new one.
133
134
// If the session is already persisted, we just retrieve it.
134
- let stack_id = get_or_create_session ( defer. ctx , & input . session_id , stacks, vb_state) ?;
135
+ let stack_id = get_or_create_session ( defer. ctx , & session_id, stacks, vb_state) ?;
135
136
136
137
let ( id, outcome) = but_action:: handle_changes (
137
138
defer. ctx ,
138
139
& summary,
139
140
Some ( prompt. clone ( ) ) ,
140
141
ActionHandler :: HandleChangesSimple ,
141
- Source :: ClaudeCode ( input . session_id ) ,
142
+ Source :: ClaudeCode ( session_id) ,
142
143
Some ( stack_id) ,
143
144
) ?;
144
145
@@ -310,8 +311,9 @@ pub fn handle_pre_tool_call() -> anyhow::Result<ClaudeHookOutput> {
310
311
input. tool_input . file_path = relative_file_path;
311
312
312
313
let ctx = & mut CommandContext :: open ( & project, AppSettings :: load_from_default_path_creating ( ) ?) ?;
314
+ let session_id = original_session_id ( ctx, input. session_id . clone ( ) ) ?;
313
315
314
- file_lock:: obtain ( ctx, input . session_id , input. tool_input . file_path . clone ( ) ) ?;
316
+ file_lock:: obtain ( ctx, session_id, input. tool_input . file_path . clone ( ) ) ?;
315
317
316
318
Ok ( ClaudeHookOutput {
317
319
do_continue : true ,
@@ -355,18 +357,19 @@ pub fn handle_post_tool_call() -> anyhow::Result<ClaudeHookOutput> {
355
357
input. tool_response . file_path = relative_file_path;
356
358
357
359
let ctx = & mut CommandContext :: open ( & project, AppSettings :: load_from_default_path_creating ( ) ?) ?;
360
+ let session_id = original_session_id ( ctx, input. session_id . clone ( ) ) ?;
358
361
359
362
let defer = ClearLocksGuard {
360
363
ctx,
361
- session_id : input . session_id . clone ( ) ,
364
+ session_id : session_id. clone ( ) ,
362
365
file_path : Some ( input. tool_response . file_path . clone ( ) ) ,
363
366
} ;
364
367
365
368
let stacks = list_stacks ( defer. ctx ) ?;
366
369
367
370
let vb_state = & VirtualBranchesHandle :: new ( defer. ctx . project ( ) . gb_dir ( ) ) ;
368
371
369
- let stack_id = get_or_create_session ( defer. ctx , & input . session_id , stacks, vb_state) ?;
372
+ let stack_id = get_or_create_session ( defer. ctx , & session_id, stacks, vb_state) ?;
370
373
371
374
let changes = but_core:: diff:: ui:: worktree_changes_by_worktree_dir ( project. path ) ?. changes ;
372
375
let ( assignments, _assignments_error) = but_hunk_assignment:: assignments_with_fallback (
@@ -404,6 +407,16 @@ pub fn handle_post_tool_call() -> anyhow::Result<ClaudeHookOutput> {
404
407
} )
405
408
}
406
409
410
+ fn original_session_id ( ctx : & mut CommandContext , current_id : String ) -> Result < String > {
411
+ let original_session_id =
412
+ crate :: db:: get_session_by_current_id ( ctx, Uuid :: parse_str ( & current_id) ?) ?;
413
+ if let Some ( session) = original_session_id {
414
+ Ok ( session. id . to_string ( ) )
415
+ } else {
416
+ Ok ( current_id)
417
+ }
418
+ }
419
+
407
420
fn get_or_create_session (
408
421
ctx : & mut CommandContext ,
409
422
session_id : & str ,
0 commit comments