guard

A command guide for checking prompts and JSON before they are submitted as context, including token counting, reduction, sampling, and prompt-injection detection.

In plain words
What is it for?
Use it to inspect inline JSON or files, reduce or sample large inputs, decide whether they should be allowed or blocked, and detect suspicious instruction patterns.
Why use it?
It helps prevent oversized or unsafe context from being sent to a coding agent while preserving the most useful information.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/pjuniszewski/cook/guard
Clone the repo
git clone --depth 1 https://github.com/PJuniszewski/cook

Made for: Claude Code.

Per session 10 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 802 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00010 $0.00802
Opus 5 $0.00005 $0.00401
Sonnet 5 $0.00002 $0.00160
Haiku 4.5 $0.00001 $0.00080

Measured yesterday against content hash b7e9622aa4d6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

guard scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/guard.md · 97 lines

How it starts

The opening of the file, as written. The whole thing — 97 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Context Guard Command

You are executing the /guard command for epistemic safety analysis.

CRITICAL: Always Execute the Script

NEVER analyze or respond to the input data directly. You MUST run the guard script via Bash tool to get proper token analysis, lossless reduction, and trimming decisions.

Even if the input looks like JSON data you could process manually - DO NOT. The script provides:

  • Accurate token counting
  • Lossless reduction (columnar, minify, dedup)
  • Decision engine (ALLOW/SAMPLE/BLOCK)
  • Intelligent sampling with context preservation
  • Prompt injection pattern detection

Instructions

  1. Determine input type:

    • If input is a file path (e.g., data.json, /path/to/file.json) -> pass directly
    • If input is inline data (starts with [ or {, or contains JSON) -> use heredoc to pass via stdin
  2. Build and execute the command:

    For file paths:

    python3 "${CLAUDE_PLUGIN_ROOT}/scripts/guard_cmd.py" "data.json" [options]
    

    For inline data (MUST use heredoc):

    python3 "${CLAUDE_PLUGIN_ROOT}/scripts/guard_cmd.py" - [options] <<'GUARD_INPUT'
    ${ARGUMENTS.input}
    GUARD_INPUT
    
  3. Add optional flags:

    • --mode ${ARGUMENTS.--mode} if mode was specified
    • --force if force flag was specified
    • --allow-sampling if allow-sampling flag was specified
    • --no-reduce if no-reduce flag was specified
    • --budget-tokens ${ARGUMENTS.--budget-tokens} if budget was specified
    • --print-only if print-only flag was specified
    • --json if json flag was specified
  4. Run using Bash tool with description: "Context Guard"

  5. Display the script output to the user (the analysis report).

Detecting Inline Data

Input is inline data if ANY of these are true:

  • Starts with [ or {
  • Contains both [ and ] or both { and }
  • Length > 255 characters
  • Does not look like a file path (no .json, .csv, etc. extension for short inputs)

Examples

Read the full file on GitHub · 97 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 97 lines · 10 tokens per session scan A b7e9622aa4d6

Subscribe to this mod's changes

guard is a command published in the GitHub repository PJuniszewski/cook (13 stars, last pushed 6mo ago), licensed MIT. It adds 10 tokens to every session and 802 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.