wolframresearch/agenttools/wolfram-debugging
Claude Code and agent skill by wolframresearch/agenttools
- community
Checking that the SKILL.md file is still in the repository.
Verified recipes and tested helpers for debugging Wolfram Language code. Use whenever code issues messages, returns $Failed, Failure or unevaluated calls, gives wrong results, is slow, hangs or crashes, or works in one environment but not another; for stack traces, call logs, profiles, mocks or overrides, watchpoints, ReadProtected definitions, edits that have no effect, failing tests, parallel, cloud or HTTP code. Use it even when Echo or Trace seem enough, as Trace records nothing in the MCP evaluator's default mode or the cloud.
Install
npx vskill@latest install wolframresearch/agenttools/wolfram-debuggingSKILL.md
Wolfram Language Debugging
Verified techniques for finding out why Wolfram Language code misbehaves, checked with Wolfram 15.0 in the MCP evaluator (both methods), wolframscript, wolfram -script and the cloud. Many standard techniques silently do nothing in some of these environments, so read the ground rules first. Paths are relative to this skill directory.
Prerequisites
You need a Wolfram kernel. If you have neither of the following, read references/GetWolframEngine.md; to set up the MCP server, read references/SetUpWolframMCPServer.md.
- MCP evaluator (preferred, for example
mcp__Wolfram__WolframLanguageEvaluator): a persistent kernel, so
definitions made in one call can be inspected in the next.
- wolframscript: a fresh kernel per run, needed for first-time effects (autoloading, package loading) and for Trace
where the MCP evaluator cannot run it. -f file.wl prints only Print output; -code '...' drops string quotes (print ToString[expr, InputForm]). Always bound runs: timeout -s KILL 300 wolframscript -f file.wl < /dev/null.
Start here: where does the code run?
| MCP Local | MCP Session | wolframscript | cloud | ||
|---|---|---|---|---|---|
Trace, TraceScan, On[sym] | work | record nothing | work | record nothing | |
| context of typed symbols | `Sessions<id> ` | `Sessions<id> ` | `Global `` | `Global `` | |
| state between calls | persists in a subkernel shared by all sessions | persists in the MCP server's own kernel | none | none | |
$MessageList | reset per input | never reset | per script | per call | |
Print, Echo | shown | shown | stdout | dropped (the remote MCP server shows Print only) | |
RunProcess, LaunchKernels | blocked (protected mode) | allowed | allowed | blocked | |
| file writes | only below $TemporaryDirectory | anywhere | anywhere | cloud files (remote MCP server: a throwaway directory) |
MCP Local and MCP Session are the two evaluation methods of the MCP evaluator; installed local servers use Session by default. "Cloud" is CloudEvaluate, deployed APIs and the remote MCP server. wolfram -script, used by the TestReport MCP tool, also records no Trace. Everything else that differs: references/Environments.md.
Ground rules
- Check `Trace[1 + 1] =!= {}` before using Trace. Where it records nothing, use message handlers with
Stack,
`InternalInheritedBlock` spies or stack sampling, or run the Trace in wolframscript (more workarounds: references/TracingAndPerformance.md`).
- Stack frames, trace items and arguments of kernel messages are wrapped in `HoldCompleteForm` (
HoldFormbefore
version 15). Match them with _[e_] and format with ToString[Unevaluated[e], InputForm, TotalWidth -> 150]. Never extract them with First, [[1]] or ReleaseHold: that evaluates the frame again.
- Filter user frames with both user contexts: `
MemberQ[{"Global", $Context}, Context[s]]``. - Each input is parsed just before it runs, so a name in the same input as the
Get/Needsthat defines it is
created in your own context. An input is one line in -f scripts and in the MCP evaluator with Chatbook 2.7.28+, but the whole call with older Chatbook. Put Get/Needs in its own call and call package functions by their full names.
- Evaluate code under test as `StackBegin[StackComplete[expr]]`.
StackBegindrops the environment's wrapper
frames (about 15 in wolframscript, 65 in CloudEvaluate); StackComplete keeps your calls, which are otherwise replaced on the stack by their right-hand sides.
- Return small data as the value. Raw stacks, traces and
TestReportObjects can be hundreds of KB (Shorthas no
effect in the MCP evaluator or wolframscript), and Print output can be lost: collect diagnostics with `InternalBag`/InternalStuffBag`` and return them.
- Scope every change: MCP kernels are shared. Use `
InternalHandlerBlock`(notInternalAddHandler``),
`InternalInheritedBlock`, Block and WithCleanup. In an MCP evaluator, never call Quit, Exit, Input, InputString, Dialog, ChoiceDialog or Run, write to "stdout", or change $RecursionLimit, $Pre, $Post, Off or SetOptions globally; in MCP Session this can silence or kill the server. In MCP Local, lower $RecursionLimit (even in a Block) only after the subkernel has printed an ordinary message (1/0; in an earlier call): a first printed message under a low limit breaks $Context` for every session.
- Reproduce autoloading and package-loading problems in wolframscript: MCP kernels have many packages loaded.
- A `Throw`-based probe can be swallowed by
Catch[..., _]orEvaluationDatain the code under test. If the
probe returns the normal result instead of your data, record without throwing.
- The remote MCP server evaluates every input inside `Quiet`, so handlers see every message as quieted: wrap the
code under test in Quiet[expr, None, All].
Symptom → first move → reference
| symptom | first move | read in references/ | |
|---|---|---|---|
messages (which, from where?), unexplained $Failed or Failure | `WolframDebuggingCollectMessages[expr]`, WolframDebuggingCaptureEvaluation[expr]``, the recipe below | MessagesAndStacks.md | |
unevaluated f[...] in the result, or the wrong rule fires | `WolframDebuggingStuckCalls[result]`, WolframDebuggingWhyNoMatch[f[args]]`` | UnevaluatedCalls.md | |
slow, hangs, times out; Trace options | `WolframDebuggingSampleStacks[expr]`, WolframDebuggingTimeCalls[expr, {f, g}]`` (no Trace needed) | TracingAndPerformance.md | |
| calls and arguments inside an evaluation; mocks (HTTP, time, randomness); a variable changes unexpectedly | `WolframDebuggingLogCalls[{f, g}, expr]`, WolframDebuggingWithOverrides[{lhs :> rhs}, expr]`, WolframDebuggingWatchChanges[{x}, expr]`` | OverridesAndWatchpoints.md | |
| definition or source file of a symbol | SymbolDefinition MCP tool, `WolframDebuggingFindSymbolSource["Ctxname"]` | DefinitionsAndSource.md | |
| edits have no effect, symbol undefined after loading, what got loaded? | `WolframDebuggingContextSourceInfo["Ctx"], WolframDebuggingLoadTrace[expr]`` | PackageLoading.md | |
| a test fails, or a test file reports 0 tests | `WolframDebuggingTestFailureSummary[report]`, WolframDebuggingCheckTestFile[file]`` | Testing.md | |
| parallel or asynchronous code misbehaves | `WolframDebuggingParallelCapture[f, list]`` | ParallelAndAsync.md | |
| deployed API or HTTP request fails | URLRead[req, {"StatusCode", "Headers", "Body"}], `WolframDebuggingDebugHTTPResponse[api, params]`` | CloudAndHTTP.md | |
| works in one environment but not another, notebook-only code, crashes | `WolframDebuggingEnvironmentInfo[]`, WolframDebuggingEnvironmentFingerprint[]`` | Environments.md, HeadlessAndCrashes.md |
The helper package
scripts/WolframDebugging.wl packages the recipes of this skill as tested functions with small, bounded results. Load it in its own call (see rule 4), then call its functions by their full names:
The helpers work in MCP Local, MCP Session, wolframscript and (most of them) CloudEvaluate; Trace-based ones return Failure["TraceUnavailable", ...] where Trace records nothing. The remote MCP server cannot load local files: use the recipes below there. Every function, option and result shape is in references/HelperFunctions.md.
Core recipes (no helper package needed)
The examples use these definitions:
The stack at the first message
A "Message" handler receives Hold[Message[name, args...], willPrint], where willPrint is False for quieted messages. Throwing the stack from the handler gives the call chain that led to the message:
Frames show expressions as they were pushed (otherFn[i], not otherFn[0]). For function names only, throw Stack[] instead of Stack[_] and return st unformatted. Match Hold[Message[Power::infy, ___], True] for one message, and Hold[Message[_, ___], _] on the remote MCP server. To collect all messages without stopping, use EvaluationData[expr]["MessagesExpressions"].
Spy on, mock or override a function
`InternalInheritedBlock`` keeps the existing definitions and attributes and restores them when the block exits, even on abort:
- To mock, prepend
HoldPattern[lhs] :> fakeValueinstead. Always useHoldPatternand:>; guard recursion as shown. - For the stack when a function gets particular arguments, prepend a rule whose condition records the stack and fails,
`HoldPattern[otherFn[0]] /; (InternalStuffBag[bag, Stack[]]; False) :> Null`, and run the code as StackBegin[StackComplete[...]] (helper: WolframDebuggingStackAtCall[expr, otherFn[0]]``).
- Some changes leak out of the block:
ClearAll/Removeof the symbol wipes the outer definitions (useClearor
DownValues[f] = {}), and Temporary or Locked set inside stay set (never set Locked in a shared kernel).
- Calls made from kernel C code (
Total,Sum, auto-compiledTable) and literal rules such asf[0] = 1are not
seen. HTTP requests from URLRead, URLExecute and CloudGet all go through URLFetch.
Why does f[args] stay unevaluated?
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingAgentSkills/Skills/wolfram-debugging/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wolframresearch/agenttools/wolfram-debugging)