niubash

The AI-native real Bash: real syntax, real Unix commands, native Windows / Linux / macOS. One niu.exe packages the language engine (rubash), real Unix commands (WinuxCmd), a git-aware prompt and a plugin system with a trust model; it is not MSYS2, Cygwin, Git Bash or WSL — no POSIX emulation layer, no path-conversion heuristics.

Rust Windows · Linux · macOS stable v1.4.4

github.com/unixwin/niubash ↗ · Star 188 · latest v1.4.4 (measured via repo-meta, 2026-10-24)

Why niubash

Writing Bash on Windows has historically meant one of a few fates: install a whole MSYS emulation layer (Git Bash — 440 MB plus an argument-rewriting msys-2.0.dll), boot a Linux VM (WSL — paths flip sides), or give up Bash for PowerShell's verb-noun dialect. niubash's answer is the fourth road: a from-scratch Rust engine that executes bash syntax directly, Windows-native as the main battleground, with the same code shipped as portable binaries on Linux and macOS.

中文原文 · Chinese original(4 张卡片 + 论证全文)

它能跑真插件、真脚本、真 dotfiles,靠的不是移植 GNU 代码,而是把兼容性当工程对象: 每一个行为主张都要对 vendored GNU bash-5.3 源码给 file:line 坐标,每一处差异都要双向差分到字节级。

  • 零 fork:三层执行模型——POSIX fork() 在 Win32 没有等价物,MSYS2/Cygwin 只能在 syscall 层伪造它。niu 的引擎 rubash 复刻 fork 的语义而非机制:子壳与命令替换在进程内完成,脚本可观察的一切与 GNU Bash 一致。命令替换类负载实测 13–62x 快于 GNU bash。
  • 无 MSYS:argv 永不改写——Git Bash 的 MSYS 运行时会在 spawn 前启发式改写「看起来像路径」的参数;niu 没有 MSYS 运行时:参数进什么,命令就收什么,无咒语可念。
  • 四大生态的路径方言全收——Windows 原生(D:\repo、D:/repo)、MSYS/Git Bash 形(/d/repo、/tmp、/usr/bin)、WSL 形(/mnt/d)、Cygwin 形(/cygdrive/d)全部接受且真折叠——既有脚本零修改。
  • 兼容性是测出来的,不是宣称的——对 GNU Bash 自己的 83 套上游语料做 true-baseline 双向测量:83/83 通过、82 套逐字节一致;另外全网 2686 仓 / 9701 资产每夜巡检,6336 条真实资产判定原文入仓可回放。

路径方言实测矩阵随审计包附上(PATH-MATRIX.md,约 100 条 PS 原生 argv 探针逐格实跑); 执行模型细读见 执行模型:零 fork 三层, 路径差异见 路径与 MSYS。

Core features

Real plugins (oh-my-bash, bash-it, bash-completion run unmodified), agent-ready flags (--encoded-command, --cwd-state), $SHELL-based agent onboarding, 12 inlined file commands + 178 applet completions, built-in wpm, a git-aware prompt that never spawns git, and console device redirects that work where Git Bash fails outright (echo >/dev/tty, exec 3<>/dev/tty, test -e /dev/tty — GNU-consistent, which is what keeps git/ssh askpass prompts working). The full ten-point list (Chinese):

中文原文 · Chinese original(十条特性全文)
  • 真·插件生态:上游 BASH 插件直接跑——oh-my-bash、bash-it、bash-completion、bash-preexec 源码一行不改原生运行;bash-completion 3796 行完整 source rc=0 曾是发布阻塞,如今是端到端门禁的一环。
  • 为 agent 而设的旗标面——niu --encoded-command <base64> 给 agent/CI 一条免引号通道;niu --cwd-state <file> 让链式一次性调用共享目录记忆。
  • AI agent 接入:$SHELL 即机制——niu 导出 $SHELL,遵循 POSIX 约定的 agent 从 niu 会话启动即用、零配置;安装器在探针路径布放 bash 启动器命中 Claude Code 的第一探针。
  • 内联命令与编译进壳的补全——12 个高频文件命令内联执行,echo | cat 全程零进程;178 个 WinuxCmd applet 的真实旗标补全编译进 shell。
  • wpm 联动:命令即包——rg / fd / bat / jq / node 一条 wpm install 到位;Windows 发行包预装 gawk、niu-git、ripgrep、fd。
  • git 感知的快速提示符——默认提示符读 .git/HEAD 文件(微秒级)渲染分支与脏标记,不再每条提示符 spawn git 子进程(实测 113–362ms)。
  • 输入管线做到字节级——多行粘贴自动误执行 186 次 → 0,257 行载荷 300s 超时 → 4.6s;ConPTY 粘贴丢字符、typeahead 吃键、控制台 read 三面逐项与 GNU 行为对齐。
  • 控制台设备重定向:Git Bash 报错的地方 niu 照跑——echo >/dev/tty、exec 3<>/dev/tty、test -e /dev/tty 与 GNU 行为一致,同组命令在 Git Bash 的 MSYS 层报 Invalid argument;引擎把 CON 拆成 CONIN$/CONOUT$ 两端,git/ssh askpass 正依赖这条路。
  • 跨平台到 CI 腿:三个发布平台,六个发布目标——Windows x64/ARM64、Linux x86_64/aarch64、macOS aarch64/x86_64 六目标每次发布冒烟四查;Android 双目标 incubating,OpenHarmony 仅 CI 编译检查。

