npm package: @mnemonik/scanner
Description: Automatic codebase indexing daemon for Mnemonik
Latest version: 2.0.1

# @mnemonik/scanner

Automatic codebase indexing daemon for [Mnemonik](https://mnemonik.dev) — persistent memory for AI coding assistants.

The scanner watches your project directories for code changes and indexes them so your AI assistant can find relevant files, functions, and patterns when you need them.

## Installation

```bash
npm install -g @mnemonik/scanner
```

## Quick Start

```bash
mnemonik-scanner start --key <your-api-key> --roots ~/Projects
```

Your API key is available on the [Mnemonik dashboard](https://app.mnemonik.dev). The `--roots` flag specifies which directories to scan for projects (comma-separated).

Configuration is saved to `~/.mnemonik/scanner.json` after first run. Subsequent starts need no arguments:

```bash
mnemonik-scanner start
```

## How It Works

1. The daemon walks your `--roots` directories looking for `.mnemonik.json` files (created automatically by your IDE's Mnemonik integration)
2. For each discovered project, it scans source files and pushes code chunks to the Mnemonik API
3. It watches for file changes and incrementally updates the index
4. Every 5 minutes, it re-scans roots to discover new projects, handle folder renames, and drop deleted projects

## Commands

| Command | Description |
|---------|-------------|
| `mnemonik-scanner start [options]` | Start the daemon |
| `mnemonik-scanner stop` | Stop the running daemon |
| `mnemonik-scanner status` | Show daemon status and watched projects |
| `mnemonik-scanner log` | Show recent log output |
| `mnemonik-scanner help` | Show usage information |

### Start Options

| Option | Description |
|--------|-------------|
| `--key <api-key>` | Mnemonik API key (or set `MNEMONIK_API_KEY` env var) |
| `--server <url>` | Server URL (default: `https://api.mnemonik.dev`) |
| `--roots <dirs>` | Comma-separated directories to scan for projects |

## Configuration

The daemon saves its configuration to `~/.mnemonik/scanner.json` with `0600` permissions (owner read/write only).

You can also set the API key via the `MNEMONIK_API_KEY` environment variable, which takes precedence over the config file and is never written to disk.

### Files

| Path | Purpose |
|------|---------|
| `~/.mnemonik/scanner.json` | Persistent configuration |
| `~/.mnemonik/daemon.pid` | PID file for the running daemon |
| `~/.mnemonik/scanner.log` | Log file (rotated at 5MB) |

## What Gets Indexed

The scanner indexes code chunks (functions, classes, modules) from these file types:

`.ts` `.tsx` `.js` `.jsx` `.py` `.rs` `.go` `.java` `.c` `.cpp` `.h` `.cs` `.rb` `.php` `.swift` `.kt` `.md`

It respects `.gitignore` and skips common directories (`node_modules`, `.git`, `dist`, `build`, etc.). Only code structure is indexed — binary files and non-code assets are ignored.

## Resource Usage

The daemon is designed to run continuously with minimal impact:

- **Memory**: Capped at 256MB
- **CPU**: Event-driven (idle when no files change)
- **Disk**: Log rotation at 5MB
- **Network**: Only changed files are pushed (hash-based diffing)

## Requirements

- Node.js 20 or later
- A Mnemonik account and API key ([sign up](https://mnemonik.dev))

## License

Proprietary. See [mnemonik.dev/terms](https://mnemonik.dev/terms) for details.