Automation Hooks

Use automation hooks to preserve session context, capture durable outcomes, and reload only the memories that should survive into the next session.

Hosted Core + Snipara Sandbox Edge

Snipara keeps the durable logic hosted. Hooks, local scripts, and compatibility CLIs form a thin edge execution layer that captures local lifecycle signals and forwards them to the hosted automation layer.

  • The edge can observe, normalize, inject, and forward.
  • The hosted core keeps review queues, memory policy, recall, and orchestration.
  • This keeps automation inspectable instead of burying business rules in shell hooks.

All Plans

Automation hooks are available on all plans, including Free.

Agents Plan Unlocks Reviewable Memory

Memory capture, transcript import, and inbox review policies are part of Snipara Agents. Use them when hooks should produce durable memory instead of only local checkpoints.

What Are Automation Hooks?

When your LLM's context window fills up, it performs a "compaction" - summarizing the conversation to free up space. Without hooks, you lose important context like what files were accessed, what decisions were made, and what the current task is.

Automation hooks let you save, review, and restore context automatically:

Automation flow
Rendering diagram...

Supported Hooks

PreCompact

Triggered before context compaction. Receives session summary via stdin. Use this to save important context that should survive the compaction.

context-checkpoint.sh

SessionStart

Triggered when starting a session after compaction or resume. Output is injected as additional context for the LLM.

session-restore.sh

PostToolUse

Triggered after a tool completes. Use with Bash matcher to save context on git commits.

commit-memory.sh
Agents plan

Canonical Event Ingestion

Hook adapters and local compatibility CLIs can now forward normalized lifecycle events into Snipara over the automation API. This is the preferred way to get closer to local-memory products without moving review or durable memory policy out of Snipara.

snipara-companion emit-event --event-type tool_call --payload '{"hook":"pre-tool","tool":"Read"}'
POST /api/projects/{project}/automation/events

{
  "events": [
    {
      "type": "tool_call",
      "client": "snipara-companion",
      "workspace": "/workspace/app",
      "session_id": "sess_123",
      "agent_id": "local-agent",
      "timestamp": "2026-04-16T18:00:00.000Z",
      "privacy_level": "standard",
      "payload": {
        "hook": "pre-tool",
        "tool": "Read"
      }
    }
  ]
}

Current compatibility mapping:

  • pre-tool forwards a canonical tool_call event
  • post-tool forwards a canonical tool_result event
  • session-end forwards a canonical session_end event

Inspecting Local Edge Events

Event forwarding is only half of the loop. The local companion can also read back recently ingested automation events so users can verify what their edge adapters actually sent.

snipara-companion events recent --limit 20
snipara-companion events recent --session-id sess_123

This is useful when debugging hook capture, checking which commands/files were forwarded, and confirming that the Snipara Sandbox edge is feeding the hosted automation layer correctly.

Supported AI Clients

Hook compatibility is agent-specific. Claude Code is the verified full-hook baseline. Codex, Cursor, Gemini CLI, and legacy Windsurf have compatible native or adapter-backed bundles where their clients expose useful lifecycle hooks. VS Code, ChatGPT, Continue, and custom MCP clients stay MCP-first unless their compatibility contract allows installation.

Automation compatibility

This matrix is derived from the shared Snipara compatibility contract. It keeps docs, dashboard states, and generated automation bundles aligned around the configured agent.

