Shell Builtins
Create and manage custom shell commands for Crush's embedded shell environment.
Installation
- Make sure Claude is on your device and in your terminal.
Skills load from
~/.claude/skills/when Claude Code starts up — so you need it on your machine first. If you don't have it yet, install it once with the command below, then runclaudein any terminal to verify.One-time setupnpm i -g @anthropic-ai/claude-codeAlready have it? Skip ahead.
- Paste into Claude Code or into your terminal.
This copies the whole skill folder into
~/.claude/skills/shell-builtins-charmbracelet/— the SKILL.md plus any scripts, reference docs, or templates the skill ships with. Safe default: works for every skill.Faster alternative (instruction-only skills)
Skips the clone and grabs only the SKILL.md file. Don't use this if the skill ships Python scripts, reference markdowns, or asset templates — they won't be downloaded and the skill will fail when it tries to load them.
Quick install (SKILL.md only)Sign up to copy - Restart Claude Code.
Quit and reopen Claude Code (or any other agent that loads from
~/.claude/skills/). New skills are picked up on startup. - Just ask Claude.
Skills auto-activate when your request matches the skill's description — no slash command needed. Trigger phrases live in the skill's own frontmatter; you can read them in the “What this skill does” section above.
Prefer to read the source first? Open on GitHub.
When Claude uses it
Use when creating a new shell builtin command for Crush (internal/shell/), editing an existing one, or when the user needs to understand how commands are intercepted in Crush's embedded shell.
What this skill does
Shell Builtins
Crush's shell (internal/shell/) uses mvdan.cc/sh/v3 for POSIX shell
emulation. Commands can be intercepted before they reach the OS by adding
builtins — functions handled in-process.
How Builtins Work
Builtins live in builtinHandler() in internal/shell/run.go. This is an
interp.ExecHandlerFunc middleware registered in standardHandlers()
before the block handler, so builtins run even for commands that would
otherwise be blocked. The same handler chain is shared by the stateful
Shell type and the stateless Run entrypoint used by the hook runner,
so builtins are available identically in the bash tool and in hooks.
The handler is a switch on args[0]. Each case either handles the command
inline or delegates to a helper function.
Adding a New Builtin
- Add the case to the switch in
builtinHandler()inrun.go. - Get I/O from the handler context, not from
os.Stdin/os.Stdout. This ensures the builtin works with pipes and redirections:case "mycommand": hc := interp.HandlerCtx(ctx) return handleMyCommand(ctx, args, hc.Stdin, hc.Stdout, hc.Stderr) - Implement the handler in its own file (e.g.,
internal/shell/mycommand.go). The function signature must accept acontext.Contextas the first parameter, plus args, stdin, stdout, and stderr:func handleMyCommand(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) error { // args[0] is the command name ("mycommand"), args[1:] are arguments. // Write output to stdout, errors to stderr. // Return nil on success, or interp.ExitStatus(n) for non-zero exit codes. } - Poll
ctxin every unbounded loop. Builtins that iterate over input, emit values in a generator-style loop, or do any other work that can exceed a few milliseconds MUST checkctx.Err()on each iteration and return it verbatim when non-nil. Hook timeouts rely on this: an unbounded builtin that never polls ctx cannot be interrupted by a hook'stimeout_sec, and the hook runner will have to abandon the goroutine (seeinternal/hooks/runner.go). Returningctx.Err()(notinterp.ExitStatus(n)) lets callers distinguish "command exited non-zero" from "we ran out of time".for _, item := range items { if err := ctx.Err(); err != nil { return err } // ... process item } - Return values: return
nilfor success,interp.ExitStatus(n)for non-zero exit codes, orctx.Err()on cancellation. Write error messages tostderrbefore returning. - No extra wiring needed —
builtinHandler()is already registered instandardHandlers().
Existing Builtins
| Command | File | Description |
|---|---|---|
jq | jq.go | JSON processor using github.com/itchyny/gojq |
Related skills
Generative Code Art
anthropics
Create algorithmic art with p5.js using randomness and interactive parameters.
Poster & Visual Design
anthropics
Create original posters and visual art in PNG and PDF formats.
Claude API Helper
anthropics
Build, debug, and optimize Claude API applications with caching and model migration support.
MCP Server Builder
anthropics
Build protocol servers that connect language models to external APIs and services.