Agent skill

Mirai

by quarto-dev in quarto-dev/quarto-r

Help users write correct R code for async, parallel, and distributed computing using mirai.

MITAuto-check passed

Install Mirai

skills CLI
$ npx skills add quarto-dev/quarto-r --skill mirai -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install quarto-dev/quarto-r mirai --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/quarto-dev/quarto-r.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/mirai .claude/skills/mirai && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
mirai
GitHub stars
160
Used in
1 other repo
Token cost
~3k tokens
SKILL.md length
616 words
Files
1
Skills in repo
10
Repo updated
First seen
Licence
MIT

At a glance

Help users write correct R code for async, parallel, and distributed computing using mirai.

  • Users need to run R code asynchronously
  • SKILL.md covers Core Principle: Explicit…, Common Mistakes, Setting Up Daemons and Memory Backpressure (memory +…, plus 7 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Write mirai code with correct dependency passing

What it does

Mirai is an agent skill from quarto-dev/quarto-r. Help users write correct R code for async, parallel, and distributed computing using mirai. Use when users need to run R code asynchronously or in parallel, write mirai code with correct dependency passing, set up parallel workers, convert from future or parallel, use miraimap, integrate with Shiny or promises, or configure cluster/HPC computing.

Its SKILL.md is about 3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

The repository describes itself as: R interface to quarto-cli. The licence is MIT.

When your agent uses it

  • Users need to run R code asynchronously
  • Write mirai code with correct dependency passing
  • Set up parallel workers
  • Convert from future

Example prompts

  • “/mirai”

What it can do on your machine

Read from SKILL.md and the folder at commit bd2329a. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are r).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Mirai loads about 3k tokens when it runs. Until then it costs about 89 tokens; SKILL.md has 616 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~89
When it runs · the whole SKILL.md, loaded when a task matches
~3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from quarto-dev/quarto-r at commit bd2329a, republished under its MIT licence (© quarto-dev). 616 words, ~3,029 tokens.

