counterfactual

counterfactual is a skill for Claude Code, Codex from Kevin-Liu-01/Agent-Machines. It costs 38 tokens per session (632 once invoked), scanned A, original, MIT.

A debugging method that compares the code's current behavior with the smallest correct algorithm. An algorithm is the exact sequence of steps a program should follow to produce the intended result.

In plain words
What is it for?
Use it when debugging regressions, reviewing complicated fixes, or explaining what the code should do versus what it currently does.
Why use it?
It helps identify the first point where actual behavior diverges from the required behavior, instead of patching symptoms. It preserves parts that already work and defines how to prove the fix correct.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when debugging regressions, reviewing complicated fixes, or explaining what the code should do versus what it currently does.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/kevin-liu-01/agent-machines/counterfactual
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.

Any agent
npx skills add Kevin-Liu-01/Agent-Machines --skill counterfactual
Clone the repo
git clone --depth 1 https://github.com/Kevin-Liu-01/Agent-Machines

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for counterfactual

README.md
[![agentmods](https://agentmods.dev/badge/skills/kevin-liu-01/agent-machines/counterfactual/github.svg)](https://agentmods.dev/skills/kevin-liu-01/agent-machines/counterfactual)
Your own site
<a href="https://agentmods.dev/skills/kevin-liu-01/agent-machines/counterfactual"><img src="https://agentmods.dev/badge/skills/kevin-liu-01/agent-machines/counterfactual/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for counterfactual

Your own site · 80×15
<a href="https://agentmods.dev/skills/kevin-liu-01/agent-machines/counterfactual"><img src="https://agentmods.dev/badge/skills/kevin-liu-01/agent-machines/counterfactual.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 38 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 632 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
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.1 $0.00038 $0.00632
Opus 5 $0.00019 $0.00316
Sonnet 5 $0.00008 $0.00126
Haiku 4.5 $0.00004 $0.00063

Measured 12d ago against content hash 0d5ad1f2a15e, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

counterfactual 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 12d ago.

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.

knowledge/skills/counterfactual/SKILL.md · 71 lines

How it starts

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

Counterfactual

Use this to avoid patching symptoms. The output must separate the minimal correct algorithm from the current algorithm, then name the smallest intervention that moves current toward correct.

Output shape

Use exactly these sections:

  1. Goal: one sentence stating the invariant we need.
  2. Minimal algorithm: pseudocode or numbered steps for the ideal implementation. No library constraints yet.
  3. Current algorithm: what the code actually does today, including ownership, blocking points, and cleanup boundaries.
  4. Gap: the first point where current diverges from minimal.
  5. Smallest fix: one intervention. Preserve working invariants.
  6. Falsifier: the test or measurement that proves the fix wrong.

Rules

  • Do not start with a proposed patch. Start with the invariant.
  • Do not compare against a strawman. Read the code and name exact functions, fields, and blocking calls.
  • Preserve constraints that are already correct. If a prior commit fixed a deadlock, do not revert it to fix a leak.
  • Prefer ownership/cancellation changes over retries, sleeps, or cleanup after the fact.
  • A good fix reduces the gap; a great fix removes an entire class of impossible states.

Checklist

  • Where is ownership supposed to live?
  • What wakes every blocking syscall?
  • Who joins or intentionally detaches each thread?
  • Which fd owner closes each fd?
  • What happens if the happy-path event never occurs?
  • What is the failure mode under load?

Example

Goal: Dropping a per-machine vhost-user server must not block the registry actor and must not leak fds when no VM ever connects.

Minimal algorithm: bind listener; spawn accept loop cancellable by a shutdown token; Drop fires token, wakes listener, signals workers, joins threads with a bound, and closes all owned fds.

Current algorithm: start() moves VhostUserDaemon into an accept thread and calls daemon.start(&mut listener). Drop removes the socket path, then tries to take the daemon from Arc<Mutex<Option<_>>>. If the thread is blocked in accept(), the option is None, so cleanup is skipped.

Read the full file on GitHub · 71 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. 12d ago First seen · 71 lines · 38 tokens per session scan A 0d5ad1f2a15e

Subscribe to this mod's changes

counterfactual is a skill published in the GitHub repository Kevin-Liu-01/Agent-Machines (29 stars, last pushed today), licensed MIT. It adds 38 tokens to every session and 632 once invoked, about $0.0002 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.

Related

Other skills, from other repositories