Compact Memory

    by Muhammet KURT

    1

    Saves your session state as Markdown before Claude Code compacts, and gives it back after.

    Free

    Security scanned

    Works with the AI Agents you already use

    What it does

    • Saves your tasks, decisions and open work to a Markdown file in your project
    • Tells Claude once when the context is about 70% full, so it saves before compacting
    • Gives the saved state back after /compact, /clear, a resume or a new session
    • Writes a short dated record for each finished piece of work
    • Writes a short note when the context was compacted before anything was saved

    Who it's for

    Developers in long Claude Code sessions

    tasks, decisions and open work survive /compact

    Try asking: “Save to compact memory that we decided to use tabs, because the team prefers them.”

    Anyone who picks up work across days

    a new session starts from the saved state instead of from zero

    Try asking: “What is in the saved project state?”

    People running several jobs at once with Lead and Managers

    the lead's task list survives compaction

    Try asking: “Record that the importer is done and the error list is next.”

    Compact Memory

    Example session with this skill installed

    Carry on with the CSV importer.

    • Read your context and instructions
    • Compiled the compact memory
    (hook)  [compact-memory] Context is about 72% full (threshold 70%; window 200000 tokens, from default).
            Before anything else in this turn, follow the compact-memory skill and save the current state to .compact-memory/state.md
    Claude: The state is saved in .compact-memory/state.md. Please run /compact when you are ready.
    You:    /compact
    (hook)  [compact-memory] Saved project state from .compact-memory/state.md (given back after compaction):
            <compact-memory>
            # Project state
            Updated: 2026-12-02
            ## Assigned tasks
            - CSV importer: parser done, error list next
            ## Decisions
            - Use tabs for indentation: the team prefers them
            ## Open work
            - Error list for invalid rows; then wire it into the import screen
            </compact-memory>
            Latest records in .compact-memory/records: 20261202-01-use-tabs.md
    Claude: Carrying on with the importer: the parser is done, the error list is next.
    

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Stop losing your place when Claude Code compacts.

    Long sessions get compacted, and the summary drops details: which tasks were running, what you decided and why, what is left to do. compact-memory keeps that in a small Markdown file in your project and gives it back to Claude after compaction and at every new session.

    How it works

    1. On each prompt, a hook estimates how full the context is. At 70% it tells Claude, once, to save the state.
    2. Claude rewrites .compact-memory/state.md: assigned tasks, decisions, open work, and what was learned. Each finished piece of work also gets a short record in records/.
    3. Claude asks you to run /compact, because it cannot run it itself. Auto-compaction is covered too: if nothing was saved in time, a minimal record marks the gap.
    4. After compaction, /clear, a resume or a new session, the saved state goes back into Claude's context.

    What you get

    • One skill (SKILL.md) and one Node script with three hook modes
    • Plain Markdown files you can read and edit. No database, no embeddings, no sync.
    • No network requests, no packages to install, no shell commands run by the script

    Requirements

    • Claude Code. The hooks need Claude Code 2.1.139+ and Node.js 18+ on your PATH.
    • The skill also works without the hooks, but then there is no automatic notice and no automatic give-back.
    • Tested on Windows 11. Not yet tested on macOS or Linux.

    Good to know

    • Context usage is an estimate, read from the session transcript (token counts only).
    • On a 1M-token context window, set COMPACT_MEMORY_WINDOW=1000000. Otherwise the first notice comes early, at about 140K tokens.
    • state.md is put into Claude's context in every session. Keep .compact-memory/ out of shared repositories.

    Pairs well with Lead and Managers: the lead keeps its task list in compact memory, so the list survives compaction.

    Inspired by avenoxbeyin by Avenox (MIT). Written from scratch. MIT licensed.

    • Claude cannot run /compact itself. It saves the state and asks you to run it. Auto-compaction is covered by the hooks.
    • Context usage is an estimate read from the session transcript (token counts only). If the transcript cannot be read, the notice does not appear.
    • On a 1M-token window, set COMPACT_MEMORY_WINDOW=1000000; otherwise the first notice comes early, at about 140K tokens.
    • Only the first 4000 characters of state.md are given back; Claude is told where the rest is.
    • A folder of Markdown files: no search, no embeddings, no sync.
    • Tested on Windows 11 with Claude Code. Not yet tested on macOS or Linux, or with other agents.
    • Through Agensi, the skill loads in every session, but the three hooks (automatic context notice and give-back after compaction) need a one-time install into each project; ask your agent to follow the README section 'Installing through an agent connection'.

    Three Claude Code hooks run one Node.js script with no packages and no network requests. UserPromptSubmit estimates context usage from the token counts of the last reply in the session transcript and, past the threshold (COMPACT_MEMORY_THRESHOLD, default 0.7), tells Claude once to save. PreCompact tells the summary what to keep and writes a short note if nothing was saved. SessionStart (startup, resume, clear, compact) puts up to 4000 characters of state.md back into context. Window size: COMPACT_MEMORY_WINDOW, then CLAUDE_CODE_AUTO_COMPACT_WINDOW, then a model ID ending in [1m], then observed usage above 200K (remembered for the session), otherwise 200K. Memory folder: .compact-memory/ or COMPACT_MEMORY_DIR. The only file written outside the project is a small per-session marker in the system temp folder. Requires Claude Code 2.1.139+ and Node.js 18+. Through Agensi, install the hooks once per project by asking your agent to follow the README section "Installing through an agent connection"; SHA-256 checksums are in the README.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 3 days ago

    • Free with an Agensi account

    Software
    Node.js 18+ (hooks only)

    Permissions

    Read Files
    Write Files
    Listed3 days ago

    What's inside

    Frequently Asked Questions

    Yes. Claude saves and reads the state when the skill tells it to. Without the hooks there is no automatic 70% notice and no automatic give-back after compaction.

    In .compact-memory/ in your project root, or in the folder set by COMPACT_MEMORY_DIR. state.md holds the current state; records/ holds one short file per finished piece of work.

    No. The script makes no network requests and installs no packages. It reads only the token counts of the last reply from the transcript, and it never copies or stores the conversation.

    No. It saves the state and asks you to run /compact. If auto-compaction happens first, the state is still given back, and a minimal record marks any gap.

    No. The skill tells Claude never to write keys, tokens or passwords, and state.md is put into Claude's context every session. Keep .compact-memory/ out of shared repositories.

    It is built and tested for Claude Code; the hooks are Claude Code hooks. Other agents are not tested.

    Ask your agent once per project: "Install compact-memory with its hooks in this project, following the README section 'Installing through an agent connection'." Then start a new session so the hooks load.

    New in Productivity

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Productivity.

    Free