Skip to content

Latest commit

Β 

History

History
672 lines (555 loc) Β· 31.5 KB

File metadata and controls

672 lines (555 loc) Β· 31.5 KB

ICR Architecture Overview

This document provides a high-level view of the ICR (Intent-Check-Receipt) plugin architecture. It's designed to help you understand the "big picture" before diving into implementation details.

Acknowledgement: This project is inspired by the YouTube video "The AI Failure Mode Nobody Warned You About (And how to prevent it from happening)". The video provides an excellent explanation of the "intent problem" that ICR addresses. We highly recommend watching it before reading this document.

Table of Contents

  1. The Problem We're Solving
  2. The Solution: Three Phases
  3. System Architecture
  4. Component Overview
  5. Data Flow
  6. Key Algorithms
  7. File Organization
  8. Runtime Data
  9. Integration Points
  10. Design Decisions

The Problem We're Solving

The Intent Problem

When you ask an AI assistant to do something, there's a gap between:

  • What you said: "Clean up old files"
  • What you meant: Delete files older than 1 year in /tmp
  • What the AI understood: Delete files older than 30 days everywhere

This gap is the Intent Problem. It leads to:

  • Actions that don't match expectations
  • Irreversible mistakes (deleted wrong files)
  • Loss of trust in AI assistants
  • No accountability when things go wrong

Why Existing Solutions Fall Short

Approach Problem
Always ask for confirmation Too many prompts, user fatigue
Never ask Risky, no safety net
Simple permission rules Doesn't understand context
Post-action logging Too late to prevent mistakes

The ICR Approach

ICR adds transparency before action and accountability after action:

  1. Make interpretation visible before acting
  2. Calibrate verification to risk level
  3. Log everything for audit and learning

The Solution: Three Phases

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚  β”‚                  β”‚  β”‚                  β”‚  β”‚                  β”‚       β”‚
β”‚  β”‚     INTENT       β”‚  β”‚      CHECK       β”‚  β”‚     RECEIPT      β”‚       β”‚
β”‚  β”‚                  β”‚  β”‚                  β”‚  β”‚                  β”‚       β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚       β”‚
β”‚  β”‚  β”‚  Generate  β”‚  β”‚  β”‚  β”‚  Evaluate  β”‚  β”‚  β”‚  β”‚    Log     β”‚  β”‚       β”‚
β”‚  β”‚  β”‚ structured β”‚  β”‚  β”‚  β”‚  against   β”‚  β”‚  β”‚  β”‚everything  β”‚  β”‚       β”‚
β”‚  β”‚  β”‚interpretationβ”‚ β”‚  β”‚  β”‚thresholds β”‚  β”‚  β”‚  β”‚that        β”‚  β”‚       β”‚
β”‚  β”‚  β”‚            β”‚  β”‚  β”‚  β”‚            β”‚  β”‚  β”‚  β”‚happened    β”‚  β”‚       β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚       β”‚
β”‚  β”‚        β”‚         β”‚  β”‚        β”‚         β”‚  β”‚        β”‚         β”‚       β”‚
β”‚  β”‚        β–Ό         β”‚  β”‚        β–Ό         β”‚  β”‚        β–Ό         β”‚       β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚       β”‚
β”‚  β”‚  β”‚   Shows    β”‚  β”‚  β”‚  β”‚  Routes    β”‚  β”‚  β”‚  β”‚  Enables   β”‚  β”‚       β”‚
β”‚  β”‚  β”‚   WHAT     β”‚  β”‚  β”‚  β”‚    to      β”‚  β”‚  β”‚  β”‚   audit    β”‚  β”‚       β”‚
β”‚  β”‚  β”‚   and      β”‚  β”‚  β”‚  β”‚  AUTO,     β”‚  β”‚  β”‚  β”‚   and      β”‚  β”‚       β”‚
β”‚  β”‚  β”‚   WHY      β”‚  β”‚  β”‚  β”‚  AI, or    β”‚  β”‚  β”‚  β”‚  learning  β”‚  β”‚       β”‚
β”‚  β”‚  β”‚            β”‚  β”‚  β”‚  β”‚  HUMAN     β”‚  β”‚  β”‚  β”‚            β”‚  β”‚       β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚       β”‚
β”‚  β”‚                  β”‚  β”‚                  β”‚  β”‚                  β”‚       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
β”‚                                                                          β”‚
β”‚                    Before Action    β”‚    After Action                    β”‚
β”‚                                     β”‚                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Phase 1: Intent

