# Compact Memory

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

Compact Memory is a free AI agent skill on Agensi by Muhammet KURT, in Productivity. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Muhammet KURT](https://www.agensi.io/creators/muhammet-kurt)
- Category: [Productivity](https://www.agensi.io/skills/productivity)
- Version: 1.0.1
- Last updated: 2026-12-02
- Security: scan passed (2026-12-02); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/compact-memory
- Tags: productivity, claude-code, memory, context, compaction, hooks, session

## 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: "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: "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: "Record that the importer is done and the error list is next."

## 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.

## Requires

- Node.js 18+ (hooks only)

## Known limitations

- 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'.

## Technical details

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 this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Compact Memory skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### Does it work without the hooks?

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.

### Where is the state stored?

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.

### Does it send my conversation anywhere?

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.

### Can Claude run /compact by itself?

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.

### Should I store secrets in it?

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.

### Does it work with agents other than Claude Code?

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

### I added this skill through Agensi. How do I get the automatic notice?

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.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
