@@ -390,12 +390,22 @@ end
390390
391391--- Start the Claude Code integration
392392--- @param show_startup_notification ? boolean Whether to show a notification upon successful startup (defaults to true )
393+ --- @param force_new_terminal ? boolean If true , creates a new terminal instance even if server is running
393394--- @return boolean success Whether the operation was successful
394395--- @return number | string port_or_error The WebSocket port if successful , or error message if failed
395- function M .start (show_startup_notification )
396+ function M .start (show_startup_notification , force_new_terminal )
396397 if show_startup_notification == nil then
397398 show_startup_notification = true
398399 end
400+
401+ -- If server is already running and we're forcing a new terminal, just create it
402+ if M .state .server and force_new_terminal then
403+ logger .info (" init" , " Creating new Claude Code terminal on existing port " .. tostring (M .state .port ))
404+ local terminal = require (" claudecode.terminal" )
405+ terminal .create_new_instance ()
406+ return true , M .state .port
407+ end
408+
399409 if M .state .server then
400410 local msg = " Claude Code integration is already running on port " .. tostring (M .state .port )
401411 logger .warn (" init" , msg )
@@ -525,10 +535,11 @@ end
525535--- Set up user commands
526536--- @private
527537function M ._create_commands ()
528- vim .api .nvim_create_user_command (" ClaudeCodeStart" , function ()
529- M .start ()
538+ vim .api .nvim_create_user_command (" ClaudeCodeStart" , function (opts )
539+ M .start (nil , opts . bang )
530540 end , {
531- desc = " Start Claude Code integration" ,
541+ bang = true ,
542+ desc = " Start Claude Code integration (use ! to create multiple instances)" ,
532543 })
533544
534545 vim .api .nvim_create_user_command (" ClaudeCodeStop" , function ()
0 commit comments