Skip to content
/

AI-AfterImage

ai-afterimage · DragonShadows1978/AI-AfterImage · ★ 22 · last commit 2026-05-10

Primitive shape 2 total
Hooks 2
00

Summary

AI-AfterImage — Summary

AI-AfterImage (DragonShadows1978/AI-AfterImage) is an episodic code memory system for AI coding agents. Named after the visual phenomenon where an image persists after you look away, it gives Claude Code persistent memory of code written across sessions. The core mechanism is a single hook file (hooks/afterimage_hook.py) that handles both PreToolUse and PostToolUse events for Write and Edit operations via a deny-then-allow pattern: the first Write/Edit attempt is denied with "You've written similar code before!" context injected, and the retry is allowed after Claude has read the context. Post-write, the code diff is stored in a local SQLite knowledge base for future recall.

22 stars, MIT license, 1 contributor (DragonShadows1978), Python 3.10+. CLI: afterimage. Install: pip install ai-afterimage. Version 0.6.0. Active development through May 2026.

Key features across versions: SQLite KB with hybrid search (v0.1), optional PostgreSQL+pgvector backend (v0.2), semantic chunking with relevance scoring (v0.3), code churn tracking with Gold/Silver/Bronze/Red tier classification (v0.3), Code Intelligence with AST parsing via tree-sitter for 6 languages (v0.5), Codex transcript support (v0.6).

Differs from seeds: closest to memsearch-cc (hook-based episodic memory, Claude Code plugin, deny-on-first-use pattern) but AI-AfterImage is a standalone Python package (not a plugin), focuses exclusively on code files (filters non-code files), adds churn tier warnings and AST-level code intelligence, and supports PostgreSQL+pgvector as an optional backend for concurrent/team use.

01

Overview

AI-AfterImage — Origin and Philosophy

Origin

Author: DragonShadows1978. 22 stars, 3 forks. MIT license. Python 3.10+. 1 contributor. Last pushed 2026-05-10. PyPI: ai-afterimage.

The project description: "Episodic memory for AI coding agents. The ghost of code written, persisting across sessions."

The Problem Statement (verbatim)

"Claude Code starts every session with amnesia. Even though transcripts exist with every Write/Edit ever made, Claude can't remember:

  • What code it wrote yesterday
  • How it solved a similar problem last week
  • Patterns it has used before in this codebase

Users re-explain context. Claude rewrites similar solutions. Institutional knowledge is lost."

Philosophy

AfterImage takes a narrow, code-specific approach to memory: it only cares about Write and Edit events on code files. Markdown, JSON, configs are filtered out. The focus is exclusively on "code written before" — not general conversation history, not project context.

The deny-then-allow pattern is philosophically significant: rather than injecting context as a system prompt addition (which the agent may ignore), AfterImage forces the agent to see the context by denying the first write attempt. The agent must read the "You've written similar code before!" message to retry.

Verbatim Hook Docstring

Provides episodic code memory through Claude Code's hook system:
1. Pre-Write/Edit: DENY first attempt with similar code context (Claude sees this!)
2. Pre-Write/Edit: Check for churn warnings (gold tier, repetitive edits, red tier)
3. Pre-Write/Edit: ALLOW retry attempts (after Claude has seen the context)
4. Post-Write/Edit: Store the code change in KB for future recall
5. Post-Write/Edit: Record edit in churn tracker

The deny-then-allow pattern ensures Claude sees relevant past code BEFORE writing.

Version History Philosophy

  • v0.1: Core deny-then-allow hook, SQLite KB, hybrid search
  • v0.2: PostgreSQL+pgvector for concurrent/team use — "Start with SQLite. Switch to PostgreSQL if you need concurrent access."
  • v0.3: Semantic chunking with explicit relevance scoring formula: Recency 20%, Proximity 25%, Semantic similarity 35%, Project awareness 20%
  • v0.3: Churn tracking — "Track file and function modification patterns" to detect premature optimization or unfixed bugs
  • v0.5: Code Intelligence — "semantic code understanding, not just text embeddings." AST parsing via tree-sitter for Python, JS/TS, Rust, C, Go
  • v0.6: Codex CLI transcript support — session_meta IDs, apply_patch parsing

