Java 26.2
Gamerule Command
Gamerule
@p
/gamerule keepInventory true
World rules
Gamerules are world switches, and the usual mistake is the value type: keepInventory takes true or false while randomTickSpeed takes an integer, and a mistyped rule name fails without much feedback. Pick the rule here and the generator constrains the value to what that rule accepts.
Java 26.2
@p
/gamerule keepInventory true