|
| 1 | +# Getting Started with StackMemory |
| 2 | + |
| 3 | +This guide walks you from zero to a fully working StackMemory setup in under 5 minutes. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- **Node.js 20+** (`node --version` to check) |
| 8 | +- **Claude Code**, **Codex**, or **OpenCode** installed |
| 9 | +- macOS, Linux, or WSL |
| 10 | + |
| 11 | +## Step 1: Install |
| 12 | + |
| 13 | +```bash |
| 14 | +npm install -g @stackmemoryai/stackmemory |
| 15 | +``` |
| 16 | + |
| 17 | +This installs the `stackmemory` CLI and wrapper scripts (`claude-sm`, `codex-sm`, `opencode-sm`). |
| 18 | + |
| 19 | +## Step 2: Initialize your project |
| 20 | + |
| 21 | +```bash |
| 22 | +cd your-project |
| 23 | +stackmemory init |
| 24 | +``` |
| 25 | + |
| 26 | +This creates a `.stackmemory/` directory with: |
| 27 | +- SQLite database for context storage |
| 28 | +- FTS5 full-text search index |
| 29 | +- Default configuration |
| 30 | + |
| 31 | +Add `.stackmemory/` to your `.gitignore` — it's local state, not shared. |
| 32 | + |
| 33 | +## Step 3: Connect to your editor |
| 34 | + |
| 35 | +```bash |
| 36 | +stackmemory setup-mcp |
| 37 | +``` |
| 38 | + |
| 39 | +This configures Claude Code's MCP settings to connect to StackMemory. After running this, **restart Claude Code**. |
| 40 | + |
| 41 | +## Step 4: Verify |
| 42 | + |
| 43 | +```bash |
| 44 | +stackmemory doctor |
| 45 | +``` |
| 46 | + |
| 47 | +You should see all green checkmarks. If anything fails, the doctor output will tell you what to fix. |
| 48 | + |
| 49 | +## Your first session |
| 50 | + |
| 51 | +### Using wrapper scripts (recommended) |
| 52 | + |
| 53 | +```bash |
| 54 | +claude-sm # Claude Code with StackMemory context auto-loaded |
| 55 | +``` |
| 56 | + |
| 57 | +The wrapper script: |
| 58 | +1. Loads your existing StackMemory context into the session |
| 59 | +2. Starts the Prompt Forge optimizer (watches CLAUDE.md for improvements) |
| 60 | +3. Runs Claude Code normally |
| 61 | + |
| 62 | +### Using MCP tools directly |
| 63 | + |
| 64 | +In Claude Code, StackMemory tools are available immediately: |
| 65 | + |
| 66 | +``` |
| 67 | +> Use get_context to see what I was working on last session |
| 68 | +
|
| 69 | +> Use add_decision to record: "Using PostgreSQL for the user service" |
| 70 | +
|
| 71 | +> Use start_frame to begin work on "Implement auth middleware" |
| 72 | +``` |
| 73 | + |
| 74 | +## How context survives sessions |
| 75 | + |
| 76 | +1. During your session, StackMemory records events, decisions, and anchors |
| 77 | +2. When you run `/clear` or close the session, hooks automatically save context |
| 78 | +3. Next session, `get_context` retrieves everything — decisions, constraints, progress |
| 79 | +4. You never re-explain context to your AI coding tool again |
| 80 | + |
| 81 | +## Key commands |
| 82 | + |
| 83 | +| Command | What it does | |
| 84 | +|---------|-------------| |
| 85 | +| `stackmemory init` | Initialize StackMemory in a project | |
| 86 | +| `stackmemory setup-mcp` | Configure Claude Code MCP connection | |
| 87 | +| `stackmemory doctor` | Verify installation health | |
| 88 | +| `stackmemory capture` | Save current session state | |
| 89 | +| `stackmemory restore` | Restore from a captured state | |
| 90 | +| `stackmemory daemon start` | Start the memory monitor daemon | |
| 91 | +| `stackmemory hooks install` | Install Claude Code hooks | |
| 92 | + |
| 93 | +## Key MCP tools |
| 94 | + |
| 95 | +| Tool | What it does | |
| 96 | +|------|-------------| |
| 97 | +| `get_context` | Retrieve project context and active frame | |
| 98 | +| `add_decision` | Record a decision or constraint | |
| 99 | +| `start_frame` | Begin a new scoped unit of work | |
| 100 | +| `close_frame` | Complete and summarize current work | |
| 101 | +| `sm_search` | Search across all context | |
| 102 | +| `cord_spawn` | Create a subtask with clean context | |
| 103 | + |
| 104 | +## Optional: Linear integration |
| 105 | + |
| 106 | +```bash |
| 107 | +# Set your Linear API key |
| 108 | +echo "LINEAR_API_KEY=lin_api_..." >> .env |
| 109 | + |
| 110 | +# Sync tasks |
| 111 | +stackmemory linear:sync |
| 112 | +``` |
| 113 | + |
| 114 | +Tasks flow bidirectionally between Linear and your coding sessions. |
| 115 | + |
| 116 | +## Optional: Hooks |
| 117 | + |
| 118 | +StackMemory can install Claude Code hooks that run automatically: |
| 119 | + |
| 120 | +```bash |
| 121 | +stackmemory hooks install |
| 122 | +``` |
| 123 | + |
| 124 | +Hooks handle: |
| 125 | +- Auto-saving context on `/clear` |
| 126 | +- Task completion tracking |
| 127 | +- Linear sync on task done |
| 128 | +- PROMPT_PLAN progress updates |
| 129 | + |
| 130 | +## Next steps |
| 131 | + |
| 132 | +- Read the [CLI Reference](./cli.md) for all commands |
| 133 | +- Explore the [Architecture](./architecture.md) to understand the call stack model |
| 134 | +- Check the [MCP Tools Reference](./MCP_TOOLS.md) for all 32 tools |
0 commit comments