Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(config): support multiple custom instruction files
Add `instruction_files` option to configuration, allowing users to specify
multiple custom instruction files to be loaded from the current working
directory. The prompt resolution logic now iterates over all configured
instruction files and includes their contents if present.

This makes it easier to manage and extend custom Copilot instructions
across different projects.
  • Loading branch information
deathbeam committed Jan 18, 2026
commit 4e8c6de6c34fbec8ef7bb49b7fb9d57594417e90
7 changes: 7 additions & 0 deletions lua/CopilotChat/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
---@field log_level 'trace'|'debug'|'info'|'warn'|'error'|'fatal'?
---@field proxy string?
---@field allow_insecure boolean?
---@field instruction_files table<int, string>?
---@field selection 'visual'|'unnamed'|nil
---@field chat_autocomplete boolean?
---@field log_path string?
Expand Down Expand Up @@ -105,6 +106,12 @@ return {
proxy = nil, -- [protocol://]host[:port] Use this proxy
allow_insecure = false, -- Allow insecure server connections

-- Instruction files to look for in current working directory
instruction_files = {
'.github/copilot-instructions.md',
'AGENTS.MD',
},

selection = 'visual', -- Selection source
chat_autocomplete = true, -- Enable chat autocompletion (when disabled, requires manual `mappings.complete` trigger)

Expand Down
24 changes: 15 additions & 9 deletions lua/CopilotChat/prompts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ local WORD_WITH_INPUT_UNQUOTED = WORD .. ':?([^%s`]*)'

--- Find custom instructions in the current working directory.
---@param cwd string
---@param config CopilotChat.config.Config
---@return table
local function find_custom_instructions(cwd)
local function find_custom_instructions(cwd, config)
local out = {}
local copilot_instructions_path = vim.fs.joinpath(cwd, '.github', 'copilot-instructions.md')
local copilot_instructions = files.read_file(copilot_instructions_path)
if copilot_instructions then
table.insert(out, {
filename = copilot_instructions_path,
content = vim.trim(copilot_instructions),
})
local files_to_check = {}
for _, relpath in ipairs(config.instruction_files or {}) do
table.insert(files_to_check, vim.fs.joinpath(cwd, relpath))
end
for _, path in ipairs(files_to_check) do
local content = files.read_file(path)
if content then
table.insert(out, {
filename = path,
content = vim.trim(content),
})
end
end
return out
end
Expand Down Expand Up @@ -314,7 +320,7 @@ function M.resolve_prompt(prompt, config)
end

local custom_instructions = vim.trim(require('CopilotChat.instructions.custom_instructions'))
for _, instruction in ipairs(find_custom_instructions(source.cwd())) do
for _, instruction in ipairs(find_custom_instructions(source.cwd(), config)) do
config.system_prompt = vim.trim(config.system_prompt)
.. '\n'
.. custom_instructions:gsub('{FILENAME}', instruction.filename):gsub('{CONTENT}', instruction.content)
Expand Down
Loading