diff --git a/lua/codecompanion/strategies/chat/keymaps.lua b/lua/codecompanion/strategies/chat/keymaps.lua index 4ad050be..421619a9 100644 --- a/lua/codecompanion/strategies/chat/keymaps.lua +++ b/lua/codecompanion/strategies/chat/keymaps.lua @@ -461,7 +461,7 @@ M.change_adapter = { -- Update the system prompt local system_prompt = config.opts.system_prompt if type(system_prompt) == "function" then - if chat.messages[1].role == "system" then + if chat.messages[1] and chat.messages[1].role == "system" then chat.messages[1].content = system_prompt(chat.adapter) end end