🙌 CodeCompanion Rules Extension! #1718
Replies: 6 comments 7 replies
-
This is awesome, you’re creating so many cool extensions! Thank you for that. Just yesterday, I converted your other checklist gist into a proper local extension. Today, I was thinking about turning a small script I already have, one that adds my CLAUDE.md rule to my system prompt as a variable, into an extension, but this solution is even better. That said, these are great extensions, but I’m curious, why not make them into proper extension? Is it because of maintainability concerns? just out of curiousity |
Beta Was this translation helpful? Give feedback.
-
Do you have any thoughts on adding this to CodeCompanion natively? |
Beta Was this translation helpful? Give feedback.
-
Awesome extension! Really fills a missing gap between tools. I would like to also add folders to the list and add everything recursively inside also to the context. |
Beta Was this translation helpful? Give feedback.
-
Yeah, @olimorris: this feels like may be worth making it a first-class feature. |
Beta Was this translation helpful? Give feedback.
-
So I used it as an excuse to poke at it and learn more about CodeCompanion, extensions, agent rules, etc., and turned this into a plugin / extension: https://github.com/minusfive/codecompanion-agent-rules @arnm it's literally copy-pasta, happy to transfer ownership anytime. LMK which license you'd like me to add. |
Beta Was this translation helpful? Give feedback.
-
Something like this: vim.api.nvim_create_autocmd("User", {
pattern = "CodeCompanionChatCreated",
callback = function(event)
local chat = require("codecompanion").buf_get_chat(event.data.bufnr)
if not chat then
return
end
local rule_files = {
".github/copilot-instructions.md",
}
local slash_commands = require("codecompanion.strategies.chat.slash_commands")
local start_path = vim.fs.dirname(vim.api.nvim_buf_get_name(0))
local found_files = {}
local function try_add_context(dir)
for _, rule in ipairs(rule_files) do
local path = vim.fs.joinpath(dir, rule)
if vim.uv.fs_stat(path) and not vim.list_contains(found_files, path) then
table.insert(found_files, path)
slash_commands.context(chat, "file", { path = path })
end
end
end
try_add_context(start_path)
for dir in vim.fs.parents(start_path) do
try_add_context(dir)
end
end,
}) also seems to be minimal and work pretty much how I want it to. Automatically add a file to the context if it exists |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Every project has its own unique set of rules and guidelines—often scattered across different files. Remembering which files to include in your AI chat is a real cognitive burden. This extension solves that by automatically detecting and attaching all relevant rule files (like
.rules
,AGENT.md
, and more) to your chat context. No more manual selection or forgetting important context!codecompanion-rules.mp4
It works just like other agentic tools you know and love (Cursor, ClaudeCode, etc.):
Add rules in two main ways. In both cases, the rules file for the paths extracted are found and added:
Setup is simple:
:CodeCompanionRulesEnable
or:CodeCompanionRulesDisable
to toggle as needed.Let your AI focus on your code, not your context—give it a try!
Beta Was this translation helpful? Give feedback.
All reactions