Files, Store, and State
$.fs reads and writes files as the Claude Code process.
$.store keeps values of the plugin between sessions.
$.state holds named values with versions during a session.
When a state value changes, the engine draws again each render hook that reads it.
There is no switch. A file is at most 4 MiB. $.store holds at most 4 MiB of JSON. $.fs uses the real file system. $.store and $.state belong to the plugin.
Official pages: Draw in the Interface, Mods Reference. Source: the Mod API type file of the 2.1.312 program (schemas/claude-code.d.ts).
"Run time" appears in a "Where it can be used" cell. It means in a hook, in a closure that a hook drew, or in a timer callback. It does not mean inside register.
Example
on("turn.complete", async ($, e, next) => {
const count = Number((await $.store.get("count")) ?? 0) + 1;
await $.store.set("count", count);
return next(e);
});
Members
| Item | Status | What it does | How it works | Where it can be used |
|---|---|---|---|---|
$. | Documented: An official docs page names this item. | Reads a file and returns its text. With { as: it returns the bytes as { base64 }. | Three call forms. Rejects when the file is missing or over 4 MiB. options. is "text" (default) or "bytes". | Run time. |
$. | Documented: An official docs page names this item. | Writes text to a file, creating it and its directories as needed. | (path, text) => Promise<void>. path is relative to the working directory, or absolute. text is the whole new content. | Run time. |
$. | Documented: An official docs page names this item. | Lists a directory: { name, kind, size, mtime for each entry. | (path?) => Promise<Fs. A symbolic link is other with is. | Run time. |
$. | Documented: An official docs page names this item. | Returns whether the path exists. | (path) => Promise<boolean>. Rejects only for a network location. | Run time. |
$. | Documented: An official docs page names this item. | Returns { kind, size, mtime of the path. Rejects when missing. | (path, options?) => Promise<Fs. With { resolve: it also gives real. A missing path rejects with ENOENT. | Run time. |
$. | Documented: An official docs page names this item. | Reads the named instruction files in every directory above the session's first working directory, the way the engine reads CLAUDE.md. | (request) => Promise<readonly Fs. Returns the . files on the path from the root to a file, root first. | Run time. |
$. | Documented: An official docs page names this item. | Returns the value under key, or undefined when unset. | (key) => Promise<unknown>. | Run time. |
$. | Documented: An official docs page names this item. | Sets key to value, which must be JSON data. | (key, value) => Promise<void>. Rejects a function, a cycle, or a store over 4 MiB. | Run time. |
$. | Documented: An official docs page names this item. | Removes key. | (key) => Promise<void>. | Run time. |
$. | Documented: An official docs page names this item. | Returns every key set, in insertion order. | () => Promise<string[]>. | Run time. |
$. | Documented: An official docs page names this item. | Resolves the value under ref and its version. A value never written is undefined at version 0. | (ref) => Promise<State. plugin and key must be literals in the source. Resolves { value, version }. | Run time. |
$. | Documented: An official docs page names this item. | Writes value under ref, which must be this plugin's own. The engine draws again the sites that read it while drawing, at the redraw rate. | (ref, value, options?) => Promise<State. if writes only at that version. Resolves { is. | Not while a ui. hook draws. |
State Helpers Imported from claude-code
These helpers are pure code. They run in the plugin's own environment.
| Item | Status | What it does | How it works |
|---|---|---|---|
atom | Documented: An official docs page names this item. | A named value with an initial value. read gives the initial value until code writes a value, so never undefined. | Type Atom. |
derive | Documented: An official docs page names this item. | A value computed from atoms and references, cached by their versions. | Type Derive. Example: derive([workers], list => list.. |
member | Documented: An official docs page names this item. | A family's member for the instance being drawn, keyed by e.. | Type Member. Example: await read($, member. |
read | Documented: An official docs page names this item. | Reads an atom, a derived value, or a reference through $. while a ui. hook draws. That subscribes the drawing. | Type Read. Example: await read($, count). |
update | Documented: An official docs page names this item. | Reads, applies fn, writes with if, and tries again on a miss. A handler closure calls it. | Type Update. Example: <Button key="more" on. |
Events Raised by These Calls
For each call, a hook above the caller returns next(e), { deny: reason }, or { value }.
| Item | Status | The argument | Input and value |
|---|---|---|---|
fs. | Documented: An official docs page names this item. | $.. as is text unless the caller asked for bytes. | Input { path:. Value string | Fs. |
fs. | Documented: An official docs page names this item. | $. | Input { path:. Value void. |
fs. | Documented: An official docs page names this item. | $. | Input { path:. Value Fs. |
fs. | Documented: An official docs page names this item. | $. | Input { path:. Value boolean. |
fs. | Documented: An official docs page names this item. | $.. resolve is false unless asked. | Input { path:. Value Fs. |
fs. | Documented: An official docs page names this item. | $. | Input Fs. Value readonly Fs. |
store. | Documented: An official docs page names this item. | $. | Input { key:. Value unknown. |
store. | Documented: An official docs page names this item. | $. | Input { key:. Value void. |
store. | Documented: An official docs page names this item. | $. | Input { key:. Value void. |
store. | Documented: An official docs page names this item. | $. | Input No. Value string[]. |
state. | Documented: An official docs page names this item. | $.: the reference itself (plugin, key, and a family member's id). Pinned. | Input State. Value State. |
state. | Documented: An official docs page names this item. | $. plus previous, what stood there. | Input State. Value State. Only the value's owner raises it. |
Related Pages
- Mod API Overview
- Clock, HTTP, Process, Env, and Settings
- Files, State, Clock, HTTP, Process, and Settings Types (shapes of
FsEntry,FsStat,StateRef, and more)