/svg-tools:svgofrom SVG Tools
Use any time the user works with SVGO or needs SVGs smaller: shrinking, minifying, or cleaning up SVG files; choosing or disabling plugins (prefixIds, removeViewBox, multipass); writing svgo.config.mjs; wiring SVGO into a build via CLI or the Node optimize() API; or fixing SVGO-caused breakage (wrong gradients, lost hover states, viewBox/scaling loss, ID collisions). Skip for raster formats, hand-editing SVG content, SVGR, and SVG hosting unrelated to byte size.
Ships in SVG Tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A manual for driving SVGO, the SVG optimizer. SVGO is a Node CLI and library that runs a configurable pipeline of plugins over an SVG to shrink it. Most of the time you want the default pipeline (preset-default); the value of this skill is knowing the few defaults to turn off for the SVG to keep working in its target context, and the few non-default plugins to turn on.
The deep references live alongside this file:
references/cli-flags.md — every flag with edge cases.references/plugins.md — every plugin, default-status, when to flip it.references/programmatic-api.md — optimize() and loadConfig() from Node.Before pinning a config, run:
npx svgo --version
SVGO 3.x and 4.x are the current majors; 2.x has a notable rename — cleanupIDs (uppercase D) became cleanupIds in v3. If you see a v2 config in a project that's being upgraded, that one rename is the most common breakage. Don't pin a major version in code you write unless the user asks.
SVGO can run three ways:
npx svgo … — fine for one-off tasks.npm install --save-dev svgo then npx svgo … (uses the pinned version).import { optimize } from 'svgo' — see references/programmatic-api.md.The most useful CLI commands:
# Optimize in place (overwrites the original — be sure that's OK)
svgo icon.svg
# Optimize to a new path
svgo icon.svg -o icon.min.svg
# Take SVG from stdin, write to stdout (great for pipelines)
cat icon.svg | svgo -i - -o -
# Optimize an SVG string directly (no file)
svgo -s '<svg>...</svg>' -o out.svg
# Optimize every *.svg under a folder, recursively, writing into a parallel tree
svgo -rf src/icons -o dist/icons
# Output as a base64 data URI (good for inlining into CSS)
svgo icon.svg --datauri base64 -o icon.datauri.txt
# Use a specific config
svgo icon.svg --config svgo.config.mjs
--exclude works only with --folder and takes regex patterns, not globs.
| Flag | What it does |
|---|---|
-i, --input <files…> | Input file(s); - reads from stdin |
-s, --string <svg> | Read SVG from a string argument |
-f, --folder <dir> | Input folder (rewrites in place unless -o is given) |
-o, --output <path…> | Output file/folder; - writes to stdout |
-r, --recursive | Recurse into --folder (no effect without -f) |
--exclude <regex…> | Skip files matching regex (folder mode only) |
-p, --precision <int> | Fractional-digit precision; overrides plugin params |
--config <path> | Custom config (.js, .mjs, .cjs) |
--multipass | Re-run the pipeline until output stops shrinking |
--pretty | Pretty-print the output |
--indent <int> | Spaces per indent level when --pretty |
--eol <lf|crlf> | Force line endings |
--final-newline | Ensure trailing newline |
--datauri <fmt> | Emit a data URI: base64, enc (URI-encoded), unenc |
--show-plugins | Print every available plugin and exit |
-q, --quiet | Suppress non-error output |
Full reference, including edge cases (stdin + folder combinations, --exclude regex semantics, what -p overrides): references/cli-flags.md.
SVGO is a pipeline of plugins. The default pipeline is the preset-default bundle (~34 plugins). You don't list those individually — you reference the bundle and override members inside it. Plugins outside the bundle are added explicitly.
Run npx svgo --show-plugins in the project to see the complete list at the version SVGO is pinned to.
Most plugins in preset-default are safe and you can ignore them. These are the ones whose default behavior most often surprises people, plus the non-default ones worth knowing:
| Plugin | In preset-default? | When to flip it |
|---|---|---|
removeViewBox | No (default off) | Leave off. Turning it on strips viewBox and breaks responsive scaling — the SVG no longer fills its container. Only enable for SVGs with fixed width/height you never resize. |
cleanupIds | Yes | Disable (cleanupIds: false) when multiple optimized SVGs get inlined into the same HTML page — short minified IDs (a, b, …) collide across files. Alternative: pair with prefixIds. |
prefixIds | No | Enable when inlining several SVGs into one HTML doc, or when IDs are referenced from external CSS/JS. Prevents the cleanupIds collision. |
removeHiddenElems | Yes | Disable if any element is intentionally hidden and revealed by CSS/JS (display:none toggled at runtime, off-screen sprite cells). It removes them by default. |
removeXMLNS | No | Only safe when the SVG is inlined into HTML. Breaks standalone use (<img src>, CSS url(), file viewers). |
removeXlink | No | Enable when targeting SVG 2 only. Rewrites xlink:href to href; older renderers may still need the namespaced form. |
convertPathData | Yes | Leave on. Disable only if you have JS/animation that targets exact path-command structure. |
mergePaths | Yes | Disable if individual <path> elements are styled or animated separately — merging makes them one path. |
inlineStyles | Yes | Disable if the SVG relies on external CSS or runtime style changes; inlining can also bloat output if many CSS rules target few elements. |
removeRasterImages | No | Enable to strip embedded PNG/JPEG fallbacks from a vector-only pipeline. |
reusePaths | No | Enable for aggressive compression when many <path>s share identical d/fill/stroke; replaces duplicates with <use> references. |
removeDimensions | No | Opposite of removeViewBox. Enable when you want responsive scaling and the source has both width/height and viewBox. |
Full catalog (every plugin, what it does, default-status, tradeoffs): references/plugins.md.
SVGO looks for svgo.config.mjs (or .js / .cjs) in the working directory. Missing config falls back silently to preset-default — no error.
Minimal config (just enables multipass on top of defaults):
// svgo.config.mjs
export default {
multipass: true,
};
Override members of preset-default:
// svgo.config.mjs
export default {
multipass: true,
plugins: [
{
name: 'preset-default',
params: {
overrides: {
// disable a default-on plugin
cleanupIds: false,
// tune a plugin's params
inlineStyles: { onlyMatchedOnce: false },
},
},
},
// add non-default plugins after the preset
'prefixIds',
'removeDimensions',
],
};
overrides only accepts plugins that are in preset-default. Putting a non-member there (e.g. removeViewBox: false) makes SVGO print a warning and ignore the entry — that's a SVGO v2 pattern that no longer applies in v3+. To keep viewBox in v3+, just don't add removeViewBox to your plugins list — it's off by default.
Custom pipeline (skip preset-default entirely — uncommon, but possible):
export default {
plugins: [
'removeDoctype',
'removeComments',
'cleanupIds',
{ name: 'prefixIds', params: { prefix: 'icon' } },
'sortAttrs',
],
};
.cjs is supported if the surrounding project is CommonJS; prefer .mjs in new code.
removeViewBox is the #1 footgun. Off by default in preset-default in SVGO v3+ — it can only run if explicitly added to a plugins list (often by an upstream build-tool config like a Vite plugin, an old Gulp/Webpack loader, or copy-pasted v2-era boilerplate). If a user reports an SVG that "won't scale" after optimization, find where removeViewBox was enabled and remove it there. Ignore advice to "add overrides: { removeViewBox: false } to preset-default" — that's the v2 fix; in v3+ SVGO warns and ignores it.cleanupIds collides across inlined SVGs. Two SVGs both shrunk to use id="a" will overwrite each other when placed in the same HTML doc. Use prefixIds, or disable cleanupIds, or both.--config path is wrong or svgo.config.mjs isn't found, SVGO uses preset-default without warning. Confirm the config actually loaded by changing one observable thing (e.g., --pretty via config) and checking output.--multipass is meaningfully slower. It re-runs the pipeline until output is stable, often 2–4 passes. Worth it for committed assets; usually overkill in dev loops.-p 0 or -p 1 is too aggressive for most icons; -p 3 is the safe default that plugins use internally. Lowering -p overrides every plugin's own precision.-f overwrites the source folder by default. Always pass -o when using -f unless you mean to rewrite in place.--exclude is regex, not glob. --exclude 'icon-.*\.svg$' works; --exclude 'icon-*.svg' does not.cleanupIDs (uppercase D) → cleanupIds. Old configs and old plugin names break silently on newer SVGO.When optimizing inside a build script or test, use the Node API rather than shelling out:
import { optimize } from 'svgo';
const result = optimize(svgString, {
path: 'icons/foo.svg', // helps some plugins (e.g., prefixIds) generate stable prefixes
multipass: true,
plugins: ['preset-default', 'prefixIds'],
});
const optimized = result.data;
For the full API surface — optimize() options, loadConfig(), error shape, types — see references/programmatic-api.md.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
svg-tools@cypherpoet-toolchest is listed by cypherpoet/cypherpoet-toolchest — review the source before installing
npx claudepluginhub cypherpoet/cypherpoet-toolchest --plugin svg-tools