Storage
The storage APIs can be used to store non-sensitive data that is persisted across command launches. Its methods are similar to the browser's localStorage. All commands in an extension have shared access to the stored data. Extensions can't access the storage of other extensions. Values can be managed through functions such as getLocalStorageItem, setLocalStorageItem, or removeLocalStorageItem. A typical use cases is storing user related data, for example entered todos.
The data is stored in the user's database. The API is not meant to store large amounts of data. For this, use Node's built-in APIs to write files, e.g. to the extension's support directory.

API Reference

allLocalStorageItems

Retrieve all stored values in the local storage of an extension.

Signature

1
async function allLocalStorageItems(): Promise<Values>
Copied!

Example

1
import { allLocalStorageItems } from "@raycast/api";
2
3
interface Values {
4
todo: string;
5
priority: number;
6
}
7
8
export default async () => {
9
const items: Values = await allLocalStorageItems();
10
console.log(`Local storage item count: ${Object.entries(items).length}`);
11
};
Copied!

Return

A promise that resolves with an object containing all LocalStorageValues.

clearLocalStorage

Removes all stored values of an extension.

Signature

1
async function clearLocalStorage(): Promise<void>
Copied!

Example

1
import { clearLocalStorage } from "@raycast/api";
2
3
export default async () => {
4
await clearLocalStorage();
5
};
Copied!

Return

A promise that resolves when all values were removed.

getLocalStorageItem

Retrieve the stored value for the given key.

Signature

1
async function getLocalStorageItem(key: string): Promise<Value | undefined>
Copied!

Example

1
import { getLocalStorageItem } from "@raycast/api";
2
3
export default async () => {
4
const item: string = await getLocalStorageItem("favorite-fruit");
5
console.log(item);
6
};
Copied!

Parameters

Name
Type
Required
Description
key
string
Yes
The key you want to retrieve the value of.

Return

A promise that resolves with the the stored value for the given key. If the key does not exist, undefined is returned.

removeLocalStorageItem

Removes the stored value for the given key.

Signature

1
async function removeLocalStorageItem(key: string): Promise<void>
Copied!

Example

1
import { removeLocalStorageItem } from "@raycast/api";
2
3
export default async () => {
4
await removeLocalStorageItem("favorite-fruit");
5
};
Copied!

Parameters

Name
Type
Required
Description
key
string
Yes
The key you want to remove the value of.

Return

A promise that resolves when the value was removed.

setLocalStorageItem

Stores a value for the given key.

Signature

1
async function setLocalStorageItem(key: string, value: LocalStorageValue): Promise<void>
Copied!

Example

1
import { setLocalStorageItem } from "@raycast/api";
2
3
export default async () => {
4
await setLocalStorageItem("favorite-fruit", "cherry");
5
};
Copied!

Parameters

Name
Type
Required
Description
key
string
Yes
The key you want to create or update the value of.
value
Yes
The value you want to create or update for the given key.

Return

A promise that resolves when the value was stored.

LocalStorageValues

Values of local storage items.
For type-safe values you can define your own interface. Use the keys of the local storage items as property name.

Properties

Name
Type
Required
Description
[key: string]
any
Yes
The local storage value of a given key.

LocalStorageValue

1
LocalStorageValue: string | number | boolean
Copied!
Supported storage value types.

Example

1
import { setLocalStorageItem } from "@raycast/api";
2
3
export default async () => {
4
// String
5
await setLocalStorageItem("favorite-fruit", "cherry");
6
7
// Number
8
await setLocalStorageItem("fruit-basket-count", 3);
9
10
// Boolean
11
await setLocalStorageItem("fruit-eaten-today", true);
12
};
Copied!
Last modified 1d ago