Install & quick start

Windows prefers winget (the official Microsoft source; the manifest carries an InstallerSha256 check):

winget install --id Unixwin.Niubash --source winget

Or a one-line PowerShell script (no admin required; sets up PATH and a Windows Terminal profile; SHA256 verified):

irm https://unixwin.dev/install.ps1 | iex

On Windows the install ships a complete command layer: the full WinuxCmd root (176 Unix commands plus the built-in wpm package manager, under {app}\winuxcmd\, PATH pointed at winuxcmd\bin), and per preinstall.json preloads gawk (with an awk shim), niu-git, ripgrep and fd — git on PATH is native git (~14 ms). Only gawk is x64-only; ARM64 installs likewise preload niu-git / ripgrep / fd.

Linux / macOS: grab the portable tar.gz and unpack:

tar -xzf niubash-v*-linux-x86_64.tar.gz && niubash-v*-linux-x86_64/niu

Build from source (Rust 1.95+):

git clone https://github.com/unixwin/niubash.git && cd niubash && cargo build --release

First run of niu starts a setup wizard: prompt theme, completion style and font detection, writing pure-bash-syntax ~/.niubashrc — afterwards, all configuration is that one file.

Deep dive: AI integration, plugins and the prompt

中文原文 · Chinese original(AI 集成 / 插件系统 / 提示符 三节全文)

AI 集成:agent 的高频调用面是一次性 -c,niu 为此做了三件事。其一,快路径:niu -c true 的冷启动地板从 105.6 ms 压到 26.3 ms(一次性快路径六连 PR;29 例行为电池零差异)。其二,免引号通道 --encoded-command:base64 载荷免掉跨进程引号转义,与 -c 同路径、同 BASH_EXECUTION_STRING 契约。其三,目录记忆 --cwd-state。会话级接入:从 niu 会话启动的 agent 直接拿到 niu 导出的 $SHELL。逐家 agent 见 AI Agent 接入目录;给 agent 的一键安装提示词见 给 AI 的门户;全部旗标语义见 CLI 与旗标参考。

插件系统:外部 bash 生态走「先装、后审、再信」:niu plugin add 克隆源(新源默认不受信),niu plugin trust 审阅校验和后放行,niu plugin enable 在 rc 尾部维护托管块——块外内容永不改写。声明式 spec(~/.niubash/plugins.toml)是唯一事实源,sync / restore / rollback 一族动词带 lockfile 锁定,镜像(niu plugin mirror)对国内网络友好。运行时信任层会复验 pin。

提示符:默认提示符是 Git Bash 骨架,但分支段读 .git/HEAD 文件而不是 fork git——「提示符永不 spawn」红线,实测冷 39 ms / 暖 p50 2.5 ms,对照 Git Bash 每提示符 __git_ps1 约 100–300 ms。PS1 / 主题声明照常接管,set -o vi 的编辑模式指示器保留。

Measured numbers

Every row is a same-machine, reproducible measurement; benchmark scripts ship with the repo. Full comparison on the benchmarks page.

