---
name: search-past-chats
description: Search past Claude Code conversation history when user asks about previous sessions, mentions "history", "past chats", "did we discuss", "what did we talk about", "show me more from that session", or wants to recall something from earlier conversations.
---

# Search Past Chats Skill

Search through past Claude Code sessions for this project using keyword or regex patterns, and retrieve full context from specific sessions.

## When to Use This Skill

Activate when the user:
- Asks about previous conversations or sessions
- Wants to find something discussed before
- References past work without specifics ("that thing we did")
- Asks "did we talk about X before?" or "what was that about Y?"
- Mentions searching chat history or past chats
- Asks for more context from a session found in search results
- Wants to see the full conversation around a specific topic

## Tool 1: Search Sessions

Find sessions matching a keyword or pattern.

```bash
node "${CLAUDE_PLUGIN_ROOT}/scripts/search-history.js" "<query>" [options]
```

### Search Options

| Option | Description | Example |
|--------|-------------|---------|
| `--regex` | Use regex pattern | `--regex "error.*handler"` |
| `--limit N` | Max results (default: 10) | `--limit 5` |
| `--after YYYY-MM-DD` | Sessions after date | `--after 2026-01-01` |
| `--before YYYY-MM-DD` | Sessions before date | `--before 2026-01-15` |
| `--include-assistant` | Search Claude's responses too | `--include-assistant` |
| `--context N` | Show N messages around match | `--context 2` |

### Search Examples

```bash
# Basic search
node "${CLAUDE_PLUGIN_ROOT}/scripts/search-history.js" "authentication"

# Search with date filter
node "${CLAUDE_PLUGIN_ROOT}/scripts/search-history.js" --after 2026-01-01 "mcp"

# Search including Claude's responses
node "${CLAUDE_PLUGIN_ROOT}/scripts/search-history.js" --include-assistant "error handling"

# Show context around matches
node "${CLAUDE_PLUGIN_ROOT}/scripts/search-history.js" --context 2 "database schema"

# Regex search
node "${CLAUDE_PLUGIN_ROOT}/scripts/search-history.js" --regex "api.*token"
```

### Search Output

Returns matching sessions with:
- Session date and title
- Session ID (use with get-session for more context)
- Matching excerpts (marked [A] for assistant responses)
- Match count

## Tool 2: Get Session Context

Retrieve full messages from a specific session by ID.

```bash
node "${CLAUDE_PLUGIN_ROOT}/scripts/get-session.js" <session-id> [options]
```

### Get-Session Options

| Option | Description | Default |
|--------|-------------|---------|
| `--around "text"` | Center on message containing text | - |
| `--context N` | Messages before/after with --around | 10 |
| `--offset N` | Start from message N | 0 |
| `--limit N` | Max messages to return | 20 |

### Get-Session Examples

```bash
# Get first 20 messages from session
node "${CLAUDE_PLUGIN_ROOT}/scripts/get-session.js" abc123-def456

# Get context around specific content
node "${CLAUDE_PLUGIN_ROOT}/scripts/get-session.js" abc123 --around "authentication" --context 5

# Paginate through session
node "${CLAUDE_PLUGIN_ROOT}/scripts/get-session.js" abc123 --offset 20 --limit 20
```

## Workflow

1. **Search first**: Use search-history.js to find relevant sessions
2. **Note the session ID**: Search results include session IDs
3. **Get more context**: Use get-session.js with the ID to see full conversation

Example:
```bash
# 1. Search finds session "abc123..." discussing authentication
node "${CLAUDE_PLUGIN_ROOT}/scripts/search-history.js" "authentication"

# 2. Get full context from that session
node "${CLAUDE_PLUGIN_ROOT}/scripts/get-session.js" abc123 --around "authentication" --context 10
```

## Best Practices

1. Start with broad keywords, then narrow down
2. Use `--include-assistant` when you need Claude's explanations too
3. Use `--context` to see conversation flow around matches
4. Use get-session with `--around` to jump directly to relevant content
5. Present findings concisely - offer to show more if needed