The Ghost Metaphor

The name "AfterImage" and the description "ghost of code written" frames the tool as passive memory that lingers without requiring active maintenance. The developer doesn't configure what to remember — the hooks automatically record everything and surface relevant patterns when needed.

02

Architecture

AI-AfterImage — Architecture

Distribution

Python package on PyPI:

pip install ai-afterimage              # SQLite backend (default)
pip install ai-afterimage[postgresql]  # with PostgreSQL+pgvector support
pip install ai-afterimage[ast]         # with Code Intelligence (tree-sitter)
pip install ai-afterimage[embeddings]  # from source with embeddings

Setup:

afterimage setup   # creates ~/.afterimage/, installs hook, configures settings.json, downloads embedding model

Required Runtime

  • Python 3.10+
  • Embedding model (~90 MB, downloaded on afterimage setup)
  • SQLite (default, built into Python)
  • Optional: PostgreSQL + pgvector extension (for concurrent/team access)
  • Optional: tree-sitter (for AST parsing in Code Intelligence)

Architecture

Claude Code
      ↓ PreToolUse / PostToolUse (Write, Edit)
hooks/afterimage_hook.py (single file, standalone Python script)
      ├── CodeFilter — is this a code file?
      ├── ChurnTracker — tier classification (Gold/Silver/Bronze/Red)
      ├── HybridSearch — keyword + semantic search
      ├── SemanticChunking — inject_semantic_context()
      └── KnowledgeBase — store/retrieve

Storage:
  SQLite: ~/.afterimage/afterimage.db (default)
  OR PostgreSQL + pgvector (optional, via AFTERIMAGE_PG_PASSWORD env var)

Embedding model: ~90MB local model
Config: ~/.afterimage/config.yaml

Repository Structure

DragonShadows1978/AI-AfterImage/
├── hooks/
│   └── afterimage_hook.py   # single hook file, handles PreToolUse + PostToolUse
├── afterimage/
│   ├── cli.py               # CLI subcommands
│   ├── kb.py                # KnowledgeBase
│   ├── search.py            # HybridSearch
│   ├── filter.py            # CodeFilter (code vs non-code files)
│   ├── embeddings.py        # EmbeddingGenerator
│   ├── churn/               # Code churn tracking + tier classification
│   ├── ast_parser/          # tree-sitter AST parsers
│   ├── language_detection/  # 20+ language detection
│   ├── semantic_chunking/   # Semantic chunking + relevance scoring
│   ├── semantic_index/      # Symbol tables, go-to-definition, call graph
│   ├── storage/
│   │   ├── SQLiteBackend
│   │   └── SyncPostgreSQLBackend
│   ├── extract.py           # Transcript extraction (Claude Code + Codex)
│   ├── inject.py            # Context injection formatting
│   ├── config.py            # Config loading (~/.afterimage/config.yaml)
│   └── migrate.py           # Schema migrations
├── afterimage_embedder/     # Embedding model package
├── docs/
│   ├── semantic_chunking.md
│   └── code_intelligence.md
├── tests/
├── pyproject.toml
└── CHANGELOG.md

Backend Architecture

SQLite (default)

SQLiteBackend at ~/.afterimage/afterimage.db. Zero-config, works out of the box. Brute-force vector search (no native index). Recommended for single-user use up to ~100K entries.

PostgreSQL + pgvector (optional, v0.2.1+)

SyncPostgreSQLBackend with IVFFlat index for native vector search. Required: AFTERIMAGE_PG_PASSWORD env var. Graceful fallback to SQLite if PostgreSQL connection fails. Suitable for concurrent Claude Code sessions or team shared memory.

Priority in hook: returns cached backend → try PostgreSQL → fall back to SQLite.

State Files

  • ~/.afterimage/afterimage.db — SQLite knowledge base
  • ~/.afterimage/config.yaml — configuration
  • ~/.afterimage/.seen_writes — content hashes of write attempts already shown context (deny-then-allow state)
  • ~/.claude/hooks/ — hook script installation target
  • ~/.claude/settings.json — hook registration
03

Components

AI-AfterImage — Components

2 Hooks (single file)

Both hooks are handled by hooks/afterimage_hook.py. The same file processes both events:

