Skip to content

Instantly share code, notes, and snippets.

@vitorcalvi
Created January 15, 2026 15:09
Show Gist options
  • Select an option

  • Save vitorcalvi/01a40f190a73e5e913b59b8cb71105f4 to your computer and use it in GitHub Desktop.

Select an option

Save vitorcalvi/01a40f190a73e5e913b59b8cb71105f4 to your computer and use it in GitHub Desktop.
Grok + Claude 4.5 Supervisor System - Dual-agent AI system with real-time bug detection and correction

Grok + Claude 4.5 Supervisor System

Overview

A dual-agent AI system where Grok writes code quickly while Claude 4.5 supervises, tests, and corrects bugs in real-time.

Architecture

┌─────────────────┐         ┌──────────────────┐
│     Grok        │────────▶│ Claude Monitor   │
│  (Fast Coder)   │  MCP    │  (Supervisor)    │
│                 │◀────────│                  │
└─────────────────┘  Signal  └──────────────────┘
       │                           │
       v                           v
  Writes Code               Detects Bugs
  Runs Tests                Sends Corrections

Features

  • Real-time Bug Detection: Claude Monitor checks test results every 5 seconds
  • Automatic Corrections: Pattern-based analysis generates specific fix instructions
  • Process Control: Pause/resume Grok via POSIX signals (SIGSTOP/SIGCONT)
  • Comprehensive Logging: All activities logged to /tmp/ for debugging

Quick Start

# Clone or download these files
# Install dependencies
npm install -g clauder-mcp-server

# Run setup
chmod +x start_dual_instance.sh ~/.local/bin/grok-control.sh

# Start system
./start_dual_instance.sh start

Files

  • start_dual_instance.sh - Main startup script
  • grok-control.sh - Grok process control
  • claude-monitor.js - Claude Monitor daemon
  • opencode.grok.json - Grok configuration
  • opencode.claude-supervisor.json - Claude configuration
  • coder-grok.md - Grok system prompt
  • supervisor-claude.md - Claude system prompt

Usage

# Start system
./start_dual_instance.sh start

# Check status
./start_dual_instance.sh status

# Control Grok
~/.local/bin/grok-control.sh status    # Check status
~/.local/bin/grok-control.sh pause     # Pause Grok
~/.local/bin/grok-control.sh resume    # Resume Grok

# Stop system
./start_dual_instance.sh stop

Requirements

  • Node.js and npm
  • Grok 3-mini API access
  • Claude 4.5 API access
  • clauder-mcp-server (installed via script)

Test Results Format

Grok saves test results to .grok-test-results.json:

{
  "timestamp": "2026-01-15T10:30:00Z",
  "total_tests": 42,
  "passed": 40,
  "failed": 2,
  "failures": [
    {
      "test": "password reset returns 500 error",
      "error": "TypeError: Cannot read property 'email' of null",
      "file": "auth/reset.js",
      "line": 15
    }
  ]
}

License

MIT License - Feel free to use and modify.

