casting-stack-conditions

Guidance for changing the rules-heavy parts of a digital Magic: The Gathering engine, including casting, the stack, priority, and conditions. The stack is the game area where spells and abilities wait to resolve.

In plain words
What is it for?
Use it when changing casting steps, optional costs, targeting, conditions, waiting states, stack resolution, or related tests.
Why use it?
It reduces the risk of implementing behavior that breaks the game's official rules or works for one card but fails for other cards using the same system.

Skill for Claude CodeCodex

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 skills/phase-rs/phase/casting-stack-conditions
Any agent
npx skills add phase-rs/phase --skill casting-stack-conditions
Clone the repo
git clone --depth 1 https://github.com/phase-rs/phase

Made for: Claude Code, Codex.

Per session 39 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,438 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.00039 $0.05438
Opus 5 $0.00019 $0.02719
Sonnet 5 $0.00008 $0.01088
Haiku 4.5 $0.00004 $0.00544

Measured 2d ago against content hash 6dfd8816a351, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

casting-stack-conditions 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 2d 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.

.claude/skills/casting-stack-conditions/SKILL.md · 440 lines

How it starts

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

Casting, Stack & Condition Systems

Hard rules — casting, stack, and priority are the most rules-dense areas of MTG (see CLAUDE.md § Design Principles):

  1. CR-correctness is non-negotiable. Casting (CR 601), activated abilities (CR 602), triggered abilities (CR 603), static abilities (CR 604), mana abilities (CR 605), stack resolution (CR 608), and priority (CR 117) are precisely specified. Every implementation must be verified against the relevant CR section and annotated. If you cannot cite the CR that governs a behavior, you have not validated it.
  2. Build for the class, not the card. Payment helpers (pay_mana_cost, pay_ability_cost), targeting, and condition checks are shared building blocks used by every spell and ability. Changes here must work for the entire class — never special-case a single card's casting behavior.
  3. Test the exact rules behavior. Every new WaitingFor state, casting step, or condition check needs tests that verify the CR-specified behavior, including edge cases (e.g., fizzle on illegal targets, intervening-if re-check at resolution). Test the building block, not one card's interaction.

Reference for the spell casting pipeline, stack resolution, sub_ability chaining, and all condition systems. Use this to understand how spells go from hand → stack → resolution, and where to extend for new casting features.

Before you start: Trace Ward for a casting-time interaction, or TriggerCondition::LifeGainedThisTurn for a condition that's checked at both trigger and resolution time.


Casting Flow — crates/engine/src/game/casting.rs

Entry point: handle_cast_spell(state, player, card_id, events)

CastSpell action
  │
  ▼
1. Find card in hand (or command zone for Commander)
  │
  ▼
2. Get ability: obj.abilities[0].clone()
   (vanilla permanents get placeholder Unimplemented)
   NOTE: Modal spells (obj.modal.is_some()) skip to step 2b
  │
  ▼
2b. Modal detection → WaitingFor::ModeChoice
   Player selects modes → handle_select_modes() builds chained ResolvedAbility
   → proceeds to targeting (walks sub_ability chain for first target filter)
  │
  ▼
3. Casting prohibition checks (prepare_spell_cast)
   ├─ Zone castability (hand, command, exile w/ permission, graveyard w/ escape/permission)
   ├─ CantCastFrom statics (Grafdigger's Cage) — is_blocked_from_casting_from_zone()
   ├─ CantCastDuring statics (Teferi) — is_blocked_by_cant_cast_during()
   ├─ PerTurnCastLimit statics (Rule of Law) — is_blocked_by_per_turn_cast_limit()
   │  └─ Uses ProhibitionScope (Controller/Opponents/AllPlayers) + optional spell_filter
   └─ Temporary zone restrictions — is_blocked_by_cast_only_from_zones()
  │
  ▼
4. Validate timing
   ├─ Instant / Flash → anytime
   └─ Sorcery-speed → main phase + empty stack + active player
  │
  ▼
5. Commander color identity check (Commander only)
  │
  ▼
6. Calculate mana cost (base + commander tax if from command zone)
  │
  ▼
7. Build ResolvedAbility from AbilityDefinition
   └─ Recursively converts sub_ability chain via build_resolved_from_def()
  │
  ▼
8. Handle targeting
   ├─ Auras: extract Enchant keyword filter
   └─ Others: extract_target_filter_from_effect()
       ├─ 0 legal targets → error
       ├─ 1 legal target → auto-assign, proceed
       └─ >1 → WaitingFor::TargetSelection
  │
  ▼
9. pay_and_push()
   ├─ X in cost → WaitingFor::ManaPayment
   ├─ pay_mana_cost() — shared mana payment building block (see below)
   ├─ Move card to Zone::Stack
   ├─ Record commander cast if applicable
   └─ stack::push_to_stack() creates StackEntry
  │
  ▼
10. Return WaitingFor::Priority

Read the full file on GitHub · 440 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. 2d ago First seen · 440 lines · 39 tokens per session scan A 6dfd8816a351

Subscribe to this mod's changes

casting-stack-conditions is a skill published in the GitHub repository phase-rs/phase (259 stars, last pushed 2d ago), licensed Apache-2.0. It adds 39 tokens to every session and 5,438 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

qa-cli-mcp-api

Select and run explicitly requested, risk-based QA for Anarlog's CLI, webhooks, stdio MCP, hosted Cloud API, and remote MCP. Test only affected lanes unless comprehensive coverage is requested.

fastrepl/anarlog · 47 tokens

product-update-newsletter

Draft, update, or audit a crisp, changelog-grounded Anarlog product-update newsletter in Loops (app.loops.so) for a desktop release. Use after the changelog is merged, when asked to draft, revise, or pre-send check the release announcement email.

fastrepl/anarlog · 62 tokens

sqlite-schema-design

Design or review schemas for crates/cloudsync using SQLite Sync constraints, not generic SQLite advice. Use when adding synced tables, changing synced columns, or planning CloudSync-safe migrations.

fastrepl/anarlog · 42 tokens

release-new-version

Release a new desktop stable version for Anarlog. Use when asked to cut, publish, or prepare a new stable desktop release after checking and merging the changelog.

fastrepl/anarlog · 38 tokens

fix-ready-prs

Inspect every open non-draft PR for CI failures and unresolved Cursor Bugbot findings, then fix them on the existing PR branches. Use when asked to check active PRs, triage ready PRs, fix CI, or address Bugbot comments.

fastrepl/anarlog · 55 tokens

reactive-sqlite-ui

Build SQLite-backed reactive UI in apps/desktop using stable patterns for reads, selection, forms, writes, and loading states. Use when implementing or reviewing screens built on useDrizzleLiveQuery and SQLite mutations.

fastrepl/anarlog · 53 tokens