Event Tool Matcher Action
PreToolUse Write, Edit DENY first attempt with code context + churn warnings; ALLOW retry
PostToolUse Write, Edit Store code diff in KB; record churn edit

Hook registration is via ~/.claude/settings.json (installed by afterimage setup).

Deny-Then-Allow Pattern (verbatim logic)

if hook_event == "PreToolUse":
    content_hash = get_content_hash(file_path, content)
    
    if not was_already_shown(content_hash):
        # Collect churn warnings + similar code injections
        if churn_warning or injection:
            mark_as_shown(content_hash)
            output = {
                "hookSpecificOutput": {
                    "hookEventName": "PreToolUse",
                    "permissionDecision": "deny",
                    "permissionDecisionReason": combined_message
                }
            }
            # Exit 0 — Claude reads the denial reason and retries

    # Was already shown: fall through and allow (exit 0 without output)

was_already_shown tracks content hashes in ~/.afterimage/.seen_writes (last 100 entries). Three key modes for the hash:

  • file (default): keyed on file path alone
  • content: keyed on file_path + first 500 chars of content
  • session_file: keyed on CLAUDE_SESSION_ID + file_path

CLI Commands (afterimage binary)

Command Description
afterimage setup Install hook, create config, download embedding model
afterimage search <query> Search KB with keyword + semantic
afterimage ingest [-d <dir>] Ingest existing Claude Code transcripts
afterimage stats KB statistics
afterimage recent Recent KB entries
afterimage config Show/edit configuration
afterimage export Export KB contents
afterimage clear Clear KB
afterimage uninstall Remove hook and config
afterimage churn <file> File churn stats and tier
afterimage churn <file> --functions Function-level churn
afterimage churn <file> --history Edit history
afterimage hotspots [--limit N] Most churned files
afterimage files --tier <tier> List files by tier (gold/silver/bronze/red)
afterimage doctor Diagnose setup issues

Churn Tier System

4-tier file classification based on edits in the last 30 days:

Tier Edits/30d Behavior
Gold 0–2 Stable — warns before modification: "Are you sure this change is necessary?"
Silver 3–10 Normal operation
Bronze 11–20 Velocity alerts
Red 21+ Excessive churn warning

Function-level churn: >3 edits to the same function in 24h triggers a "repetitive function edit" warning suggesting root cause investigation.

Code Intelligence (v0.5.0, optional)

Install with pip install ai-afterimage[ast]:

Language Detection (20+ languages):

  • Pattern-based with confidence scoring
  • Handles polyglot files (HTML+JS+CSS)
  • Extensionless scripts (shebang detection)

AST Parsing (tree-sitter):

  • Languages: Python, JavaScript, TypeScript, Rust, C, Go
  • Incremental parsing for large files
  • Extracts: functions, classes, imports, dependencies

Semantic Index:

  • Symbol tables with scope-aware resolution
  • Go-to-definition across files
  • Find all references
  • Call graph generation
  • Hover information provider
  • Basic type inference

Semantic Chunking (v0.3.0)

Relevance scoring formula:

  • Recency: 20%
  • Proximity (same file/directory): 25%
  • Semantic similarity (embedding cosine): 35%
  • Project awareness (same project context): 20%

Groups 3+ similar snippets via summarization to reduce token usage. 108x speedup on repeated operations via caching.

Config in ~/.afterimage/config.yaml:

semantic_chunking:
  enabled: true
  max_tokens: 2000
  summarization:
    enabled: true
    summary_mode_threshold: 3

Search: HybridSearch

afterimage/search.py — keyword + semantic search. Runs against backend (SQLite or PostgreSQL). limit=10, threshold=0.01 default. Results ranked by hybrid score.

CodeFilter

afterimage/filter.py — determines if a file is code (not .md, .json, config files). Only code files are stored and searched.

Extract Module (v0.6.0)

afterimage/extract.py — extracts code from Claude Code JSONL transcripts AND Codex transcripts:

  • Claude Code: standard JSONL format
  • Codex: session_meta session IDs, response_item envelope format (function_call + custom_tool_call), apply_patch unified diff parsing
05

Prompts

AI-AfterImage — Prompts and Instructions

Hook Docstring (verbatim)

