Skip to main content

lean-session plugin

OpenCode plugin that makes clear-over-compact safe for interactive sessions by preserving .agents/ state through context resets. Source: templates/lean-compaction-plugin.ts in this repo. Install: copy (compiled as JS) to ~/.config/opencode/plugins/lean-session.js.

Problem it solves

Clear-over-compact (starting a fresh context per task) loses in-session state: active task list, design decisions, loop iteration count. Without intervention, compaction silently discards the .agents/ scratchpad — the agent resumes with no memory of what it was doing. lean-session injects .agents/ content into the compaction summary so it survives the reset.

Hooks


Files read / written


Checkpoint format

Written to .agents/checkpoint.md on session.idle:

Installation

The installed file must be JS. OpenCode loads plugins from ~/.config/opencode/plugins/ at startup.

Why this matters

Without lean-session, compaction discards .agents/ — the agent loses its task list, decisions, and loop state. With it, the compaction summary carries all three forward. This is what makes the Lean Agentic Coding Workflow viable across multi-hour sessions with multiple context resets.