SLOPSHOPPER

context-guardian

Warns at 70% context and, at 85%, tells the model to wrap up and run /compact with keep-rules.

newtoastprompt
A shopper browsing a rack in a slop shop
README

context-guardian

Warns before the context window fills up.

Toasts at 70% context. At 85% it also adds an instruction telling the model to wrap up the current step and run /compact, keeping the task, changed files, failing output, decisions and branch state.

Install

/plugin marketplace add cloudcruncher/claude-mod-garage
/plugin install context-guardian@mod-garage

Run /reload-plugins (or restart Claude Code) afterwards. To try it from a local clone without installing: claude --plugin-dir ./dev-mods/context-guardian

Use it

  • Automatic once installed.

What you'll see

Illustrative output.

At 70%

Context is 70% full. Consider /compact or delegating.

At 85% (sent to the model)

Context is nearly full (85% or more). Wrap up the current step, then run /compact.

Notes

  • Toast wording is illustrative.
Source 2 files
hooks/register.ts 27 lines
1import type { Register } from 'claude-code'
2import { COMPACT_SECTION_TEXT, levelFor, shouldToast } from './guard'
3
4export const register: Register = on => {
5  let level = levelFor(undefined)
6  let warned = false
7
8  on('session.measure', ($, e, next) => {
9    level = levelFor(e.context.percent)
10    if (level === 'ok') warned = false
11    else if (shouldToast(level, warned)) {
12      warned = true
13      $.ui.toast(`Context at ${e.context.percent}%: consider wrapping up and compacting soon.`)
14    }
15    return next(e)
16  })
17
18  on('prompt.compose', async ($, e, next) => {
19    const r = await next(e)
20    if (level !== 'compact') return r
21    return {
22      ...r,
23      sections: [...r.sections, { id: 'context-guardian:compact', text: COMPACT_SECTION_TEXT, scope: 'session' as const }],
24    }
25  })
26}
27
hooks/guard.ts 23 lines
1export type Level = 'ok' | 'warn' | 'compact'
2
3export const WARN_AT = 70
4export const COMPACT_AT = 85
5
6export function levelFor(percent: number | undefined): Level {
7  if (percent === undefined) return 'ok'
8  if (percent >= COMPACT_AT) return 'compact'
9  if (percent >= WARN_AT) return 'warn'
10  return 'ok'
11}
12
13/** Warn toast fires once per climb; resets after context drops below the warn level (e.g. after /compact). */
14export function shouldToast(level: Level, alreadyWarned: boolean): boolean {
15  return level !== 'ok' && !alreadyWarned
16}
17
18export const COMPACT_SECTION_TEXT = [
19  'Context is nearly full (85% or more). Wrap up the current step, then run /compact.',
20  'When compacting, keep: the task and acceptance criteria; files changed and why; failing test output verbatim; decisions made; branch/PR state.',
21  'Drop: exploratory reads and passing output.',
22].join('\n')
23