Generate a structured document that makes the AI's interpretation explicit:

  • Task: What exactly will happen
  • Who/What: What will and won't be affected
  • Boundaries: Explicit limits on scope
  • Reversibility: Can it be undone? How?
  • Alternatives: Other interpretations considered

Phase 2: Check

Evaluate whether verification is needed:

  • Severity: How risky is this action type?
  • Confidence: How certain are we about the interpretation?
  • Decision: Route to AUTO, AI review, or HUMAN review

Phase 3: Receipt

Log everything for accountability:

  • Timestamp and session info
  • The intent document
  • The decision made
  • User response (if asked)
  • Execution outcome

System Architecture

High-Level Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           CLAUDE CODE                                    β”‚
β”‚                                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚    User     β”‚  β”‚   Claude    β”‚  β”‚    Tool     β”‚  β”‚   Plugin    β”‚    β”‚
β”‚  β”‚   Input     │──│   Brain     │──│  Executor   │──│   System    β”‚    β”‚
β”‚  β”‚             β”‚  β”‚             β”‚  β”‚             β”‚  β”‚             β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                                                             β”‚           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                              β”‚
                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                            ICR PLUGIN                                    β”‚
β”‚                                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚                         ENTRY POINTS                             β”‚    β”‚
β”‚  β”‚                                                                  β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚    β”‚
β”‚  β”‚  β”‚    HOOKS    β”‚  β”‚   SKILLS    β”‚  β”‚  COMMANDS   β”‚              β”‚    β”‚
β”‚  β”‚  β”‚             β”‚  β”‚             β”‚  β”‚             β”‚              β”‚    β”‚
β”‚  β”‚  β”‚ PreToolUse  β”‚  β”‚   Intent    β”‚  β”‚ /icr:*      β”‚              β”‚    β”‚
β”‚  β”‚  β”‚ Permission  β”‚  β”‚  Analysis   β”‚  β”‚             β”‚              β”‚    β”‚
β”‚  β”‚  β”‚ SubagentStp β”‚  β”‚             β”‚  β”‚             β”‚              β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚    β”‚
β”‚  β”‚         β”‚                                                        β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚            β”‚                                                             β”‚
β”‚            β–Ό                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚                       CORE ENGINE                                β”‚    β”‚
β”‚  β”‚                                                                  β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚    β”‚
β”‚  β”‚  β”‚ Severity β”‚ β”‚Confidenceβ”‚ β”‚ Decision β”‚ β”‚  Intent  β”‚            β”‚    β”‚
β”‚  β”‚  β”‚Classifierβ”‚ β”‚Calculatorβ”‚ β”‚   Tree   β”‚ β”‚Generator β”‚            β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜            β”‚    β”‚
β”‚  β”‚       β”‚            β”‚            β”‚            β”‚                   β”‚    β”‚
β”‚  β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚    β”‚
β”‚  β”‚                           β”‚                                      β”‚    β”‚
β”‚  β”‚                           β–Ό                                      β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚    β”‚
β”‚  β”‚  β”‚                   STORAGE LAYER                           β”‚   β”‚    β”‚
β”‚  β”‚  β”‚                                                           β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β”‚ Receipts β”‚  β”‚ Session  β”‚  β”‚  Config  β”‚               β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β”‚          β”‚  β”‚  State   β”‚  β”‚          β”‚               β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚   β”‚    β”‚
β”‚  β”‚  β”‚                                                           β”‚   β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚    β”‚
β”‚  β”‚                                                                  β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Component Layers

Layer Purpose Components
Entry Points Interface with Claude Code Hooks, Skills, Commands
Core Engine Business logic Severity, Confidence, Decision, Intent
Storage Persistence Receipts, Session State, Config

Component Overview

Entry Point Components

Hooks

Automatically triggered by Claude Code events:

Hook Trigger Purpose
PreToolUse Before any tool runs Main ICR check
PermissionRequest When asking user Add ICR context
SubagentStop After subagent finishes Review aggregate work

Commands

User-invocable slash commands:

Command Purpose
/icr:receipts View audit trail
/icr:config Manage settings
/icr:check Force manual check
/icr:trust Toggle trust mode
/icr:audit Pattern analysis
/icr:export Export receipts
/icr:stats View statistics
/icr:debug Debug confidence
/icr:simulate Dry-run check

