Skip to main content

/clear

Removes items from a player's inventory. Can target specific items and limit how many are removed.

Category
Player
Permission Level
Game Master
Version Added
1.0

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

NameTypeRequiredDescription
targetsentityOptionalThe player(s) whose inventory to clear. Defaults to the executing player.
itemitem_predicateOptionalThe item to remove. If omitted, all items are cleared.
maxCountintegerOptionalThe 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 @p

Clears the entire inventory of the nearest player.

/clear @a minecraft:dirt

Removes all dirt blocks from every player's inventory.

/clear @s minecraft:diamond 0

Checks 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

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.

/give/item/replaceitem

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 [] [] []. The required arguments are none, and the optional ones are targets, item, and maxCount.

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