wiki

What is command context?

All commands exist in a context.

This context is first set when the command is run and consists of multiple parts that all describe the “situation” that a command is run in.

All of which can be modified individually with the 1.13+ Java as well as 1.19.1+ Bedrock execute command.

See the Minecraft wiki on the execute command for which subcommands modify which context.

Defaults

When a command is run, it will get some default values depending on how it is run.

Context in Functions

Functions keep the context that they’re run in.

So a function run in chat will have the same defaults as any other command run from a player in chat. The same is true for a function command run from a commandblock, it will have the same context as any command run from a commandblock would.

A command run from either the #minecraft:load or #minecraft:tick function tags will run positioned at world spawn (at the lowest end of the block, unlike the commandblock), rotated 0 0 and without an executing entity.

This allows a lot of optimization since you can use a selector once, running the function as that entity and then refer to that entity as @s for the rest of the function. It also allows for entityless raycasting as the position and rotation is preserved between function calls.