matlab/matlab-export-session-script
Export conversation MATLAB code to a clean, runnable .m script. Use when asked to save or export session work. TRIGGER: user asks to save, export, or generate a script from the current session's MATLAB code. Also when asked for a reproducible script or clean version of what was run.
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-export-session-script
Extracts all MATLAB code executed during the current conversation, assembles it into a well-documented, runnable .m script, and saves it to the working directory.
| Step | Action |
|------|--------|
| 1. Scan | Walk assistant messages chronologically; extract each executed MATLAB code block |
| 2. Deduplicate | Keep only the final successful version of repeated blocks |
| 3. Order | Arrange into logical workflow order (setup, model, config, analysis, visualization) |
| 4. Format | Add %% section headers, consolidate parameters at top |
| 5. Save | Write to Results/<descriptive_name>.m under the working directory |
addpath calls needed for utility functions used during the sessionsbm wrappersfprintf statements used to relay info back (keep user-facing ones)'Visible','off' on figures -- the exported script is for interactive useWhen the same block was run multiple times (e.g., to fix an error), keep only the final successful version. Do not include intermediate failed attempts or parameter corrections -- use the values that worked.
Walk through all assistant messages chronologically. For each MATLAB code block that was executed (via MCP, -batch, or similar), extract the MATLAB portion and note:
Arrange extracted code into a natural workflow order, which may differ from execution order:
%% <Title> -- <One-line summary>
% <Multi-line description of what this script does.>
% <Key context: what design, what board, what analysis, etc.>
%
% Required toolboxes: <list only what was actually used>
%% Step 1: <Description>
% <Why this step matters>
<code>
%% Step 2: <Description>
<code>
%% section breaks for each logical step (creates foldable sections in MATLAB Editor)title() / xlabel() TeX strings: \_ not _Derive from the session's primary task. Use lowercase with underscores:
openrex_core_rail_dc_analysis.mhairpin_filter_design_2p4ghz.mvia_crosstalk_sweep.mSave to Results/ under the working directory. Create the folder if it doesn't exist.
Tell the user:
freq, substrate, dimensions) into the setup section so the user can modify them without hunting through the script.if ~exist('BATCH_MODE', 'var') guards. But default to showing figures for interactive use.fullfile() for cross-platform paths. Never hard-code absolute paths.matlab -batch, add at the top: %% Configuration
BATCH_MODE = exist('BATCH_MODE', 'var') || ~usejava('desktop');
if ~BATCH_MODE, close all; clc; end
Results/ subfolder: resultsDir = fullfile(pwd, 'Results');
if ~exist(resultsDir, 'dir'), mkdir(resultsDir); end
sbm wrapper invocations must be stripped. If a shell step is essential (e.g., downloading a file), replace it with a comment noting the prerequisite.freq, substrate, dimensions, file paths) into the setup section at the top.C:\Users\viyer\... break on other machines. Use fullfile() and relative paths, or place path variables in the setup section.'Visible','off' on figures. Agent sessions suppress figure windows for non-interactive execution, but exported scripts are meant for interactive use. Remove 'Visible','off' arguments from figure() calls._ as a subscript in title(), xlabel(), ylabel(), and legend() calls by default. Use \_ or set 'Interpreter','none'.----
Copyright 2026 The MathWorks, Inc.
Take matlab/matlab-export-session-script from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.