/bodnar-skills:nushellfrom bodnar-skills
Comprehensive guide for writing Nushell (v0.112.2+) scripts, modules, and commands. Use when creating or working with Nushell code, pipelines, data transformations, structured data processing, custom commands, modules, or any task involving Nushell scripting. Covers syntax, idioms, functional programming patterns, Unix Philosophy principles, type system, error handling, testing, tooling (nu-lint, LSP, MCP), and v0.111/v0.112 features (try..catch..finally, let mid-pipeline, % sigil, from md, alias parent commands, new config options).
Ships in bodnar-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.
Read when SKILL.md points to them; scripts run unread.
Comprehensive guide for writing idiomatic, functional Nushell code aligned with Unix Philosophy principles. Targets Nushell v0.112.2 and newer.
Nushell is a modern, structured-data shell that extends Unix pipeline philosophy with a rich type system and functional programming patterns.
Core Principles:
each, where, reduce)Essential Patterns:
# Pipeline composition
ls | where size > 10mb | sort-by modified | first 5
# Structured data transformation
open data.json | select name age | where age > 21
# Functional iteration
[1 2 3 4] | each {|x| $x * 2 } | reduce {|acc, x| $acc + $x }
# String interpolation
let name = "World"
$"Hello, ($name)!"
# Type-safe transformations
"42" | into int | $in * 2
# let mid-pipeline (v0.111+): capture a value, keep flowing
"hello" | let msg | str length # returns 5, $msg is "hello"
# try..catch..finally (v0.111+): finally always runs
try { risky } catch {|e| handle $e } finally { cleanup }
The references/ directory contains detailed documentation organized by topic:
references/deprecated-and-errors.md — Deprecated commands, removed commands, and common syntax errors.
references/quick-reference.md — Cheat sheet and quick tour.
references/types-and-data.md — Types system and data structures.
references/pipelines-and-composition.md — Pipeline patterns and the $in variable.
$in behavior.references/programming-guide.md — Variables, control flow, functions, error handling.
references/modules-and-organization.md — Module creation and management.
references/scripts-and-cli.md — Script files, main commands, shebangs.
references/style-guide.md — Formatting, naming conventions, best practices.
references/testing.md — Testing framework and assertions.
references/standard-library.md — Standard library modules.
references/special-variables.md — $nu, $env, $in, and other special variables.
references/data-loading.md — File formats, parsing, data import.
references/plugins.md — Plugin system and extensions.
tooling.md — nu-check, nu-lint, nu --lsp, nu --mcp, IDE integration, CI/CD.
# Basic command
export def greet [name: string] {
$"Hello, ($name)!"
}
# With flags
export def greet [
name: string
--loud (-l) # Flag with shorthand (boolean switch, no type)
] {
let msg = $"Hello, ($name)!"
if $loud { $msg | str upcase } else { $msg }
}
# Pipeline input
export def double []: int -> int {
$in * 2
}
# Main command (for scripts)
def main [path: string, --verbose (-v)] {
if $verbose { print "Processing..." }
open $path | process
}
# Table operations
ls
| where size > 1mb
| select name size modified
| sort-by size --reverse
# Record manipulation
{ name: "Alice", age: 30 }
| update age ($in.age + 1)
| insert job "Engineer"
# List processing
[1 2 3 4 5]
| each {|x| $x * 2 }
| where $in > 5
| reduce {|acc, x| $acc + $x }
let Mid-Pipeline (v0.111+)let can be placed inside a pipeline to capture a value and continue processing. The value passes through unchanged.
# Capture and continue (value passes through)
"hello" | let msg | str length
# => 5
$msg
# => hello
# End of pipeline: value is assigned AND output
ls | length | let y
# => 36 (output)
$y
# => 36
# With $in mid-pipeline
10 | let x | $in + 5
# => 15
$x
# => 10
Use | ignore if you do not want the end-of-pipeline value displayed.
try..catch..finally (v0.111+)finally runs whether try succeeded, catch ran, a return was hit, or even exit was called.
# Basic try..finally (cleanup always runs)
try { risky-operation } finally { cleanup }
# try..catch..finally
try {
open file.txt
} catch {|e|
print $"Error: ($e.msg)"
""
} finally {
print "done"
}
# finally receives a value from try/catch
try { 111 } finally {|v| print $v }
# prints 111
try { 1 / 0 } finally {|v| print $v.msg }
# prints the error message
# finally runs even on early return
def work [] {
try {
return 10
} finally {
print "cleanup"
}
}
work
# prints "cleanup" then returns 10
# finally runs even on exit (unless --abort)
try { exit } finally { print "saved!" } # prints "saved!"
try { exit --abort } finally { print "saved!" } # does NOT print
Streaming note: try does not stream if catch or finally exists. catch does not stream if finally exists.
% (v0.112.1+)The % sigil forces resolution to a built-in command, bypassing custom commands, aliases, and any shadowing. It is the complement to ^ (force external).
# User shadowed the built-in
def ls [] { "my custom ls" }
ls # calls the custom command
%ls # calls the built-in ls
^ls # calls the external binary
# Useful when a built-in has been hidden
hide version
version # ERROR: not found
%version # works, uses the built-in
Error if the name is not a built-in:
%lss # Error: "percent sigil requires a built-in command"
# module.nu
export def public-command [] {
helper-function
}
# Local/private function
def helper-function [] {
"internal use only"
}
# Export environment
export-env {
$env.MY_VAR = "value"
}
Aliasing a parent command makes sub-commands usable under the alias.
alias pl = polars
ps | pl into-df | pl select [(pl col name)] | pl collect
alias m = math
[1 2 3] | m sum
Primitives: int, float, string, bool, duration, filesize, date
Structured: list, record, table, range
Special: nothing (null), any, cell-path, closure, block
Type Annotations:
def typed [x: int]: list<string> -> string {
$in | each {|s| $"($x): ($s)" } | str join "\n"
}
Naming Conventions:
kebab-case (e.g., fetch-user)snake_case (e.g., user_id)--kebab-case (accessed as $snake_case)SCREAMING_SNAKE_CASECode Organization:
mod.nu for directory modulesPipeline Design:
$in for pipeline valueslet mid-pipeline for intermediate capture (v0.111+)Functional Style:
each, where, reduce over loopsDocumentation:
Linting and Validation:
nu-check for syntax validationnu-lint check for idiomatic codenu --lsp in your editor for real-time feedbackCommon script patterns are available in scripts/:
scripts/cli-tool.nu — CLI tool with argument parsingscripts/data-pipeline.nu — Data transformation pipelinescripts/module-template.nu — Module structure templatescripts/test-syntax-patterns.nu — Test suite demonstrating correct syntax patternsThe test script validates syntax patterns and can verify that common patterns work correctly:
nu scripts/test-syntax-patterns.nu
use std/assert
# Test command
def "test my-command" [] {
assert equal (my-command "input") "expected"
assert ($result | str contains "substring")
}
# Run tests
nu -c 'source tests.nu; test my-command'
--no-std-lib for scripts that do not need ittimeit from std/benchpar-each (unordered) now streams as of v0.112.1input list now streams upstream lists/ranges incrementally (v0.112.1)These commands and flags were removed in v0.112.1 and will fail with parser errors:
| Removed | Replacement |
|---|---|
random dice | std/random dice |
metadata set --merge {...} | metadata set {|| merge {...} } |
watch --debounce-ms <n> | watch --debounce <duration> |
into value --columns | detect type --columns |
into value --prefer-filesizes | detect type --prefer-filesizes |
into value (inference from strings) | detect type + update cells |
See references/deprecated-and-errors.md for migration details.
filter → where (deprecated v0.105.0)# ❌ DEPRECATED
[1 2 3 4] | filter {|x| $x > 2 }
# ✅ CORRECT
[1 2 3 4] | where {|x| $x > 2 }
The where command accepts closure predicates from variables, making it fully equivalent to the old filter command.
# ❌ WRONG - type annotation on switch
def cmd [
--verbose: bool = false
--flag: bool
] { }
# ✅ CORRECT - plain switches (implicitly boolean)
def cmd [
--verbose
--flag
] { }
Switches are implicitly boolean. They default to false when not provided and true when provided. Adding : bool or = false causes a parser error. Since v0.111 switch flags are properly typed as bool at parse time.
# ❌ WRONG - operators at line end
data | where {|x|
($x.field1 > 10) and
($x.field2 == "value") and
($x.field3 != null)
}
# ✅ CORRECT - wrap in parens, operators at line start
data | where {|x|
(
($x.field1 > 10)
and ($x.field2 == "value")
and ($x.field3 != null)
)
}
Nushell's parser treats and/or at the end of a line as incomplete. Wrap the expression in parentheses and place operators at the start of lines.
# ❌ WRONG - missing parameter syntax for complex uses
[1 2 3] | each { $in * 2 } # Only works for simple cases
# ✅ CORRECT - explicit parameter
[1 2 3] | each {|x| $x * 2 }
Mutable variables cannot be captured in closures
# ❌ Error
mut x = 0
[1 2 3] | each { $x += 1 }
# ✅ Use reduce instead
[1 2 3] | reduce {|_, acc| $acc + 1 } --fold 0
$in changes in different contexts
Commands vs Externals vs Built-ins
ls # Normal resolution (custom > built-in)
^ls # External system command (forced)
%ls # Built-in (forced, v0.112.1+)
String interpolation requires parentheses
$"Value: ($x)" # ✅
$"Value: $x" # ❌
it is a reserved variable name (v0.111+)
# ❌ Error in v0.111+
let $it = 1
mut $it = 1
# ✅ Use any other name
let item = 1
$nu, $env, $in cannot be used as implicit loop variables (v0.112.1+)
# ❌ Error
for nu: int in [1 2 3] {}
match [1 2 3] { [$in, $nu, $env] => ... }
# ✅ Use different names
for n in [1 2 3] {}
open file.md returns an AST, not a string (v0.112.1+)
# ❌ Surprise: now returns a structured AST
open README.md
# ✅ Get raw string
open --raw README.md
# ✅ Or hide the converter
hide 'from md'
open README.md # now returns a string again
pipefail is on by default (v0.111+)
# A non-zero external exit code now fails the pipeline
^false | lines # returns [] with failure status
Nushell embodies Unix Philosophy through:
Before generating Nushell code, verify:
filter commands (use where instead)random dice, metadata set --merge, watch --debounce-ms, into value --columns, into value --prefer-filesizesand/or operators at start of lines, not end{|param| body } syntax$in correctly($var) not $varit as a variable nameopen on markdown files uses --raw if raw string is wantedAlways validate generated Nushell scripts. Full tooling details in tooling.md.
# Check syntax (built-in, fastest)
nu-check script.nu
# Lint for idiomatic issues (requires nu-lint)
nu-lint check script.nu
# Validate from a function
def validate-nushell-script [path: path] {
try {
^nu -c $'nu-check ($path)'
print $"✓ ($path) is valid"
true
} catch {
print $"✗ ($path) has syntax errors"
false
}
}
This skill targets: Nushell v0.112.2+
Before generating code, verify version compatibility:
nu --version # Should be 0.112.2 or newer
Known breaking changes by version:
from md — open *.md now returns structured AST, not string (use open --raw)job tag renamed to job describe; --tag flag renamed to --description$nu, $env, $in reserved more aggressively in implicit variable declarationspipefail is now the default (non-zero external exit code fails pipeline)it is now a reserved variable nameinput list was rewritten (config shape, flags, keybindings changed)mktemp without a template creates in tmpdir, not cwd$nu.temp-path and $nu.home-path renamedinto value (string-to-type inference) deprecated, later removed in v0.112.1filter deprecated → use whereWhen uncertain about syntax or features, use the context7 MCP to fetch the latest Nushell documentation:
context7:resolve-library-id --libraryName "nushell"
context7:get-library-docs --context7CompatibleLibraryID "/nushell/nushell"
| Feature | Version | Syntax |
|---|---|---|
finally block | v0.111.0 | try { ... } catch { ... } finally { ... } |
let mid-pipeline pass-through | v0.111.0 | "x" | let v | str length |
| Alias parent commands | v0.111.0 | alias pl = polars; pl into-df |
umask command | v0.111.0 | umask 0022 |
clip copy / clip paste (experimental) | v0.111.0 | NU_EXPERIMENTAL_OPTIONS=native-clip |
from md structured parsing | v0.112.1 | open README.md returns AST |
% sigil for built-ins | v0.112.1 | %ls, %version |
cell-path-types (experimental) | v0.112.1 | NU_EXPERIMENTAL_OPTIONS=cell-path-types |
str escape-regex | v0.112.1 | $input | str escape-regex |
to nuon --list-of-records | v0.112.1 | ls | to nuon --list-of-records |
into duration hh:mm:ss | v0.112.1 | "3:34:0" | into duration |
url parse --base | v0.112.1 | $url | url parse --base "https://..." |
group-by --prune | v0.112.1 | $t | group-by col --prune |
frameless table theme | v0.112.1 | $env.config.table.mode = "frameless" |
$env.config.history.path | v0.112.1 | configurable history file location |
$env.config.hinter.closure | v0.112.1 | custom autosuggest hints |
$env.config.auto_cd_implicit | v0.112.1 | cd without ./ prefix |
help commands or https://www.nushell.sh/commands/This skill targets Nushell v0.112.2 and newer.
Always validate generated code with nu-check and test in your target Nushell version. See tooling.md for nu-lint, LSP, and MCP setup.
nushell-skill-changelog.md (opens in a new tab)references/data-loading.md (opens in a new tab)references/deprecated-and-errors.md (opens in a new tab)references/modules-and-organization.md (opens in a new tab)references/nushell-commands-summary.md (opens in a new tab)references/nushell-skill-changelog.md (opens in a new tab)references/nushell-skill-update-summary.md (opens in a new tab)references/pipelines-and-composition.md (opens in a new tab)references/plugins.md (opens in a new tab)references/programming-guide.md (opens in a new tab)references/quick-reference.md (opens in a new tab)references/scripts-and-cli.md (opens in a new tab)references/special-variables.md (opens in a new tab)references/standard-library.md (opens in a new tab)references/style-guide.md (opens in a new tab)references/testing.md (opens in a new tab)references/types-and-data.md (opens in a new tab)scripts/cli-tool.nu (opens in a new tab)scripts/data-pipeline.nu (opens in a new tab)scripts/module-template.nu (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
28 skills in this plugin
/act-platform-engineeringToolkit for Daniel Bodnar's Animal Care Technologies (ACT) platform engineering, SRE, sysadmin, and DBA work. Use this skill whenever the user mentions ACT, vsurv_production, dbprimary, pimsserver, payment gateway reliability, Zach's Bodnar Tasks, Internal Needs (EC-142), Sysadmin/IAC (EC-120), Zoho Projects task or issue creation, PostgreSQL or ZFS assessment on ACT infrastructure, PVE nodes (10.0.50.1-3), the act-infra repo, WAL shipping, dbhotswap failover, PVE3 failing drives, PowerEdge 730, Pims Garden, Miller, Ben Jumper, the assessment cheatsheet or checklist, observability deployment (Grafana, Netdata), centralized log management, secrets management, or pimsserver branch consolidation. Trigger even when the user uses shorthand like "the assessment", "the checklist", "INT-XX", "SY1-XX", or references infrastructure work without explicit naming. Also use when drafting Zoho tasks/issues, running assessment commands on dbprimary, or generating documentation for ACT infrastructure./aitmpl-composeAuthor and compose `claude-code-templates` (aitmpl.com) workflows. Use whenever the user wants to bundle catalog components (agents, commands, MCPs, hooks, settings, skills) into a reusable `workflow.yaml` or `template.json`, merge multiple templates or workflows, expand Bodnar `pack` macros, validate a workflow against the live catalog, or scaffold `.claude/workflows/`. Trigger on "aitmpl", "claude-code-templates", "compose templates", "merge templates", "scaffold a workflow", "share my Claude Code setup", "author a workflow", "author a template", "make a pack", "new pack", "expand pack", "validate workflow.yaml", or any mention of `npx claude-code-templates@latest --workflow` or `--template`. Also use when the user lists components to assemble, or describes a project intent (such as a Cloudflare Worker scaffold with security hardening) that should resolve to a concrete component bundle. Output is upstream-native YAML in `.claude/workflows/`; never invent a parallel bundle format.npx claudepluginhub danielbodnar/agent-plugins --plugin bodnar-skills