Skills

AI-invocable capabilities:

Skill Purpose
intent-analysis Generate intent explanations

Core Engine Components

Severity Classifier

Classifies actions into risk levels:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              SEVERITY CLASSIFIER                β”‚
β”‚                                                 β”‚
β”‚   Input: Tool name + Arguments                  β”‚
β”‚                                                 β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚ Layer 1: Static Rules                    β”‚  β”‚
β”‚   β”‚   Bash β†’ HIGH                           β”‚  β”‚
β”‚   β”‚   Read β†’ LOW                            β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                      β–Ό                          β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚ Layer 2: Metadata Inference              β”‚  β”‚
β”‚   β”‚   "rm -rf" β†’ CRITICAL                   β”‚  β”‚
β”‚   β”‚   "delete" β†’ CRITICAL                   β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                      β–Ό                          β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚ Layer 3: User Rules                      β”‚  β”‚
β”‚   β”‚   Custom patterns override              β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                      β–Ό                          β”‚
β”‚   Output: LOW | MEDIUM | HIGH | CRITICAL       β”‚
β”‚                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Confidence Calculator

Calculates certainty score (0.0 - 1.0):

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚            CONFIDENCE CALCULATOR                β”‚
β”‚                                                 β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  Weight: 30%                 β”‚
β”‚   β”‚  Ambiguity  β”‚  How many interpretations?   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                              β”‚
β”‚          β”‚                                      β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  Weight: 25%                 β”‚
β”‚   β”‚  Distance   β”‚  Semantic gap?               β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                              β”‚
β”‚          β”‚                                      β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  Weight: 20%                 β”‚
β”‚   β”‚ Historical  β”‚  Seen before?                β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                              β”‚
β”‚          β”‚                                      β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  Weight: 25%                 β”‚
β”‚   β”‚ Uncertainty β”‚  Hedging language?           β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                              β”‚
β”‚          β”‚                                      β”‚
β”‚          β–Ό                                      β”‚
β”‚   Weighted Average β†’ 0.0 to 1.0                β”‚
β”‚                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Decision Tree

Routes to appropriate verification:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               DECISION TREE                     β”‚
β”‚                                                 β”‚
β”‚   Inputs:                                       β”‚
β”‚   - Severity (LOW/MEDIUM/HIGH/CRITICAL)        β”‚
β”‚   - Confidence (0.0 - 1.0)                     β”‚
β”‚   - Trust Mode (on/off)                        β”‚
β”‚   - Manual Check Flag                          β”‚
β”‚                                                 β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚ Manual check requested?                  β”‚  β”‚
β”‚   β”‚   YES β†’ HUMAN_REVIEW                    β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                      β”‚ NO                       β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚ Trust mode on AND not CRITICAL?          β”‚  β”‚
β”‚   β”‚   YES β†’ AUTO_APPROVE_TRUST_MODE         β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                      β”‚ NO                       β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚ Confidence >= autoApprove threshold?     β”‚  β”‚
β”‚   β”‚   YES β†’ AUTO_APPROVE                    β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                      β”‚ NO                       β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚ Confidence >= aiReview threshold?        β”‚  β”‚
β”‚   β”‚   YES β†’ AI_REVIEW                       β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                      β”‚ NO                       β”‚
β”‚                      β–Ό                          β”‚
β”‚   HUMAN_REVIEW                                  β”‚
β”‚                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Intent Generator

Creates structured intent documents:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚             INTENT GENERATOR                    β”‚
β”‚                                                 β”‚
β”‚   Inputs:                                       β”‚
β”‚   - User prompt                                β”‚
β”‚   - Tool name + arguments                      β”‚
β”‚   - Confidence breakdown                       β”‚
β”‚                                                 β”‚
β”‚   Outputs:                                      β”‚
β”‚   {                                            β”‚
β”‚     "task": "...",                             β”‚
β”‚     "whoWhat": {                               β”‚
β”‚       "affected": [...],                       β”‚
β”‚       "excluded": [...]                        β”‚
β”‚     },                                         β”‚
β”‚     "boundaries": [...],                       β”‚
β”‚     "ifUncertain": "...",                      β”‚
β”‚     "reversibility": {...},                    β”‚
β”‚     "alternatives": [...],                     β”‚
β”‚     "confidenceBreakdown": {...}               β”‚
β”‚   }                                            β”‚
β”‚                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

