#!/bin/bash # System Event: Inject a text event into an existing Claude Code session. # Lighter than agentTurn — does not create a new session. # # Bash 3.2 compatible. # # Usage: ./system-event.sh "session-name" "Event text to inject" # # Placeholders: # {{WORKING_DIR}} - absolute path to project directory WORKING_DIR="{{WORKING_DIR}}" SESSION_NAME="${1:-}" EVENT_TEXT="${2:-}" if [ -z "$SESSION_NAME" ] || [ -z "$EVENT_TEXT" ]; then echo "Usage: $0 " echo "Example: $0 'agent:researcher:turn' 'New data available in /data/inbox'" exit 1 fi LOG_DIR="$WORKING_DIR/logs" mkdir -p "$LOG_DIR" TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ) echo "$TIMESTAMP | system-event | INJECT: $SESSION_NAME -- $EVENT_TEXT" >> "$LOG_DIR/system-event.log" cd "$WORKING_DIR" # Resume the named session and inject the event OUTPUT=$(claude --resume "$SESSION_NAME" -p "$EVENT_TEXT" \ --output-format text \ --max-turns 3 2>&1) EXIT_CODE=$? TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ) if [ "$EXIT_CODE" -eq 0 ]; then echo "$TIMESTAMP | system-event | DELIVERED: $SESSION_NAME (exit $EXIT_CODE)" >> "$LOG_DIR/system-event.log" else echo "$TIMESTAMP | system-event | FAILED: $SESSION_NAME (exit $EXIT_CODE)" >> "$LOG_DIR/system-event.log" fi