context-guardian

Proactive context monitoring with smart 3-level alerts. Know when to restart before quality degrades.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "context-guardian" with this command: npx skills add brucey0017-cloud/context-guardian

Context Guardian 🛡️

Your context guardian. Alerts before errors happen.

Proactive context monitoring that warns you at 60%, 70%, and 85% usage — before context pollution causes errors and hallucinations.


Why You Need This

The Problem:

  • Long conversations lead to context pollution
  • Quality degrades silently as context fills up
  • You don't know when to restart until it's too late
  • Errors and hallucinations increase after ~70% usage

The Solution:

  • Continuous monitoring of context usage
  • Smart 3-level alerts (⚠️ 60%, 🟠 70%, 🔴 85%)
  • Actionable suggestions at each level
  • Prevents duplicate alerts

Quick Start

For Agents: Heartbeat Integration

When you receive a heartbeat poll, include this check:

  1. Call session_status tool to get current context usage
  2. Parse the context percentage from the output
  3. Compare against thresholds: 60% (warning), 70% (danger), 85% (critical)
  4. If threshold exceeded and not a duplicate alert, display the appropriate alert message
  5. Update state file to track alert history

Implementation:

During heartbeat:
1. Get context usage from session_status
2. Check if usage >= 60%, 70%, or 85%
3. Load state from memory/context-guardian-state.json
4. Determine if alert should be sent (prevent duplicates)
5. If yes, display alert and update state

For Users: Enable in HEARTBEAT.md

Add to your HEARTBEAT.md:

## Context Monitoring
- Check context usage
- Alert if thresholds exceeded (60%, 70%, 85%)

The agent will automatically handle the rest.


How It Works

Monitoring

The skill calls session_status to check your current context usage percentage.

Alert Levels

⚠️ Warning (60%)

⚠️ Context: 60%
Getting full. Consider wrapping up or starting fresh soon.

🟠 Danger (70%)

🟠 Context: 70%
Pollution risk rising. Recommend:
• Finish current task
• Start new session for next task
• Or compress with context-optimizer

🔴 Critical (85%)

🔴 Context: 85% - CRITICAL
High error risk. STRONGLY recommend:
• Save work
• Start new session NOW
• Quality degradation likely

Smart Duplicate Prevention

The skill tracks alert history and only alerts when:

  1. First time reaching a threshold
  2. Alert level upgrades (60% → 70% → 85%)
  3. Usage drops below threshold then rises again

Configuration

Edit config/default.json or create config/user.json:

{
  "enabled": true,
  "checkInterval": "heartbeat",
  "thresholds": {
    "warning": 60,
    "danger": 70,
    "critical": 85
  },
  "alertMethod": "message",
  "alertStyle": "emoji",
  "preventDuplicates": true,
  "trackHistory": true,
  "suggestions": {
    "autoSuggest": true,
    "suggestCompression": true,
    "suggestRestart": true
  }
}

Options

checkInterval:

  • "heartbeat" - Check during heartbeat polls (default)
  • "cron" - Independent cron job (future)
  • number - Check every N minutes (future)

thresholds:

  • Customize alert levels (default: 60, 70, 85)

alertMethod:

  • "message" - Send as message (default)
  • "log" - Log only
  • "notification" - System notification (future)

alertStyle:

  • "emoji" - Emoji + concise text (default)
  • "text" - Plain text
  • "detailed" - Full explanation

Manual Check

You can manually check context status:

bash {baseDir}/scripts/check.sh

Integration with Other Skills

context-optimizer

When you reach 70%, the skill suggests using context-optimizer to compress your context instead of restarting.

context-recovery

After context recovery, the skill automatically resumes monitoring.


Implementation Guide for Agents

Step-by-Step Process

1. Get Context Usage

Call session_status tool and parse the output:

Example output: "Context: 54k/200k (27%)"
Extract: 27

2. Determine Alert Level

if (usage >= 85) level = "critical"
else if (usage >= 70) level = "danger"
else if (usage >= 60) level = "warning"
else level = null

3. Load State

Read {workspace}/memory/context-guardian-state.json:

{
  "lastCheck": 1709452800,
  "lastUsage": 54,
  "lastAlertLevel": "warning",
  "lastAlertTime": 1709452500,
  "history": [...]
}