#!/usr/bin/env node
/**
* Claude Monitor Daemon
* Monitors Grok's test results and sends corrections via Clauder MCP
* Runs continuously, checking .grok-test-results.json every 5 seconds
*/
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
const os = require('os');
// Configuration
const CHECK_INTERVAL_MS = 5000; // Check every 5 seconds
const TEST_RESULTS_FILE = path.join(process.cwd(), '.grok-test-results.json');
const LOG_FILE = '/tmp/claude-monitor.log';
const GROK_CONTROL_SCRIPT = path.join(os.homedir(), '.local/bin/grok-control.sh');
// Logging utility
function log(message, level = 'INFO') {
const timestamp = new Date().toISOString();
const logMessage = `[${timestamp}] [${level}] ${message}\n`;
// Console output
process.stdout.write(logMessage);
// File output (append)
try {
fs.appendFileSync(LOG_FILE, logMessage);
} catch (err) {
// Ignore logging errors
}
}
// Read test results file
function readTestResults() {
try {
if (!fs.existsSync(TEST_RESULTS_FILE)) {
return null;
}
const content = fs.readFileSync(TEST_RESULTS_FILE, 'utf8');
return JSON.parse(content);
} catch (err) {
log(`Error reading test results: ${err.message}`, 'ERROR');
return null;
}
}
// Get file modification time
function getFileMtime(filepath) {
try {
const stats = fs.statSync(filepath);
return stats.mtimeMs;
} catch (err) {
return 0;
}
}
// Send message to Grok via grok-control.sh
function sendCorrectionToGrok(message) {
return new Promise((resolve) => {
log(`Sending correction to Grok: ${message}`, 'INFO');
const grokControl = spawn(GROK_CONTROL_SCRIPT, ['send', message], {
stdio: ['ignore', 'pipe', 'pipe']
});
let stdout = '';
let stderr = '';
grokControl.stdout.on('data', (data) => {
stdout += data.toString();
});
grokControl.stderr.on('data', (data) => {
stderr += data.toString();
});
grokControl.on('close', (code) => {
if (code === 0) {
log('Correction sent successfully', 'INFO');
if (stdout.trim()) log(`stdout: ${stdout.trim()}`, 'DEBUG');
resolve(true);
} else {
log(`Failed to send correction (exit code ${code})`, 'WARN');
if (stderr.trim()) log(`stderr: ${stderr.trim()}`, 'DEBUG');
resolve(false);
}
});
grokControl.on('error', (err) => {
log(`Error spawning grok-control: ${err.message}`, 'ERROR');
resolve(false);
});
});
}
// Analyze test failure and generate correction
function analyzeFailure(failure) {
const { test, error, file, line } = failure;
// Pattern-based analysis
let correction = null;
// Null/undefined errors
if (error.includes('Cannot read property') || error.includes('undefined')) {
const match = error.match(/Cannot read property '(\w+)'/);
const property = match ? match[1] : 'property';
correction = `[SUPERVISOR] Bug found: ${test}
Fix this by: Add null/undefined check before accessing '${property}' in ${file}:${line}
Example fix:
if (!obj || typeof obj.${property} === 'undefined') {
return { error: 'Invalid state: ${property} is undefined' };
}`;
}
// Type errors
else if (error.includes('TypeError') || error.includes('is not a')) {
correction = `[SUPERVISOR] Bug found: ${test}
Fix this by: Check type before operation in ${file}:${line}
Error: ${error}
Add type validation:
if (typeof variable !== 'expected_type') {
return { error: 'Invalid type' };
}`;
}
// Reference errors
else if (error.includes('ReferenceError') || error.includes('not defined')) {
correction = `[SUPERVISOR] Bug found: ${test}
Fix this by: Ensure variable is defined before use in ${file}:${line}
Error: ${error}
Check variable scope and declaration.`;
}
// Async/await errors
else if (error.includes('async') || error.includes('Promise')) {
correction = `[SUPERVISOR] Bug found: ${test}
Fix this by: Ensure async/await is used correctly in ${file}:${line}
Error: ${error}
Make sure to await async calls and handle promises properly.`;
}
// Generic error
else {
correction = `[SUPERVISOR] Bug found: ${test}
Fix this by: Debug and fix this error in ${file}:${line}
Error: ${error}
Review the code logic and add appropriate error handling.`;
}
return correction;
}
// Process test results
async function processTestResults(results) {
const { total_tests, passed, failed, failures, timestamp } = results;
log(`Processing test results: ${passed}/${total_tests} passed, ${failed} failed`, 'INFO');
if (failed === 0) {
log('All tests passed! No corrections needed.', 'INFO');
return true;
}
if (!failures || failures.length === 0) {
log('Warning: failed count > 0 but no failures array', 'WARN');
return false;
}
// Process each failure
let criticalBug = false;
for (const failure of failures) {
const correction = analyzeFailure(failure);
if (correction) {
log(`Generated correction for: ${failure.test}`, 'INFO');
// Send correction
const sent = await sendCorrectionToGrok(correction);
if (sent) {
// Check if this is a critical bug (should pause Grok)
if (failure.error.includes('TypeError') ||
failure.error.includes('ReferenceError') ||
failure.error.includes('Cannot read')) {
criticalBug = true;
}
} else {
log('Failed to send correction, continuing...', 'WARN');
}
// Small delay between corrections
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
// If critical bug found, consider pausing Grok
if (criticalBug) {
log('Critical bug detected. Consider pausing Grok.', 'WARN');
log('Run: grok-control.sh pause', 'WARN');
}
return true;
}
// Main monitoring loop
let lastMtime = 0;
let lastResults = null;
async function monitoringLoop() {
log('Starting monitoring cycle...', 'DEBUG');
// Check if test results file exists and has been modified
const currentMtime = getFileMtime(TEST_RESULTS_FILE);
if (currentMtime === 0) {
log('Test results file does not exist yet', 'DEBUG');
} else if (currentMtime > lastMtime) {
log('Test results file has been modified', 'INFO');
lastMtime = currentMtime;
// Read and process results
const results = readTestResults();
if (results) {
// Check if results are actually different
const resultsJson = JSON.stringify(results);
const lastResultsJson = lastResults ? JSON.stringify(lastResults) : '';
if (resultsJson !== lastResultsJson) {
await processTestResults(results);
lastResults = results;
} else {
log('Test results unchanged (same timestamp)', 'DEBUG');
}
}
} else {
log('Test results file unchanged', 'DEBUG');
}
// Schedule next check
setTimeout(monitoringLoop, CHECK_INTERVAL_MS);
}
// Graceful shutdown handler
function handleShutdown(signal) {
log(`Received ${signal}, shutting down gracefully...`, 'INFO');
process.exit(0);
}
// Main entry point
async function main() {
log('=================================', 'INFO');
log('Claude Monitor Daemon Starting...', 'INFO');
log(`PID: ${process.pid}`, 'INFO');
log(`Check Interval: ${CHECK_INTERVAL_MS}ms`, 'INFO');
log(`Test Results File: ${TEST_RESULTS_FILE}`, 'INFO');
log('=================================', 'INFO');
// Register signal handlers
process.on('SIGTERM', () => handleShutdown('SIGTERM'));
process.on('SIGINT', () => handleShutdown('SIGINT'));
// Initial check
const initialResults = readTestResults();
if (initialResults) {
log('Found existing test results on startup', 'INFO');
lastMtime = getFileMtime(TEST_RESULTS_FILE);
await processTestResults(initialResults);
lastResults = initialResults;
} else {
log('No existing test results found, waiting for Grok...', 'INFO');
}
// Start monitoring loop
monitoringLoop();
}
// Start the daemon
main().catch((err) => {
log(`Fatal error: ${err.message}`, 'ERROR');
console.error(err);
process.exit(1);
});

Grok Coder - System Prompt

You are Grok, a fast coding agent. Your role is to write code quickly and efficiently.

Your Core Responsibilities

  1. Write Code Fast: Implement features rapidly without overthinking
  2. Run Tests: Always run tests after each feature completion
  3. Save Results: Save test results to .grok-test-results.json in the project root
  4. Accept Corrections: When you receive bug reports from Claude, implement fixes immediately
  5. Stay Focused: Don't argue with supervisor corrections - just fix the bugs

Test Results Format

After running tests, save results in this JSON format:

{
  "timestamp": "2026-01-15T10:30:00Z",
  "total_tests": 42,
  "passed": 40,
  "failed": 2,
  "failures": [
    {
      "test": "password reset returns 500 error",
      "error": "TypeError: Cannot read property 'email' of null",
      "file": "auth/reset.js",
      "line": 15
    }
  ]
}

Communication with Supervisor

You will receive messages from Claude (the supervisor) via the Clauder MCP connection. These messages will appear at your prompt input and follow this format:

[SUPERVISOR] Bug found: <description>
Fix this by: <actionable solution>

When you receive such a message:

  1. Acknowledge: Note the bug report
  2. Implement: Apply the suggested fix
  3. Verify: Run tests again
  4. Report: Save new test results

What NOT to Do

  • ❌ Don't skip tests to save time
  • ❌ Don't argue with supervisor corrections
  • ❌ Don't ignore bug reports
  • ❌ Don't modify .grok-test-results.json manually
  • ❌ Don't try to outsmart the supervisor

What TO Do

  • ✅ Write code quickly and confidently
  • ✅ Run tests after every feature
  • ✅ Save test results immediately
  • ✅ Accept corrections gracefully
  • ✅ Fix bugs when reported
  • ✅ Keep code functional even if not perfect

Process Flow

  1. Receive task from user
  2. Implement feature rapidly
  3. Run tests
  4. Save test results to .grok-test-results.json
  5. If tests fail, wait for supervisor correction
  6. Apply correction
  7. Re-run tests
  8. Continue to next feature

Speed vs Quality Tradeoff

You prioritize speed over perfection. The supervisor (Claude) will catch your bugs and guide you to fixes. Your job is to generate code volume quickly.

Remember: You are the "fast coder" in this system. Embrace speed, accept that bugs will happen, and trust the supervisor to catch them.

#!/bin/bash
# Grok Process Control Script
# Manages Grok instance lifecycle: status, pause, resume, stop, kill
set -euo pipefail
# Configuration
GROK_PID_FILE="$HOME/.opencode/grok.pid"
GROK_PORT=4096
LOG_FILE="/tmp/grok-control.log"
# Logging function
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
}
# Check if PID file exists and process is running
is_grok_running() {
if [[ -f "$GROK_PID_FILE" ]]; then
local pid
pid=$(cat "$GROK_PID_FILE" 2>/dev/null || echo "")
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
return 0 # Running
fi
fi
return 1 # Not running
}
# Get Grok PID
get_grok_pid() {
if [[ -f "$GROK_PID_FILE" ]]; then
cat "$GROK_PID_FILE" 2>/dev/null || echo ""
fi
}
# Status command
cmd_status() {
echo "=== Grok Instance Status ==="
echo ""
if is_grok_running; then
local pid
local state
pid=$(get_grok_pid)
# Check if process is stopped (paused) or running
if kill -0 "$pid" 2>/dev/null; then
# Use ps to check process state
state=$(ps -o state= -p "$pid" 2>/dev/null | tr -d ' ' || echo "?")
case "$state" in
T*)
echo "Status: PAUSED (stopped)"
echo "PID: $pid"
echo "Port: $GROK_PORT"
echo "Process State: $state"
;;
S*|R*|D*)
echo "Status: RUNNING"
echo "PID: $pid"
echo "Port: $GROK_PORT"
echo "Process State: $state"
;;
*)
echo "Status: UNKNOWN"
echo "PID: $pid"
echo "Process State: $state"
;;
esac
fi
echo ""
echo "✓ Grok instance is active"
return 0
else
echo "Status: NOT RUNNING"
echo ""
echo "✗ No Grok instance found"
return 1
fi
}
# Pause command - Send SIGSTOP (cannot be ignored)
cmd_pause() {
if ! is_grok_running; then
log "ERROR: Grok is not running"
echo "ERROR: Grok is not running"
return 1
fi
local pid
pid=$(get_grok_pid)
log "Pausing Grok (PID: $pid)"
echo "Pausing Grok instance..."
if kill -STOP "$pid" 2>/dev/null; then
log "Grok paused successfully"
echo "✓ Grok paused (SIGSTOP sent)"
echo " Grok cannot continue until resumed"
return 0
else
log "ERROR: Failed to pause Grok"
echo "ERROR: Failed to pause Grok"
return 1
fi
}
# Resume command - Send SIGCONT
cmd_resume() {
if ! is_grok_running; then
log "ERROR: Grok is not running"
echo "ERROR: Grok is not running"
return 1
fi
local pid
pid=$(get_grok_pid)
log "Resuming Grok (PID: $pid)"
echo "Resuming Grok instance..."
if kill -CONT "$pid" 2>/dev/null; then
log "Grok resumed successfully"
echo "✓ Grok resumed (SIGCONT sent)"
return 0
else
log "ERROR: Failed to resume Grok"
echo "ERROR: Failed to resume Grok"
return 1
fi
}
# Stop command - Graceful shutdown (SIGTERM)
cmd_stop() {
if ! is_grok_running; then
log "WARNING: Grok is not running"
echo "WARNING: Grok is not running"
# Clean up stale PID file
rm -f "$GROK_PID_FILE" 2>/dev/null || true
return 0
fi
local pid
pid=$(get_grok_pid)
log "Stopping Grok gracefully (PID: $pid)"
echo "Stopping Grok instance..."
if kill -TERM "$pid" 2>/dev/null; then
# Wait for process to terminate (max 10 seconds)
local count=0
while kill -0 "$pid" 2>/dev/null && [[ $count -lt 10 ]]; do
sleep 1
count=$((count + 1))
done
if ! kill -0 "$pid" 2>/dev/null; then
log "Grok stopped successfully"
rm -f "$GROK_PID_FILE" 2>/dev/null || true
echo "✓ Grok stopped gracefully"
return 0
else
log "WARNING: Grok did not stop gracefully, may need to use kill"
echo "WARNING: Grok did not stop within 10 seconds"
echo "Use 'grok-control.sh kill' to force terminate"
return 1
fi
else
log "ERROR: Failed to send SIGTERM to Grok"
echo "ERROR: Failed to stop Grok"
return 1
fi
}
# Kill command - Force terminate (SIGKILL)
cmd_kill() {
if ! is_grok_running; then
log "WARNING: Grok is not running"
echo "WARNING: Grok is not running"
rm -f "$GROK_PID_FILE" 2>/dev/null || true
return 0
fi
local pid
pid=$(get_grok_pid)
log "Force killing Grok (PID: $pid)"
echo "Force terminating Grok instance..."
if kill -KILL "$pid" 2>/dev/null || kill -9 "$pid" 2>/dev/null; then
sleep 1
if ! kill -0 "$pid" 2>/dev/null; then
log "Grok killed successfully"
rm -f "$GROK_PID_FILE" 2>/dev/null || true
echo "✓ Grok force terminated (SIGKILL)"
return 0
else
log "ERROR: Grok is still running after SIGKILL"
echo "ERROR: Grok is still running"
return 1
fi
else
log "ERROR: Failed to kill Grok"
echo "ERROR: Failed to kill Grok"
return 1
fi
}
# Send message to Grok via Clauder MCP
cmd_send_message() {
local message="$1"
if [[ -z "$message" ]]; then
echo "ERROR: Message cannot be empty"
return 1
fi
if ! is_grok_running; then
echo "ERROR: Grok is not running"
return 1
fi
log "Sending message to Grok: $message"
echo "Sending message to Grok..."
# Use Clauder MCP to send message
# This requires clauder-mcp-server to be installed
if command -v npx &>/dev/null; then
echo "$message" | npx -y clauder-mcp-server send 2>/dev/null || {
log "WARNING: Could not send via Clauder MCP (may not be configured)"
echo "WARNING: Could not send message via Clauder MCP"
echo "Message: $message"
return 1
}
log "Message sent successfully"
echo "✓ Message sent"
return 0
else
log "ERROR: npx not found, cannot send message"
echo "ERROR: npx not found. Cannot send message."
return 1
fi
}
# Show usage
cmd_usage() {
cat <<EOF
Grok Process Control Script
Usage: $(basename "$0") <command>
Commands:
status Check if Grok is running and its state
pause Pause Grok (SIGSTOP) - cannot be ignored
resume Resume paused Grok (SIGCONT)
stop Graceful shutdown (SIGTERM)
kill Force terminate (SIGKILL)
send <message> Send message to Grok via Clauder MCP
Examples:
$(basename "$0") status
$(basename "$0") pause
$(basename "$0") resume
$(basename "$0") send "[SUPERVISOR] Bug found: Fix the null check"
Files:
PID File: $GROK_PID_FILE
Log File: $LOG_FILE
Port: $GROK_PORT
EOF
}
# Main command dispatcher
main() {
local command="${1:-}"
case "$command" in
status)
cmd_status
;;
pause)
cmd_pause
;;
resume)
cmd_resume
;;
stop)
cmd_stop
;;
kill)
cmd_kill
;;
send)
if [[ -z "${2:-}" ]]; then
echo "ERROR: send command requires a message argument"
echo ""
cmd_usage
exit 1
fi
cmd_send_message "$2"
;;
help|--help|-h)
cmd_usage
;;
*)
echo "ERROR: Unknown command '$command'"
echo ""
cmd_usage
exit 1
;;
esac
}
# Run main
main "$@"
{
"model": "claude-4-5",
"temperature": 0.2,
"agents": {
"supervisor": {
"model": "claude-4-5",
"max_steps": 100,
"tools": {"bash": true, "execute": true}
}
},
"mcp": {
"clauder": {
"command": "npx",
"args": ["-y", "clauder-mcp-server"]
}
}
}
{
"model": "grok-3-mini",
"temperature": 0.5,
"agents": {
"build": {
"model": "grok-3-mini",
"tools": {"edit": true, "bash": true, "execute": true}
}
},
"mcp": {
"clauder": {
"command": "npx",
"args": ["-y", "clauder-mcp-server"]
}
}
}
#!/bin/bash
# Grok + Claude 4.5 Supervisor - Startup Script
# Launches both Grok (coder) and Claude Monitor (supervisor) instances
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
GROK_PID_FILE="$HOME/.opencode/grok.pid"
MONITOR_PID_FILE="$HOME/.opencode/claude-monitor.pid"
GROK_LOG_FILE="/tmp/grok-instance.log"
MONITOR_LOG_FILE="/tmp/claude-monitor.log"
# Ensure ~/.local/bin is in PATH
export PATH="$HOME/.local/bin:$PATH"
# Helper functions
log_info() {
echo -e "${BLUE}[INFO]${NC} $*"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $*"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $*"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $*"
}
# Check if instances are already running
check_existing_instances() {
local grok_running=false
local monitor_running=false
if [[ -f "$GROK_PID_FILE" ]]; then
local pid
pid=$(cat "$GROK_PID_FILE" 2>/dev/null || echo "")
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
grok_running=true
fi
fi
if [[ -f "$MONITOR_PID_FILE" ]]; then
local pid
pid=$(cat "$MONITOR_PID_FILE" 2>/dev/null || echo "")
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
monitor_running=true
fi
fi
if $grok_running || $monitor_running; then
log_warn "Existing instances detected:"
$grok_running && echo " - Grok instance running (PID: $(cat $GROK_PID_FILE))"
$monitor_running && echo " - Claude Monitor running (PID: $(cat $MONITOR_PID_FILE))"
echo ""
read -p "Stop existing instances and restart? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
stop_existing_instances
else
log_error "Aborted. Stop existing instances manually or choose to restart."
exit 1
fi
fi
}
# Stop existing instances
stop_existing_instances() {
log_info "Stopping existing instances..."
if [[ -f "$MONITOR_PID_FILE" ]]; then
local pid
pid=$(cat "$MONITOR_PID_FILE" 2>/dev/null || echo "")
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
log_info "Stopping Claude Monitor (PID: $pid)..."
kill "$pid" 2>/dev/null || true
sleep 1
kill -9 "$pid" 2>/dev/null || true
fi
rm -f "$MONITOR_PID_FILE"
fi
if [[ -f "$GROK_PID_FILE" ]]; then
local pid
pid=$(cat "$GROK_PID_FILE" 2>/dev/null || echo "")
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
log_info "Stopping Grok instance (PID: $pid)..."
kill "$pid" 2>/dev/null || true
sleep 1
kill -9 "$pid" 2>/dev/null || true
fi
rm -f "$GROK_PID_FILE"
fi
log_success "Existing instances stopped"
}
# Check prerequisites
check_prerequisites() {
log_info "Checking prerequisites..."
local missing=()
# Check for node
if ! command -v node &>/dev/null; then
missing+=("node")
fi
# Check for npm
if ! command -v npm &>/dev/null; then
missing+=("npm")
fi
# Check for npx
if ! command -v npx &>/dev/null; then
missing+=("npx")
fi
if [[ ${#missing[@]} -gt 0 ]]; then
log_error "Missing prerequisites: ${missing[*]}"
log_error "Please install missing dependencies and try again."
exit 1
fi
log_success "Prerequisites check passed"
}
# Install clauder-mcp-server if needed
check_clauder_mcp() {
log_info "Checking clauder-mcp-server..."
# Check if it's already installed globally
if npm list -g clauder-mcp-server &>/dev/null; then
log_success "clauder-mcp-server already installed"
return 0
fi
# Try to install
log_info "Installing clauder-mcp-server globally..."
if npm install -g clauder-mcp-server; then
log_success "clauder-mcp-server installed successfully"
return 0
else
log_warn "Failed to install clauder-mcp-server"
log_warn "It will be installed on-demand via npx"
return 0
fi
}
# Start Grok instance
start_grok() {
log_info "Starting Grok coder instance..."
# Placeholder: Create a sleep process to simulate Grok running
sleep 3600 &
local grok_pid=$!
echo "$grok_pid" > "$GROK_PID_FILE"
log_success "Grok instance started (PID: $grok_pid)"
log_info "Grok log: $GROK_LOG_FILE"
}
# Start Claude Monitor
start_claude_monitor() {
log_info "Starting Claude Monitor daemon..."
# Start the monitor in background
node "$HOME/.local/bin/claude-monitor.js" > "$MONITOR_LOG_FILE" 2>&1 &
local monitor_pid=$!
echo "$monitor_pid" > "$MONITOR_PID_FILE"
# Wait a moment and check if it's still running
sleep 2
if kill -0 "$monitor_pid" 2>/dev/null; then
log_success "Claude Monitor started (PID: $monitor_pid)"
log_info "Monitor log: $MONITOR_LOG_FILE"
else
log_error "Claude Monitor failed to start"
log_info "Check log file: $MONITOR_LOG_FILE"
return 1
fi
}
# Show status
show_status() {
echo ""
echo "=========================================="
echo " Grok + Claude 4.5 Supervisor System "
echo "=========================================="
echo ""
# Grok status
if [[ -f "$GROK_PID_FILE" ]]; then
local pid
pid=$(cat "$GROK_PID_FILE" 2>/dev/null || echo "")
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
echo -e "${GREEN}✓${NC} Grok Instance: ${GREEN}RUNNING${NC} (PID: $pid)"
else
echo -e "${RED}✗${NC} Grok Instance: ${RED}STOPPED${NC}"
fi
else
echo -e "${RED}✗${NC} Grok Instance: ${RED}NOT STARTED${NC}"
fi
# Monitor status
if [[ -f "$MONITOR_PID_FILE" ]]; then
local pid
pid=$(cat "$MONITOR_PID_FILE" 2>/dev/null || echo "")
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
echo -e "${GREEN}✓${NC} Claude Monitor: ${GREEN}RUNNING${NC} (PID: $pid)"
else
echo -e "${RED}✗${NC} Claude Monitor: ${RED}STOPPED${NC}"
fi
else
echo -e "${RED}✗${NC} Claude Monitor: ${RED}NOT STARTED${NC}"
fi
echo ""
echo "Control Commands:"
echo " grok-control.sh status - Check Grok status"
echo " grok-control.sh pause - Pause Grok"
echo " grok-control.sh resume - Resume Grok"
echo " grok-control.sh stop - Stop Grok gracefully"
echo " grok-control.sh kill - Force stop Grok"
echo ""
echo "Log Files:"
echo " Grok: $GROK_LOG_FILE"
echo " Monitor: $MONITOR_LOG_FILE"
echo ""
}
# Stop all instances
stop_all() {
log_info "Stopping all instances..."
stop_existing_instances
log_success "All instances stopped"
}
# Main function
main() {
local command="${1:-start}"
case "$command" in
start)
echo ""
log_info "Starting Grok + Claude 4.5 Supervisor System..."
echo ""
check_prerequisites
check_clauder_mcp
check_existing_instances
start_grok
start_claude_monitor
show_status
log_success "System startup complete!"
;;
stop)
stop_all
;;
restart)
stop_all
sleep 1
main start
;;
status)
show_status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
}
# Run main
main "$@"

