From claude-commands
Searches and displays Claude Code project memories and conversation history from ~/.claude/projects using optional query or recent browse mode. Resilient via Python permission fallbacks.
npx claudepluginhub jleechanorg/claude-commands --plugin claude-commandscommands/## β‘ EXECUTION INSTRUCTIONS FOR CLAUDE **When this command is invoked, YOU (Claude) must execute these steps immediately:** **This is NOT documentation - these are COMMANDS to execute right now.** **Use TodoWrite to track progress through multi-phase workflows.** ## π¨ EXECUTION WORKFLOW ### Phase 0: Claude Auto-Memory Read **Action Steps:** 1. **Discover memory files**: Use Python to find all project memory files: 2. **If search query provided**: Filter memory files by keyword match against file content; surface matching memories 3. **If no query (browse mode)**: Read MEMORY.md inde...
/search-sessionsSearches past Claude Code and OpenClaw session history by metadata (default, instant) or full message content (--deep), listing matches with project, date, summary, and UUID for resuming. Supports --limit N, --project FILTER, --openclaw, --agent NAME.
/search-historianSearches past Claude conversation history for solutions, decisions, and context matching a query. Retrieves up to 5 relevant results via historian MCP.
/restore-historyRestores past Claude Code and Codex session transcripts to Obsidian vault as structured documents. Supports scopes: recent N, date range, current/all projects, resume.
/contextSearches project and global memories by keyword with smart expansion to related terms (e.g., authβJWT/OAuth, dbβPrisma/PostgreSQL), displaying matching key-value entries.
/searchSearches CORE memory for past conversations, user preferences, project context, and decisions using a provided query. Displays relevant episodes, facts, and timestamps.
/historyQueries past Claude Octopus workflow runs from local run-log.jsonl, showing last N or filtered by workflow type, date, provider; supports stats and experiments.
Share bugs, ideas, or general feedback.
When this command is invoked, YOU (Claude) must execute these steps immediately: This is NOT documentation - these are COMMANDS to execute right now. Use TodoWrite to track progress through multi-phase workflows.
Action Steps:
import glob, os, subprocess
try:
git_root = subprocess.check_output(['git', 'rev-parse', '--show-toplevel'], text=True).strip()
project_key = git_root.replace('/', '-') # preserve leading dash: /Users/... β -Users-...
pattern = os.path.expanduser(f'~/.claude/projects/{project_key}/memory/*.md')
index_pattern = os.path.expanduser(f'~/.claude/projects/{project_key}/memory/MEMORY.md')
memory_files = [f for f in glob.glob(pattern) if not f.endswith('MEMORY.md')]
memory_index = glob.glob(index_pattern)[:1]
except Exception:
memory_files = [] # skip if not in a git repo β no cross-project fallback
memory_index = []
Action Steps:
glob.glob(os.path.expanduser('~/.claude/projects/*/*.jsonl'))The /history command is designed to be 100% reliable regardless of file permission configurations.
Usage: /history [search_query] [--options]
Purpose: Search through Claude Code CLI conversation history stored in ~/.claude/projects using intelligent execution optimization and multiple search strategies.
MANDATORY: If you encounter ANY permission issues while accessing ~/.claude/projects/, immediately use Python to read the files:
This command is designed to be resilient to permission issues by automatically falling back to Python-based file operations.
/history uses /execute for intelligent workflow optimization as requested by the user.
Composition Pattern: This command delegates to /execute which provides:
# Basic keyword search
/history "git merge conflicts"
# Search with date filter
/history "database migration" --date "2025-08-01"
# Search specific project
/history "authentication bug" --project "your-project.com"
# Search by command type
/history --type "tool_use" --keyword "pytest"
# Complex search with multiple filters
/history "performance issue" --date "2025-08" --project "worldarchitect" --limit 10
# Search by git branch
/history "feature branch" --branch "dev1754"
# Fuzzy search for typos
/history "databse migratoin" --fuzzy
# Recent conversations only
/history "latest deployment" --recent 7 # last 7 days
--fuzzy flag for handling typos and variations--date "YYYY-MM-DD" - Exact date match--date "YYYY-MM" - Month match--after "YYYY-MM-DD" - After specific date--before "YYYY-MM-DD" - Before specific date--recent N - Last N days--project "name" - Filter by project directory path--cwd "/path" - Filter by working directory--branch "branch-name" - Filter by git branch--type "user|assistant|summary|tool_use" - Filter by message type (including tool executions)--user-type "external" - Filter by user type--has-tools - Convenience flag equivalent to --type "tool_use" or messages with tool activity--has-errors - Messages with error indicators--limit N - Maximum results (default: 20)--context N - Lines of context around matches (default: 2)--format "json|text|table" - Output format (default: text)--files-only - Show only matching file names1. Parse search query and extract filters
2. Discover candidate files based on project/date filters
3. For each file (in parallel):
- Stream parse JSONL line by line
- Pre-filter by metadata (timestamp, cwd, branch)
- Apply text search to message content
- Collect matches with context
4. Aggregate, rank, and format results
5. Apply output limits and formatting
Based on research of ~/.claude/projects structure:
Directory Structure:
~/.claude/projects/
βββ -home-$USER-projects-worldarchitect-ai/
β βββ uuid1.jsonl
β βββ uuid2.jsonl
β βββ ...
βββ -home-$USER-projects-other-project/
βββ ...
Note on naming: project directories are sanitized absolute paths where / is replaced with - (e.g., /home/$USER/projects/your-project.com β -home-$USER-projects-worldarchitect-ai). On Windows, backslashes \ are normalized similarly.
JSONL Format (per conversation file):
{"type":"summary","summary":"Conversation summary","leafUuid":"uuid"}
{"parentUuid":null,"userType":"external","cwd":"/path","sessionId":"uuid","version":"1.0.67","gitBranch":"main","type":"user","message":{"role":"user","content":"user message"},"uuid":"uuid","timestamp":"2025-08-09T..."}
{"parentUuid":"uuid","type":"assistant","message":{"role":"assistant","content":"assistant response"},"uuid":"uuid","timestamp":"2025-08-09T..."}
Detection rules:
type:"tool_use" or message.toolCalls/toolUse present.error:true at top-level, or message.level in {"error","fatal"}, or message.content containing standardized error markers.
Document any repository-specific variations here to keep the filters accurate./executeThe /history command delegates its execution to /execute with a comprehensive task description that includes secure file access and robust permission handling:
/execute Search through Claude Code CLI conversation history with robust file access:
- Query: [user_search_query]
- Filters: [parsed_filter_options]
- Strategy: Python-first file access with permission error handling
- Primary Access: Use Python subprocess with explicit file operations
- Fallback Strategy: If permission denied or file access fails, ALWAYS use Python3 directly
- File Discovery: python3 -c "import glob, os; print('\n'.join(glob.glob(os.path.expanduser('~/.claude/projects/*/*.jsonl'))))"
- Content Reading: Use Python Read tool or Python subprocess to read JSONL files
- Permission Recovery: On ANY permission error, immediately switch to Python-based file operations
- Error Handling: Explicit fallback instructions - "Use Python to read files if you encounter permission issues"
- Algorithm: Python file discovery β JSONL parsing β Text search β Context extraction β Results formatting
- Output: Formatted search results with conversation context
CRITICAL PERMISSION HANDLING PROTOCOL: If Claude encounters ANY of the following issues:
python3 -c "import os; os.listdir(os.path.expanduser('~/.claude/projects'))"Python Fallback Commands:
# Directory listing
python3 -c "import os; print('\n'.join(os.listdir(os.path.expanduser('~/.claude/projects'))))"
# File discovery
python3 -c "import glob, os; print('\n'.join(glob.glob(os.path.expanduser('~/.claude/projects/*/*.jsonl'))))"
# File content reading (single line executable)
python3 -c "import json,sys; [print(json.dumps(json.loads(l)) if l.strip() else '') for l in open(sys.argv[1])]" ~/.claude/projects/-home-user-projects-worldarchitect-ai/uuid.jsonl
# File content reading (with error handling)
python3 -c "import json,sys; exec('for l in open(sys.argv[1]):\\n try:\\n print(json.dumps(json.loads(l)))\\n except: print(f\"Parse error: {l.strip()}\", file=sys.stderr)')" ~/.claude/projects/-home-user-projects-worldarchitect-ai/uuid.jsonl
This allows /execute to:
=== Conversation History Search Results ===
Query: "git merge conflicts"
Found: 3 matches in 2 conversations
π your-project.com | π
2025-08-01 | πΏ dev1754132318
π¬ "I need help resolving git merge conflicts in the authentication module..."
Context: Discussion about merge strategy and conflict resolution tools
File: 7859c820-1ba2-41c5-9db1-22c6814455e6.jsonl
π your-project.com | π
2025-07-28 | πΏ main
π¬ "The git merge created conflicts in package.json..."
Context: Package dependency conflicts during feature merge
File: a1b2c3d4-e5f6-7890-abcd-ef1234567890.jsonl
--format json){
"query": "git merge conflicts",
"total_matches": 3,
"total_files": 2,
"results": [
{
"conversation_id": "7859c820-1ba2-41c5-9db1-22c6814455e6",
"project": "your-project.com",
"date": "2025-08-01",
"branch": "dev1754132318",
"match": {
"message": "I need help resolving git merge conflicts...",
"context": ["Previous message...", "Matched message", "Next message..."],
"timestamp": "2025-08-01T11:00:11.845Z"
}
}
]
}
--format table)Query: git merge conflicts | Matches: 3 | Files: 2
ββββββββββββββββββββββββ¬ββββββββββββββββ¬βββββββββββββββ¬ββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β conversation_id β project β date β branch β message_snippet β
ββββββββββββββββββββββββΌββββββββββββββββΌβββββββββββββββΌββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ€
β 7859c820-...-55e6 β worldarchitectβ 2025-08-01 β dev1754132318 β I need help resolving git merge ... β
β a1b2c3d4-...-7890 β worldarchitectβ 2025-07-28 β main β The git merge created conflicts ... β
ββββββββββββββββββββββββ΄ββββββββββββββββ΄βββββββββββββββ΄ββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββ
~/.claude/projects doesn't exist - use Python to check with os.path.exists()The command uses secure direct access to ~/.claude/projects/ directory, avoiding symlink vulnerabilities while maintaining search functionality within the project workspace.
Search patterns and frequently accessed conversations can be cached in Memory MCP for faster repeated searches.
Can be combined with other commands:
/history "database issue" | /learn # Learn from historical database solutions
/history "deployment error" | /debug # Debug with historical context
# Find all tool usage in August 2025
/history --type "tool_use" --date "2025-08" --format table
# Search for authentication-related conversations in specific project
/history "auth login password" --project "worldarchitect" --limit 5
# Find recent error discussions
/history "error exception failed" --recent 14 --has-tools
# Fuzzy search with context
/history "databse migratoin problm" --fuzzy --context 5
# Find conversations about specific files
/history "main.py" --project "worldarchitect" --format json
This command provides comprehensive conversation history search capabilities while leveraging /execute for intelligent performance optimization as requested.