Session artifacts for Claude Code. Captures important context (file paths, errors, commands, URLs) during your session and makes it queryable after auto-compact.
When context grows too large, Claude Code runs "auto-compact" — an in-memory summarization that loses details: file paths, error messages, code snippets, architectural decisions. You end up re-explaining things Claude already knew.
artifacts-mcp works in three layers:
- PostToolUse hook — after every tool call, extracts artifacts (file paths, commands, errors, URLs) and stores them to disk
- PreCompact hook — when auto-compact fires, injects preservation instructions into the compact prompt
- MCP server — gives Claude tools to query stored artifacts after compaction
You work normally
|
v
Every tool call --> PostToolUse hook extracts artifacts
(file paths, commands, errors, URLs)
Stored to ~/.config/artifacts-mcp/sessions/
|
v
Context fills up --> Claude auto-compact fires
PreCompact hook adds preservation instructions
|
v
After compact --> Claude can query_artifacts via MCP
Recovers file paths, errors, decisions lost in compact
No kill, no resume, no JSONL modification. Works with Claude's native auto-compact.
git clone https://github.com/user/artifacts-mcp.git ~/artifacts-mcp
cd ~/artifacts-mcp
npm install
bin/cbp install
source ~/.zshrcThen restart Claude Code for the MCP server to activate.
- Checks prerequisites (Node 22+, Claude CLI)
- Registers 3 hooks in
~/.claude/settings.json(PostToolUse, PreCompact, SessionEnd) - Registers MCP server in
~/.claude.json - Sets up
claudealias → wrapper script (setsCLAUDE_AUTOCOMPACT_PCT_OVERRIDE) - Adds
bin/to PATH (socbpworks from anywhere) - Runs 12 verification checks
- Node.js 22+ (for
--experimental-strip-types) - Claude Code CLI (
claudecommand)
| Command | What it does |
|---|---|
cbp install |
Register hooks, MCP server, set up alias, verify |
cbp uninstall |
Remove hooks, MCP server, alias |
cbp verify |
Run 12 installation checks |
cbp enable |
Turn on artifact extraction |
cbp disable |
Turn off (hooks pass through silently) |
cbp status |
Show state: hooks, MCP, sessions, artifact counts |
cbp set-key <key> |
Save Gemini API key to config |
cbp config |
Show current configuration |
cbp cleanup |
Remove stale files, expired sessions |
Runs after every tool call. No LLM, pure parsing — fast:
| Tool | Extracted |
|---|---|
Write, Edit, Read |
file_path + config detection |
Bash |
command, error (if exit ≠ 0) |
Glob, Grep |
discovered file_paths |
| Any tool | URLs from output |
Artifacts are stored in ~/.config/artifacts-mcp/sessions/<session-id>.jsonl.
When Claude's auto-compact fires, the PreCompact hook outputs additional instructions that get added to the compact prompt:
- Lists all stored artifact counts
- Enumerates file paths referenced in the session
- Instructs Claude to preserve file paths, errors, code snippets, decisions
After compaction, Claude has 3 tools to recover lost context:
| Tool | Description |
|---|---|
store_artifact |
Manually store important info (decisions, code snippets) |
query_artifacts |
Search artifacts by type and/or text query |
get_session_summary |
Overview of all artifacts grouped by type |
The wrapper script (cclaude.sh) sets CLAUDE_AUTOCOMPACT_PCT_OVERRIDE to trigger auto-compact earlier (default: 50% of effective window ≈ 90K tokens). This gives more room for the compacted summary. Configurable via autoCompactPercent in config.json.
~/.config/artifacts-mcp/config.json — create to override defaults:
When launched via cclaude.sh (the alias), debug logging is enabled automatically:
# Artifact extraction log
tail -f ~/.config/artifacts-mcp/logs/extractor.log
# PreCompact hook log
tail -f ~/.config/artifacts-mcp/logs/precompact.log- Session starts → MCP server spawns (stdio), PostToolUse hook active
- Tool calls → artifacts extracted and stored to session JSONL
- Auto-compact fires → PreCompact adds instructions, Claude summarizes
- After compact → Claude queries artifacts via MCP tools
- Session ends → SessionEnd hook marks session, starts 24h TTL
- 24h later → session artifacts auto-cleaned
artifacts-mcp/
bin/
cbp -- CLI tool (install, manage, verify)
cclaude.sh -- wrapper: sets AUTOCOMPACT_PCT, debug env
artifacts-server.js -- MCP server entry point
src/
artifact-extractor.ts -- PostToolUse hook: extracts artifacts
precompact-hook.ts -- PreCompact hook: preservation instructions
session-end-hook.ts -- SessionEnd hook: TTL management
config.ts -- config loading, defaults
mcp-server/
server.ts -- MCP server (store, query, summary tools)
store.ts -- ArtifactStore: JSONL-based per-session storage
types.ts -- TypeScript types
| Path | Purpose | Lifetime |
|---|---|---|
~/.config/artifacts-mcp/sessions/<id>.jsonl |
Session artifacts | 24h after session end |
~/.config/artifacts-mcp/sessions/<id>.meta.json |
Session metadata | 24h after session end |
~/.config/artifacts-mcp/config.json |
User configuration | Permanent |
~/.config/artifacts-mcp/enabled |
Kill switch | Until disabled |
~/.config/artifacts-mcp/logs/*.log |
Debug logs | Permanent |
cbp uninstall
# Optionally remove all data:
rm -rf ~/.config/artifacts-mcp
{ // Trigger auto-compact at this % of effective window (default 50) "autoCompactPercent": 50 }