How do I know how many items were cleared with the clear command?

It should say Cleared the inventory of player, removing x items. You can also do /clear player item 0 for a specific amount.


Most commands have return values. In the case of /clear it's the number of items that were cleared, which is exactly what you want. Now the next question: How to use this value? In 1.12 it was complicated, you needed /stats and know who or what executed the command, you needed to prepare some things, etc. Now in 1.13 it's much easier:

/execute store result score @s <score> run clear <selector>

Here <score> is the name of a scoreboard where you want to store the number in and <selector> is the player name or selector of which you want to clear the inventory (or items of a type). You can also directly store it in NBT or a bossbar by using something else than score. More information in the wiki article about /execute (archive).