4. Check if Should Alert

Prevent duplicate alerts:

shouldAlert = false

// First time reaching threshold
if (!lastAlertLevel && level) shouldAlert = true

// Level upgrade (warning → danger → critical)
if (levelNum[level] > levelNum[lastAlertLevel]) shouldAlert = true

// Usage dropped below threshold and rose again
if (lastUsage < threshold - 5 && usage >= threshold) shouldAlert = true

5. Send Alert

If shouldAlert, display the appropriate message:

⚠️ Context: 60%
Getting full. Consider wrapping up or starting fresh soon.

6. Update State

Save new state to memory/context-guardian-state.json:

{
  "lastCheck": <current_timestamp>,
  "lastUsage": <current_usage>,
  "lastAlertLevel": <level_if_alerted>,
  "lastAlertTime": <timestamp_if_alerted>,
  "history": [..., {"timestamp": <now>, "usage": <usage>}]
}

Alert Messages

Warning (60%):

⚠️ Context: 60%
Getting full. Consider wrapping up or starting fresh soon.

Danger (70%):

🟠 Context: 70%
Pollution risk rising. Recommend:
• Finish current task
• Start new session for next task
• Or compress with context-optimizer

Critical (85%):

🔴 Context: 85% - CRITICAL
High error risk. STRONGLY recommend:
• Save work
• Start new session NOW
• Quality degradation likely

State Management

State is stored in {workspace}/memory/context-guardian-state.json:

{
  "lastCheck": 1709452800,
  "lastUsage": 54,
  "lastAlertLevel": null,
  "lastAlertTime": null,
  "history": [
    {"timestamp": 1709452800, "usage": 54}
  ]
}

Troubleshooting

No alerts appearing:

  • Check that HEARTBEAT.md includes context monitoring
  • Verify heartbeat is running
  • Check state file for errors

Too many alerts:

  • Increase thresholds in config
  • Check preventDuplicates is enabled

Alerts not accurate:

  • Verify session_status is working
  • Check OpenClaw version compatibility

Examples

Heartbeat Integration

Add to HEARTBEAT.md:

## Context Monitoring
- Check context usage
- Alert if thresholds exceeded

Custom Thresholds

Create config/user.json:

{
  "thresholds": {
    "warning": 50,
    "danger": 65,
    "critical": 80
  }
}

Technical Details

Dependencies:

  • OpenClaw 2026.2.0+
  • session_status tool
  • Bash

Performance:

  • Zero overhead (only checks during heartbeat)
  • Minimal state storage (~1KB)

Privacy:

  • All data stored locally
  • No external calls
  • No telemetry

Roadmap

v1.1.0:

  • Historical trend tracking
  • Usage prediction
  • Independent cron mode

v1.2.0:

  • Auto-trigger context-optimizer
  • Visual trend graphs
  • Multi-session monitoring

Contributing

Found a bug? Have a suggestion? Open an issue or PR on GitHub.


License

MIT

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Trump Truth Social Tracker

跟踪特朗普 Truth Social 帖子数据。从 CNN 归档 API 获取数据并同步到本地 SQLite 数据库,支持查询、统计和分析。触发场景:(1) 用户要求同步/更新 Truth Social 数据 (2) 查询特朗普帖子内容、互动数据 (3) 分析帖子趋势或统计信息 (4) 用户提到"Truth So...

Registry SourceRecently Updated
941Profile unavailable
General

Ghostty — Your Always-On Digital Self

Your always-on digital self — monitors all your communication channels in parallel, learns your writing style, drafts replies in your voice, and routes them...

Registry SourceRecently Updated
770Profile unavailable
General

ClawRadar — Real-Time Trend Monitor for OpenClaw

Monitors AI, indie hacking, and entrepreneurship trends on X and Reddit in real-time, scoring viral posts for timely Telegram alerts with engagement insights.

Registry SourceRecently Updated
1060Profile unavailable
General

Disk Watch

Monitor disk space across drives. Alert before disks fill up. Track usage trends, find space hogs, suggest cleanup. Every server needs this.

Registry SourceRecently Updated
4080Profile unavailable