Run a function
/function mypack:startRuns every command of data/mypack/function/start.mcfunction once, in order.

/function runs every command of a .mcfunction file from a data pack, in order, with the same executor and position as the caller. It turns long command chains into readable files and can pass arguments to macro functions. A function tag runs several functions in one call.
/function <name> [<arguments>|with]| Argument | Expects | What it does |
|---|---|---|
| name | Function | Function or function tag ID, for example mypack:start or #minecraft:load. |
| argumentsoptional | NBT compound | Compound with the macro values, for example {name:"Alex",count:3}. |
| sourceoptional | Block coordinates (x y z) | Where the macro values come from: block coordinates, an entity or a storage ID, depending on the keyword. |
| pathoptional | NBT path | Optional NBT path inside the source; the compound found there becomes the macro arguments. |
/function mypack:startRuns every command of data/mypack/function/start.mcfunction once, in order.
/function mypack:greet {name:"Alex"}In greet.mcfunction, the macro line $say Hello $(name) becomes say Hello Alex.
/function mypack:greet with storage mypack:data playerTakes the macro values from the player compound of the mypack:data storage.
/function #minecraft:loadRuns every function in the minecraft:load tag, the ones that normally run after loading.
/execute as @a at @s run function mypack:checkThe function runs once per player, with @s and ~ ~ ~ pointing to that player.
Fill in the fields, then copy the command.
Command generatorA function is a text file at data/<namespace>/function/<name>.mcfunction inside a data pack, called as namespace:name. Write one command per line, without the leading slash; lines starting with # are comments. The function tags #minecraft:load and #minecraft:tick run their functions after loading and on every game tick. After editing a file, run /reload, and check with /datapack that the pack is enabled.
A line that starts with $ is a macro line: each $(key) is replaced before the command runs. Pass the values as a compound such as {name:"Alex"}, or read them from NBT with with entity, with block or with storage. A missing key stops the call with "Missing argument ... to function ...". Macro functions cannot be delayed with /schedule.
execute as @a at @s run function mypack:check runs the file once per player.function-permission-level in server.properties.✓ Checked in Java Edition 26.3 · updated 2 November 2026
No, write each command without the slash. Lines starting with # are comments, and lines starting with $ are macro lines.
Add it to the minecraft:tick function tag, in the file data/minecraft/tags/function/tick.json of your pack. Keep it light, since it runs 20 times per second.
Type it in the chat with cheats on: /function <name> [<arguments>|with].
Cheats on, or operator level 2.
/scheduleCheats/returnCheats/randomEveryone/triggerEveryone/teamCheats/computeCheats/stopwatchCheats/datapackCheats