Complete Request Flow

User Request: "Clean up old files"
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    CLAUDE CODE        β”‚
β”‚    Interprets as:     β”‚
β”‚    Bash: rm -rf ...   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚ PreToolUse event
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  pre-tool-check.sh    β”‚
β”‚                       β”‚
β”‚  1. Check exclusions  │──▢ If excluded: proceed
β”‚  2. Load config       β”‚
β”‚  3. Classify severity │──▢ severity.sh β†’ CRITICAL
β”‚  4. Generate intent   │──▢ intent.sh β†’ document
β”‚  5. Calc confidence   │──▢ confidence.sh β†’ 0.62
β”‚  6. Make decision     │──▢ decision.sh β†’ HUMAN_REVIEW
β”‚  7. Create receipt    │──▢ receipt.sh β†’ saved
β”‚  8. Return decision   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     USER PROMPT       β”‚
β”‚                       β”‚
β”‚  Task: Delete files   β”‚
β”‚  Severity: CRITICAL   β”‚
β”‚  Confidence: 0.62     β”‚
β”‚                       β”‚
β”‚  [1] Proceed          β”‚
β”‚  [2] Edit             β”‚
β”‚  [3] Abort            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚ User selects [1]
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   RECEIPT UPDATED     β”‚
β”‚   - response: PROCEED β”‚
β”‚   - outcome: proceededβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   TOOL EXECUTES       β”‚
β”‚   rm -rf runs         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Algorithms

Confidence Calculation

function calculate_confidence(user_prompt, tool, args, config):
    # Get individual scores
    ambiguity = analyze_ambiguity(user_prompt)
    distance = calculate_distance(user_prompt, tool, args)
    historical = analyze_historical(tool, args)
    uncertainty = analyze_uncertainty(user_prompt)

    # Get weights from config
    weights = config.confidence.weights

    # Weighted average
    confidence = (
        ambiguity * weights.ambiguityAnalysis +
        distance * weights.intentToActionDistance +
        historical * weights.historicalPatterns +
        uncertainty * weights.uncertaintyMarkers
    )

    return clamp(confidence, 0.0, 1.0)

Decision Routing

function make_decision(severity, confidence, config, session_state):
    # Manual check overrides everything
    if session_state.manualCheckNext:
        return HUMAN_REVIEW

    # Trust mode check
    if session_state.trustModeEnabled and severity != CRITICAL:
        return AUTO_APPROVE_TRUST_MODE

    # Get thresholds for this severity
    thresholds = config.thresholds[severity]

    # Check against thresholds
    if confidence >= thresholds.autoApprove:
        return AUTO_APPROVE

    if confidence >= thresholds.aiReview:
        return AI_REVIEW

    return HUMAN_REVIEW

Severity Classification

function classify_severity(tool, args, config):
    # Layer 1: Static rules
    if tool in config.severity.staticRules:
        base_severity = config.severity.staticRules[tool]
    else:
        base_severity = MEDIUM

    # Layer 2: Metadata inference
    inferred = infer_from_metadata(tool, args)
    if inferred.severity > base_severity:
        base_severity = inferred.severity

    # Layer 3: User rules (highest priority)
    for rule in config.severity.userRules:
        if matches(rule.pattern, tool) and evaluates(rule.condition, args):
            return rule.severity

    return base_severity

File Organization

Source Files

icr/
β”œβ”€β”€ .claude-plugin/
β”‚   └── plugin.json         # Plugin manifest - START HERE
β”‚
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ pre-tool-check.sh   # Main entry point
β”‚   β”œβ”€β”€ permission-check.sh # Permission dialog hook
β”‚   β”œβ”€β”€ subagent-check.sh   # Subagent completion hook
β”‚   β”œβ”€β”€ statusline.sh       # Status line display
β”‚   └── lib/
β”‚       β”œβ”€β”€ common.sh       # Shared utilities
β”‚       β”œβ”€β”€ severity.sh     # Severity classification
β”‚       β”œβ”€β”€ confidence.sh   # Confidence calculation
β”‚       β”œβ”€β”€ decision.sh     # Decision tree
β”‚       β”œβ”€β”€ intent.sh       # Intent generation
β”‚       β”œβ”€β”€ receipt.sh      # Receipt logging
β”‚       └── checkpoint.sh   # Checkpoint management
β”‚
β”œβ”€β”€ commands/               # Slash commands (9 files)
β”œβ”€β”€ skills/                 # AI skills (1 directory)
β”œβ”€β”€ config/                 # Default configuration
β”œβ”€β”€ schemas/                # JSON validation schemas
β”œβ”€β”€ prompts/                # LLM prompt templates
└── docs/                   # Documentation

