/clear
Removes items from a player's inventory. Can target specific items and limit how many are removed.
Overview
Removes items from a player's inventory. Can target specific items and limit how many are removed. In vanilla Minecraft Java Edition it is one of the player commands and has been available since version 1.0.
It is invoked as /clear [ and accepts 3 optional arguments ([targets], [item], and [maxCount]).
When maxCount is 0 the command succeeds if the player has the item but removes nothing. This is useful for testing in conditional command blocks.
A maxCount of 0 turns the command into a non-destructive counter — it reports matching items without removing any, which command blocks can read as a success/fail condition.
Syntax & Arguments
/clear [<targets>] [<item>] [<maxCount>]The full syntax is /clear [. Angle brackets < > mark required arguments and square brackets [ ] mark optional ones; a vertical bar | between words means you pick exactly one of those literals. Every argument is optional, so the bare command is valid on its own. The arguments [targets], [item], and [maxCount] may be omitted, in which case the documented default applies.
- targets
- Optional, of type an entity. The player(s) whose inventory to clear. Defaults to the executing player.
- item
- Optional, of type an item_predicate. The item to remove. If omitted, all items are cleared.
- maxCount
- Optional, of type an integer. The maximum number of items to remove. If 0, counts matching items without removing them.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| targets | entity | Optional | The player(s) whose inventory to clear. Defaults to the executing player. |
| item | item_predicate | Optional | The item to remove. If omitted, all items are cleared. |
| maxCount | integer | Optional | The maximum number of items to remove. If 0, counts matching items without removing them. |
Examples
The 3 examples below are ready to copy and adapt. For instance, /clear @p clears the entire inventory of the nearest player. Each example varies the arguments to show a different real use of /clear; read the note under every snippet to see exactly what changes.
/clear @pClears the entire inventory of the nearest player.
/clear @a minecraft:dirtRemoves all dirt blocks from every player's inventory.
/clear @s minecraft:diamond 0Checks how many diamonds the executing player has without removing any (useful in command blocks).
Permission Level & Requirements
/clear sits at permission Level 2 - Game Master / Cheats, which means it needs permission level 2, the level cheats grant to single-player worlds and that operators hold by default.
In a single-player world you must have "Allow Cheats" turned on (or open the world to LAN with cheats) before it will run; on a multiplayer server the player needs to be an operator at the matching level.
Java vs Bedrock — Bedrock's /clear uses a numeric data value and max-count rather than an item predicate, and its 'test' behaviour differs slightly.
Common Mistakes
- Forgetting that maxCount 0 tests for the item but does not remove it, useful for detection but surprising if you expected deletion.
- Not specifying an item when you only want to remove a specific type, omitting the item argument clears the ENTIRE inventory.
Notes
When maxCount is 0 the command succeeds if the player has the item but removes nothing. This is useful for testing in conditional command blocks.
Related Commands
If /clear is part of your toolkit, the commands below are the ones you will most often reach for alongside it: /give, /item, and /replaceitem. They cover closely related tasks, so the links above jump straight to each one.
Frequently Asked Questions about /clear
What does the /clear command do in Minecraft?
Removes items from a player's inventory. Can target specific items and limit how many are removed. It belongs to the player command group and was added in Java Edition 1.0.
What is the correct syntax for /clear?
/clear [
What permission level does /clear need?
It requires permission Level 2 - Game Master / Cheats. On a server the player must be an operator at that level, or have cheats enabled in single-player.
What is a common mistake when using /clear?
Forgetting that maxCount 0 tests for the item but does not remove it, useful for detection but surprising if you expected deletion.
Can you give an example of /clear in use?
Yes. /clear @a minecraft:dirt — removes all dirt blocks from every player's inventory.
Need a Minecraft server?
Try these commands on Astroworld or host your own server.
Try Astroworld Hosting