This file provides context for Claude (or other AI assistants) when working with this codebase.
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 brilliantly articulates the "intent problem" in AI agents - the gap between what users mean and what AI interprets - which this plugin aims to solve.
ICR (Intent-Check-Receipt) is a Claude Code plugin that implements a safety layer for AI agent operations. It addresses the "intent problem" - the gap between what users mean and what AI interprets.
- Intent: Before executing an action, generate a structured document showing what the AI believes the user wants
- Check: Pause for verification (human and/or AI reviewer) based on action severity and confidence
- Receipt: Log the full audit trail including interpretation, approval, and outcome
icr/
βββ .claude-plugin/
β βββ plugin.json # Plugin manifest - defines hooks, commands, skills
β
βββ commands/ # Slash commands (user-invocable)
β βββ receipts.md # /icr:receipts - View receipt history
β βββ config.md # /icr:config - View/edit configuration
β βββ check.md # /icr:check - Manual check trigger
β βββ trust.md # /icr:trust - Trust mode toggle
β βββ audit.md # /icr:audit - Deep receipt analysis
β βββ export.md # /icr:export - Export receipts
β βββ stats.md # /icr:stats - Session statistics
β βββ debug.md # /icr:debug - Confidence debugging
β βββ simulate.md # /icr:simulate - Dry-run intent check
β
βββ skills/
β βββ intent-analysis/
β βββ SKILL.md # AI-invocable intent analysis skill
β
βββ hooks/
β βββ hooks.json # Hook event configuration
β
βββ scripts/ # Bash scripts (hook implementations)
β βββ pre-tool-check.sh # Main PreToolUse hook handler
β βββ permission-check.sh # PermissionRequest hook
β βββ subagent-check.sh # SubagentStop hook
β βββ statusline.sh # Status line display
β βββ lib/ # Core library scripts
β βββ common.sh # Shared utilities (logging, JSON helpers)
β βββ severity.sh # Severity classification (LOW/MEDIUM/HIGH/CRITICAL)
β βββ confidence.sh # Confidence scoring (0.0-1.0)
β βββ decision.sh # Decision tree (AUTO_APPROVE/AI_REVIEW/HUMAN_REVIEW)
β βββ intent.sh # Intent document generation
β βββ receipt.sh # Receipt logging and rotation
β βββ checkpoint.sh # Checkpoint management for rollback
β
βββ config/
β βββ defaults.json # Default configuration (Conservative preset)
β
βββ schemas/ # JSON Schema validation
β βββ config.json # Configuration schema
β βββ receipt.json # Receipt format schema
β βββ intent-doc.json # Intent document schema
β
βββ prompts/ # LLM prompt templates
β βββ intent-generation.md # Template for generating intent documents
β βββ self-critique.md # AI self-review template
β βββ devils-advocate.md # Adversarial safety review template
β
βββ docs/ # Documentation
β βββ ICR_PLUGIN_SPEC.md # Full specification (4700+ lines)
β βββ SUMMARY.md # Original intent problem research
β βββ QUICK_START.md # Quick start with 10 use cases
β βββ USER_GUIDE.md # Comprehensive user documentation
β βββ DEVELOPER_GUIDE.md # Comprehensive developer documentation
β βββ ARCHITECTURE.md # System architecture overview
β βββ CONTRIBUTING.md # Contribution guidelines
β βββ TROUBLESHOOTING.md # Common issues and solutions
β
βββ README.md # Project overview and quick reference
βββ CHANGELOG.md # Version history
βββ LICENSE # MIT License
βββ CLAUDE.md # This file
| Technology | Purpose | Documentation |
|---|---|---|
| Bash | All scripts are written in Bash | Scripts use set -euo pipefail for safety |
| jq | JSON processing in shell scripts | Used for parsing/generating JSON |
| JSON | Configuration, receipts, schemas | Standard JSON format throughout |
| JSON Schema | Validation | Draft-07 JSON Schema |
| Markdown | Commands, skills, prompts | Frontmatter YAML + Markdown content |
-
Create
commands/<name>.mdwith frontmatter:--- description: Brief description for help text user_invocable: true --- # Command Name [Command documentation...]
-
Add command to
plugin.json:{ "commands": [ {"name": "icr:<name>", "path": "commands/<name>.md"} ] }
Edit config/defaults.json:
{
"severity": {
"userRules": [
{
"pattern": "ToolName",
"condition": "args.property === 'value'",
"severity": "CRITICAL",
"reason": "Why this is critical"
}
]
}
}Edit config/defaults.json:
{
"confidence": {
"weights": {
"ambiguityAnalysis": 0.30,
"intentToActionDistance": 0.25,
"historicalPatterns": 0.20,
"uncertaintyMarkers": 0.25
}
}
}- Create script in
scripts/<hook-name>.sh - Register in
hooks/hooks.json:{ "hooks": { "HookEventName": [{ "hooks": [{ "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/scripts/<hook-name>.sh" }] }] } }
All scripts follow this pattern:
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LIB_DIR="${SCRIPT_DIR}/lib"
source "${LIB_DIR}/common.sh"
main() {
require_jq
local input
input=$(read_json_input)
# ... processing ...
echo "$result"
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi- Hooks receive JSON via stdin
- Hooks output JSON to stdout
- Use
jqfor all JSON operations:# Reading local value=$(echo "$json" | jq -r '.field') # Writing jq -n --arg f "$field" '{"field": $f}'
- Scripts use
set -euo pipefailfor strict error handling - Graceful degradation: if component fails, escalate to HUMAN_REVIEW
- All errors are logged to
.claude/icr/errors.log
# Test severity classification
echo '{"tool_name": "Bash", "tool_input": {"command": "rm -rf /"}}' | \
bash scripts/lib/severity.sh
# Test confidence calculation
bash scripts/lib/confidence.sh "delete old files" "Bash" '{"command": "rm"}' '{}' ".claude/icr/receipts"Use Claude Code with --plugin-dir ./icr to test the full plugin.
ICR stores runtime data in .claude/icr/:
.claude/icr/
βββ config.json # User overrides (merged with defaults)
βββ session-state.json # Current session state
βββ errors.log # Error log
βββ receipts/ # Audit trail
β βββ YYYY-MM-DD/
β βββ session-xxx/
β βββ session-meta.json
β βββ 001-receipt.json
βββ exports/ # Exported receipts
βββ checkpoints/ # Checkpoint metadata
| Level | Risk | Examples | Default Behavior |
|---|---|---|---|
| LOW | Minimal | Read, Glob, Grep | Auto-approve |
| MEDIUM | Moderate | Write, Edit | Confidence-based |
| HIGH | Significant | Bash | Usually review |
| CRITICAL | Dangerous | Delete, rm -rf | Always human review |
Calculated from 4 weighted signals:
- Ambiguity Analysis (30%): How many valid interpretations exist
- Intent-to-Action Distance (25%): Semantic gap between request and action
- Historical Patterns (20%): Similarity to past successful actions
- Uncertainty Markers (25%): Hedging language in the request
- AUTO_APPROVE: Confidence β₯ auto threshold β proceed immediately
- AI_REVIEW: Confidence between AI and auto thresholds β AI validates
- HUMAN_REVIEW: Confidence < human threshold β user must approve
scripts/pre-tool-check.sh: Main entry point, orchestrates the full ICR flowscripts/lib/decision.sh: Decision tree logic for routingconfig/defaults.json: All configurable options with defaultsdocs/ICR_PLUGIN_SPEC.md: Complete specification (reference for any questions)
- JSON escaping: Always use
jqfor JSON generation, never string concatenation - Variable quoting: Always quote variables in Bash:
"$variable" - Exit codes: Hook scripts must exit 0 for success
- Stdin consumption: Read stdin once and store in variable
- Full Spec:
docs/ICR_PLUGIN_SPEC.mdhas exhaustive details - User Guide:
docs/USER_GUIDE.mdfor end-user documentation - Developer Guide:
docs/DEVELOPER_GUIDE.mdfor implementation details - Troubleshooting:
docs/TROUBLESHOOTING.mdfor common issues