agent-session.nvim
AGENTS.md3 starsChanged 3 days agoMITView on GitHub
agent-session.nvim is a Neovim plugin (pure Lua, no build step) that manages multiple AI agent CLI sessions (Claude Code, codex, gemini, arbitrary shells, etc.) as terminal buffers, with floating/split windows, a left sidebar explorer, and statusline/lualine/heirline integration. There is no build system, no linter config beyond StyLua, and no automated test runner. This is a small, dependency-free Lua plugin loaded directly by Neovim's runtime. All modules live under lua/agent-session/ and are required lazily from lua/agent-session/init.lua, the public API surface (require("agent-session")).…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 33,398 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- CLAUDE.mdCLAUDE.md
The file
We split this AGENTS.md into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 19
All modules live under lua/agent-session/ and are required lazily from lua/agent-session/init.lua, the public API surface …
≈ “Common” is an estimate: at least 1 in 5 of the 43,423 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
This file provides guidance to AI coding assistants (Antigravity, Claude Code, Codex, Cursor, etc.) when working with code in this repository.
Overview
agent-session.nvim is a Neovim plugin (pure Lua, no build step) that manages multiple AI agent CLI sessions (Claude Code, codex, gemini, arbitrary shells, etc.) as terminal buffers, with floating/split windows, a left sidebar explorer, and statusline/lualine/heirline integration.
Development
There is no build system, no linter config beyond StyLua, and no automated test runner. This is a small, dependency-free Lua plugin loaded directly by Neovim's runtime.
- Format:
stylua .(config in.stylua.toml: 2-space indent, 120 col width, double quotes). - Manual/interactive testing:
nvim -u tests/minimal_init.luabootstraps lazy.nvim into an isolated.tests/sandbox (its own XDG dirs) and loads the plugin from the working directory. There is no headless/CI test suite; verify changes by exercising commands inside this sandboxed Neovim instance. - Lua LSP:
.luarc.jsontargets LuaJIT with thevimglobal and the$VIMRUNTIME/luvlibraries. Keep this in mind when writing code that must satisfy the language server, since it assumes nothing beyond the Neovim/luv API surface.
Architecture
All modules live under lua/agent-session/ and are required lazily from lua/agent-session/init.lua, the public API surface (require("agent-session")). plugin/agent-session.lua wires up user commands (:AgentSession, :AgentSessionNew, etc.) and delegates directly to init.lua functions; it contains no logic of its own.
Module responsibilities:
config.luaholdsM.defaults, merges useroptsviavim.tbl_deep_extend("force", ...)onsetup(), and createssession_dirif configured.M.get()is the single source of truth read by every other module (it falls back to defaults ifsetup()was never called).session.luais the process/session model.M._active_sessions(table keyed by generated id) andM._current_session_idare module-level state, kept in memory only;persist.luasnapshots them to disk.M.create()opens a scratch buffer, spawns the agent command withvim.fn.termopen, and attaches a buffer listener (nvim_buf_attachon_lines) plus a libuv idle timer to derive session status transitions: fromrunningtoidleafteridle_timeoutms of silence, then tostoppedwhen the process exits. Status changes always flow throughM.set_status(), which fires theon_status_changehook, aUser AgentSessionStatusChangedautocmd, and refreshes both the window title (ui.refresh_title) and the sidebar (sidebar.render). Anything that needs to react to session state hooks in here.ui.luamanages windows for the "active" session view: floating window or split/vsplit, title/winbar formatting driven by session status,vim.ui.select-based pickers for choosing a session or an agent to launch. It tracks only one window at a time (M._current_win); opening a session while a window exists reuses it rather than creating a new one.sidebar.luais a separate, persistent left-docked explorer with its own buffer/window state, independent ofui.lua's window. It lists sessions grouped by status with per-line buffer-local keymaps (open/new/delete/resize), and auto-redocks itself underneo-tree/NvimTree/aerial/Outlinewhen one of those opens, so it always sits directly beneath the file tree in the left column. It subscribes to the sameAgentSessionStatusChangedautocmd asui.luato stay in sync.persist.luasaves open sessions per project (keyed by the cwd at startup) as JSON undersession_dir/projects/, and relaunches them on:AgentSessionRestoreor startup (persist.auto_restore).session.luacallspersist.save()(debounced) on create/rename/delete and inset_status()andpersist.on_submit()after the user's first prompt, which discovers the agent's conversation ID (discover = "codex" | "agy" | fn) or confirms a pre-assigned one (resume.exists). The saved file is read once into_pendingand every write merges live sessions with_pending, so it is never clobbered implicitly; only restore, discard, or closing all sessions clears it. Resume behavior per agent lives inconfig.lua(agents[name].resume).statusline.luaholds read-only consumers ofsession.get_current()/config.get()that format status for lualine, Heirline, and AstroNvim'sastroui.statusbuilder (auto-detected viapcall(require, "astroui.status")). These have no side effects on session state.
Key conventions to preserve when extending this codebase:
- Session status is derived, not set directly. Always go through
session.set_status()so hooks/autocmds/UI refresh stay consistent; never mutatesession.statusin place elsewhere. - Agent definitions (
opts.agents[name] = { cmd, args, env }) resolve through a fallback chain: explicit config entry, then avim.fn.executable(name)check, thenvim.o.shell. Bothinit.lua(new_session) andsession.lua(create) implement pieces of this resolution; keep them consistent if you change agent lookup behavior. - UI dimensions (
width/heightin config) accept either a float< 1(percentage ofvim.o.columns/vim.o.lines) or an integer (fixed columns/lines). This pattern repeats acrossui.luaandsidebar.luaand should stay consistent for new size options. pcallguards mostvim.apicalls that touch windows/buffers that may have been closed asynchronously (terminal exit, user closing a split); follow this pattern for new window/buffer manipulation to avoid E5108 errors from stale handles.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