AI-AfterImage Hook for Claude Code v0.3.0

Provides episodic code memory through Claude Code's hook system:
1. Pre-Write/Edit: DENY first attempt with similar code context (Claude sees this!)
2. Pre-Write/Edit: Check for churn warnings (gold tier, repetitive edits, red tier)
3. Pre-Write/Edit: ALLOW retry attempts (after Claude has seen the context)
4. Post-Write/Edit: Store the code change in KB for future recall
5. Post-Write/Edit: Record edit in churn tracker

The deny-then-allow pattern ensures Claude sees relevant past code BEFORE writing.

Context Injection Banner (verbatim)

============================================================
📚 AFTERIMAGE [SQLITE]: You've written similar code before!
============================================================

Review these patterns before proceeding:

**From:** `<file path>`

<code content, up to 400 chars>


Consider these patterns. Retry your write now.
============================================================

The backend type (SQLITE or POSTGRESQL) is shown in the banner header.

Gold Tier Warning (verbatim from README)

File: src/core/auth.py
Tier: GOLD (Stable - rarely changed)

This file is stable and rarely modified.
  - Total edits: 2
  - Last edit: 2026-01-01T10:30:00

Are you sure this change is necessary?
Retry your write if intentional.

Repetitive Function Warning (verbatim from README)

File: src/handlers/api.py
Function: process_request()

This function has been modified 4 times in the last 24 hours.

Possible issues:
  - Bug not fully fixed
  - Requirements unclear
  - Function needs redesign

Consider stepping back to understand the root cause.

README Problem Statement (verbatim)

Claude Code starts every session with amnesia. Even though transcripts exist 
with every Write/Edit ever made, Claude can't remember:
- What code it wrote yesterday
- How it solved a similar problem last week
- Patterns it has used before in this codebase

Users re-explain context. Claude rewrites similar solutions. Institutional 
knowledge is lost.

Project Description (verbatim)

"Episodic memory for AI coding agents. The ghost of code written, persisting across sessions."

Semantic Chunking Scoring Formula (from README)

- Recency: 20%
- Proximity (same file/directory): 25%
- Semantic similarity (embedding cosine): 35%
- Project awareness (same project context): 20%

Config Structure (~/.afterimage/config.yaml)

Key configuration options:

storage:
  backend: sqlite   # or: postgresql
  sqlite:
    path: ~/.afterimage/afterimage.db
  postgresql:
    host: localhost
    port: 5432
    database: afterimage
    user: afterimage
    # password via AFTERIMAGE_PG_PASSWORD env var

embeddings:
  embedding_dim: 384

hook:
  seen_write_key: file   # or: content, session_file

semantic_chunking:
  enabled: true
  max_tokens: 2000
  summarization:
    enabled: true
    summary_mode_threshold: 3
09

Uniqueness

AI-AfterImage — Uniqueness and Positioning

Differs from Seeds

Closest to memsearch-cc (hook-based episodic memory for Claude Code, deny-on-first-use pattern) but with several key distinctions:

  1. Code-only scope: AI-AfterImage filters non-code files via CodeFilter. Only Write/Edit events on code files are stored or searched. memsearch-cc captures all tool interactions regardless of file type. This narrowing reduces noise — the KB only contains patterns relevant to future coding decisions.

  2. Single hook file: The entire hook logic lives in hooks/afterimage_hook.py (one file, ~700 lines). memsearch-cc uses 4 separate hook scripts. AfterImage's single-file design makes it auditable and portable without a plugin system.

  3. Deny-then-allow with hash tracking: The deny mechanism uses content hash tracking (.seen_writes file) to ensure Claude sees the context exactly once, then proceeds. memsearch-cc injects context as memory context, not a denial. The denial mechanism forces the agent to read the context, not just optionally incorporate it.

  4. Churn tier system: Gold/Silver/Bronze/Red classification with function-level tracking (AST-based for Python, regex for others). No other framework in the corpus tracks code modification velocity as a quality signal. "Repetitive function edits" detection surfaces potential bug loops or requirements confusion.

  5. Code Intelligence (AST, v0.5): tree-sitter AST parsing for Python, JS/TS, Rust, C, Go. Symbol tables, go-to-definition, find-all-references, call graph. This goes beyond pure text similarity into semantic code understanding.

  6. PostgreSQL+pgvector backend: Optional concurrent-access backend. memsearch-cc and agentmemory use local-only storage. AfterImage's PostgreSQL path enables team-shared code memory.

  7. Codex transcript support (v0.6): Parses both Claude Code and Codex CLI transcript formats, including apply_patch unified diff parsing. Most memory tools support only their primary host agent.