Claude Supervisor - System Prompt

You are Claude 4.5, the quality supervisor. Your role is to watch Grok's work, test everything, and ensure bug-free code.

Your Core Responsibilities

  1. Watch Grok: Monitor .grok-test-results.json for test results after every commit
  2. Test Everything: Run the full test suite after each Grok commit
  3. Detect Bugs: Identify test failures immediately
  4. Provide Specific Fixes: Give actionable, precise bug corrections
  5. Prevent Cascades: Pause Grok early to prevent bug accumulation

Test Results Monitoring

Read .grok-test-results.json after each Grok action:

{
  "timestamp": "2026-01-15T10:30:00Z",
  "total_tests": 42,
  "passed": 40,
  "failed": 2,
  "failures": [
    {
      "test": "password reset returns 500 error",
      "error": "TypeError: Cannot read property 'email' of null",
      "file": "auth/reset.js",
      "line": 15
    }
  ]
}

Bug Detection Protocol

When tests fail:

  1. Analyze: Read the error message and stack trace
  2. Locate: Find the exact file and line number
  3. Diagnose: Identify root cause (not just symptoms)
  4. Prescribe: Provide specific fix instructions

Correction Message Format

Send corrections to Grok via Clauder MCP in this format:

[SUPERVISOR] Bug found: <specific test failure>

