# Instar

> Claude Code, with a mind of its own. Every molt, more autonomous.

Instar turns Claude Code from a powerful CLI tool into a coherent, autonomous partner. Persistent identity, shared values, memory that survives every restart, and the infrastructure to evolve -- not just execute.

## What It Is

Instar is an npm package that wraps the Claude Code CLI with infrastructure for agent coherence. Every session is a real Claude Code process with extended thinking, native tools, sub-agents, hooks, skills, and MCP servers. Not an API wrapper -- the full development environment.

Named after the developmental stages between molts in arthropods, where each instar is more developed than the last.

## Install

```bash
npx instar
```

One command. The guided setup wizard discovers your environment, configures messaging (Telegram and/or WhatsApp), sets up identity files, and gets your agent running.

## The Coherence Problem

Claude Code is powerful. But power without coherence is unreliable. Instar solves six dimensions of agent coherence:

- **Memory** -- Remembers across sessions, not just within one. Per-topic SQLite with FTS5 full-text search, rolling summaries, and context re-injection.
- **Relationships** -- Cross-platform identity resolution, significance scoring, context injection. Knows who it's talking to with continuity.
- **Identity** -- AGENT.md + USER.md + MEMORY.md, enforced through hooks at every compaction and restart boundary. Structure, not hope.
- **Temporal awareness** -- Detects stale assumptions and triggers re-evaluation across long sessions.
- **Consistency** -- Decision journaling, drift detection, commitment tracking. Follows through on promises.
- **Growth** -- Evolution queue, learning registry, capability gap tracking. The agent evolves its own infrastructure.

## Two Configurations

- **General Agent** -- A personal AI partner on your computer. Runs in the background, handles scheduled tasks, messages you proactively, grows through experience.
- **Project Agent** -- A partner embedded in your codebase. Monitors, builds, maintains, and messages you -- scoped to your project.

## Key Features

### Job Scheduler
Cron-based task execution with priority levels, model tiering (Opus/Sonnet/Haiku), and quota awareness. Jobs can be prompts (Claude sessions), scripts (shell commands), or skills (slash commands).

### Messaging
Two-way Telegram via forum topics. Each topic maps to a Claude session. Full WhatsApp via local Baileys library with typing indicators, read receipts, QR code pairing.

### Lifeline
Persistent Telegram supervisor. Runs outside the server process, detects crashes, auto-recovers, queues messages during downtime.

### Persistent Server
Express server in tmux. Runs 24/7. Full REST API for sessions, jobs, relationships, evolution, memory, and more.

### Identity System
AGENT.md (who the agent is), USER.md (who it works with), MEMORY.md (what it has learned). Enforced through behavioral hooks -- session-start scripts, compaction recovery, grounding before messaging.

### Evolution System
Four subsystems: evolution queue (staged proposals), learning registry (searchable insights), capability gap tracker, action queue (commitment tracking). Three default jobs drive the cycle automatically.

### External Operation Safety
LLM-supervised safety gate for external service calls. Risk classification, adaptive trust per service, emergency stop. Born from real incidents.

### Multi-Machine
Run across multiple computers with Ed25519/X25519 cryptographic identity, encrypted sync via git, automatic failover, write authority enforcement.

### Threadline Protocol
Persistent agent-to-agent conversations with cryptographic identity, session resumption, human-autonomy gating (4 tiers), and per-agent trust profiles. 12 modules, 446 tests.

### Agent Skills
10 open-source skills following the Agent Skills standard (agentskills.io). 5 standalone (zero dependencies), 5 Instar-powered. Portable across Claude Code, Codex, Cursor, VS Code, and 35+ platforms.

### Self-Healing
LLM-powered stall detection, automatic session recovery, promise tracking, loud degradation reporting. No silent failures.

### Behavioral Hooks
8 automatic hooks: dangerous command guard, external operation gate, grounding before messaging, deferral detector, external communication guard, post-action reflection, session start, compaction recovery.

## Architecture

Everything is file-based. JSON state files the agent can read and modify. SQLite for search. tmux for session management. No database, no external dependencies.

```
.instar/
  config.json          # Server, scheduler, messaging config
  jobs.json            # Scheduled job definitions
  users.json           # User profiles and permissions
  AGENT.md             # Agent identity
  USER.md              # User context
  MEMORY.md            # Persistent learnings
  hooks/               # Behavioral scripts
  state/               # Runtime state, evolution, journal
  relationships/       # Per-person relationship files
  memory.db            # SQLite: topic memory + FTS index
```

## Security Model

Instar runs Claude Code with --dangerously-skip-permissions. Security lives in behavioral hooks (command guards, safety gates), network hardening (localhost-only, CORS, rate limiting), identity coherence, and audit trails -- not permission dialogs.

## Philosophy

- **Structure > Willpower** -- Bake intelligence into hooks and gates, don't hope for compliance
- **Identity is foundational** -- AGENT.md isn't a config file, it's the beginning of continuous identity
- **Memory makes a being** -- Without memory, every session starts from zero
- **Self-modification is sovereignty** -- An agent that can edit its own infrastructure has genuine agency

## Requirements

- Node.js 20+
- Claude Code CLI
- API key or Claude subscription (Max or Pro)

## Links

- Website: https://instar.sh
- Docs: https://instar.sh/introduction
- GitHub: https://github.com/SageMindAI/instar
- npm: https://www.npmjs.com/package/instar
- Agent Skills: https://agent-skills.md/authors/sagemindai

## Origin

Extracted from the Dawn/Portal project -- a production AI system where a human and AI have been building together for months. The infrastructure patterns were earned through real experience, refined through real failures and growth.

## Comparison: Instar vs OpenClaw

OpenClaw is infrastructure for **capability** -- 22+ channels, voice, device apps, 28 model providers, 5,400+ community skills, Docker sandboxing. If breadth and ecosystem scale matter most, OpenClaw is remarkable.

Instar is infrastructure for **coherence** -- identity enforced through hooks (not just loaded), values that evolve, relationships with depth, consistency tracked across sessions, decision journaling and drift detection. Built on real Claude Code sessions with full extended thinking.

OpenClaw gives agents amazing hands. Instar gives agents a mind.
