My nvim configuration
feat: history limit in claude plugin
4 files changed, +33 -2
+5-0claude-nvim/lua/claude/init.lua
| @@ -7,6 +7,7 @@ local edit = require("claude.edit") | ||
| 7 | 7 | local timetravel = require("claude.timetravel") |
| 8 | 8 | local commit = require("claude.commit") |
| 9 | 9 | local find = require("claude.find") |
| 10 | +local store = require("claude.store") | |
| 10 | 11 | |
| 11 | 12 | ---@class ClaudeConfig |
| 12 | 13 | local defaults = { |
| @@ -16,12 +17,16 @@ local defaults = { | ||
| 16 | 17 | skip_permissions = false, |
| 17 | 18 | --- Write raw stream events + cmd + exit codes to <data>/claude-nvim/debug.log |
| 18 | 19 | debug = false, |
| 20 | + --- Max number of history entries surfaced by the prompts/sessions pickers. | |
| 21 | + --- nil or 0 means unlimited (default: nil). | |
| 22 | + history_limit = nil, | |
| 19 | 23 | } |
| 20 | 24 | |
| 21 | 25 | --- Setup the Claude CLI wrapper plugin. |
| 22 | 26 | ---@param opts? ClaudeConfig |
| 23 | 27 | function M.setup(opts) |
| 24 | 28 | opts = vim.tbl_deep_extend("force", defaults, opts or {}) |
| 29 | + store.setup(opts) | |
| 25 | 30 | ui.setup(opts) |
| 26 | 31 | runner.setup(opts) |
| 27 | 32 | edit.setup(opts) |
+1-1claude-nvim/lua/claude/pickers.lua
| @@ -176,7 +176,7 @@ local function list_sessions() | ||
| 176 | 176 | end |
| 177 | 177 | end |
| 178 | 178 | table.sort(out, function(a, b) return a.mtime > b.mtime end) |
| 179 | - return out | |
| 179 | + return store.apply_history_limit(out) | |
| 180 | 180 | end |
| 181 | 181 | |
| 182 | 182 | function M.sessions_picker() |
+26-1claude-nvim/lua/claude/store.lua
| @@ -1,5 +1,30 @@ | ||
| 1 | 1 | local M = {} |
| 2 | 2 | |
| 3 | +--- Runtime config (populated by M.setup from the plugin's options). | |
| 4 | +M.config = { | |
| 5 | + --- Max number of history entries to surface; nil/0 = unlimited. | |
| 6 | + history_limit = nil, | |
| 7 | +} | |
| 8 | + | |
| 9 | +function M.setup(opts) | |
| 10 | + M.config.history_limit = opts and opts.history_limit or nil | |
| 11 | +end | |
| 12 | + | |
| 13 | +--- Truncate a newest-first list to the configured history limit. | |
| 14 | +---@param list table | |
| 15 | +---@return table | |
| 16 | +function M.apply_history_limit(list) | |
| 17 | + local limit = M.config.history_limit | |
| 18 | + if not limit or limit <= 0 or #list <= limit then | |
| 19 | + return list | |
| 20 | + end | |
| 21 | + local out = {} | |
| 22 | + for i = 1, limit do | |
| 23 | + out[i] = list[i] | |
| 24 | + end | |
| 25 | + return out | |
| 26 | +end | |
| 27 | + | |
| 3 | 28 | local function data_dir() |
| 4 | 29 | local d = vim.fn.stdpath("data") .. "/claude-nvim" |
| 5 | 30 | vim.fn.mkdir(d, "p") |
| @@ -90,7 +115,7 @@ function M.all_prompts(cwd) | ||
| 90 | 115 | end |
| 91 | 116 | end |
| 92 | 117 | table.sort(out, function(a, b) return (a.ts or 0) > (b.ts or 0) end) |
| 93 | - return out | |
| 118 | + return M.apply_history_limit(out) | |
| 94 | 119 | end |
| 95 | 120 | |
| 96 | 121 | function M.uuid() |
+1-0lua/plugins/claude.lua
| @@ -5,6 +5,7 @@ return { | ||
| 5 | 5 | event = "VeryLazy", |
| 6 | 6 | config = function() |
| 7 | 7 | require("claude").setup({ |
| 8 | + history_limit = 20, | |
| 8 | 9 | width = 100, |
| 9 | 10 | skip_permissions = true |
| 10 | 11 | }) |