Fix this by: <actionable solution steps>

Example:
[SUPERVISOR] Bug found: password reset returns 500 error

Fix this by: Check for null email parameter before sending email. Add this validation at line 15 in auth/reset.js:

if (!email || typeof email !== 'string') {
  return { error: 'Invalid email parameter' };
}

Process Signals

When bugs are detected, you may need to pause Grok:

  • SIGSTOP: Pause Grok mid-execution (cannot be ignored)
  • SIGCONT: Resume Grok after fix is provided
  • SIGTERM: Graceful shutdown

Testing Strategy

After Each Grok Commit:

  1. Read test results: cat .grok-test-results.json
  2. If failed > 0:
    • Analyze failures
    • Send correction message
    • Consider pausing if critical bug
  3. If all pass:
    • Log success
    • Let Grok continue

Test Categories:

  • Unit Tests: Individual function correctness
  • Integration Tests: Module interactions
  • Regression Tests: Previous bugs haven't returned
  • Edge Cases: Boundary conditions, null inputs, etc.

Quality Standards

What Constitutes a Bug:

  • ❌ Tests fail
  • ❌ Runtime exceptions
  • ❌ Null/undefined errors
  • ❌ Type mismatches
  • ❌ Security vulnerabilities
  • ❌ Performance degradation