Dependency Graph

plugin.json
    β”‚
    β”œβ”€β”€β–Ά hooks/hooks.json
    β”‚        β”‚
    β”‚        └──▢ scripts/pre-tool-check.sh
    β”‚                    β”‚
    β”‚                    β”œβ”€β”€β–Ά lib/common.sh
    β”‚                    β”œβ”€β”€β–Ά lib/severity.sh ───▢ lib/common.sh
    β”‚                    β”œβ”€β”€β–Ά lib/confidence.sh ─▢ lib/common.sh
    β”‚                    β”œβ”€β”€β–Ά lib/decision.sh ──▢ lib/common.sh
    β”‚                    β”œβ”€β”€β–Ά lib/intent.sh ────▢ lib/common.sh
    β”‚                    β”œβ”€β”€β–Ά lib/receipt.sh ───▢ lib/common.sh
    β”‚                    └──▢ lib/checkpoint.sh β–Ά lib/common.sh
    β”‚
    β”œβ”€β”€β–Ά commands/*.md
    β”‚
    └──▢ skills/intent-analysis/SKILL.md

Runtime Data

Storage Location

All runtime data is stored in .claude/icr/:

.claude/icr/
β”œβ”€β”€ config.json             # User configuration overrides
β”œβ”€β”€ session-state.json      # Current session state
β”œβ”€β”€ errors.log              # Error log
β”‚
β”œβ”€β”€ receipts/               # Audit trail
β”‚   β”œβ”€β”€ index.json          # Fast lookup index
β”‚   β”œβ”€β”€ 2026-01-01/
β”‚   β”‚   └── session-abc123/
β”‚   β”‚       β”œβ”€β”€ session-meta.json
β”‚   β”‚       β”œβ”€β”€ 001-receipt.json
β”‚   β”‚       └── 002-receipt.json
β”‚   └── 2026-01-02/
β”‚       └── ...
β”‚
β”œβ”€β”€ exports/                # Exported receipts
β”‚   └── 2026-01-02T103000Z.json
β”‚
└── checkpoints/            # Checkpoint metadata
    └── chk-xyz789.json

Data Retention

Data Type Default Retention Configurable
Receipts 90 days Yes
Exports Permanent N/A
Session state Current session N/A
Error logs 30 days No

Integration Points

Claude Code Integration

ICR integrates with Claude Code through:

  1. Plugin System: Discovered via plugin.json
  2. Hook Events: Receives PreToolUse, PermissionRequest, SubagentStop
  3. Commands: Registered slash commands
  4. Skills: AI-invocable capabilities
  5. Status Line: Optional status display

Configuration Integration

ICR configuration is merged from multiple sources:

Priority (lowest to highest):
1. Built-in defaults (config/defaults.json)
2. User global config (~/.claude/icr/config.json)
3. Project config (.claude/icr/config.json)
4. Runtime overrides (/icr:config set)

Checkpoint Integration

ICR integrates with Claude Code checkpoints:

  1. Creates checkpoints before HIGH/CRITICAL actions
  2. Links checkpoints to receipts
  3. Suggests rollback when problems detected

Design Decisions

Why Bash Scripts?

Consideration Decision
Claude Code hooks execute shell Native integration
Cross-platform (macOS, Linux, WSL) Maximum compatibility
No build step required Faster iteration
Easy to modify and debug Lower barrier

Why jq for JSON?

Consideration Decision
Standard JSON tool Available everywhere
Powerful query language Complex transformations
Single dependency Minimal requirements

Why Three-Phase Design?

Phase Purpose
Intent Transparency - show what AI thinks
Check Control - let user/AI verify
Receipt Accountability - log everything

Why Configurable Thresholds?

Different users have different risk tolerances:

  • Security-focused: Higher thresholds (more checks)
  • Productivity-focused: Lower thresholds (fewer interruptions)
  • Mixed: Different thresholds per severity level

Why Trust Mode?

Constant verification causes fatigue. Trust mode provides:

  • Escape hatch for known-safe work
  • Still logs everything
  • Never bypasses CRITICAL by default

Further Reading