Download SKILL.mdSave it as .claude/skills/mirai/SKILL.md (or your agent's skills folder).
name
mirai
description
Help users write correct R code for async, parallel, and distributed computing using mirai. Use when users need to run R code asynchronously or in parallel, write mirai code with correct dependency passing, set up parallel workers, convert from future or parallel, use mirai_map, integrate with Shiny or promises, or configure cluster/HPC computing.
metadata.author
Charlie Gao (@shikokuchuo)
metadata.version
1.2
license
MIT

mirai is a minimalist R framework for async, parallel, and distributed evaluation, built on nanonext.

Core Principle: Explicit Dependency Passing

mirai evaluates expressions in a clean environment on a daemon process. Nothing from the calling environment is available unless passed explicitly — this is the #1 source of mistakes.

r
# WRONG: my_data and my_func are not available on the daemon
m <- mirai(my_func(my_data))

There are two ways to pass objects, and the names used must match the names referenced in the expression.

Objects in .args populate the expression's local evaluation environment — available directly by name inside the expression.

r
m <- mirai(my_func(my_data), .args = list(my_func = my_func, my_data = my_data))
... (dot-dot-dot)

Objects passed via ... are assigned to the daemon's global environment. Use this when objects need to be found by R's standard scoping rules (e.g., helper functions called by other functions).

r
m <- mirai(my_func(my_data), my_func = my_func, my_data = my_data)
Shortcut: pass the whole calling environment
r
# .args form — populates local eval env
process <- function(x, y) mirai(x + y, .args = environment())

# ... form — single unnamed environment, populates daemon global env
df_matrix <- function(x, y) mirai(as.matrix(rbind(x, y)), environment())
When to use which
ScenarioUse
Data and simple functions.args
Helper functions called by other functions that need lexical scoping...
Pass entire local scope to local eval env.args = environment()
Pass entire local scope to daemon global envmirai(expr, environment())
Large objects shared across many taskseverywhere() first, then reference by name

Common Mistakes

Unqualified package functions

Daemons start with no user packages loaded. Same applies inside mirai_map() callbacks.

r
# WRONG: dplyr is not loaded on the daemon
m <- mirai(filter(df, x > 5), .args = list(df = my_df))

# CORRECT: namespace-qualify
m <- mirai(dplyr::filter(df, x > 5), .args = list(df = my_df))

# CORRECT: load inside the expression
m <- mirai({
  library(dplyr)
  filter(df, x > 5)
}, .args = list(df = my_df))

# CORRECT: pre-load on all daemons
everywhere(library(dplyr))
m <- mirai(filter(df, x > 5), .args = list(df = my_df))
Expecting results immediately

m$data accesses the value but may still be unresolved. Use m[] (or collect_mirai(m)) to block until done; use unresolved(m) for a non-blocking check.

r
m <- mirai(slow_computation())
result <- m[]                          # blocks until resolved
if (!unresolved(m)) result <- m$data   # non-blocking

Setting Up Daemons

No daemons required

mirai() works without calling daemons() first — it launches a transient background process per call. Setting up daemons is only needed for persistent pools of workers.

Local daemons
r
# Start 4 local daemon processes (with dispatcher, the default)
daemons(4)

# Direct connection (no dispatcher) — lower overhead, round-robin scheduling
daemons(4, dispatcher = FALSE)

# Concise programmatic statistics (vs. the richer status())
info()

# Reset (daemons otherwise persist for the session)
daemons(0)
Scoped daemons (auto-cleanup)

with(daemons(...), {...}) creates daemons and automatically cleans them up when the block exits.

r
with(daemons(4), {
  m <- mirai(expensive_task())
  m[]
})
Scoped compute profile switching

local_daemons() and with_daemons() switch the active compute profile to one that already exists — they do not create daemons.

r
daemons(4, .compute = "workers")

# Switch active profile for the duration of the calling function
my_func <- function() {
  local_daemons("workers")
  mirai(task())[]  # uses "workers" profile
}

# Switch active profile for a block
with_daemons("workers", {
  m <- mirai(task())
  m[]
})
Compute profiles (multiple independent pools)
r
daemons(4, .compute = "cpu")
daemons(2, .compute = "gpu")

m1 <- mirai(cpu_work(), .compute = "cpu")
m2 <- mirai(gpu_work(), .compute = "gpu")

Memory Backpressure (memory + try_mirai())

For high-throughput producers (Shiny, promises, ingest pipelines), use the memory argument to daemons() to cap the queued task payload at dispatcher (MB, metric). Pair it with try_mirai() so the host R thread never blocks on submission.

r
# 100 MB queue cap. mirai() blocks on submission once the queue is full.
daemons(4, memory = 100)

# try_mirai() returns NULL (invisibly) instead of blocking when the cap is hit.
m <- try_mirai(work(x), .args = list(x = x))
if (is.null(m)) {
  # backpressure: drop, retry later, or signal upstream
} else {
  # m is a regular mirai
}

# Inspect current and peak queue usage
status()$memory

memory requires dispatcher. Without dispatcher (or with memory = NULL), try_mirai() always returns a mirai.

mirai_map: Parallel Map

Requires daemons to be set. Maps .x element-wise over a function, distributing across daemons. Namespace-qualify any package functions used inside the callback (see Mistake 2).

r
daemons(4)

# Basic map — collect with []
results <- mirai_map(1:10, function(x) x^2)[]

# Constants via .args, helpers via ... (same passing rules as mirai())
results <- mirai_map(
  data_list,
  function(x, power) helper(x, power),
  .args = list(power = 3),
  helper = my_helper_func
)[]

# Flatten results to a vector
results <- mirai_map(1:10, sqrt)[.flat]

# Progress bar (requires cli package)
results <- mirai_map(1:100, slow_task)[.progress]

# Early stopping on error
results <- mirai_map(1:100, risky_task)[.stop]

# Combine options
results <- mirai_map(1:100, task)[.stop, .progress]
Show full SKILL.md (241 more words)Show less
Mapping over multiple arguments (data frame rows)
r
# Each row becomes arguments to the function
params <- data.frame(mean = 1:5, sd = c(0.1, 0.5, 1, 2, 5))
results <- mirai_map(params, function(mean, sd) rnorm(100, mean, sd))[]
Process as completed (race_mirai)

race_mirai() returns the integer index of the first resolved mirai in a list (or 0L if empty). Useful when you want to handle results in completion order rather than submission order.

r
remaining <- mirai_map(jobs, run)
while (length(remaining) > 0) {
  idx <- race_mirai(remaining)
  process(remaining[[idx]]$data)
  remaining <- remaining[-idx]
}

everywhere: Pre-load State on All Daemons

r
daemons(4)

# Load packages on all daemons
everywhere(library(DBI))

# Set up persistent connections
everywhere(con <<- dbConnect(RSQLite::SQLite(), db_path), db_path = tempfile())

# Export objects to daemon global environment via ...
# The empty {} expression is intentional — the point is to export objects via ...
everywhere({}, api_key = my_key, config = my_config)

# .min = N forces a synchronization point: the call must complete on at least
# N daemons before subsequent mirai evaluations proceed. Useful when launching
# remote daemons that connect over time.
everywhere(library(arrow), .min = 4)

Error Handling

r
m <- mirai(stop("something went wrong"))
m[]

is_mirai_error(m$data)       # TRUE for execution errors
is_mirai_interrupt(m$data)   # TRUE for cancelled tasks
is_error_value(m$data)       # TRUE for any error/interrupt/timeout

m$data$message               # Error message
m$data$stack.trace           # Full stack trace
m$data$condition.class       # Original error classes

# Timeouts (requires dispatcher)
m <- mirai(Sys.sleep(60), .timeout = 5000)  # 5-second timeout

# Cancellation (requires dispatcher)
m <- mirai(long_running_task())
stop_mirai(m)

Shiny / Promises Integration

ExtendedTask pattern
r
library(shiny)
library(bslib)
library(mirai)

daemons(4)
onStop(function() daemons(0))

ui <- page_fluid(
  input_task_button("run", "Run Analysis"),
  plotOutput("result")
)

server <- function(input, output, session) {
  task <- ExtendedTask$new(
    function(n) mirai(rnorm(n), .args = list(n = n))
  ) |> bind_task_button("run")

  observeEvent(input$run, task$invoke(input$n))
  output$result <- renderPlot(hist(task$result()))
}

For high-traffic apps, set daemons(4, memory = ...) and submit with try_mirai() to apply backpressure without stalling the Shiny event loop.

Promise piping
r
library(promises)
mirai({Sys.sleep(1); "done"}) %...>% cat()

Remote / Distributed Computing

SSH (direct connection)
r
daemons(
  url = host_url(tls = TRUE),
  remote = ssh_config(c("ssh://user@node1", "ssh://user@node2"))
)
SSH (tunnelled, for firewalled environments)
r
daemons(
  n = 4,
  url = local_url(tcp = TRUE),
  remote = ssh_config("ssh://user@node1", tunnel = TRUE)
)
HPC cluster (Slurm/SGE/PBS/LSF)
r
daemons(
  n = 1,
  url = host_url(),
  remote = cluster_config(
    command = "sbatch",
    options = "#SBATCH --job-name=mirai\n#SBATCH --mem=8G\n#SBATCH --array=1-50",
    rscript = file.path(R.home("bin"), "Rscript")
  )
)
HTTP launcher (e.g., Posit Workbench)
r
daemons(n = 2, url = host_url(), remote = http_config())

Converting from future

futuremirai
Auto-detects globalsMust pass all dependencies explicitly
future({expr})mirai({expr}, .args = list(...))
value(f)m[] or collect_mirai(m)
plan(multisession, workers = 4)daemons(4)
plan(sequential) / resetdaemons(0)
future_lapply(X, FUN)mirai_map(X, FUN)[]
future_map(X, FUN) (furrr)mirai_map(X, FUN)[]
future_promise(expr)mirai(expr, ...) (auto-converts to promise)

The key conversion step: identify all objects the expression uses from the calling environment and pass them explicitly via .args or ....

Converting from parallel

parallelmirai
makeCluster(4)daemons(4) or make_cluster(4)
clusterExport(cl, "x")Pass via .args / ..., or use everywhere()
clusterEvalQ(cl, library(pkg))everywhere(library(pkg))
parLapply(cl, X, FUN)mirai_map(X, FUN)[]
parSapply(cl, X, FUN)mirai_map(X, FUN)[.flat]
mclapply(X, FUN, mc.cores = 4)daemons(4); mirai_map(X, FUN)[]
stopCluster(cl)daemons(0)
Drop-in replacement via make_cluster

For code that already uses the parallel package extensively, make_cluster() provides a drop-in backend:

r
cl <- mirai::make_cluster(4)
parallel::parLapply(cl, 1:100, my_func)
mirai::stop_cluster(cl)

# R >= 4.5: native integration
cl <- parallel::makeCluster(4, type = "MIRAI")

Random Number Generation

r
# Default: L'Ecuyer-CMRG stream per daemon (statistically safe, non-reproducible)
daemons(4)

# Reproducible: L'Ecuyer-CMRG stream per mirai call.
# Results are the same regardless of daemon count or scheduling.
daemons(4, seed = 42)

Debugging

r
# Synchronous mode — runs in the host process, supports browser()
daemons(sync = TRUE)
m <- mirai({
  browser()
  result <- tricky_function(x)
  result
}, .args = list(tricky_function = tricky_function, x = my_x))
daemons(0)

# Capture daemon stdout/stderr
daemons(4, output = TRUE)

Advanced Pattern: Nested Parallelism

Inside daemon callbacks (e.g., mirai_map), use local_url() + launch_local() instead of daemons(n) to avoid conflicting with the outer daemon pool.

r
mirai_map(1:10, function(x) {
  daemons(url = local_url())
  launch_local(2)
  result <- mirai_map(1:5, function(y, x) x * y, .args = list(x = x))[]
  daemons(0)
  result
})[]

© quarto-dev, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/mirai of quarto-dev/quarto-r.

Open the folder on GitHubat commit bd2329a

Used in 1 other repository

We found 1 copy of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in quarto-dev/quarto-r, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Mirai next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Mirai compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Mirai this skillquarto-dev/quarto-r1601 repos~3kAutomated safety check: PassMIT
Csharp Asyncgithub/awesome-copilot40k2 repos~466Automated safety check: PassMIT
Correctcursor/plugins10k3 repos~612Automated safety check: PassNone
Parallels Discord Roundtripopenclaw/openclaw392k—~788Automated safety check: PassMIT
Openclaw Parallels Smokeopenclaw/openclaw392k—~8.4kAutomated safety check: NotesMIT
CorrectionNxcoreAI/EverRoom3k—~290Automated safety check: PassCustom licence

Similar skills

  • Csharp Async

    github/awesome-copilot

    Official

    Get best practices for C async programming. An agent skill from github/awesome-copilot.

    40k GitHub starsUsed in 2 repos~466 tokens
    DevelopmentAuto-check passed
  • Correct

    cursor/plugins

    Official

    Find the mistakes agents keep repeating in this repo and make each one impossible.

    10k GitHub starsUsed in 3 repos~612 tokens
    Auto-check passed
  • Run macOS Parallels smoke with Discord send, host verification, host reply, and guest readback proof.

    392k GitHub stars~788 tokensUpdated today
    Auto-check passed
  • Openclaw Parallels Smoke

    openclaw/openclaw

    Prepare, snapshot, run, rerun, debug, or interpret OpenClaw Parallels guest install, onboarding, gateway smoke, and upgrade checks across macOS, Windows, and Linux.

    392k GitHub stars~8.4k tokensUpdated today
    Auto-check: notes
  • Correction

    NxcoreAI/EverRoom

    Compute Room overview corrections—citation corrections as per-claim edits and general corrections as a single proposal.

    3k GitHub stars~290 tokensUpdated today
    Research & ScienceAuto-check passed
  • Async

    onsi/gomega

    Polling assertions in Gomega — Eventually (poll until it passes) and Consistently (must keep passing), the func(g Gomega) callback idiom, WithTimeout/WithPolling/Within/ProbeEvery, WithContext and…

    2.4k GitHub stars~2.2k tokensUpdated 13 days ago
    DevelopmentAuto-check passed

More from quarto-dev/quarto-r

All 10 skills in this repo
  • Release Post

    quarto-dev/quarto-r

    Create professional package release blog posts following Tidyverse or Shiny blog conventions.

    160 GitHub starsUsed in 1 repo~2.5k tokens
    Auto-check passed
  • Create Release Checklist

    quarto-dev/quarto-r

    Create a release checklist and GitHub issue for an R package.

    160 GitHub starsUsed in 1 repo~1.9k tokens
    Auto-check: notes
  • Alt Text

    quarto-dev/quarto-r

    Generate and improve accessible alt text for data visualizations and images in R packages and Quarto documents.

    160 GitHub starsUsed in 1 repo~1.7k tokens
    Auto-check passed
  • CLI

    quarto-dev/quarto-r

    Comprehensive R package for command-line interface styling, semantic messaging, and user communication.

    160 GitHub starsUsed in 1 repo~2.8k tokens
    Auto-check passed
  • Quarto Authoring

    quarto-dev/quarto-r

    A skill your agent uses when the user is explicitly working with Quarto, .qmd files, quarto.yml, Quarto projects, or Quarto features such as callouts, cross-references, citations, Mermaid diagrams…

    160 GitHub starsUsed in 1 repo~1.9k tokens
    Auto-check passed
  • Testing R Packages

    quarto-dev/quarto-r

    Best practices for writing R package tests using testthat version 3+.

    160 GitHub starsUsed in 1 repo~2.8k tokens
    Auto-check passed

Questions about Mirai

What does Mirai do?

Help users write correct R code for async, parallel, and distributed computing using mirai. Mirai is an agent skill from quarto-dev/quarto-r. Help users write correct R code for async, parallel, and distributed computing using mirai.

When should I use Mirai?

Mirai fits situations like: users need to run R code asynchronously; write mirai code with correct dependency passing; set up parallel workers; convert from future.

How do I install Mirai in Claude Code?

Run `npx skills add quarto-dev/quarto-r --skill mirai -a claude-code`. Or copy the skill folder (.claude/skills/mirai in quarto-dev/quarto-r) into .claude/skills/mirai in your project. Claude Code loads it when a task matches its description.

How do I install Mirai in Codex?

Run `npx skills add quarto-dev/quarto-r --skill mirai -a codex`. Or copy the skill folder (.claude/skills/mirai in quarto-dev/quarto-r) into .agents/skills/mirai in your project. Codex loads it when a task matches its description.

Can I use Mirai in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add quarto-dev/quarto-r --skill mirai -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/mirai, .gemini/skills/mirai, .github/skills/mirai and .opencode/skills/mirai in your project.

What does Mirai need to run?

SKILL.md names no scripts, command-line tools or credentials: Mirai is instructions for the agent only.

Does Mirai access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Mirai safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Mirai use?

Mirai is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Mirai use?

About 3k tokens (SKILL.md is roughly 12k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Mirai?

Skills that share tags, products or a category with Mirai: Csharp Async (github/awesome-copilot, 40k stars), Correct (cursor/plugins, 10k stars), Parallels Discord Roundtrip (openclaw/openclaw, 392k stars) and Openclaw Parallels Smoke (openclaw/openclaw, 392k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Mirai?

quarto-dev (a GitHub organization) maintains it in quarto-dev/quarto-r, which has 160 GitHub stars. The repository holds 10 skills in this directory. The repository was last updated on September 10, 2026.

Source: quarto-dev/quarto-r on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.