
## Session State Protocol (Wayfind)

**Memory system:** Hierarchical plain-markdown files. No CLI tools, no databases.

**Important:** Claude Code has its own auto-memory system that writes to `~/.claude/projects/<project>/memory/MEMORY.md`. Wayfind's memory files live in a separate `wayfind/` subfolder to avoid conflicts. Do NOT write Wayfind state files to the root memory directory — that's Claude Code's native auto-memory space.

### File Hierarchy

```
~/.claude/
  global-state.md          # Thin index — ALWAYS load at session start
  state.md                 # Admin/non-repo work
  memory/                  # Cross-repo topic files — load on demand
    <topic>.md
    journal/YYYY-MM-DD.md  # Daily work log

<repo>/.claude/
  team-state.md            # Shared team context — committed to git
  personal-state.md        # Personal context — gitignored
```

### Session Start (REQUIRED)

1. Read `~/.claude/global-state.md`
2. Read `.claude/team-state.md` (shared team context) and `.claude/personal-state.md` (your personal context) in the current repo, if they exist. Fall back to `.claude/state.md` for older repos not yet migrated. (Or `~/.claude/state.md` if in home dir.)
3. Check the Memory Files table in global-state.md — load any `~/.claude/memory/` files whose keywords match this session's topic
4. Summarize current state, then ask: **"What's the goal for this session? What does success look like?"**

### Using the Wayfind MCP Server

The `search_context` MCP tool is the right way to answer questions about past decisions, architectural choices, and team activity. **Do not read state files or repo files to answer these questions** — the content store covers the entire team's decision history across all repos and all engineers, which state files cannot.

Use `search_context` when asked about:
- What was decided about X
- What work has been done on X
- What the team's approach to X is
- Recent activity in a repo or area

State files (`team-state.md`, `personal-state.md`) are for **current status** — who's working on what right now. The content store is for **decision history** — what was decided and why.

### Mid-Session

If work drifts from the stated goal, flag it: *"Quick check — we set out to [goal]. This feels like [tangent]. Stay the course or pivot?"*

### Session End (on "stop" / "done" / "pause" / "tomorrow")

1. Update `.claude/team-state.md` with shared changes and `.claude/personal-state.md` with personal changes. (For older repos not yet migrated, update `.claude/state.md` as before.)
2. Do NOT update `~/.claude/global-state.md` — its Active Projects table is rebuilt automatically by `wayfind status`.
3. Create/update topic files in `~/.claude/memory/` for significant new cross-repo context
4. Append to `~/.claude/memory/journal/YYYY-MM-DD.md`:
   ```
   ## [Repo] — [Title]
   **Why:** [Stated goal]
   **What:** [What was done]
   **Outcome:** [Did we hit it?]
   **On track?:** [Focused or drift?]
   **Lessons:** [Cross-session learnings]
   ```
5. Confirm: **"State saved. Say 'let's continue' next time."**

### Rules

- **NEVER write secrets, API keys, tokens, passwords, or credentials into memory or state files.** Store a pointer to where the secret lives (e.g., "API key is in `~/.config/myapp/.env`"), not the secret itself. Memory files are plain text, may be synced to git, and are readable by any tool with filesystem access.
- Keep `global-state.md` under 80 lines. Detail goes in `~/.claude/memory/` files.
- Per-repo `state.md` stays focused on that repo only.
- New cross-repo topics get new files in `~/.claude/memory/`, not appended to global-state.md.
- Do NOT write Wayfind files to `~/.claude/projects/<project>/memory/` root — that's Claude Code's native auto-memory space.
- Do NOT use external memory databases or CLI tools for state storage. Use plain markdown files only.