Positioning

AI-AfterImage is positioned as the minimal, code-focused memory layer. Where agentmemory aims to be comprehensive (53 tools, 12 hooks, 16+ platforms), AfterImage does one thing: remembers code patterns written before and surfaces them at write time via a denial interrupt.

The 22-star count reflects early-stage adoption, not low quality — the code is well-structured with CI badges, codecov integration, and comprehensive tests.

Observable Failure Modes

  1. AFTERIMAGE_PATH fallback: The hook searches ~/AI-AfterImage as a default install path. If the package was installed via pip to a different location, the hook fails silently (exits without storing or searching). Diagnosis: afterimage doctor.

  2. Content hash collision: The .seen_writes file only stores 100 hashes (last 100 entries). In long sessions with many writes, old hashes cycle out and the hook may re-inject context for the same pattern. The seen_write_key: content mode mitigates this by using content-based hashing.

  3. Embedding model absent: If afterimage setup was skipped or the model wasn't downloaded, embeddings are silently omitted — only keyword search runs. The agent gets no warning that semantic search is unavailable.

  4. Single-file import complexity: The hook searches SEARCH_PATHS in priority order and loads the afterimage package dynamically. On some system configurations (virtual envs, conda), the import can fail silently and AfterImage operates in a degraded state (no KB access, just exits 0 allowing all writes).

  5. Gold tier over-warning: A file with 0–2 edits in 30 days triggers a denial on every write attempt. For new projects or rarely-touched files, this can be noisy — the agent gets warned about "stable files" that simply haven't been written to yet.

04

Workflow

AI-AfterImage — Workflow

Setup

1. pip install ai-afterimage
2. afterimage setup
   → creates ~/.afterimage/
   → installs hook to ~/.claude/hooks/
   → writes hook registration to ~/.claude/settings.json
   → downloads embedding model (~90 MB)
3. (optional) afterimage ingest   # backfill existing transcripts

Per-Write Event Flow

Claude writes a file
         ↓
PreToolUse hook fires (Write or Edit)
         ↓
Is this a code file? (CodeFilter)
   No → exit 0 (allow silently)
   Yes ↓
         ↓
First attempt for this hash?
  (check ~/.afterimage/.seen_writes)
         ↓ YES (first time)
Check churn tier for file/function
         ↓
Is file Gold tier? or function edited >3x in 24h?
  → churn warning message
         ↓
Search KB for similar code
  → HybridSearch (keyword + semantic)
  → SemanticChunking (inject_semantic_context) if available
         ↓
Any messages to show?
  YES → mark hash as shown
      → output permissionDecision: "deny"
      → permissionDecisionReason: "[AFTERIMAGE]: You've written similar code before! ..."
      → Claude reads context → retries write
         ↓ NO (nothing to show)
         ↓ OR: SECOND ATTEMPT (hash already shown)
Allow write (exit 0 with no output)
         ↓
PostToolUse hook fires
         ↓
Store code in KB (kb.store with embedding)
         ↓
Record churn edit in ChurnTracker

Backfill Flow

For existing transcripts:

afterimage ingest                                    # Claude Code JSONL (default path)
afterimage ingest -d ~/.claude/projects/            # specific directory

The extract module (extract.py) parses Claude Code JSONL and Codex transcript formats, extracting Write/Edit operations with their code content and session IDs.

Search Flow

afterimage search "authentication middleware"   # CLI
# or: during session via deny-then-allow context injection

HybridSearch: keyword match (term frequency) + semantic similarity (embedding cosine). Returns ranked results with file_path, code content, session_id, timestamp.

Churn Monitoring

afterimage churn src/app.py              # file tier + recent edit count
afterimage hotspots --limit 10           # top 10 most-churned files
afterimage files --tier red              # all Red-tier files

