Skip to content

anthhub/claude-context-saver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

context-saver

A Claude Code plugin that automatically saves conversations before context compaction and injects historical context after compaction.

Features

  • Auto-save conversations - Automatically saves full conversation to Markdown before context compression
  • Context injection - Injects summary of recent conversations after compaction for Claude's reference
  • Dual format - Saves both Markdown (human-readable) and JSON (programmatic access)
  • Auto-cleanup - Keeps only the most recent 50 archives to save disk space
  • Index file - Maintains an index of all archived conversations

Installation

From Marketplace

/plugin marketplace add anthhub/claude-context-saver
/plugin install context-saver@anthhub

Manual Installation

# Clone the repository
git clone https://github.com/anthhub/claude-context-saver.git

# Load the plugin locally
claude --plugin-dir ./claude-context-saver

How It Works

PreCompact Hook

When context is about to be compacted (manually via /compact or automatically when context window fills):

  1. Captures the full conversation transcript
  2. Converts it to readable Markdown format
  3. Saves to .claude/context-archives/ in project directory
  4. Also saves raw JSON for programmatic access
  5. Updates latest.md symlink and index.md

SessionStart Hook (compact matcher)

When a new session starts after compaction:

  1. Reads recent archive files
  2. Extracts key conversation snippets
  3. Outputs a summary for Claude to reference
  4. Provides path to full archives

File Structure

After installation, archives are stored in:

your-project/
└── .claude/
    └── context-archives/
        ├── index.md                      # Index of all archives
        ├── latest.md -> conversation_xxx.md  # Symlink to latest
        ├── conversation_20260205_143022.md   # Markdown archive
        ├── conversation_20260205_143022.json # JSON archive
        └── ...

Archive Format

Markdown Format

# Conversation Archive

| Property | Value |
|----------|-------|
| Saved At | 2026-02-05 14:30:22 |
| Session ID | `abc123` |
| Trigger | manual |
| Message Count | 42 |
| Project Dir | `/path/to/project` |

---

## Conversation

### User

What is the authentication flow in this project?

---

### Claude

The authentication flow consists of...

---

JSON Format

{
  "session_id": "abc123",
  "timestamp": "20260205_143022",
  "trigger": "manual",
  "cwd": "/path/to/project",
  "message_count": 42,
  "messages": [
    {"role": "user", "content": "..."},
    {"role": "assistant", "content": "..."}
  ]
}

Configuration

The plugin works out of the box with sensible defaults. No configuration required.

Storage Location

  • Project-level (default): .claude/context-archives/ in your project
  • Global fallback: ~/.claude/context-archives/ if no project directory

Retention

  • Keeps the most recent 50 archives per directory
  • Older archives are automatically deleted

Testing Locally

# 1. Make scripts executable
chmod +x claude-context-saver/scripts/*.sh

# 2. Start Claude Code with the plugin
claude --plugin-dir ./claude-context-saver

# 3. Have a conversation, then trigger compaction
/compact

# 4. Check the saved archive
cat .claude/context-archives/latest.md

# 5. Start a new session to see context injection
# (or wait for auto-compaction on long conversations)

Requirements

  • Claude Code CLI
  • jq command-line JSON processor
  • Bash shell

License

MIT License - see LICENSE file.

Author

anthhub

Contributing

Contributions welcome! Please open an issue or pull request on GitHub.

About

Claude Code plugin: Auto-save conversations before context compaction and inject historical context after

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages