CivSwitchFS-kaiHEN
[!IMPORTANT] Thanks to Slapah for the ns2jb filesystem port to CivSwitch and Kurumuz for the improved fork of ns2jb from pepsipu, which laid the groundwork for this research. All kudos goes to them for the Civ FS port :heart: This is a fork of CivSwitchFS which is by Nerisma, who did the difficult work of getting FS acquisition work locally!
CivSwitchFS provides access to FS privileges through an elevated fsp-srv handle. It runs inside the CivSwitch Remote JS Loader. The FS access can be chained into a full kaiHEN boot (homebrew enabler), which is what this fork provides, see Booting kaiHEN.
A bit of a preface
Smol demo of CivSwitchFS: https://streamable.com/bhgobg
Smol demo of CivSwitchFS booting KaiHEN: https://youtu.be/2pGN9HiXaZg (skip from 0:40 to 4:00)
CivSwitchFS is semi-untethered, RPC was fully removed :tada: ! It should also be more consistent for any hardware.
Repo state
This is meant to be sharing early code. It's not cleaned properly. The branch is called slop for a reason.
There will be updates, and you'll need to update manually.
Beware that fs vuln can be risky to utilize and may corrupt things like your save file, or more. If you want minimal brick risk, then wait on. Meanwhile, see BRICK_RISKS.
Tested configuration
- Nintendo Switch 2, firmware 23.0.1 (only exFAT fw tested, FAT32 should work too). Do not use on lower firmware!
- Civilization VII 1.0.0, physical cartridge
- CivSwitch Remote JS Loader already running (follow CivSwitch instructions)
- kaiHEN 20261201 (later versions may not work)
Requirements
- Node.js 20 or later and npm
- A Switch 2 with the CivSwitch Remote JS Loader already running and reachable on the local network when installing persistence or sending a payload
- A microSD card, formatted fat32 or exfat (can be non-express, press home on micronag)
- A Switch 1 or 2 game, physical or digital, can be a demo.
Usage
Install dependencies once from this repository:
npm installPersist the whole kaiHEN chain (recommended)
-
Set up your save file with CivSwitch. You may need to go to Data Management to delete your save file and reinstall it occasionally. This esp32 LDN approach is highly recommended.
-
Download our kaiHEN 20261201 release for SD card use (
kaiHEN-20261201-civswitchfs.zip, e.g. from here), copy the contents of itssdcard/folder to the root of your microSD card, also copybootstrap.binto/kaihen/bin/bootstrap.bin(our chain reads it from the card, unlike upstream's own acquisition tool), and then insert the card before you start. -
Set up a network connection that won't get you Nintendo server access. Be very careful with this. If you don't know how to do this right, DO NOT USE THIS YET. It's not worth the risk of getting the blacklist update that'll lock you out of Civ 7 without a reboot. If you will set up 90DNS, follow the instructions on Gitlab precisely, do not skip any steps.
-
Boot into CivSwitch console by going to Civ 7 -> Load Game. Wait for
Awaiting payload. -
From this repository's folder, run the launcher with your console's IP address:
npm run persist:chain -- <console-ip> -
Wait for about a minute while the save file is set up.
-
Close Civilization VII normally. All subsequent starts of Civ 7 will automatically acquire FS then run kaiHEN.
-
After finishing the CivSwitchFS-kaiHEN runs, hold R while opening a switch 2 game. The first time, HEN only records the game's signing policy and the game starts as usual. The next R-held launch opens hbmenu. If it doesn't work, restart your system and run Civ7 to try again.
-
HEN lasts until the console restarts. To use homebrew again after a restart, go into Civ7 and hit load again.
Tip: You can go to Civ 7 settings -> Console to disable opening movies.
Note: To run a different kaiHEN build than the one marked as supported by
the version of CivSwitchFS-kaiHEN you're running, create an empty
file /kaihen/civswitchfs-skipcheck on the card. You'll need to copy over the new sdcard/ folder contents over, alongside putting bootstrap.bin to /kaihen/bin/bootstrap.bin. No support will be provided for users running unsupported versions.
Our releases are cut from the upstream build plus two additions: the
kaihen-civswitch.json support descriptor (lets the payload check it is
running against a release it knows) and payload.js (the kaiHEN chain,
used by the split persistent install), with upstream's root-level
bootstrap.bin also copied to sdcard/kaihen/bin/bootstrap.bin because
our chain reads it from the card.
Launch CivSwitchFS by itself (not for end users)
If you are not going for persistence, just start the CivSwitch Remote JS Loader using your usual CivSwitch setup. Then send the payload
npm run send -- <console-ip>Wait for You just Civ Sevened your machine, congrats which obviously means success :tada: !
Then, the loader automatically shows Awaiting payload at <ip>:9026 and you are free to send payloads.
Race timing schedule
The canary campaign uses this fixed schedule, in nanoseconds:
var roleDelays = [0, 300000, 350000, 450000, 550000, 650000, 1000000, 1200000, 1300000, 1700000];
var guardDelays = [150000, 300000];The payload reads these values from src/core/config.mjs. It does not load or save timing schedules in save data; changing the schedule requires changing the code.
Controls
- B: stops after the current wave clean up
- Y: toggle between normal and verbose summaries
Booting kaiHEN manually
tools/kaihen.mjs chains the FS access into a full kaiHEN
boot. Once kaiHEN runs, holding R while opening a game starts hbmenu
instead of the game. kaiHEN normally starts from SmileBASIC (a Switch
game with a built-in BASIC interpreter); this chain starts it from
Civilization VII. Targets the 20261201 release on firmware 23.0.1.
On top of the usual setup you need:
- the kaiHEN release unpacked on your computer (the 20261201 zip as
extracted,
sdcard/andbootstrap.binincluded) - an SD card in the console: the first run copies hbmenu, the game loader,
the HEN programs and the shared libraries to it, later runs can pass
--no-stage
Run the exploit first, wait for the success line, then the launcher:
npm run send -- <console-ip> # wait for "You just Civ Sevened"
node tools/kaihen.mjs <console-ip> --dir /path/to/kaiHEN-20261201A successful run ends with:
KH: === HEN IS RUNNING ===
-- kaiHEN is running. Close Civilization VII normally; hold R while opening a Switch 1 or 2 game twice. --
Then close Civ 7 normally (don't power off), hold R while opening another game twice. The first R-held launch only records the game's signing policy and the game starts as usual; the second R-held launch opens hbmenu. kaiHEN keeps running until the console restarts.
The launcher stages the SD card, then runs the chain: it re-arms the endpoint (the fs write path), reads the domain layout, copies the game's loader fs session, builds a donor (a stand-in code filesystem), performs the launch (the game's code filesystem is exchanged for kaiHEN's), and finally runs the bootstrap NRO, which talks to that loader session copy to start the HEN. Everything it prints goes to stdout; tee it if you want to keep it.
| Option | Effect |
|---|---|
--dir DIR | kaiHEN release folder (default ../kaiHEN-20261201 from the repo root). The 20261201 layout (sdcard/), the older flat layout and our SD-shaped layout are auto-detected |
--status-only | report SD state and exit |
--force | restage files even when their size already matches |
--no-hbmenu, --no-programs | skip staging those files |
--no-stage | skip the SD probe and staging entirely (files must already be on the card) |
--probes, --dx | also run the debug diagnostics (TS/SR/SB probes / DX experiments; default skip list is dx,probes). Their sends close the loader session copy the bootstrap needs. |
--skip A,B | explicit skip list, overrides the default dx,probes |
When it fails
- If it fails or freezes, restart your console (only hard-restart by holding power for 15 seconds, don't close game normally outside of a success) and retry.
- One kaiHEN launch per console boot. After a run that reached
launch complete, you cannot update or restart kaiHEN without a restart; the launcher refuses a second launch on the same boot.
Troubleshooting
If you're having issues with a reduced success rate, etc, you should reset your save fully and reinstall. This is recommended to do when you're updating, especially if you're moving to v2 or onwards (v2 was released 2026-11-18).
- (make sure your kaiHEN files on SD are up to date)
- Delete your Civ7 save in Settings -> Data Management
- Remove your cartridge, press + on Civ 7, delete it too (to wipe your cache we think, as it's a cartridge game you can just plug it back in), plug your cartridge back in
- Boot up civ7, set up civswitch somehow (again, ldn is my favorite), then FIRST make sure you got the most recent copy of this repo locally, then run:
npm run persist:chain -- your.ip.here.blarf - Restart your console fully instead of just the game, just for good measure
- Boot up civ7, let it boot up kaiHEN
- Then all subsequent attempts to boot kaiHEN should, hopefully, be less painful.
Notes
- You can learn about how the exploit works there
License
CivSwitchFS is MIT, ns2jb and kaiHEN are GPL v2.0, and so the code ported from those in this repo are under GPL v2.0.
See LICENSE and THIRD_PARTY_NOTICES.md for detailed notices.
Standing on the shoulders of giants
- Nerisma's CivSwitchFS, which makes all this possible on-device. Amazing stuff.
- Gezine for CivSwitch, the Civ7 entrypoint.
- civswitch-kit, the original Civ7 FS kit, based on slapah/Hokage's work, which is itself based on ns2jb.
- civ7-fs, the Civ7 FS port this repository builds on.
- kurumuz for kaiHEN and his ns2jb fork.
- pepsipu for discovering nsj2b vuln, and the ns2jb codebase.
- epiccsolar, who got kaihen booting ~13 hours before me, this repo doesn't use her code, but I want to acknowledge her work.
- LLMs were involved in the development of this. Please don't use it if you don't trust it.