ChurnTracker uses AST parsing (Python) or regex (other languages) to track function-level edits across sessions.

Team / PostgreSQL Flow

For concurrent access:

  1. Install PostgreSQL + pgvector
  2. Set AFTERIMAGE_PG_PASSWORD=<password> env var
  3. Edit ~/.afterimage/config.yamlstorage.backend: postgresql
  4. Multiple Claude Code sessions share the same PostgreSQL KB
  5. On connection failure → graceful fallback to SQLite

Context Injection Format

When denying with context (verbatim from hook):

============================================================
📚 AFTERIMAGE [SQLITE]: You've written similar code before!
============================================================

Review these patterns before proceeding:

**From:** `src/middleware/auth.py`

<code preview, up to 400 chars>


Consider these patterns. Retry your write now.
============================================================

Semantic chunking wraps the same banner around the semantic injection output.

06

Memory Context

AI-AfterImage — Memory and Context

Storage Architecture

Primary: SQLite at ~/.afterimage/afterimage.db. KnowledgeBase class (kb.py) wraps the backend with an abstraction layer.

Optional: PostgreSQL + pgvector at a configured host. IVFFlat index for native vector search. Scales to millions of entries with concurrent write access.

Backend abstraction: Both backends implement the same interface — SQLiteBackend and SyncPostgreSQLBackend. The hook caches the backend instance at module level to reuse connection pools across invocations.

Knowledge Base Schema

Each stored entry contains:

  • file_path: path to the code file
  • new_code: code content (after the Write/Edit)
  • old_code: previous content (for Edit operations)
  • context: empty string (not used currently)
  • session_id: Claude Code session ID (from CLAUDE_SESSION_ID env var)
  • embedding: vector embedding (optional, if EmbeddingGenerator is available)
  • timestamp: when stored

Embedding Model

~90 MB local model, downloaded by afterimage setup. Generates embeddings for hybrid search. Works offline after download. Embedding dimension: 384.

search.py — keyword + semantic search:

  1. BM25-style keyword match on code content
  2. Cosine similarity on stored embeddings (if available)
  3. Combined score for ranking

PostgreSQL backend uses native pgvector IVFFlat index; SQLite uses brute-force cosine similarity.

Churn Tracking Storage

afterimage/churn/ — separate tracking store. Records per-function edits with timestamps and session IDs. Used to compute tier classification (Gold/Silver/Bronze/Red) and detect repetitive function edits within 24h windows.

AST-based function detection: Python (tree-sitter/ast module), regex for JavaScript/TypeScript/Go/Rust/C.

Seen-Writes State

~/.afterimage/.seen_writes — plain text file, one content hash per line, last 100 entries. Implements the deny-once-allow-retry pattern without persistent database overhead. Cleared on restart (no TTL — file accumulates until explicitly cleared or rolled by the 100-entry window).

Three keying modes:

  • file: resets denial per session (same file → re-denies next session)
  • content: keyed on file + content hash (each unique change shown once)
  • session_file: keyed on session + file (denied once per session per file)

Context Injection Scope

Injected context shows at most 3 past files, with 400-character code previews (truncated with "... (truncated)" if longer). Deduplication by file path (same file shown once). Semantic chunking mode can group multiple results from the same file.

Persistence Scope

Global (cross-project, cross-session): the SQLite KB at ~/.afterimage/afterimage.db is a single global store. All code written across all projects and sessions accumulates in one place. Search runs across the entire history unless filtered by --path.

This is a deliberate choice: the goal is cross-project pattern recall ("how did I solve this last week in the other codebase?"), not project-isolated memory.

Codex Transcript Format (v0.6.0)

extract.py handles Codex-specific transcript formats:

  • session_meta JSON blocks for session ID extraction
  • response_item envelope format with function_call + custom_tool_call
  • apply_patch unified diff format for file additions and updates

This extends the memory to cover both Claude Code and Codex CLI transcript histories.

07

Orchestration

AI-AfterImage — Orchestration

Single-Agent Design

AI-AfterImage is a single-developer, single-agent memory tool. There is no multi-agent orchestration, no task decomposition, no sub-agent spawning. The hook fires on every Write/Edit by the single active Claude Code session.

