
AST Class/Visitor Pattern
Guides the agent to model multi-variant unions as frozen classes with a visitor interface.
- Repository
- prisma/orm
- Stars
- 47,663
- Licence
- Apache-2.0
- Files
- 1 file
What it does
When the agent works on a set of related variants (such as commands or syntax-tree nodes) that get handled in several places, it follows a specific code design: each variant becomes a frozen class with a shared visitor interface, instead of a plain union checked by switch statements. This makes adding a new variant cause compile errors at every place that must handle it. It also tells the agent to always build these objects with constructors rather than frozen plain objects.
Great for
- TypeScript developers maintaining a compiler, query builder, or code generator with several switch-based consumers
- Teams refactoring a discriminated union that has grown many switch statements
- Contributors to the Prisma codebase working on Mongo query or DDL AST code
Skip it if
- Small projects with one switch site or fewer than three variants, where the skill itself says the boilerplate is not worth it
- Non-TypeScript codebases, since the examples and guidance are TypeScript-specific
Try asking
- “Refactor this discriminated union of IR nodes that is switched over in four renderers into visitor-based classes”
- “Add a new DDL command variant and show me every place that needs handling”
- “Create a factory function that returns a new node class instance instead of a frozen object literal”
Install in 3 steps
- 1
Download the skill
The ZIP contains the 1 original files, the Apache-2.0 licence and an attribution note.
ast-visitor-pattern.zip - 2
Add it to your agent
Claude Code (all projects)
mkdir -p ~/.claude/skills && unzip ast-visitor-pattern.zip -d ~/.claude/skills/Claude Code / Agent SDK (this project only)
mkdir -p .claude/skills && unzip ast-visitor-pattern.zip -d .claude/skills/Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.
- 3
Ask for the task
No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.
Get better results
- Point the agent at an existing union with multiple switch sites so it can judge whether the pattern applies before refactoring.
- Ask for the visitor interface and concrete classes to be generated together so the compiler checks coverage.
- Note that the skill's file paths refer to the Prisma monorepo; adjust the codebase examples if you use it elsewhere.
What's inside
- SKILL.md
Redistributed unmodified from prisma/orm under the Apache-2.0 licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.