claude-code-project-intelligence
CLAUDE.md9 starsChanged 10 months agoMITView on GitHub
Project Intelligence: a learning system for Claude Code built around three concepts — progressions (track evolving understanding of a topic), recall (search past sessions), and remember (store explicit preferences). Implemented entirely in Bash. Archives session transcripts, generates searchable summaries, and manages a Git-backed knowledge repo for cross-machine persistence. Also a Claude Code plugin (.claude-plugin/plugin.json). Tests create temp databases in /tmp and clean up via trap. Most tests don't need ANTHROPIC_API_KEY — they either use --no-summary or mock the API. Everything…
- Reads credentials
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
We split this CLAUDE.md into the rules it gives an agent
8 rules. About 0 are common, 0 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 51
Everything is Bash: No package manager, no build step.
- Very specific: line 89
Every lib/*.sh module sources config.sh as its first action
- Very specific: line 91
Never call
sqlite3directly: Use the wrappers in db.sh: - Very specific: line 96
SQL string escaping: Use episodic_sql_escape "$value" (defined in db.sh).
- Very specific: line 97
FTS5 query escaping: Use episodic_fts5_escape "$user_input" (defined in db.sh) before passing user input to FTS5 MATCH.
- Very specific: line 101
Use sha256sum with shasum -a 256 fallback (Linux vs macOS)
- Very specific: line 102
Use sed with temp file instead of sed -i '' (macOS-only flag)
- Very specific: line 103
Use stat -c%s (Linux) vs stat -f%z (macOS) for file sizes
≈ “Common” is an estimate: at least 1 in 5 of the 28,633 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
What This Is
Project Intelligence: a learning system for Claude Code built around three concepts — progressions (track evolving understanding of a topic), recall (search past sessions), and remember (store explicit preferences). Implemented entirely in Bash. Archives session transcripts, generates searchable summaries, and manages a Git-backed knowledge repo for cross-machine persistence. Also a Claude Code plugin (.claude-plugin/plugin.json).
Development Commands
# Run all tests (8 core suites)
./tests/run-all.sh
# Run a single test suite
./tests/test-init.sh # DB schema + idempotency
./tests/test-archive.sh # Session archival + dedup
./tests/test-query.sh # FTS5 search + BM25 ranking
./tests/test-roundtrip.sh # Full capture -> store -> retrieve cycle
./tests/test-knowledge.sh # Knowledge repo git operations
./tests/test-index.sh # Document indexing + search
./tests/test-project-name.sh # Project name derivation from paths
./tests/test-progression-search.sh # Progression cross-project FTS5 search
# Run individual regression tests (not in run-all.sh)
./tests/test-busy-timeout.sh # SQLite busy_timeout wrappers
./tests/test-git-lockfile.sh # Knowledge repo lockfile mechanism
./tests/test-sql-escape.sh # Centralized SQL escaping
./tests/test-large-text-sql.sh # Large text handling via temp files
./tests/test-config-defaults.sh # Config centralization
./tests/test-content-hash.sh # sha256sum/shasum portability
./tests/test-schema-consistency.sh # No duplicate schema definitions
./tests/test-sql-escape-context.sh # SQL escaping in episodic-context
./tests/test-knowledge-init-env.sh # sed portability in knowledge init
./tests/test-archive-retry.sh # Failed summaries leave retryable state
./tests/test-fts5-escape.sh # FTS5 MATCH injection prevention
./tests/test-insert-session-escape.sh # SQL escaping in session inserts
./tests/test-git-conflict-safety.sh # Git rebase conflict marker detection
# Install (sets up hooks, DB)
./install.sh
# Uninstall (removes hooks, symlinks)
./uninstall.shTests create temp databases in /tmp and clean up via trap. Most tests don't need ANTHROPIC_API_KEY — they either use --no-summary or mock the API.
Architecture
Everything is Bash. No package manager, no build step. Dependencies: sqlite3, curl, jq, git.
Three Concepts
- Progressions (
/progress): Track evolving understanding of a topic as a sequence of documents (baseline, deepenings, corrections, pivots). Stored in the knowledge repo per-project. Supports cross-project progressions via--projectoverride and_globalnamespace. Searchable via FTS5. - Recall (
/recall): Full-text search across all archived sessions. BM25-ranked results from the SQLite FTS5 index. - Remember (
/remember): Explicit user preferences stored in_user/preferences.mdin the knowledge repo. Injected into every session. Add/list/remove directives with dedup and symlink protection.
Core Data Flow
- Stop hook (
hooks/on-stop.sh): Quick metadata-only archive of current session (no API call), pushes knowledge repo changes - SessionStart hook (
hooks/on-session-start.sh): Background tasks (git pull knowledge, archive previous session with full summary, index documents) + foreground context injection - Archive (
bin/pi-archive): Parses JSONL -> extracts metadata (lib/extract.sh) -> calls Anthropic API for structured summary (lib/summarize.sh) -> stores in SQLite (lib/db.sh) -> copies raw JSONL to archive dir - Context injection (
bin/pi-context): Outputs recent sessions, preferences, and active progressions as markdown for the current project
Three Storage Layers
- SQLite FTS5 (
~/.claude/memory/episodic.db): Local cache, fully regenerable. Tables:sessions,summaries,sessions_fts,documents,documents_fts,synthesis_log,archive_log - JSONL archives (configurable dir): Raw session transcripts, lossless copies
- Knowledge repo (separate Git repo at
~/.claude/knowledge/): Source of truth. Per-project dirs withprogressions/. Global_user/preferences.mdfor cross-project preferences.
Library Modules (lib/)
config.sh— Single source of truth for all defaults. Paths, model IDs, thresholds — all as env-var-overridable variables. Sourced by every other module. Supports.envlocal overrides. No other module should redeclare defaults.db.sh— SQLite schema init (idempotent), CRUD, FTS5 search. All SQLite access goes through wrapper functions (see Key Patterns below).extract.sh— JSONL parsing. Filters out progress/snapshot events, extracts user+assistant messages for summarization.summarize.sh— Anthropic API call (supports extended thinking). Sends extracted transcript, gets structured JSON summary.knowledge.sh— Git operations for the knowledge repo (clone, pull, push, conflict handling). All git operations serialized via lockfile.progression.sh— Progression tracking. Topic slug generation, YAML metadata management, document sequencing (init/add/conclude/status/search). Supports cross-project search and_globalnamespace.index.sh— Document text extraction (format-aware: direct read, pdftotext, html-strip, textutil/pandoc for docx) + FTS5 indexing with SHA-256 change detection. Schema is owned bydb.sh— this module delegatesepisodic_db_init.activity.sh— Activity tracking for session context.
Archive Directory
The archive/ directory contains code for removed features (synthesize, deep-dive, patterns, checkpoints, save-skill). Kept for reference but not active.
Key Patterns
- Every
lib/*.shmodule sourcesconfig.shas its first action bin/*scripts are the CLI entry points; they source neededlib/modules- Never call
sqlite3directly. Use the wrappers indb.sh:episodic_db_exec <sql> [db]— single statement with busy_timeoutepisodic_db_query_json <sql> [db]— single statement returning JSONepisodic_db_exec_multi <db> <<'SQL'— multi-statement heredoc with busy_timeout- For temp-file based SQL (large text), prepend
.timeout ${EPISODIC_BUSY_TIMEOUT}in the file and usesqlite3 "$db" < "$sql_file"
- SQL string escaping: Use
episodic_sql_escape "$value"(defined indb.sh). Never use inline${var//\'/\'\'}. - FTS5 query escaping: Use
episodic_fts5_escape "$user_input"(defined indb.sh) before passing user input to FTS5 MATCH. It wraps each token in double quotes to neutralize FTS5 operators (OR, AND, NOT, NEAR,*,:). Apply FTS5 escape first, then SQL escape:query=$(episodic_sql_escape "$(episodic_fts5_escape "$input")"). - Large text in SQL: For inserts with potentially large text (summaries, extracted document text), write SQL to a temp file via
printfinstead of using heredoc expansion. Usetrap 'rm -f "$sql_file"' RETURNfor cleanup. Seeepisodic_db_insert_summaryandepisodic_index_filefor examples. - Knowledge repo locking:
episodic_knowledge_lock/episodic_knowledge_unlockinknowledge.shserialize concurrent git operations usingmkdir-based atomic locks with PID stale detection. - Cross-platform portability:
- Use
sha256sumwithshasum -a 256fallback (Linux vs macOS) - Use
sedwith temp file instead ofsed -i ''(macOS-only flag) - Use
stat -c%s(Linux) vsstat -f%z(macOS) for file sizes
- Use
- SQLite busy timeout:
EPISODIC_BUSY_TIMEOUT(default 5000ms) is set indb.sh, notconfig.sh. All db wrappers apply it automatically. For rawsqlite3calls via temp files, prepend.timeout ${EPISODIC_BUSY_TIMEOUT}. - FTS5 virtual tables need special CREATE handling (check
sqlite_masterfirst) - Schema is defined once in
episodic_db_initindb.sh— no other module should define tables - Tests override
EPISODIC_DB,EPISODIC_LOG, andEPISODIC_ARCHIVE_DIRto temp paths and usetrap cleanup EXIT - The
config.shmodel IDs in the README may differ from actualconfig.shdefaults —config.shis the source of truth
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