Team Use (PostgreSQL backend)

The only "multi-agent" scenario is shared team memory via PostgreSQL:

  • Multiple developers (or multiple concurrent Claude Code sessions) point at the same PostgreSQL+pgvector database
  • Each write from any session gets stored with its session_id
  • Any session's search returns results from all sessions' histories

This is collaborative memory sharing, not agent coordination. There is no signal bus, no lease mechanism, no session graph — just a shared KB.

No Orchestration Primitives

AI-AfterImage has no:

  • Subagent spawning
  • Task decomposition
  • Workflow phases
  • Approval gates
  • Cross-agent signals

The tool's scope is narrow: intercept Write/Edit events, inject relevant past code, store new code. Everything else is out of scope.

Isolation

By default (SQLite): complete isolation — only the local developer's history. With PostgreSQL: no isolation between sessions — all code from all sessions is merged into one KB. The --path filter in search provides soft project isolation.

Hook Concurrency

The hook script handles one event at a time (synchronous Python process). The SQLite backend may have write contention if multiple Claude Code sessions run simultaneously — this is documented as the primary reason to switch to PostgreSQL.

The _cached_backend module-level singleton reuses connection pools across hook invocations, which avoids the overhead of re-establishing connections on each Write/Edit event.

08

Ui Cli Surface

AI-AfterImage — UI and CLI Surface

CLI Binary: afterimage

Installed via pip install ai-afterimage. 15 subcommands:

afterimage setup                       # install hook, configure, download model
afterimage search "<query>"           # search KB
afterimage search "<query>" --path validators  # filter by file path
afterimage search "<query>" --json    # JSON output
afterimage ingest [-d <dir>] [-v]     # backfill transcripts
afterimage stats                       # KB entry count, size
afterimage recent                      # most recent KB entries
afterimage config                      # show config
afterimage export                      # export KB
afterimage clear                       # clear KB
afterimage uninstall                   # remove hook + config

# Churn commands (v0.3.0)
afterimage churn <file>               # file tier + edit count
afterimage churn <file> --functions   # function-level details
afterimage churn <file> --history     # full edit history
afterimage hotspots [--limit N]       # top N most churned
afterimage files --tier <tier>        # list by tier (gold/silver/bronze/red)

# Diagnostics
afterimage doctor                      # diagnose setup issues

No Web Dashboard

No web UI. All interaction is through the CLI or via hook-injected messages in Claude Code's output.

Hook Output (in Claude Code)

Context appears inline in Claude Code's tool response as a denial message. The agent reads it as part of the normal conversation flow before retrying the write. No separate panel or dashboard.

Installation Footprint

~/.afterimage/
├── afterimage.db       # SQLite knowledge base
├── config.yaml         # configuration
└── .seen_writes        # deny-once state (last 100 hashes)

~/.claude/
├── hooks/
│   └── afterimage_hook.py   # installed hook script
└── settings.json            # hook registration entry

Uninstall

afterimage uninstall   # removes hook from settings.json and ~/.claude/hooks/
                       # does NOT delete KB data (run afterimage clear first)

Doctor Command

afterimage doctor checks:

  • Hook is installed and registered in settings.json
  • Backend is accessible
  • Embedding model is downloaded
  • Python path is correct

Related frameworks

same archetype · same primary tool · same memory type

MemPalace ★ 53k

Verbatim local-first AI memory with 96.6% R@5 retrieval on LongMemEval using zero API calls — structured into a palace hierarchy…

Beads (Yegge) ★ 24k

Dolt-powered distributed graph issue tracker where AI agents track tasks with hierarchical IDs and dependency edges, claim work…

deepagents (LangChain) ★ 23k

Opinionated Python agent harness on top of LangGraph with sub-agents, filesystem, memory, and context compaction bundled in

agentmemory ★ 18k

Persistent, searchable memory for AI coding agents that captures every tool interaction, compresses it via LLM, and injects…

Open Multi-Agent ★ 6.3k

Give a natural-language goal to a coordinator agent and get a dynamically decomposed, parallelized task DAG executed by…

Basic Memory ★ 3.1k

Gives AI agents a persistent, human-readable knowledge graph of project decisions, observations, and relations stored as plain…