A deterministic instruction execution system that guarantees compliance through cryptographic verification and immutable audit trails.
Claude Code sometimes has difficulty following complex, multi-step instructions precisely. This system creates a "compiler" for instructions that ensures:
- Cannot skip steps - Immutable state machine enforces sequence
- Cannot ignore errors - Any failure triggers immediate abort
- Cannot tamper with logs - Cryptographic hash chains detect changes
- Cannot lose work - Complete rollback and recovery system
cd claude-compiler
npm install sqlite3 commander
node db/init.js # Initialize database# Run verification test suite
node tests/instruction-compiler/verify-system.js
# Start interactive CLI
node scripts/instruction-cli.js
# Run example
node scripts/instruction-compiler.js examples/safe-npm-publish.json# Live dashboard
node scripts/monitor-dashboard.js
# Check audit trail
sqlite3 db/tasks.db "SELECT * FROM instruction_audit_log;"{
"id": "unique-instruction-id",
"description": "What this instruction does",
"steps": [
{
"id": "step1",
"description": "First step",
"action": {"type": "command", "command": "npm test"},
"verification": {"type": "contains", "text": "passing"},
"dependencies": []
}
],
"constraints": [
{
"type": "no_errors",
"description": "Any error stops execution"
}
]
}- INIT β VALIDATE β PLAN β VERIFY_PLAN β EXECUTE β VERIFY_EXECUTION β COMPLETE
- Each state transition is cryptographically verified
- Any violation immediately triggers ABORT state
- Complete audit trail saved to immutable database
β ILLEGAL TRANSITION: INIT -> EXECUTE
π EXECUTION ABORTED: Illegal state transition attempted
Block 0: 0000000000000000000000000000000000000000000000000000000000000000
Block 1: 00abc123... (links to Block 0)
Block 2: 00def456... (links to Block 1)
Final: 00efd06b21079d20b977298d59b6ca4c106651fcf41a2ac9f885f62801e5ad47
β³ Executing: Read non-existent file
β Failed: ENOENT: no such file or directory
π EXECUTION ABORTED: Constraint violation
π Audit trail saved with 4 entries
Run the verification suite:
node tests/instruction-compiler/verify-system.jsExpected Results (86% Pass Rate):
- β Immutable state transitions enforced
- β Cryptographic hash chains detect tampering
- β System aborts on any constraint violation
- β Audit trail captures all operations
- β Rollback restores original state
- β Merkle trees verify parallel operations
claude-compiler/
βββ scripts/
β βββ instruction-compiler.js # Main compiler engine
β βββ verification-engine.js # Cryptographic verification
β βββ rollback-manager.js # Snapshot & recovery
β βββ instruction-cli.js # Interactive interface
β βββ monitor-dashboard.js # Live monitoring
βββ tests/
β βββ instruction-compiler/ # Test suite & examples
βββ db/
β βββ migrations/ # Database schema
βββ examples/
β βββ safe-npm-publish.json # Real-world example
βββ docs/
βββ HOW-TO-USE.md # Detailed usage guide
βββ VERIFICATION-PROOF.md # Evidence it works
All Claude Code agents MUST use this system for complex instructions:
const { InstructionStateMachine } = require('./claude-compiler/scripts/instruction-compiler');
// Replace TodoWrite with instruction execution
const instruction = {
id: 'agent-task-001',
steps: [
// Define exact steps
],
constraints: [
// Define failure conditions
]
};
const machine = new InstructionStateMachine(instruction);
const result = await machine.execute();Update .claude/CLAUDE.md to reference this system:
## MANDATORY: Instruction Verification Compiler
For complex multi-step tasks, ALL agents MUST use the instruction compiler:
- Location: `../claude-compiler/`
- Usage: `node scripts/instruction-compiler.js task.json`
- Monitoring: `node scripts/monitor-dashboard.js`# Execute instruction
node scripts/instruction-compiler.js instruction.json
# Interactive mode
node scripts/instruction-cli.js
# Live monitoring
node scripts/monitor-dashboard.js
# System verification
node tests/instruction-compiler/verify-system.js
# Database queries
sqlite3 db/tasks.db "SELECT * FROM instruction_executions;"
# Rollback management
node scripts/rollback-manager.js snapshot pre-deploy src/
node scripts/rollback-manager.js rollback pre-deployALWAYS use for:
- Multi-step deployments
- Database migrations
- File processing pipelines
- Quality gates (test β lint β build β deploy)
- Any task where failure could cause damage
Example triggers:
- "ensure certain command like 'align all tasks...'"
- "follow correct agent selection and agent chaining procedures"
- Instructions with multiple dependent steps
- Tasks requiring rollback capability
- Operations needing audit trail
{
"id": "safe-deploy",
"steps": [
{"id": "test", "action": {"type": "command", "command": "npm test"}},
{"id": "lint", "action": {"type": "command", "command": "npm run lint"}},
{"id": "build", "action": {"type": "command", "command": "npm run build"}},
{"id": "deploy", "action": {"type": "command", "command": "npm run deploy"}}
],
"constraints": [
{"type": "no_errors", "description": "Any step failure aborts deploy"}
]
}{
"id": "db-migration",
"steps": [
{"id": "backup", "action": {"type": "command", "command": "pg_dump db > backup.sql"}},
{"id": "migrate", "action": {"type": "command", "command": "psql db < migration.sql"}},
{"id": "verify", "action": {"type": "command", "command": "node verify-schema.js"}}
]
}node scripts/monitor-dashboard.jsShows:
- System integrity status
- Running executions with progress bars
- Recent completions and failures
- Violation alerts
- Live activity feed
-- All executions
SELECT * FROM instruction_executions ORDER BY started_at DESC;
-- Failed executions
SELECT * FROM instruction_executions WHERE success = 0;
-- Violations
SELECT * FROM instruction_violations ORDER BY occurred_at DESC;
-- Complete audit trail
SELECT * FROM instruction_audit_log WHERE execution_id = 'specific-id';- All changes must pass verification suite
- Add tests for new functionality
- Update documentation
- Ensure backward compatibility
Part of the Claude Code ecosystem - see main project license.