Cusom system prompt ignored? #1839
-
Hello 👋 I'm trying to customize the system prompt but it looks like it's ignored at the moment. I'd like to re-use the default system prompt with a few minor additions. Right now these additions seem ignored, and I don't know if it's because these additions really have no effect or if my custom system prompt isn't loaded. Is there a command to print the system prompt in the chat? That would definitely help me debug my prompt. Here is my setup: local function load_system_prompt()
-- https://codecompanion.olimorris.dev/configuration/system-prompt.html#configuring-the-system-prompt
local lines = vim.fn.readfile(
"/home/djipey/.config/nvim/lua/plugins/codecompanion/system_prompt.txt")
return table.concat(lines, "\n")
end
local function load_project_manager_prompt()
local lines = vim.fn.readfile(
"/home/djipey/.config/nvim/lua/plugins/codecompanion/project_manager_prompt.txt")
return table.concat(lines, "\n")
end
return {
{
"olimorris/codecompanion.nvim",
dependencies = {
"nvim-lua/plenary.nvim", "nvim-treesitter/nvim-treesitter",
"j-hui/fidget.nvim"
},
opts = {
system_prompt = function(opts)
return load_system_prompt()
end,
adapters = {
copilot = function()
return require("codecompanion.adapters").extend("copilot", {
-- schema = {model = {default = "claude-sonnet-4"}}
schema = {model = {default = "gpt-4.1"}}
})
end,
},
strategies = {
chat = {adapter = "copilot"},
inline = {adapter = "copilot"}
},
extensions = {
mcphub = {
callback = "mcphub.extensions.codecompanion",
opts = {
show_result_in_chat = true, -- Show mcp tool results in chat
make_vars = true, -- Convert resources to #variables
make_slash_commands = true -- Add prompts as /slash commands
}
}
-- vectorcode = {opts = {add_tool = true}}
},
prompt_library = {
["Project manager prompt"] = {
strategy = "chat",
description = "A project manager prompt",
prompts = {
{
role = "system",
content = load_project_manager_prompt()
}, {
role = "user",
content = "I need help managing my project. Can you assist me with that?"
}
}
}
}
},
init = function()
require("plugins.codecompanion.fidget-spinner"):init()
vim.keymap.set({"n", "v"}, "<Leader>cc",
"<cmd>CodeCompanionChat Toggle<cr>",
{noremap = true, silent = true})
vim.keymap.set('v', '<leader>ce',
":'<,'>CodeCompanion /explain<CR>", {
noremap = true,
silent = true,
desc = "CodeCompanion: Explain code"
})
vim.keymap.set('v', '<leader>cf', ":'<,'>CodeCompanion /fix<CR>", {
noremap = true,
silent = true,
desc = "CodeCompanion: Fix code"
})
end
}
} The additions I'm trying to add to the default prompt revolve around adding memory through the basic-memory MCP server:
The MCP server works and I can use the memory, but I really need to force Codecompanion. I was hoping that Codecompanion would use the memory with less friction. Did I make a mistake in the setup? Is it maybe because the MCP servers aren't loaded yet when the system prompt "runs" ? EDIT: I'm actually confident that my system prompt modifications are ignored. I changed the system prompt directly in |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
local function load_project_manager_prompt()
return "Test system prompt"
end
["Project manager prompt"] = {
strategy = "chat",
description = "A project manager prompt",
prompts = {
{
role = "system",
content = load_project_manager_prompt(),
},
{
role = "user",
content = "I need help managing my project. Can you assist me with that?"
},
},
}, The above works and loads the custom system prompt alongside the default plugin system prompt. I can't comment on what you're trying to do regarding reading a file but I recommend this section in the docs for additional config tips. |
Beta Was this translation helpful? Give feedback.
-
Hi @olimorris , thank you for your answer. Yes the opts = {
system_prompt = function(opts)
return load_system_prompt()
end, I actually even tried hardcoding the custom prompt in the config like this:
And even with the hardcoded prompt, it looks like the system prompt is unchanged (it still behaves like the default system prompt). For example, my name is in the custom system prompt. When I ask Codecompanion "What is my name?", Codecompanion is unable to answer the question. I'm sorry, I should have been clearer. I don't think the problem is with reading the system prompt from file. It's simply that any custom system prompt I put in my config seems ignored. |
Beta Was this translation helpful? Give feedback.
-
I had the same problem, the opts of system prompt should be inside the opts too, so you put opts twice then system prompt. So it should be opts = { opts = { system_prompt ... |
Beta Was this translation helpful? Give feedback.
I had the same problem, the opts of system prompt should be inside the opts too, so you put opts twice then system prompt.
So it should be
opts = { opts = { system_prompt ...