---
name: context-mode
description: Query, list, inspect and purge entries stored by the Context Mode hook (PostToolUse intercept of verbose outputs). Requires --with-context-mode to have been run at install time.
context: fork
---

# Context Mode

The Context Mode hook intercepts verbose tool outputs (> ~2K tokens) and stores them in a local SQLite database, returning a compact pointer `[context-mode#<id>]` instead. This skill lets you retrieve, inspect, and manage those stored entries.

**Database**: `~/.claude/state/context-mode.sqlite`
**Requires**: `sqlite3` (standard on macOS/Linux) + Context Mode hook installed (`./install.sh --with-context-mode`)

---

## Commands

### `/context-mode query <id>`

Retrieve the full content of an intercepted output.

```bash
sqlite3 ~/.claude/state/context-mode.sqlite \
  "SELECT tool, byte_size, created_at, content FROM entries WHERE id='<id>';"
```

Display format:
```
tool      : Bash
size      : 42 183 bytes (~10 500 tokens)
captured  : 2026-04-29 14:32:07
---
[full content]
```

---

### `/context-mode list [--limit N] [--tool <name>]`

List recent intercepted entries (default: last 10).

```bash
# All recent entries
sqlite3 -column -header ~/.claude/state/context-mode.sqlite \
  "SELECT id, tool, byte_size, substr(created_at,1,16) as ts
   FROM entries ORDER BY created_at DESC LIMIT 10;"

# Filter by tool
sqlite3 -column -header ~/.claude/state/context-mode.sqlite \
  "SELECT id, tool, byte_size, substr(created_at,1,16) as ts
   FROM entries WHERE tool LIKE '%Bash%'
   ORDER BY created_at DESC LIMIT 10;"
```

Display format:
```
id          tool   byte_size  ts
----------  -----  ---------  ----------------
a1b2c3d4    Bash   42183      2026-04-29 14:32
e5f6g7h8    Bash   18940      2026-04-29 13:11
```

---

### `/context-mode stats`

Show aggregate statistics for the stored entries.

```bash
sqlite3 ~/.claude/state/context-mode.sqlite "
SELECT
  COUNT(*)                              AS total_entries,
  SUM(byte_size)                        AS total_bytes,
  ROUND(SUM(byte_size) / 4.0 / 1000,1) AS tokens_saved_k,
  ROUND(SUM(byte_size) / 4.0 / 1000000 * 15, 2) AS usd_saved_est
FROM entries;
"

sqlite3 -column -header ~/.claude/state/context-mode.sqlite "
SELECT tool, COUNT(*) as hits, SUM(byte_size) as bytes
FROM entries GROUP BY tool ORDER BY bytes DESC;
"
```

Display format:
```
Total entries   : 38
Total bytes     : 1 842 300
Tokens saved    : ~460.5k
Cost saved (est): ~$6.91

By tool:
Bash            : 31 hits  (1 540 200 bytes)
mcp__github__*  :  7 hits  (  302 100 bytes)
```

---

### `/context-mode purge [--older-than <N>d] [--all]`

Delete stored entries to free disk space.

```bash
# Purge entries older than 7 days (default)
sqlite3 ~/.claude/state/context-mode.sqlite \
  "DELETE FROM entries WHERE datetime(created_at) < datetime('now', '-7 days'); VACUUM;"

# Purge entries older than N days
sqlite3 ~/.claude/state/context-mode.sqlite \
  "DELETE FROM entries WHERE datetime(created_at) < datetime('now', '-<N> days'); VACUUM;"

# Purge everything
sqlite3 ~/.claude/state/context-mode.sqlite "DELETE FROM entries; VACUUM;"
```

Always confirm before `--all`:
```
⚠️  Purge ALL context-mode entries? This cannot be undone.
Entries: <N>  |  Total size: <X> bytes
Type "yes" to confirm:
```

---

## Schema reference

```sql
CREATE TABLE IF NOT EXISTS entries (
  id         TEXT PRIMARY KEY,
  tool       TEXT,
  byte_size  INTEGER,
  content    TEXT,
  created_at TEXT DEFAULT (datetime('now'))
);
```

## Tips

- `[context-mode#<id>]` pointers in the conversation → use `query <id>` to expand inline
- Run `stats` after a long session to see cumulative savings
- `purge --older-than 30d` as a monthly hygiene routine (automate via `2b3` Phase 3)
- If the DB grows large: `purge --older-than 7d` + `VACUUM` reclaims disk space
