---
description: The tofu workspace delete command is used to delete a workspace.
---

# Command: workspace delete

The `tofu workspace delete` command is used to delete an existing workspace.

## Usage

Usage: `tofu workspace delete [OPTIONS] NAME [DIR]`

This command will delete the specified workspace.

To delete a workspace, it must already exist, it must not be tracking resources,
and it must not be your current workspace. If the workspace is tracking resources,
OpenTofu will not allow you to delete it unless the `-force` flag is specified.

Additionally, different [backends](../../../language/settings/backends/configuration.mdx#backend-types) may implement other
restrictions on whether a workspace is considered safe to delete without the `-force` flag, such as whether the workspace is locked.

If you delete a workspace which is tracking resources (via `-force`), then resources
may become "dangling". These are resources that physically exist but that
OpenTofu can no longer manage. This is sometimes preferred: you may want
OpenTofu to stop managing resources, so they can be managed some other way.
Most of the time, however, this is not intended and so OpenTofu protects you
from getting into this situation.

:::note
Use of variables in [module sources](../../../language/modules/sources.mdx#support-for-variable-and-local-evaluation),
[backend configuration](../../../language/settings/backends/configuration.mdx#variables-and-locals),
or [encryption block](../../../language/state/encryption.mdx#configuration)
requires [assigning values to root module variables](../../../language/values/variables.mdx#assigning-values-to-root-module-variables)
when running `tofu workspace delete`.
:::

The command-line flags are all optional. The only supported flags are:

* `-force` - Delete the workspace even if it is tracking resources. After deletion, OpenTofu can no longer track or manage the workspace's infrastructure. Defaults to false.

* `-lock=false` - Don't hold a state lock during the operation. This is
  dangerous if others might concurrently run commands against the same
  workspace.

* `-lock-timeout=DURATION` - Duration to retry a state lock. Default 0s.

* `-var 'NAME=VALUE'` - Sets a value for a single
  [input variable](../../../language/values/variables.mdx) declared in the
  root module of the configuration. Use this option multiple times to set
  more than one variable. Refer to
  [Input Variables on the Command Line](../plan.mdx#input-variables-on-the-command-line) for more information.

* `-var-file=FILENAME` - Sets values for potentially many
  [input variables](../../../language/values/variables.mdx) declared in the
  root module of the configuration, using definitions from a
  ["tfvars" file](../../../language/values/variables.mdx#variable-definitions-tfvars-files).
  Use this option multiple times to include values from more than one file.

* `-json` - Enables the [machine readable JSON UI](../../../internals/machine-readable-ui.mdx) output.

* `-json-into=out.json` - Produces the same output as -json, but redirected to a file. This allows
  for simultaneous capture of both human readable and machine readable logs.

There are several other ways to set values for input variables in the root
module, aside from the `-var` and `-var-file` options. Refer to
[Assigning Values to Root Module Variables](../../../language/values/variables.mdx#assigning-values-to-root-module-variables) for more information.

## Example

```
$ tofu workspace delete example
Deleted workspace "example".
```
