stack-based-backtrack

stack-based-backtrack is a skill for Claude Code from jimmc414/claude-code-plugin-marketplace. It costs 27 tokens per session (730 once invoked), scanned A, original, MIT.

A search pattern that keeps decisions on an explicit stack and reverses them when a path fails. This is depth-first search with backtracking, meaning the search tries one route, undoes it, and tries another.

In plain words
What is it for?
Use it for puzzle solving, game-tree searches, undo and redo behavior, and other searches where failed choices must be undone.
Why use it?
It avoids relying on deep recursive calls and makes state restoration explicit when exploring alternatives.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the norvig-patterns plugin — 54 skills shipped together

Good fit Use it for puzzle solving, game-tree searches, undo and redo behavior, and other searches where failed choices must be undone.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/jimmc414/claude-code-plugin-marketplace/stack-based-backtrack
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 jimmc414/claude-code-plugin-marketplace --skill stack-based-backtrack
Clone the repo
git clone --depth 1 https://github.com/jimmc414/claude-code-plugin-marketplace

Made for: Claude Code.

Or install norvig-patterns, the plugin that ships this one along with the rest of its 54 skills.

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 stack-based-backtrack

README.md
[![agentmods](https://agentmods.dev/badge/skills/jimmc414/claude-code-plugin-marketplace/stack-based-backtrack/github.svg)](https://agentmods.dev/skills/jimmc414/claude-code-plugin-marketplace/stack-based-backtrack)
Your own site
<a href="https://agentmods.dev/skills/jimmc414/claude-code-plugin-marketplace/stack-based-backtrack"><img src="https://agentmods.dev/badge/skills/jimmc414/claude-code-plugin-marketplace/stack-based-backtrack/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 stack-based-backtrack

Your own site · 80×15
<a href="https://agentmods.dev/skills/jimmc414/claude-code-plugin-marketplace/stack-based-backtrack"><img src="https://agentmods.dev/badge/skills/jimmc414/claude-code-plugin-marketplace/stack-based-backtrack.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 27 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 730 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.
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.00027 $0.00730
Opus 5.5 $0.00011 $0.00292
Sonnet 5.5 $0.00005 $0.00146
Haiku 4.5 $0.00003 $0.00073

Measured 1mo ago against content hash d9d6fa2c4cee, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

stack-based-backtrack 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 1mo 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.

plugins/norvig-patterns/skills/stack-based-backtrack/SKILL.md · 121 lines

How it starts

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

stack-based-backtrack

When to Use

  • DFS with backtracking
  • Puzzle solving
  • Game tree search
  • Undo/redo functionality
  • When recursion depth is too deep

When NOT to Use

  • Simple recursion works
  • BFS needed (use queue)
  • No backtracking required

The Pattern

Maintain explicit stack of decisions; pop and undo on failure.

def search_with_backtrack(initial_state):
    """DFS with explicit stack for backtracking."""
    stack = [(initial_state, get_choices(initial_state))]

    while stack:
        state, choices = stack[-1]

        if is_goal(state):
            return state

        if not choices:
            # Backtrack: no more choices at this level
            stack.pop()
            if stack:
                undo_last_choice(stack[-1][0])
            continue

        # Try next choice
        choice = choices.pop()
        new_state = apply_choice(state, choice)

        if is_valid(new_state):
            stack.append((new_state, get_choices(new_state)))

    return None  # No solution

Example (from pytudes)

# pal2.py - Panama palindrome search
class Panama:
    def search(self, steps=50000000):
        """Depth-first search with explicit backtrack stack."""
        for _ in range(steps):
            if not self.stack:
                return 'done'

            action, direction, substr, arg = self.stack[-1]

            if action == 'added':
                # Undo the addition
                self.remove(direction, arg)

            elif action == 'trying':
                if arg:  # More candidates to try
                    word = arg.pop()
                    self.add(direction, word)
                    self.consider_candidates()
                else:  # Exhausted candidates
                    self.stack.pop()

        return 'incomplete'

    def consider_candidates(self):
        """Push new choice points onto stack."""
        substr = self.get_target_substring()
        direction = 'left' if self.diff < 0 else 'right'

        candidates = self.find_candidates(substr, direction)
        if candidates:
            self.stack.append(('trying', direction, substr, candidates))

# Conceptual example: N-Queens
def solve_queens(n):
    """Place N queens with backtracking."""
    stack = [([], list(range(n)))]  # (placed, available_rows)

    while stack:
        placed, available = stack[-1]

        if len(placed) == n:
            return placed  # Solution found

        if not available:
            stack.pop()  # Backtrack
            continue

        row = available.pop()
        col = len(placed)

        if is_safe(placed, row, col):
            new_placed = placed + [row]
            new_available = [r for r in range(n)
                            if r not in new_placed and is_safe(new_placed, r, col+1)]
            stack.append((new_placed, new_available))

    return None

Read the full file on GitHub · 121 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. 1mo ago First seen · 121 lines · 27 tokens per session scan A d9d6fa2c4cee

Subscribe to this mod's changes

stack-based-backtrack is a skill published in the GitHub repository jimmc414/claude-code-plugin-marketplace (4 stars, last pushed today), licensed MIT. It adds 27 tokens to every session and 730 once invoked, about $0.0001 per session on Opus 5.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-09-04.

Related

Other skills, from other repositories

extract-ssot

Deduplicate repeated markdown (rule files, skill bodies, ADRs, docs) into one named source of truth and migrate every call site to cite it by exact heading. Use when the same prose, literal, or concept recurs across files: 'DRY this prose', 'extract a shared rule', 'single source of truth for X', a value-bump diff…

melodic-software/claude-code-plugins · 99 tokens

audit-encapsulation

Audit skill-encapsulation violations; remediation runs only behind an explicit fix FILE:LINE. External citations reaching into private surfaces inside .claude/skills/X/ or plugins/PLUGIN/skills/X/ (marketplace monorepos) beyond the slash invocation. Use when: 'audit encapsulation', 'find skill leaks', 'skill boundary…

melodic-software/claude-code-plugins · 99 tokens

generate

Build a source-backed AI industry briefing from official vendor publications, configured RSS feeds, GitHub releases, reputable secondary reporting, and user-supplied URLs. Use when: 'ai briefing', 'ai news', 'what's new in AI', 'catch me up on AI', 'prep for AI meeting', 'AI roundup', or 'generate AI slides'.

melodic-software/claude-code-plugins · 72 tokens

audit-progressive-disclosure

Read-only progressive-disclosure audit of agent-facing instruction markdown: grades each file against always-loaded, invocation-loaded, and on-demand tiers and flags split and disclosure defects. Use when: 'progressive disclosure', 'split this file', 'this file is too long', 'too much context', 'mixed concerns', 'hub…

melodic-software/claude-code-plugins · 113 tokens

firecrawl

Scrape, search, crawl, map, parse, or interact with web pages via the firecrawl-cli binary, writing results to disk instead of streaming them into context. Actions: scrape, search, crawl, map, parse, interact, agent, monitor, developer, research, doctor, search-feedback, credit-usage. Use when: 'scrape this page'…

melodic-software/claude-code-plugins · 161 tokens

quiz-me

Post-work comprehension check: a self-contained HTML report of a completed change (context, intuition, decisions) with a quiz at the bottom that tests the human, not the artifact; also recalls prior quizzed work. Non-gating by default; the quizpolicy userConfig tunes offer cadence. Use when the user says 'quiz me'…

melodic-software/claude-code-plugins · 152 tokens