Skip to main content

Overview

The remove command deletes a key and its associated value from the vault. The operation completes silently even if the key doesn’t exist.

Syntax

vault remove <key>

Parameters

key
string
required
The key to delete from the vault.

Examples

Basic Usage

vault remove api_key

Expected Output

Removing key: key api_key from vault
The command outputs the same message regardless of whether the key existed or not.

Complete Workflow Example

# Add a key
vault add temp_data "temporary value"

# Verify it exists
vault get temp_data
# Output: temporary value

# Remove it
vault remove temp_data
# Output: Removing key: key temp_data from vault

# Verify it's gone
vault get temp_data
# Output: Key not found

# Remove it again (no error)
vault remove temp_data
# Output: Removing key: key temp_data from vault

Implementation Details

Under the Hood

The remove command executes the following SQL query (KVSTORE.cs:63-66):
DELETE FROM store
WHERE key = $key
The full implementation (KVSTORE.cs:60-71):
public int Remove(string key)
{
    using var command = connection.CreateCommand();
    command.CommandText = """
        DELETE FROM store
        WHERE key = $key
    """;
    command.Parameters.AddWithValue("$key", key);
    command.ExecuteNonQuery();
    Console.WriteLine($"Removing key: key {key} from vault");
    return 0;
}

Validation

The command validates that exactly 1 argument is provided (KVSTORE.cs:169-173):
case "remove":
    if (args.Length == 1)
    {
        return Command.REMOVE;
    }

Behavior Notes

Idempotent OperationThe remove command is idempotent - you can safely run it multiple times on the same key without error. The command does NOT check whether the key exists before attempting deletion.The same success message is displayed regardless of whether the key was found:
Removing key: key mykey from vault
If you need to verify whether a key existed before removal, use get first.
No ConfirmationThe remove command does not ask for confirmation before deleting. Once executed, the key-value pair is permanently removed from the vault.Make sure you want to delete the key before running this command!

Error Cases

Invalid ArgumentsProviding the wrong number of arguments will result in:
Please enter a valid command, could not execute

Use Cases

  • Clean up temporary or outdated credentials
  • Remove sensitive data that’s no longer needed
  • Delete test entries from the vault
  • Clear out deprecated configuration values
  • Implement data retention policies

Best Practices

  1. Verify before removing: Use vault get <key> to confirm the key exists and check its value before deletion
  2. List keys first: Run vault list to see all keys before bulk removals
  3. No undo: Remember that removed keys cannot be recovered - there’s no undo operation
  • add - Add a new key-value pair
  • get - Verify a key exists before removing it
  • list - List all keys to see what can be removed
  • update - Update a value instead of removing it

Build docs developers (and LLMs) love