agentleFS
Idle-SyncIdle-Sync/skills/context-check/SKILL.md

context-check

Skill1 starsChanged 7 months agoMITView on GitHub

Report REAL context-window usage from the watchdog hook — invoke whenever asked to "check context", before deciding to close out or hand off, or when unsure how full the window is. Reads the actual token count instead of estimating. Self-installing: the first invocation on a machine wires up the hook that produces the number.

3 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions3 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 3

    1. sunitghub/canon-skills★ 9same name
    2. tmusser/ai-engineering-skills★ 6same name
    3. philpalmieri/engineering-manager-skills★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repositoryOne other file it gives its agents.

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never estimate context usage.

    line 13
  2. Distinctive:

    Run this first, every invocation:

    line 39
  3. Distinctive:

    Keep the two reasons to hand off separate: context pressure (this number) vs.

    line 96
  4. Very specific:

    $CLAUDE_CODE_SESSION_ID unset: read the newest .watchdog-*.log in the directory and say the number may belong to a sibling session.

    line 102

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

context-check — read real context usage, don't guess

Never estimate context usage. Read the measured number.

The number comes from a watchdog hook that fires on every UserPromptSubmit and Stop, takes the latest assistant turn's footprint (input_tokens + cache_read_input_tokens + cache_creation_input_tokens) from the session transcript, and appends one line per firing to .claude/hooks/.watchdog-<session-id>.log in the current project. Logs are per-session, so concurrent sessions never mix lines.

Requirements

jq is needed only for the bash hook. The PowerShell hook has no dependencies beyond Windows PowerShell 5.1, which ships with Windows 10 1809+ and Windows 11.

PlatformHook usedNotes
macOS, Linuxhooks/context-check.shbash 3.2+ (macOS system bash included) and jq. No GNU-only tools.
Windows + WSL 1/2hooks/context-check.shA Linux environment; same as above.
Windows native + Git for Windowshooks/context-check.shRegistered with shell: "bash" so it is never routed to PowerShell. Install jq separately (winget install jqlang.jq).
Windows native, no Git Bashhooks/context-check.ps1Registered as powershell.exe -NoProfile -ExecutionPolicy Bypass -File …. No jq, no Git for Windows.

Register one hook per machine, not both — they write to the same log, so a double registration produces two lines per event. setup.ps1 warns when it sees the bash hook already registered.

Step 1 — Ensure the hook exists

Run this first, every invocation:

On macOS, Linux, WSL, or Git Bash — anywhere the Bash tool is available:

SK=$(ls -d "$HOME/.claude/skills/context-check" "${CLAUDE_PROJECT_DIR:-.}/.claude/skills/context-check" 2>/dev/null | head -n 1)
bash "$SK/scripts/setup.sh"

On native Windows without Git Bash, where the harness gives you the PowerShell tool instead of Bash, run the PowerShell installer — same behaviour, same log format:

$sk = @("$env:USERPROFILE\.claude\skills\context-check", "$env:CLAUDE_PROJECT_DIR\.claude\skills\context-check") |
      Where-Object { Test-Path $_ } | Select-Object -First 1
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$sk\scripts\setup.ps1"

It is idempotent: on an already-wired machine it prints up-to-date / already registered and changes nothing. It installs hooks/context-check.sh to ~/.claude/hooks/ (with --project, to $CLAUDE_PROJECT_DIR/.claude/hooks/), registers it for UserPromptSubmit + Stop in the matching settings.json leaving other hooks untouched, and prints the newest log line.

Act on its output:

  • log: none yet / no line for this session yet — first install, or the session predates registration. The hook writes its first line on the next prompt or turn end, so there is no measured number for this moment. Say that. Do not produce a figure; the user's status line (which shows remaining) is the only stand-in until the next firing.
  • MISSING / NOT registered / STALE, or a jq is required error — report the blocker verbatim. jq is a hard dependency.
  • A log line is shown — continue to Step 2.

Step 2 — Read this session's number

tail -n 3 "${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/.watchdog-${CLAUDE_CODE_SESSION_ID}.log"

Each line is TIMESTAMP EVENT PCT% (USED tokens, window WINDOW, MODEL). PCT% is the real percentage used against the correct window. Apply no math and no 2× correction.

Window detection: 1,000,000 for opus and for Fable pinned to the [1m] long-context model in ~/.claude/settings.json; 500,000 for plain Fable; 500,000 otherwise. CLAUDE_CONTEXT_WINDOW overrides it; CLAUDE_CONTEXT_WARN_PCT sets the warn threshold (default 70).

Step 3 — Report and advise

Report as: N% used (M% remaining) — ~USED of WINDOW tokens, model MODEL. Include remaining, because the status line frames it that way ("N% ctx" = N% remaining).

  • < 70% used — healthy. Keep working; no close-out on context grounds alone.
  • ≥ 70% used — finish the current unit, update whatever handoff/progress docs the project uses, prompt the user to start a fresh session.

Keep the two reasons to hand off separate: context pressure (this number) vs. a new major task (a fresh session is cheap regardless of the number). Do not cite context pressure when the reason is a clean task boundary.

Fallbacks

  • $CLAUDE_CODE_SESSION_ID unset: read the newest .watchdog-*.log in the directory and say the number may belong to a sibling session.
  • Newest line is stale (timestamp well before now): note that it reflects the last hook firing, not this instant.
  • Project-level registration: a project settings.json hook shadows the global one. Both write the same format, so the reading is unaffected.
  • Session logs older than 7 days are pruned by the hook.
  • A shared .watchdog.log from a pre-per-session version is unused; delete it with setup.sh --prune-legacy.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.