/xmake-skills:xmake-script-modulesfrom xmake-skills
Reference for xmake's built-in script-domain APIs (os.*, io.*, path.*, etc.) for writing custom logic in xmake.lua without import().
Ships in xmake-skills. 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.
None: SKILL.md is the whole skill.
Inside the script domain (on_load, on_build, after_build, on_run, on_test, task/rule/plugin bodies, imported .lua modules) xmake provides a set of pre-imported modules. No import(...) needed for any of these — they are injected into the sandbox.
For how to write modules and use import() itself, see xmake-scripting.
os — filesystem, process, envos.exists("path") -- true if file or dir exists
os.isfile("path")
os.isdir("path")
os.mkdir("a/b/c") -- recursive
os.rmdir("a")
os.rm("file-or-glob")
os.cp("src", "dst") -- file or dir; glob patterns supported
os.mv("src", "dst")
os.ls("dir") -- returns list of basenames
os.files("src/**/*.cpp") -- glob list of files
os.dirs("src/**") -- glob list of dirs
os.filedirs("src/**") -- glob files + dirs
os.emptydir("build") -- delete all contents
Globs: * one level, ** recursive, ? single char. (...) in the pattern preserves directory structure during copy.
os.exec("cmd arg1 arg2") -- raises on non-zero exit, streams output
os.execv(program, {args}) -- list form — no shell parsing (prefer this)
os.run("cmd") -- silent unless it fails
os.runv(program, {args})
os.vrun("cmd") -- silent; print only in -v mode
os.vrunv(program, {args})
os.iorun("cmd") -- returns stdout
os.iorunv(program, {args}) -- returns stdout, stderr
*v (list) forms are safer — they bypass shell quoting entirely. Prefer them whenever arguments come from variables.
os.getenv("PATH")
os.setenv("FOO", "bar") -- scope: current xmake process only
os.host() -- "macosx" | "linux" | "windows" | ...
os.arch() -- "x86_64" | "arm64" | ...
os.subhost() -- detailed host info
os.tmpdir() -- scratch dir
os.curdir() -- cwd
os.cd("path") -- change cwd
os.mtime("file") -- modification time
os.time() -- current unix time
os.date("%Y-%m-%d")
os.nuldev() -- /dev/null or NUL
os.argv() -- raw CLI args
io — file I/Oio.readfile("path") -- whole file → string
io.writefile("path", "content") -- overwrite
io.open("path", "r") -- Lua-style file handle
for line in io.lines("path") do ... end
io.gsub("path", "pattern", "replace") -- in-place regex replace
io.gsub is the one-liner for string editing a file:
io.gsub("version.h", '#define VERSION "[^"]*"', '#define VERSION "1.2.3"')
path — path manipulationCross-platform path handling (forward slash on Unix, backslash on Windows, auto-normalized):
path.join("a", "b", "c.txt") -- "a/b/c.txt"
path.filename("a/b/c.txt") -- "c.txt"
path.basename("a/b/c.txt") -- "c" (no extension)
path.extension("c.txt") -- ".txt"
path.directory("a/b/c.txt") -- "a/b"
path.absolute("rel") -- absolute form
path.relative("/a/b/c", "/a") -- "b/c"
path.translate("a\\b/c") -- normalize separators to host
path.is_absolute("/x")
Always prefer path.join over string concatenation — it handles separators per OS.
table — xmake-extendedStandard Lua table.* plus:
table.contains(tbl, value)
table.concat(tbl, ", ")
table.insert(tbl, value)
table.remove(tbl, idx)
table.unique(tbl) -- dedupe in place
table.join(tbl1, tbl2, ...) -- merge (returns new table)
table.copy(tbl) -- shallow copy
table.keys(tbl)
table.values(tbl)
table.unpack(tbl) -- Lua 5.1 / 5.3 unified
table.pack(...)
table.orderkeys(tbl) -- stable key order
table.wrap(x) -- if x not table, wrap as {x}
string — xmake-extendedstring.split("a,b,c", ",") -- {"a","b","c"}
string.trim(" x ") -- "x"
string.startswith("hello", "he")
string.endswith("hello", "lo")
string.format("%d: %s", 1, "ok") -- standard
string.upper("abc") / string.lower("ABC")
hash — cryptographic hasheshash.md5("string-or-file-path")
hash.sha1("...")
hash.sha256("...")
hash.xxh64("...") -- fast non-crypto
Accepts either a string or a file path. Use for cache keys, change detection, integrity checks.
print("hello %s", name) -- with newline
printf("hello %s", name) -- no newline
cprint("${bright green}done${clear}") -- with color tags
cprintf("${red}warning") -- color, no newline
utils.vprint("only in -v mode") -- gated by -v
utils.cprint("same as cprint")
raise("fatal: %s", reason) -- throw, with format args
See xmake-color-output for the ${...} tag reference.
try / catch / finallyXmake's structured error handling:
try {
function ()
os.exec("some-command")
end,
catch {
function (errors)
print("failed: %s", errors)
end
},
finally {
function ()
print("cleanup")
end
}
}
All three blocks are optional (a plain try { function () ... end } is fine). The catch block receives the error message.
if is_host("windows") then
import("core.base.winos") -- winos needs import
-- winos.version(), winos.registry_*() etc.
end
linuxos.name() -- available without import
linuxos.version()
macos.version()
hashset / heap / list — extended data structuresimport("core.base.hashset")
local s = hashset.new()
s:insert("a")
s:contains("a")
Needs import — not pre-injected.
These need import(...):
core.base.option, core.base.task, core.base.globalcore.project.project, core.project.configcore.platform.platform, core.tool.toolchain, core.tool.compiler, core.tool.linkercore.package.packagelib.detect.find_tool, lib.detect.find_package, lib.detect.has_cfuncs, etc.net.http, devel.git, utils.archivecore.base.hashset, core.base.heap, core.base.listSee xmake-scripting for the import mechanics.
after_build(function (target)
local dist = path.join(os.projectdir(), "dist")
os.mkdir(dist)
os.cp(target:targetfile(), dist)
end)
before_build(function (target)
local version = try {function () return os.iorun("git describe --tags") end} or "unknown"
io.writefile("src/version.h",
string.format('#define VERSION "%s"\n', version:trim()))
end)
on_load(function (target)
for _, file in ipairs(os.files("src/**/generated_*.cpp")) do
target:add("files", file)
end
end)
before_build(function (target)
import("lib.detect.find_tool")
local protoc = assert(find_tool("protoc"), "protoc not found on PATH")
os.vrunv(protoc.program, {"--cpp_out=gen", "proto/foo.proto"})
end)
os.cp, os.exec, io.writefile) raise. Move to on_load or later hooks.os.exec("cmd " .. var). Prefer os.execv with a list — no shell parsing, no quoting surprises.os.iorun in description domain. Runs on every parse of xmake.lua. Move into on_load or a task."src\\\\main.cpp" breaks on Unix. Use path.join or forward slashes (xmake normalizes forward slashes on all platforms).table.pack / table.unpack. Xmake's extended table shims these for Lua 5.1/5.3 consistency — safe to use, but don't mix with unpack (global).import() / native modules → xmake-scriptingcprint → xmake-color-outputhas_cfuncs, check_cxxsnippets) → xmake-feature-checktarget:add, target:targetfile) → xmake-targetsWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub xmake-io/xmake-skills --plugin xmake-skills58 skills in this plugin
/xmake-addon-developmentUse when writing an Xmake addon — the `addon.lua` manifest, the payload layout (plugins/rules/toolchains/modules/includes/templates), `@self` references, shipping package definitions with an addon, `add_globalmodules`, testing it locally, and publishing it to xmake-repo as an `addon` kind package./xmake-addonsUse when installing or using an Xmake addon — `xmake addon --install/--list/--remove/--upgrade/--search`, declaring `add_addons(...)` in a project, and referencing addon payloads with `@addon/<name>/<rule>`, `@addon.<name>.<module>` or `@self`. For writing and publishing one, see xmake-addon-development./xmake-async-jobsUse when running parallel / async work inside xmake scripts — `async.runjobs` for parallel job execution, `async.jobgraph` (DAG) for dependency-ordered jobs, `async.jobpool` (tree structure), `core.base.scheduler` coroutine scheduling, semaphores, and `on_build_files(..., {jobgraph = true})` in rules. For running external compile jobs faster, see `xmake-build-optimization`./xmake-basicsUse when the user is starting a new Xmake project, installing Xmake, or needs the minimal xmake.lua structure. Covers installation, `xmake create`, the project layout, and the smallest valid xmake.lua./xmake-build-cacheUse when configuring or debugging xmake's local build cache (built-in, replaces ccache) or the remote compile cache service (shared across machines via `xmake service --ccache`). Covers enabling/disabling, fallbacks to external ccache, remote cache server/client setup, and cache cleaning./xmake-build-optimizationUse when a project builds slowly and you want to make it faster — parallel jobs, unity build, precompiled headers, build cache, LTO, link-time improvements, binary package cache, and profiling with `XMAKE_PROFILE=perf:*`. Covers idiomatic xmake speedups and the order to try them.Other plugins' skills for the same job