by ravitemer
A history management extension for codecompanion AI chat plugin that enables saving, browsing and restoring chat sessions.
# Add to your Claude Code skills
git clone https://github.com/ravitemer/codecompanion-history.nvimA history management extension for codecompanion.nvim that enables saving, browsing and restoring chat sessions.
gcsNo comments yet. Be the first to share your thoughts!
gbs to explore all summaries@memory tool in new chats when VectorCode is installedThe following CodeCompanion features are preserved when saving and restoring chats:
| Feature | Status | Notes | |---------|--------|-------| | System Prompts | ✅ | System prompt used in the chat | | Messages History | ✅ | All messages | | Images | ✅ | Restores images as base64 strings | | LLM Adapter | ✅ | The specific adapter used for the chat | | LLM Settings | ✅ | Model, temperature and other adapter settings | | Tools | ✅ | Tool schemas and their system prompts | | Tool Outputs | ✅ | Tool execution results | | Variables | ✅ | Variables used in the chat | | References | ✅ | Code snippets and command outputs added via slash commands | | Pinned References | ✅ | Pinned references | | Watchers | ⚠ | Saved but requires original buffer context to resume watching |
When restoring a chat:
Note: While watched buffer states are saved, they require the original buffer context to resume watching functionality.
[!NOTE] As this is an extension that deeply integrates with CodeCompanion's internal APIs, occasional compatibility issues may arise when CodeCompanion updates. If you encounter any bugs or unexpected behavior, please raise an issue to help us maintain compatibility.
@memory tool)Using lazy.nvim:
{
"olimorris/codecompanion.nvim",
dependencies = {
--other plugins
"ravitemer/codecompanion-history.nvim"
}
}
require("codecompanion").setup({
extensions = {
history = {
enabled = true,
opts = {
-- Keymap to open history from chat buffer (default: gh)
keymap = "gh",
-- Keymap to save the current chat manually (when auto_save is disabled)
save_chat_keymap = "sc",
-- Save all chats by default (disable to save only manually using 'sc')
auto_save = true,
-- Number of days after which chats are automatically deleted (0 to disable)
expiration_days = 0,
-- Picker interface (auto resolved to a valid picker)
picker = "telescope", --- ("telescope", "snacks", "fzf-lua", or "default")
---Optional filter function to control which chats are shown when browsing
chat_filter = nil, -- function(chat_data) return boolean end
-- Customize picker keymaps (optional)
picker_keymaps = {
rename = { n = "r", i = "<M-r>" },
delete = { n = "d", i = "<M-d>" },
duplicate = { n = "<C-y>", i = "<C-y>" },
},
---Automatically generate titles for new chats
auto_generate_title = true,
title_generation_opts = {
---Adapter for generating titles (defaults to current chat adapter)
adapter = nil, -- "copilot"
---Model for generating titles (defaults to current chat model)
model = nil, -- "gpt-4o"
---Number of user prompts after which to refresh the title (0 to disable)
refresh_every_n_prompts = 0, -- e.g., 3 to refresh after every 3rd user prompt
---Maximum number of times to refresh the title (default: 3)
max_refreshes = 3,
format_title = function(original_title)
-- this can be a custom function that applies some custom
-- formatting to the title.
return original_title
end
},
---On exiting and entering neovim, loads the last chat on opening chat
continue_last_chat = false,
---When chat is cleared with `gx` delete the chat from history
delete_on_clearing_chat = false,
---Directory path to save the chats
dir_to_save = vim.fn.stdpath("data") .. "/codecompanion-history",
---Enable detailed logging for history extension
enable_logging = false,
-- Summary system
summary = {
-- Keymap to generate summary for current chat (default: "gcs")
create_summary_keymap = "gcs",
-- Keymap to browse summaries (default: "gbs")
browse_summaries_keymap = "gbs",
generation_opts = {
adapter = nil, -- defaults to current chat adapter
model = nil, -- defaults to current chat model
context_size = 90000, -- max tokens that the model supports
include_references = true, -- include slash command content
include_tool_outputs = true, -- include tool execution results
system_prompt = nil, -- custom system prompt (string or function)
format_summary = nil, -- custom function to format generated summary e.g to remove <think/> tags from summary
},
},
-- Memory system (requires VectorCode CLI)
memory = {
-- Automatically index summaries when they are generated
auto_create_memories_on_summary_generation = true,
-- Path to the VectorCode executable
vectorcode_exe = "vectorcode",
-- Tool configuration
tool_opts = {
-- Default number of memories to retrieve
default_num = 10
},
-- Enable notifications for indexing progress
notify = true,
-- Index all existing memories on startup
-- (requires VectorCode 0.6.12+ for efficient incremental indexing)
index_on_startup = false,
},
}
}
}
})
[!WARNING] Title and summary generation defaults to current chat's adapter and model. Make sure to set cheaper models in
title_generation_optsandsummary.generation_optsto avoid using premium models.
:CodeCompanionHistory - Open the history browser:CodeCompanionSummaries - Browse all summariesHistory Management:
gh - Open history browser (customizable via opts.keymap)sc - Save current chat manually (customizable via opts.save_chat_keymap)Summary System:
gcs - Generate summary for current chat (customizable via opts.summary.create_summary_keymap)gbs - Browse saved summaries (customizable via opts.summary.browse_summaries_keymap)The history browser shows all your saved chats with: