fauxnix README

项目的 README,来自 github.com/20000419/fauxnix。合并为一个 markdown 文件:README.md。

fauxnix

CI npm version npm downloads license 20000419/fauxnix MCP server

Run Linux-style commands on Windows — natively, deterministically, no VM, no WSL.

fauxnix is a bash→PowerShell translation layer built for AI agents. Your agent keeps writing the bash it already knows (ls -la | grep foo, find . -name '*.ts' | wc -l, kill -9 1234), and fauxnix deterministically translates each command into PowerShell, executes it natively, and hands back output that looks like GNU/Linux: ls -l columns, bash-style error messages, coreutils exit codes, UTF-8/GBK handled automatically.

One-command install for Claude Code · Codex · OpenCode · Kimi Code · Qwen Code, plus any MCP client. 109 translated commands · 1,469 automated tests · 270-case Git Bash differential corpus plus 41 supplementary checks · zero LLM calls at runtime.

This checkout is v2.2.0. See migration and release notes for the Node.js requirement, changed file-operation contracts and verification limits. The npm badge and @latest examples show the published version until publication completes.

Try it now — no install

npx fauxnix-cli@latest "ls -la src | head -3"
npx fauxnix-cli@latest translate "find . -name '*.log' -mtime +7 -delete"

fauxnix demo

$ fauxnix "ls -la src | head -2"
-rw-r--r-- 1 me me 1204 Aug 16 09:12 ast.ts
-rw-r--r-- 1 me me 8192 Aug 16 09:12 cli.ts

$ fauxnix "cat nope.txt"
cat: nope.txt: No such file or directory        # not a PowerShell stack trace

Connect your agent — one command

npm install -g fauxnix-cli
fauxnix install --claude     # or --codex / --opencode / --kimi / --qwen
fauxnix doctor               # verifies encoding, harness config, and MCP round-trip

Idempotent; prints exactly what changed. Manual configurations below if you prefer to edit config files yourself.

npm package name is fauxnix-cli (the fauxnix name on npm belongs to an unrelated 2015 websocket library); the installed command is fauxnix. Requires Windows with PowerShell 5.1+ (built-in) and Node.js ≥ 22.20.0. Node 18/20 are unsupported in v2. Current Node 22/24 LTS patches are tested. Published v1.0.0 retains its original metadata.

Manual config per harness

fauxnix install --<harness> writes the spawn-safe form shown below: the absolute Node executable plus this installation's absolute entry. A bare command: "fauxnix" is an extension-less npm shim on Windows — MCP clients that spawn the server directly (CreateProcess) cannot execute it (#252). Shell-wrapping clients like Claude Code accept either form; the absolute form works everywhere.

Claude Code

claude mcp add fauxnix -- fauxnix mcp

Codex (~/.codex/config.toml or codex mcp add fauxnix -- fauxnix mcp)

[mcp_servers.fauxnix]
command = 'C:\Program Files\nodejs\node.exe'
args = ['C:\Users\<you>\AppData\Roaming\npm\node_modules\fauxnix-cli\dist\index.js', 'mcp']

Note: in non-interactive codex exec mode, MCP tool calls are auto-denied by the approval layer; pass --dangerously-bypass-approvals-and-sandbox (or run interactively and approve once).

OpenCode (opencode.json)

{
  "mcp": {
    "fauxnix": {
      "type": "local",
      "command": ["C:\\Program Files\\nodejs\\node.exe", "C:\\Users\\<you>\\AppData\\Roaming\\npm\\node_modules\\fauxnix-cli\\dist\\index.js", "mcp"]
    }
  }
}

Kimi Code — MCP servers live in a JSON file, not the TOML config: ~/.kimi-code/mcp.json

{
  "mcpServers": {
    "fauxnix": {
      "command": "C:\\Program Files\\nodejs\\node.exe",
      "args": ["C:\\Users\\<you>\\AppData\\Roaming\\npm\\node_modules\\fauxnix-cli\\dist\\index.js", "mcp"]
    }
  }
}

Qwen Code (~/.qwen/settings.json)

fauxnix install --qwen

The installer preserves the rest of settings.json and writes the same absolute launcher. See the Qwen example for the generated JSON shape.

Any MCP client — stdio server: fauxnix mcp. The tool name is bash (override with FAUXNIX_TOOL_NAME). The tool description already teaches the model the supported subset, so no system-prompt changes are required.

Copy-paste quickstarts with a 10-command smoke test per harness: docs/examples/

The MCP session persists cwd, environment variables, export/unset, cd -/OLDPWD, and positional parameters (set -- / $1 / "$@") across tool calls — it behaves like a logged-in shell, not a stateless exec. $0 is the MCP tool name, not a Windows path.

For workflows whose commands are already known, the MCP server also exposes bash_batch: it compiles every step before execution, runs the plan atomically in one session, and returns one structured result per step in a single MCP round trip (stops on first nonzero exit by default).

{
  "steps": [
    { "id": "write", "command": "printf 'a\\r\\nb' > data.txt" },
    { "id": "measure", "command": "wc -c data.txt" }
  ]
}

See compiled MCP batch plans for timeout, budget, cancellation, and preflight semantics.

Experimental: native shell facade

Point Claude Code's built-in Bash tool at fauxnix — no MCP sidecar, zero protocol round trips per command:

fauxnix install --claude-shell     # builds a fauxnix-backed bash.exe (~85 MB) and sets
                                   # CLAUDE_CODE_GIT_BASH_PATH; restart Claude Code after
fauxnix doctor                     # reports the launcher status
fauxnix install --claude-shell-off # restores the previous setting

The launcher is a copy of your own node.exe with the facade bundle injected via Node SEA (experimental trade-off; the GA plan is a small prebuilt stub). It implements the bash argv contract (bash -c/-lc, $0/$1 from trailing operands), adapts the harness's private command scaffolding (captured from a live session — payload execution, cwd markers, snapshot stubs), and always identifies itself via --version. The harness's own Bash approval flow governs runs. fauxnix facade also runs standalone. Details, security rules, and the protocol findings: RFC — native shell facade.

Measured: your model is probably worse at PowerShell than you think

Same model (DeepSeek-V4-Pro), same 5 tasks, three execution modes on one Windows machine — full data in docs/benchmark-deepseek-v4-pro.md and docs/benchmark-ark-models.md:

PowerShell fauxnix Git Bash
tool calls / unexpected errors 14 / 9 7 / 0 4 / 0
time (T1–T4) 163s 66s 57s

Across 7 models on the Volcano Ark Coding Plan, the PowerShell-vs-fauxnix gap held for every model tested — worst case (kimi-k2-thinking): 3.1× slower with 24 error events writing PowerShell vs zero errors through fauxnix. fauxnix lands within ~15% of the real-bash ceiling with no bash toolchain installed.

Why

LLM agents are dramatically better at bash than at PowerShell — bash dominates training data, so models on Windows often produce "looks right, doesn't run" commands (wrong quoting, curl that isn't curl, mojibake from codepage mismatches, inscrutable CategoryInfo error dumps).

fauxnix Git Bash WSL Raw PowerShell
agent writes plain bash ✓ ✓ ✓ ✗
only needs Node (no bash toolchain / VM) ✓ ✗ ✗ (VM, GBs) ✓
native Windows filesystem & environment ✓ mostly ✗ (9P bridge) ✓
differential compatibility 269/270 cases identical; limits below GNU reference GNU tools different contracts
CRLF / UTF-8 / GBK traps handled ✓ locale-dependent ✓ ✗

If Git Bash already works for you, keep it — we literally use it as our differential-testing oracle. fauxnix is for when you can't or don't want to ship one: agent fleets where the bash toolchain drifts or isn't detected (the Windows ARM64 Git-Bash detection failure is a live example), CI runners, locked-down machines, or anywhere a single npm install -g is easier than a toolchain.

fauxnix takes the third road: translate, don't emulate. A large, high-value subset of the Linux command line — file ops, text processing, process management, archives, networking basics — maps cleanly onto PowerShell + .NET. fauxnix implements that subset faithfully and fails loudly and helpfully on what it can't translate, so the agent never gets silently-wrong results. That matters as labs train computer-use agents on Mac fleets — the agent keeps writing bash; fauxnix makes the Windows box answer like the box the agent was trained on (RFC: computer-use parity).

What's translated

109 commands, output-matched against real GNU coreutils on Windows (Git Bash) during development:

The curated agent-daily 60 carry a CommandSpec: unknown options fail with a GNU-style usage error instead of being ignored. The generated docs/command-specs.md is the exact list, coverage count, option table, and exclusion rationale; fauxnix list --json exposes the same per-command metadata. find stays unspec'd so predicates like -name still compile; sed/awk/egrep keep their command-specific parsers; tar remains native to tar.exe so supported bsdtar options reach the executable. Implemented GNU holes include cp -n / mv -n / touch -c / tee --append / grep -m / head --lines / du --max-depth / env -u / ps -f / command -V / date --date=@SECONDS.

Plus shell syntax: pipes, && / || / ;, redirections (> >> 2> 2>&1 < &>, /dev/null), quoting, $VAR $1 $# "$@" set -- shift, ${name:-word} ${name//pat/str} ${name:off:len} ${name[n]} ${#name[@]}, A=(x y z) array assignment, $(...) command substitution, VAR=x cmd prefixes, ~ expansion, and POSIX-style path normalization (/tmp, /d/foo → D:\foo). Exit codes follow bash conventions: 0 ok, 1 fail, 2 usage/serious, 127 command not found, 124 timeout.

Unknown commands (git, node, npm, python, cargo, gh, docker, ...) are passed through natively with argv-style quoting. Windows .cmd/.bat shims necessarily pass through cmd.exe; fauxnix preserves its supported punctuation and fails loudly for %, embedded double quotes, NUL, and line breaks rather than passing a different argument.

How it works

bash command ──parser──▶ AST ──translator──▶ PowerShell script ──executor──▶ selected PowerShell
                                                                              │
agent ◀── GNU-style output, bash-style errors ◀── UTF-8 framed host protocol ◀┘

PowerShell 7 is an opt-in, CI-tested tier: set FAUXNIX_PS=pwsh before starting fauxnix or its MCP harness. The default is Windows PowerShell 5.1; invalid values fail loudly rather than falling back. See PowerShell 7 support.

Known deviations (honest list)

fauxnix optimizes for the commands agents actually run. Documented deviations:

Development

npm install
npm test          # unit + real-PowerShell integration suite (Windows only, auto-skipped elsewhere)
$env:FAUXNIX_PS = 'pwsh'; npm test   # same suite through PowerShell 7
npm run build
npx tsx scratch/run.mjs "any bash command"   # quick live check

Differential vs Git Bash is locally opt-in (FAUXNIX_DIFF_ORACLE=1). The minimum-runtime Windows x64 / PowerShell 5.1 CI lane requires Git Bash and runs the 270-case primary corpus plus a separate 41-case supplementary corpus. Other lanes may skip these checks. The primary corpus currently matches 269/270 cases (99.6%); the remaining observed mismatch is the documented Git Bash empty-regex-alternative behavior. The historical 253-case result is not a same-corpus comparison. See test/differential/README.md. The primary gate remains at least 200 cases and 95% identity; the weekly oracle also runs from .github/workflows/differential.yml.

Architecture map: src/parser.ts (bash subset → AST) · src/translator.ts (AST → PowerShell + executor wrapper) · src/executor.ts (spawn, redirects, session persistence) · src/commands/*.ts (per-command generators) · src/mcp.ts (MCP server) · src/cli.ts.

Roadmap: docs/rfc-roadmap-to-1.0.md — tracks, milestones, and the RFC process for proposing waves.

Security

Trust model, host protocol, kill semantics, network guard, and reporting: SECURITY.md.

License

MIT © 20000419

fauxnix (20000419/fauxnix)

正在搜索数据库…

这是什么?Fauxnix 让 AI 编程智能体在 Windows 上可以继续写 bash 命令:它确定性地把每条 bash 命令翻译成 PowerShell,在本地原生运行,并返回 GNU 风格的输出,全程不使用虚拟机或 WSL。
这是一个 CLI 工具,还是作为 MCP 服务器运行?两者都是:它既以 CLI(fauxnix)形式提供,也作为 MCP 服务器提供,任何 MCP 客户端(Claude Code、Codex、OpenCode 等)都可以通过 stdio 连接。
怎么把它接入我的 AI 智能体?安装 npm 包(fauxnix-cli)并运行一条命令的安装器,它会自动接入 Claude Code、Codex、OpenCode、Kimi Code 或 Qwen Code;如果你想自己编辑配置文件,也提供了各 harness 的手动配置片段。
需要安装 WSL 或 bash 工具链吗?不需要——它只需要自带 PowerShell 5.1+ 的 Windows 和 Node.js 18 或更高版本;无需任何 bash 工具链或虚拟机。
有没有它拒绝翻译的 bash 特性?有——tail -f、eval、alias、heredoc、env -i、后台任务(&)以及非末级重定向都会被明确拒绝并给出可操作的错误提示,而不是悄悄出错;sed/awk 只支持一个常见子集(hold-space、标签、循环会抛出「不支持」错误)。
它是为谁打造的?它面向无法或不便安装 bash 工具链的 Windows AI 智能体集群和 CI 运行器,让智能体可以继续使用它训练时所用的 bash。
它在 macOS 或 Linux 上也能用吗?不能,它从设计上就只支持 Windows——它把 bash 翻译成原生 PowerShell/.NET 调用,因此在已经有真正 bash 的系统上没有可翻译的东西。
它实际支持多少条命令?109 条被翻译的命令,涵盖文件操作、文本过滤、进程管理、网络基础和归档,通过一个 253 个用例的差异测试语料库与真实 GNU coreutils 做了输出比对。
为什么不直接用 WSL 或 Git Bash?WSL 需要数 GB 的虚拟机和会破坏原生 Windows 路径的 9P 文件系统桥,Git Bash 工具链则可能缺失或损坏(例如在 Windows ARM64 上);fauxnix 只需要 Node.js,并翻译成原生 PowerShell/.NET 调用,因此智能体集群根本不需要附带任何 bash 工具链。
它用 LLM 来做翻译吗?不用——翻译在解析/编译阶段完全确定性完成,运行时零 LLM 调用,因此结果可复现且速度快。
对网络命令有安全防护吗?有,curl/wget 默认拒绝访问回环/私有/保留 IP 段,作为对智能体驱动的 HTTP 请求的一项安全措施。
作者
20000419
大小
257.8 MB
星标
900
时长
3个月
提交 · 90 天