What to Ignore:

  • ✅ Code style issues (Grok prioritizes speed)
  • ✅ Minor optimizations
  • ✅ Documentation gaps
  • ✅ Non-blocking warnings

Communication Style

Be Specific, Not Vague:

❌ Bad: "Fix the auth bug" ✅ Good: "In auth/reset.js line 15, add null check before accessing email property"

Provide Complete Solutions:

❌ Bad: "Handle the error case" ✅ Good: "Wrap in try-catch, return { error: 'Reset failed' } on exception"

Act Fast:

  • Test within 5 seconds of Grok commit
  • Send correction within 10 seconds of detecting bug
  • Don't wait for multiple failures - pause at first critical bug

Escalation Matrix

Bug Type Action Timeline
Critical (crashes) Pause + Immediate Fix < 5 seconds
Major (tests fail) Correction Message < 10 seconds
Minor (warnings) Log, Continue < 30 seconds
Style (formatting) Ignore N/A

Monitoring Loop

Every 5 seconds:

  1. Check if Grok committed (file modification time)
  2. If yes, read .grok-test-results.json
  3. If failures detected:
    • Pause Grok (if critical)
    • Analyze failure
    • Send correction via Clauder MCP
    • Resume Grok
  4. Log all actions

Success Metrics

You're doing your job when:

  • ✅ Zero bugs reach production
  • ✅ All test failures are caught within 10 seconds
  • ✅ Grok receives actionable fix instructions
  • ✅ Mean time to fix (MTTF) < 30 seconds
  • ✅ No cascading failures occur

Remember

Grok is fast but buggy. You are the safety net. Without your supervision, bugs would accumulate. Your precision prevents disaster.

Be thorough. Be specific. Be fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment