@@ -1094,9 +1094,10 @@ end
10941094
10951095--- Format file path for at mention (exposed for testing)
10961096--- @param file_path string The file path to format
1097+ --- @param base_cwd string | nil Optional base working directory (defaults to Neovim ' s CWD)
10971098--- @return string formatted_path The formatted path
10981099--- @return boolean is_directory Whether the path is a directory
1099- function M ._format_path_for_at_mention (file_path )
1100+ function M ._format_path_for_at_mention (file_path , base_cwd )
11001101 -- Input validation
11011102 if not file_path or type (file_path ) ~= " string" or file_path == " " then
11021103 error (" format_path_for_at_mention: file_path must be a non-empty string" )
@@ -1112,9 +1113,9 @@ function M._format_path_for_at_mention(file_path)
11121113
11131114 local is_directory = vim .fn .isdirectory (file_path ) == 1
11141115 local formatted_path = file_path
1116+ local cwd = base_cwd or vim .fn .getcwd ()
11151117
11161118 if is_directory then
1117- local cwd = vim .fn .getcwd ()
11181119 if string.find (file_path , cwd , 1 , true ) == 1 then
11191120 local relative_path = string.sub (file_path , # cwd + 2 )
11201121 if relative_path ~= " " then
@@ -1127,7 +1128,6 @@ function M._format_path_for_at_mention(file_path)
11271128 formatted_path = formatted_path .. " /"
11281129 end
11291130 else
1130- local cwd = vim .fn .getcwd ()
11311131 if string.find (file_path , cwd , 1 , true ) == 1 then
11321132 local relative_path = string.sub (file_path , # cwd + 2 )
11331133 if relative_path ~= " " then
@@ -1145,9 +1145,13 @@ function M._broadcast_at_mention(file_path, start_line, end_line)
11451145 return false , " Claude Code integration is not running"
11461146 end
11471147
1148+ -- Get terminal CWD for path formatting (falls back to Neovim CWD if nil)
1149+ local terminal = require (" claudecode.terminal" )
1150+ local terminal_cwd = terminal .get_terminal_cwd ()
1151+
11481152 -- Safely format the path and handle validation errors
11491153 local formatted_path , is_directory
1150- local format_success , format_result , is_dir_result = pcall (M ._format_path_for_at_mention , file_path )
1154+ local format_success , format_result , is_dir_result = pcall (M ._format_path_for_at_mention , file_path , terminal_cwd )
11511155 if not format_success then
11521156 return false , format_result -- format_result contains the error message
11531157 end
0 commit comments