MetricniuContrastSource
One-shot execution niu -c true 26.3 ms (was 105.6 ms — six one-shot fast-path PRs) Git Bash 71 ms GITBASH-KILLER facet 6 · niubash PR #267–#272
Prompt git segment reads .git/HEAD, ≤29 ms git spawned per prompt: 113–362 ms GITBASH-KILLER facet 3 (real repo, min-of-20)
Install size niu ≈16 MB, zero DLLs Git Bash 440 MB + 20 MB msys-2.0.dll GITBASH-KILLER facet 4 (measured on real installs)
Multiline paste auto-execution misfires 186 → 0; 257-line payload 300 s timeout → 4.6 s — niubash PR #252/#288 · paste_multiline_bench.py
Workspace unit tests 1026 passed / 0 failed — CI run 39191023176 (FACTS.json)

Release feed

VersionDateSummary
v1.4.4 2026-10-22 Ships the rubash 1.4.3 engine: root fix for ping/netstat/tracert "command not found" (System32 stores them as UPPERCASE PING.EXE etc. — command-stem case folding); ${v^^} interactive crash fix; WinuxCmd v1.1.20 pin; MSIX foreign-env hardening.
v1.4.3 2026-10-21 Listed on the official winget source (Unixwin.Niubash); interactive multiline groups no longer wedge the REPL; vendored bash bumped to patch 20; -EncodedCommand full spelling; installer hardening.
v1.4.2 2026-10-20 Root fix for windowless parents flashing a console (WinuxCmd shim v1.1.18 + engine-side suppression); x64 preload leg fails closed; gawk-preinstall 404 root-fixed.
v1.4.0 2026-10-10 Git Bash-compatible default prompt (reads .git/HEAD, no git spawn), --encoded-command and --cwd-state, end-to-end vi mode, agent skill bundle, release packages preload gawk/niu-git/ripgrep/fd.
v1.3.4 2026-10-05 Theme choice survives source and fresh terminals; multiline-theme cursor placement fixed; 178/178 WinuxCmd applet completions embedded; the golden user journey became a release gate.
v1.3.3 2026-10-04 PROMPT_COMMAND probe first-key-eating fixed (typeahead guard); tr pipe option fixed; parse throughput +13% (nvm GNU ratio 18.0x → 15.6x).

Latest releases from changelogs.json (the niubash repo's CHANGELOG.md); the full feed lives on the changelog.

On this site

Off site

FAQ

How is niubash different from Git Bash / WSL?

niubash is a native Windows program written in Rust: no bundled MSYS emulation layer, no WSL VM. Git Bash heuristically rewrites path-looking arguments before spawn (the reason the MSYS_NO_PATHCONV incantation exists); niu passes argv through byte-for-byte. The installed family is ≈16 MB versus Git Bash's ~440 MB.

Do I need WSL or MSYS to use niubash?

No. Bash semantics run directly on the Rust engine (rubash), Unix commands come from WinuxCmd (176+ commands), and Git from niu-git — all native binaries with zero DLL dependencies and zero telemetry in the shell.

What does "83/83 GNU suites" mean?

All 83 upstream GNU Bash test suites pass on real hardware Windows, with 82 suites byte-identical to GNU Bash 5.3 output; the single residual line (nameref) is proven byte-by-byte to be GNU's own coproc reap race. Compatibility is measured, not claimed: a nightly patrol additionally sweeps 2,686 real-world ecosystem repos / 9,701 assets.

How do I switch an agent's shell (Claude Code / Cursor etc.) to niubash, and how do I roll back?

Open the agent directory (/agents/): each of 24 mainstream agents has its own page with a copy-paste switch script, a real verify command (echo "SHELL=$SHELL"; uname -s) and rollback steps. AI users can also paste the install prompt from /ai/ and let the agent install and wire itself.

Is it free? Which platforms are supported?

Everything is open source and free. niubash ships native Windows x64 / arm64 installers (winget: Unixwin.Niubash); the rubash engine additionally has CI-gated builds for five platforms: Linux (gnu/musl), macOS, Android and OpenHarmony.

How is the performance?

One-shot execution (niu -c true) is 19.8 ms after dedicated optimization; niu-git starts in ~14 ms (Git Bash: 45–103 ms); command-substitution and subshell workloads run 13–62x faster than GNU bash. Every number ships with its measurement method and reproducible artifacts — see Benchmarks (/benchmarks/).

What is the relation between niu and niubash?

niu is the executable name of niubash (after winget install the command is niu). The family splits as: rubash (the embeddable Bash 5.3-compatible engine), WinuxCmd (Unix commands), niu-git (Git), wpm (package manager) and oh-my-niu (theme framework).