Skip to content

Security Audit, Policy & Incident Response

Chakshu acts as a passive guardian eye over local AI coding agents, analyzing every recorded tool invocation for security risks, evaluating actions against built-in security policies, maintaining tamper-evident audit chains, tracking incidents, and providing emergency OS process controls.


1. Real-Time Security Audit (internal/audit)

Every ToolCall captured by Chakshu can be inspected via audit.AnalyzeCall(c) in real time (chakshu audit and the #/audit Web UI).

Chakshu Executive Security Posture & Audit

Risk Severity Levels

Findings are classified into five levels: - INFO (none) - low (LOW) - medium (MEDIUM) - high (HIGH) - critical (CRITICAL)

Detection Categories

Category What It Detects
destructive Destructive shell commands (rm -rf, disk wipes, force git operations such as git reset --hard, git push --force)
remote_exec Piped remote script execution (curl \| bash, wget \| sh)
reverse_shell Reverse shell patterns and outbound interactive socket binds
sensitive_file Reads or writes targeting .env files, SSH keys (~/.ssh/), cloud credentials, or private keys
path_traversal Path traversal sequences (../) attempting to escape workspace boundaries
system_path Modifications to critical OS system directories
outside_cwd File or command operations targeting paths outside the session's working directory

Secret Redaction & Credential Access Tracking

Before persisting approval/audit details or rendering them in the terminal or web UI, Chakshu semantically redacts detected credentials, API keys, tokens, and URL passwords (RedactValue, MaskSecret, redactCredentials, redactSensitivePaths) so secrets are never leaked in observability logs.

audit.CredentialAccesses(c) also extracts structured credential access events (variable names, access types, and masked values) for display in the Web UI's Security & Secrets session subtab (#/sessions/:id/security) and Skill Intelligence security verdicts.

Cryptographic Audit Chaining (internal/audit/chainer.go)

Structured SecurityEvent records support tamper-evident SHA-256 hash chaining: - GenesisHash: 64-character zero sentinel for the root of a chain. - ChainEvent(prevHash, evt): Computes a deterministic SHA-256 hash (EventHash) over the canonical event payload (EventID, Timestamp, SessionID, AgentID, Tool, ActionType, RiskScore, Severity, Decision, and PreviousEventHash). - VerifyChain(events): Walks an ordered sequence of security events to verify hash linkage and detect any tampering or missing records.

CLI Usage

# Inspect recent tool calls for security risks
chakshu audit

# Filter by risk level, session, or agent
chakshu audit --level critical
chakshu audit --session #ab12cd34 --agent codex
chakshu audit --limit 500

2. Policy Engine (internal/policy)

The policy engine evaluates tool calls against structured security policies (internal/policy/rules.go) and maps violations to PolicyViolation records with severity and threat categories:

Category Policy Focus
DESTRUCTIVE_EXEC Prohibit destructive shell operations
REMOTE_EXEC Block piped remote execution and reverse shells
NETWORK_EGRESS Prevent cloud metadata SSRF exfiltration
DATA_LEAKAGE Detect sensitive credential and private key access
PATH_TRAVERSAL Flag workspace boundary path traversal
SUPPLY_CHAIN Detect CI/CD workflow and security hook tampering
PRIVILEGE_ESCALATION Flag unauthorized privilege escalation (sudo, sandbox bypass)
PROMPT_INJECTION Detect prompt injection and jailbreak indicators

Policy Decisions & Custom Policy Sets

Each rule produces one of four policy.Decision outcomes: - OBSERVED_CLEAN — No violation detected - DETECTED_VIOLATION — Policy rule violated (logged and scored) - ENFORCED_BLOCKED — Marked as blocked - REQUIRE_APPROVAL — Flagged as requiring human approval

Custom policy sets can be loaded from a directory via policy.Engine.LoadPoliciesFromDir(dir) using JSON or YAML PolicySet definitions:

version: "1.0"
rules:
  - id: CUSTOM-001
    name: Block Production Push
    category: DESTRUCTIVE_EXEC
    description: Flag force pushes to main
    condition:
      tool_matches: ["bash", "exec_command"]
      command_regex: "git\\s+push\\s+.*--force"
      exempt_commands: ["git status"]
    action:
      risk_score_penalty: 40
      severity: HIGH
      default_decision: DETECTED_VIOLATION
      require_approval: true
      alert: true

Runtime Policy Wiring, MCP Pinning & Guardrails

  • Watcher & Importer Policy Evaluation: internal/policy is evaluated automatically during live chakshu daemon ingestion and chakshu import, chaining flagged events into security_events via audit.ChainEvent.
  • Runaway Loop & Token Burn Guardrails (internal/watcher/guardrails.go): Detects sliding-window retry loops and sudden token spikes in real time, surfacing live alert banners in the Web UI and warnings in chakshu tail / chakshu logs -f.
  • MCP Config Pinning & Drift Detection: internal/mcp records SHA-256 hashes of discovered MCP server configurations (including ~/.claude.json) and flags configuration drift in AuditView (#/audit).

3. Incident Management & Pre-Execution Rollback (internal/incident, internal/snapshot)

High- and critical-severity security events are correlated into tracked Security Incidents stored in SQLite (incidents table):

  • Lifecycle: Incidents track status (OPEN or RESOLVED), severity (HIGH, CRITICAL, etc.), title, target resource, tool, lineage, and summary.
  • Auto-Ingestion: Running chakshu incidents automatically backfills OPEN incidents from recent HIGH and CRITICAL tool call findings if none have been ingested yet.
chakshu incidents

Pre-Execution File Snapshots & Rollback (internal/snapshot)

Chakshu supports content-addressed pre-edit file backups so unintended agent edits can be reverted cleanly: - Capture (chakshu snapshot-hook): Reads PreToolUse JSON on stdin and stores a content-addressed backup in file_snapshots. - Restore (chakshu rollback): List captured snapshots (chakshu rollback --list [--session ID]) or restore a file by call ID (chakshu rollback <call-id>), or trigger one-click rollback from the Session Files Web UI (/api/snapshots, /api/rollback).


4. Agent Process Discovery & Emergency Controls (ps & kill)

Chakshu can discover active AI coding agent processes running on the host and issue emergency OS process signals.

Process Discovery (chakshu ps)

Scans the local process table for active AI coding agents (Claude, Codex, Gemini) and reports: - PID and Agent Name - RSS RAM (MB), VSZ (MB), and %MEM - Memory Status: normal, elevated (> 400 MB), or leak_warning (> 1 GB) - Command Line Preview

chakshu ps

Emergency Kill Switch (chakshu kill)

Sends OS signals to a running agent process:

Action OS Signal Effect
terminate (default) SIGTERM Gracefully request process shutdown
kill SIGKILL Forcefully terminate process immediately
pause SIGSTOP Suspend process execution without terminating
resume SIGCONT Resume a paused process

Safety Validation: Before sending any signal, incident.ValidateAgentPID(pid) verifies that the target PID is a known AI coding agent process to prevent accidental termination of unrelated system processes. Pass --force (-f) only if you explicitly want to override this check.

chakshu kill 12345 pause
chakshu kill 12345 resume
chakshu kill 12345 terminate
chakshu kill 12345 kill