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.
A render hook that reads a state value is drawn again when the value changes.
There is no switch. A file is at most 4 MiB, and $.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 program (types-2.1.304.d.ts).
In a "Where it can be used" cell, "Run time" 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 | 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 | 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 | Lists a directory: { name, kind, size, mtime for each entry. | (path?) => Promise<Fs. A symbolic link is other with is. | Run time. |
$. | Documented | Returns whether the path exists. | (path) => Promise<boolean>. Rejects only for a network location. | Run time. |
$. | Documented | 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 | 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 | Returns the value under key, or undefined when unset. | (key) => Promise<unknown>. | Run time. |
$. | Documented | 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 | Removes key. | (key) => Promise<void>. | Run time. |
$. | Documented | Returns every key set, in insertion order. | () => Promise<string[]>. | Run time. |
$. | Documented | 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 | Writes value under ref, which must be this plugin's own. Sites that read it while drawing are drawn again, 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 | A named value with an initial value. read gives the initial value while nothing is written, so never undefined. | Type Atom. |
derive | Documented | A value computed from atoms and references, cached by their versions. | Type Derive. Example: derive([workers], list => list.. |
member | Documented | A family's member for the instance being drawn, keyed by e.. | Type Member. Example: await read($, member. |
read | Documented | 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 | 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 | $.. as is text unless the caller asked for bytes. | Input { path:. Value string | Fs. |
fs. | Documented | $. | Input { path:. Value void. |
fs. | Documented | $. | Input { path:. Value Fs. |
fs. | Documented | $. | Input { path:. Value boolean. |
fs. | Documented | $.. resolve is false unless asked. | Input { path:. Value Fs. |
fs. | Documented | $. | Input Fs. Value readonly Fs. |
store. | Documented | $. | Input { key:. Value unknown. |
store. | Documented | $. | Input { key:. Value void. |
store. | Documented | $. | Input { key:. Value void. |
store. | Documented | $. | Input No. Value string[]. |
state. | Documented | $.: the reference itself (plugin, key, and a family member's id). Pinned. | Input State. Value State. |
state. | Documented | $. 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)