AgentGenerated by create-sniparaHook install statusAutomation path
Claude Code
Hosted MCP, project instructions, and verified lifecycle hooks.
AGENTS.md, CLAUDE.md, .mcp.json, .claude/settings.json, .claude/hooks/*.shSupported nowSelect hooks in Snipara settings, then apply with npx -y snipara-companion@latest automations install --client claude-code.
OpenAI Codex
Hosted MCP, AGENTS.md, Codex config, and native hook automation.
AGENTS.md, .codex/config.toml, .codex/hooks.json, .codex/hooks/*.shSupported nowSelect hooks in Snipara settings, then apply with npx -y snipara-companion@latest automations install --client claude-code.
Cursor
Hosted MCP, project rules, and native hook automation.
AGENTS.md, .cursor/mcp.json, .cursor/rules/snipara.mdc, .cursor/hooks.json, .cursor/hooks/*.shSupported nowSelect hooks in Snipara settings, then apply with npx -y snipara-companion@latest automations install --client claude-code.
VS Code / Copilot
Hosted MCP and Copilot instructions; hook support is preview-gated.
.vscode/mcp.json, .github/copilot-instructions.mdPreview gatedUse Hosted MCP and generated rules/templates. Native hook files stay disabled by default.
Gemini CLI
Hosted MCP, GEMINI.md, and native hook automation.
GEMINI.md, .gemini/settings.json, .gemini/hooks/*.shSupported nowSelect hooks in Snipara settings, then apply with npx -y snipara-companion@latest automations install --client claude-code.
Mistral Le Chat / Vibe
Hosted MCP for Le Chat and Vibe plus ChatMistralAI tool calling templates.
AGENTS.md, MISTRAL.md, .vibe/config.toml, mistral-le-chat-mcp.json, mistral-langchain-tools.tsMCP onlyUse Hosted MCP and generated rules/templates. Native hook files stay disabled by default.
MCP-only / Custom
Hosted MCP tools and explicit commands only.
mcp-config.jsonMCP onlyUse Hosted MCP and generated rules/templates. Native hook files stay disabled by default.

Select hook behavior in Snipara project settings, then install the compatible selected bundle locally with npx -y snipara-companion@latest automations install. Unsupported hook options are disabled instead of being written as broken local scripts.

Quick Setup (Claude Code)

Required Dependencies:
  • bash (v4+) - Pre-installed on macOS/Linux
  • jq - JSON processor: brew install jq (macOS) or apt install jq (Linux)

Step 1: Generate Configuration

Go to your project's Automation page in the Snipara dashboard and enable the desired options:

  • Preserve on Compaction: Save context when Claude compacts
  • Restore on Session Start: Restore context after compaction
  • Auto-Inject Context: Sync context to Snipara cloud

Download or copy the generated configuration files.

Step 2: Add Files to Your Project

Copy the generated files to your project root:

mkdir -p .claude/hooks
chmod +x .claude/hooks/*.sh

Step 3: Configuration Structure

Your Claude MCP server belongs in .mcp.json. Your .claude/settings.json should contain hooks only:

{
  "hooks": {
    "PreCompact": [{
      "matcher": "auto",
      "hooks": [{ "type": "command", "command": ".claude/hooks/context-checkpoint.sh" }]
    }],
    "SessionStart": [{
      "matcher": "compact",
      "hooks": [{ "type": "command", "command": ".claude/hooks/session-restore.sh" }]
    }]
  }
}

Hook Scripts

PreCompact Hook (context-checkpoint.sh)

This script runs before compaction and saves the session context:

#!/bin/bash
# Pre-Compaction Hook for Context Preservation
set -e
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
CHECKPOINT_FILE="$PROJECT_DIR/.claude/.session-context"
# Read context from stdin (Claude passes session summary)
CONTEXT=$(cat)
if [ -n "$CONTEXT" ]; then
  mkdir -p "$(dirname "$CHECKPOINT_FILE")"
  echo "$CONTEXT" > "$CHECKPOINT_FILE"
  echo "PreCompact: Checkpoint saved"
fi

SessionStart Hook (session-restore.sh)

This script runs after compaction and restores the saved context:

#!/bin/bash
# Session Restore Hook for Context Restoration
set -e
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
CHECKPOINT_FILE="$PROJECT_DIR/.claude/.session-context"
if [ -f "$CHECKPOINT_FILE" ]; then
  CONTEXT=$(cat "$CHECKPOINT_FILE")
  if [ -n "$CONTEXT" ]; then
    # Output JSON for Claude to inject as context
    jq -n --arg content "$CONTEXT" '{
      hookSpecificOutput: {
        hookEventName: "SessionStart",
        additionalContext: $content
      }
    }'
  fi
fi

Memory Capture & Review

Agents plan required: Memory Injection requires a plan that includes reviewed agent memory. Check the current pricing page for the latest plan names and amounts.

Memory capture turns hook output into durable project memory. Instead of only saving raw context, hooks can store decisions, learnings, preferences, and workflow changes that are later recalled semantically.

Memory capture flow
Rendering diagram...

Memory Types

TypeUse CaseDefault TTL
FACTProject-specific knowledgeNo default expiry
DECISIONArchitectural or implementation choices30 days
LEARNINGDiscovered patterns or behaviors30 days
PREFERENCEUser preferencesNo default expiry
TODOTask items and reminders14 days
CONTEXTSession context (auto-saved by hooks)7 days

Auto-Save on Commit

CLI Only: PostToolUse hooks currently work in the Claude Code CLI, not the VSCode extension. Use the CLI (claude command) to enable this feature.

Automatically capture durable outcomes when a git commit is made. This ensures the work is preserved even if you close the session before compaction or handoff.

Commit capture flow
Rendering diagram...

Hook Configuration:

{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Bash",
      "hooks": [{
        "type": "command",
        "command": ".claude/hooks/commit-memory.sh",
        "timeout": 15
      }]
    }]
  }
}

Enable in your dashboard: Project → Automation → Memory Injection → Save Memory on Commit

Review Modes

ModeBehaviorBest For
AUTOAutomated memory writes are approved immediately and can be recalled later.Trusted automation with low review overhead
INBOXAutomated writes land as PENDING and stay out of recall/session bootstrap until approved.Teams that want human review before memories become durable

Transcript Import Bootstrap

Use Import Transcript on the Memory page to paste a task transcript, retrospective, or handoff summary. Snipara previews durable candidates, classifies them, and imports them into the inbox for review.

  • Extracts decisions, learnings, preferences, todos, and longer context fragments
  • Deduplicates repeated lines before import
  • Imports previewed candidates as pending review so they do not leak into recall early

Cloud Sync (Optional)

When Auto-Inject Context is enabled, the PreCompact hook syncs context to Snipara cloud, enabling cross-session persistence:

POST /api/projects/{project}/automation/inject
Content-Type: application/json
X-API-Key: snp-...

{
  "context": "Session context to store",
  "sessionId": "default",
  "append": false,
  "source": "hook"
}

The context can be retrieved later:

GET /api/projects/{project}/automation/inject?sessionId=default
X-API-Key: snp-...

Response:
{
  "success": true,
  "data": {
    "id": "ctx_123",
    "sessionId": "default",
    "context": "Stored context...",
    "updatedAt": "2025-01-20T..."
  }
}

Testing Your Setup

Test Local Checkpoint

echo '{"test": "context data"}' | bash .claude/hooks/context-checkpoint.sh
PreCompact: Context checkpoint saved (25 bytes)

Test Local Restore

bash .claude/hooks/session-restore.sh
{
  "hookSpecificOutput": {
    "hookEventName": "SessionStart",
    "additionalContext": "{\"test\": \"context data\"}"
  }
}

Test Cloud API

curl -s -X POST "https://www.snipara.com/api/projects/your-project/automation/inject" \
  -H "X-API-Key: snp-your-key" \
  -H "Content-Type: application/json" \
  -d '{"context": "Test context", "source": "manual"}'

Troubleshooting

IssueCauseSolution
"Invalid API key"API key not foundRegenerate key from dashboard
"API key does not match project"Key belongs to different projectUse correct key for project
"Project not found"Invalid slug/ID in URLVerify project slug in dashboard
Hook not triggeringScripts not executablechmod +x .claude/hooks/*.sh
Empty context restoredCheckpoint file missingCheck .claude/.session-context exists
jq not foundjq not installedInstall jq: brew install jq

Failure Modes & Recovery

Hooks are designed to fail gracefully. Here's what happens in common failure scenarios:

ScenarioBehaviorRecovery
jq not installedSessionStart outputs raw text instead of JSONInstall jq or use snipara_inject fallback
Cloud sync failsLocal checkpoint still savedContext persists locally; cloud sync retries next compaction
Hook script errorsLLM continues without restored contextRun scripts manually to debug: bash .claude/hooks/session-restore.sh
Permission deniedHook fails silentlyRun chmod +x .claude/hooks/*.sh

Manual Injection Fallback

If hooks aren't working, you can inject context manually via MCP tools:

snipara_inject({ context: "Working on auth refactor. Key files: auth.ts, middleware.ts" })

MCP Alternative

For clients without hook support, you can use MCP tools to manage context manually:

snipara_inject

Inject context into the current session. Use this before compaction to save important context.

snipara_inject("Working on auth refactor")

snipara_context

View current session context. Check what context is currently stored.

snipara_context()

Next Steps