Skip to main content

Episodic memory for Claude Code - persistent memory of code written across sessions

Project description

AI-AfterImage

Tests codecov PyPI Python 3.10+ License: MIT

Give Claude Code memory of code it wrote in past sessions.

Claude starts every session with amnesia. AfterImage fixes this by intercepting Write/Edit operations and showing Claude similar code it wrote before - using a clever deny-then-allow hook pattern that injects context directly into Claude's view.

Quick Start (< 5 minutes)

Step 1: Install

pip install ai-afterimage

Step 2: Set Up Hook

afterimage setup

This automatically:

  • Creates ~/.afterimage/ configuration
  • Installs the hook to ~/.claude/hooks/
  • Configures ~/.claude/settings.json
  • Downloads the embedding model (~90MB)

Step 3: You're Done

Start Claude Code. AfterImage now works invisibly in the background:

  • Before writes: Shows similar past code (if found)
  • After writes: Stores the code for future recall

How It Actually Works

The magic is in the deny-then-allow pattern:

  1. Claude tries to Write/Edit a file
  2. Hook searches knowledge base for similar past code
  3. If found: DENY with past code in the reason message
  4. Claude sees the deny reason (this is documented Claude Code behavior!)
  5. Claude retries the same write
  6. Hook recognizes retry (same content hash) → ALLOW
  7. File is written
  8. Post-hook stores the new code in KB

This is the only way to inject context into Claude's view before a write. The deny reason IS the injection mechanism.

Verify It's Working

# Check KB stats
afterimage stats

# Search your code memory
afterimage search "authentication"

# See recent code stored
afterimage recent

All Your Code Stays Local

  • SQLite database: ~/.afterimage/memory.db
  • No cloud sync, no API calls
  • Works fully offline after setup
  • Your code never leaves your machine

CLI Reference

Command Description
afterimage setup First-time setup
afterimage search <query> Search past code
afterimage stats Show KB statistics
afterimage recent Recent stored entries
afterimage ingest Import existing transcripts
afterimage config View/edit configuration
afterimage uninstall Clean removal

Requirements

  • Python 3.10+
  • Claude Code CLI
  • Linux or macOS (Windows support planned)

Uninstall

afterimage uninstall          # Remove hook, keep data
afterimage uninstall --purge  # Remove everything

License

MIT License - Do whatever you want with it.

Support

If AfterImage saves you time, consider starring the repo - it helps others find it.


The ghost of what was written, persisting across sessions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_afterimage-0.1.0.tar.gz (48.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_afterimage-0.1.0-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file ai_afterimage-0.1.0.tar.gz.

File metadata

  • Download URL: ai_afterimage-0.1.0.tar.gz
  • Upload date:
  • Size: 48.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ai_afterimage-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9081049d2d30f761025fddebc702737c1914af338dab6d0c0f35d59cc68e7519
MD5 e2b4bc921360f96d1e8331dfffe0197f
BLAKE2b-256 25ef006c816072a3ad510afe1b0ef107b8dd6bd0d47b47665ba7403b564dd213

See more details on using hashes here.

File details

Details for the file ai_afterimage-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ai_afterimage-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ai_afterimage-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7958748f451aa25932793762e7f2910738c3ca2d697b2476e2dd0f30cd19fcd
MD5 f7c9d23e65d2d4bd56e529bf46a79854
BLAKE2b-256 7437665785766f0add15791ac076c02bf0eb63ab888f1b2b178a2659188c0820

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page