The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
feat: add memory persistence hooks and context files
Affaan Mustafaf96ef1e6ab35
diff --git a/contexts/dev.md b/contexts/dev.mdnew file mode 100644index 000000000..28b64ab26--- /dev/null+++ b/contexts/dev.md@@ -0,0 +1,20 @@+# Development Context++Mode: Active development+Focus: Implementation, coding, building features++## Behavior+- Write code first, explain after+- Prefer working solutions over perfect solutions+- Run tests after changes+- Keep commits atomic++## Priorities+1. Get it working+2. Get it right+3. Get it clean++## Tools to favor+- Edit, Write for code changes+- Bash for running tests/builds+- Grep, Glob for finding codediff --git a/contexts/research.md b/contexts/research.mdnew file mode 100644index 000000000..a29819484--- /dev/null+++ b/contexts/research.md@@ -0,0 +1,26 @@+# Research Context++Mode: Exploration, investigation, learning+Focus: Understanding before acting++## Behavior+- Read widely before concluding+- Ask clarifying questions+- Document findings as you go+- Don't write code until understanding is clear++## Research Process+1. Understand the question+2. Explore relevant code/docs+3. Form hypothesis+4. Verify with evidence+5. Summarize findings++## Tools to favor+- Read for understanding code+- Grep, Glob for finding patterns+- WebSearch, WebFetch for external docs+- Task with Explore agent for codebase questions++## Output+Findings first, recommendations seconddiff --git a/contexts/review.md b/contexts/review.mdnew file mode 100644index 000000000..fce643dff--- /dev/null+++ b/contexts/review.md@@ -0,0 +1,22 @@+# Code Review Context++Mode: PR review, code analysis+Focus: Quality, security, maintainability++## Behavior+- Read thoroughly before commenting+- Prioritize issues by severity (critical > high > medium > low)+- Suggest fixes, don't just point out problems+- Check for security vulnerabilities++## Review Checklist+- [ ] Logic errors+- [ ] Edge cases+- [ ] Error handling+- [ ] Security (injection, auth, secrets)+- [ ] Performance+- [ ] Readability+- [ ] Test coverage++## Output Format+Group findings by file, severity firstdiff --git a/hooks/memory-persistence/pre-compact.sh b/hooks/memory-persistence/pre-compact.shnew file mode 100755index 000000000..296fce9e1--- /dev/null+++ b/hooks/memory-persistence/pre-compact.sh@@ -0,0 +1,36 @@+#!/bin/bash+# PreCompact Hook - Save state before context compaction+#+# Runs before Claude compacts context, giving you a chance to+# preserve important state that might get lost in summarization.+#+# Hook config (in ~/.claude/settings.json):+# {+# "hooks": {+# "PreCompact": [{+# "matcher": "*",+# "hooks": [{+# "type": "command",+# "command": "~/.claude/hooks/memory-persistence/pre-compact.sh"+# }]+# }]+# }+# }++SESSIONS_DIR="${HOME}/.claude/sessions"+COMPACTION_LOG="${SESSIONS_DIR}/compaction-log.txt"++mkdir -p "$SESSIONS_DIR"++# Log compaction event with timestamp+echo "[$(date '+%Y-%m-%d %H:%M:%S')] Context compaction triggered" >> "$COMPACTION_LOG"++# If there's an active session file, note the compaction+ACTIVE_SESSION=$(ls -t "$SESSIONS_DIR"/*.tmp 2>/dev/null | head -1)+if [ -n "$ACTIVE_SESSION" ]; then+ echo "" >> "$ACTIVE_SESSION"+ echo "---" >> "$ACTIVE_SESSION"+ echo "**[Compaction occurred at $(date '+%H:%M')]** - Context was summarized" >> "$ACTIVE_SESSION"+fi++echo "[PreCompact] State saved before compaction" >&2diff --git a/hooks/memory-persistence/session-end.sh b/hooks/memory-persistence/session-end.shnew file mode 100755index 000000000..93b0f6370--- /dev/null+++ b/hooks/memory-persistence/session-end.sh@@ -0,0 +1,61 @@+#!/bin/bash+# Stop Hook (Session End) - Persist learnings when session ends+#+# Runs when Claude session ends. Creates/updates session log file+# with timestamp for continuity tracking.+#+# Hook config (in ~/.claude/settings.json):+# {+# "hooks": {+# "Stop": [{+# "matcher": "*",+# "hooks": [{+# "type": "command",+# "command": "~/.claude/hooks/memory-persistence/session-end.sh"+# }]+# }]+# }+# }++SESSIONS_DIR="${HOME}/.claude/sessions"+TODAY=$(date '+%Y-%m-%d')+SESSION_FILE="${SESSIONS_DIR}/${TODAY}-session.tmp"++mkdir -p "$SESSIONS_DIR"++# If session file exists for today, update the end time+if [ -f "$SESSION_FILE" ]; then+ # Update Last Updated timestamp+ sed -i '' "s/\*\*Last Updated:\*\*.*/\*\*Last Updated:\*\* $(date '+%H:%M')/" "$SESSION_FILE" 2>/dev/null || \+ sed -i "s/\*\*Last Updated:\*\*.*/\*\*Last Updated:\*\* $(date '+%H:%M')/" "$SESSION_FILE" 2>/dev/null+ echo "[SessionEnd] Updated session file: $SESSION_FILE" >&2+else+ # Create new session file with template+ cat > "$SESSION_FILE" << EOF+# Session: $(date '+%Y-%m-%d')+**Date:** $TODAY+**Started:** $(date '+%H:%M')+**Last Updated:** $(date '+%H:%M')++---++## Current State++[Session context goes here]++### Completed+- [ ]++### In Progress+- [ ]++### Notes for Next Session+-++### Context to Load+\`\`\`+[relevant files]+\`\`\`+EOF+ echo "[SessionEnd] Created session file: $SESSION_FILE" >&2+fidiff --git a/hooks/memory-persistence/session-start.sh b/hooks/memory-persistence/session-start.shnew file mode 100755index 000000000..57a8c1424--- /dev/null+++ b/hooks/memory-persistence/session-start.sh@@ -0,0 +1,37 @@+#!/bin/bash+# SessionStart Hook - Load previous context on new session+#+# Runs when a new Claude session starts. Checks for recent session+# files and notifies Claude of available context to load.+#+# Hook config (in ~/.claude/settings.json):+# {+# "hooks": {+# "SessionStart": [{+# "matcher": "*",+# "hooks": [{+# "type": "command",+# "command": "~/.claude/hooks/memory-persistence/session-start.sh"+# }]+# }]+# }+# }++SESSIONS_DIR="${HOME}/.claude/sessions"+LEARNED_DIR="${HOME}/.claude/skills/learned"++# Check for recent session files (last 7 days)+recent_sessions=$(find "$SESSIONS_DIR" -name "*.tmp" -mtime -7 2>/dev/null | wc -l | tr -d ' ')++if [ "$recent_sessions" -gt 0 ]; then+ latest=$(ls -t "$SESSIONS_DIR"/*.tmp 2>/dev/null | head -1)+ echo "[SessionStart] Found $recent_sessions recent session(s)" >&2+ echo "[SessionStart] Latest: $latest" >&2+fi++# Check for learned skills+learned_count=$(find "$LEARNED_DIR" -name "*.md" 2>/dev/null | wc -l | tr -d ' ')++if [ "$learned_count" -gt 0 ]; then+ echo "[SessionStart] $learned_count learned skill(s) available in $LEARNED_DIR" >&2+fi