agentc
GitHubagentc-sh/agentc
agentc
GitHubagentc-sh/agentc
›Introduction
Get started›Concepts in 5 minutes›Build your first agent›Add your first tool›Serve and connect
Concepts›Architecture overview›The manifest›The compilation pipeline›Archetypes›The graph›Tools and capabilities›Runtime libraries›Skills›Agents and prompts›Serving and protocols›Observability
Guides›Author a manifest›Write a tool›Give your agent a filesystem›Control network egress›Connect external tools via MCP›Connect agents via A2A›Use the bash tool›Control tool access with capabilities›Write templated prompts›Manage prompts with Langfuse›Pass context from the client›Configure a model provider›Connect a CopilotKit frontend›Deploy a standalone binary›Deploy with Docker and PostgreSQL›Instrument with OpenTelemetry›Extend code generation with blocks
Reference
Manifest
Runtime
Standard library
Filesystem
›TypeScript
HTTP
›Observability

TypeScript

Every export of agentc:fs for TypeScript components.

import { readFile, writeFile } from "agentc:fs"

Dirent, Stats, and FileHandle are also installed as globals. See fs for the semantics that hold in every language.

Overview

Reading and writing files
readFilereadFileSync

Read the entire contents of a file.

writeFilewriteFileSync

Write data to a file, replacing any existing contents.

appendFileappendFileSync

Append data to a file.

copyFilecopyFileSync

Copy a file to another path.

truncatetruncateSync

Resize a file to a given length.

Directories
mkdirmkdirSync

Create a directory.

mkdtempmkdtempSync

Create a uniquely named directory from a prefix.

readdirreaddirSync

List directory entries.

rmdirrmdirSync

Remove a directory.

Removing and renaming
rmrmSync

Remove a path.

unlinkunlinkSync

Remove a file or symbolic link.

renamerenameSync

Move a path to a new location.

Metadata and permissions
statstatSync

Read metadata, following a final symbolic link.

lstatlstatSync

Read metadata without following a final symbolic link.

accessaccessSync

Check that a path is reachable with a given access mode.

chmodchmodSync

Replace permission bits on a path.

chownchownSync

Replace the owning user and group on a path.

lchownlchownSync

Replace the owning user and group on a symbolic link itself.

Symbolic links
symlinksymlinkSync

Create a symbolic link.

readlinkreadlinkSync

Read the absolute target of a symbolic link.

File descriptors
openopenSync

Open a file.

closeSync

Close a descriptor.

readSync

Read bytes from a descriptor into a buffer.

writeSync

Write bytes from a buffer to a descriptor.

fstatSync

Read metadata about an open descriptor.

ftruncateSync

Resize the file behind a descriptor.

fsyncSync

Flush the file behind a descriptor.

fdatasyncSync

Flush file data behind a descriptor.

Classes
FileHandle

An open file returned by open.

Stats

Metadata about a path.

Dirent

A directory entry returned by readdir.

Types
FileEncoding

Supported string encodings.

FileOptions

Common file options.

MkdirOptions

Directory creation options.

ReaddirOptions

Directory listing options.

RmOptions

Removal options.

RmdirOptions

Directory removal options.

ReadOptions

Low-level read options.

ReadResult

The result of a descriptor or handle read.

WriteBufferResult

The result of a buffer write.

WriteStringResult

The result of a string write.

Constants
constants

Access modes, file kinds, permission bits, open flags, and copy flags.

Reading and writing files

readFile

asyncsync
readFile(path: string, options: FileEncoding | (FileOptions & { encoding: FileEncoding })): Promise<string>
readFile(path: string, options?: FileOptions): Promise<Uint8Array>
readFileSync(path: string, options: FileEncoding | (FileOptions & { encoding: FileEncoding })): string
readFileSync(path: string, options?: FileOptions): Uint8Array

Reads the entire contents of a file.

Parameters
path
stringrequired

The path to operate on.

options
FileEncoding | FileOptions

An encoding name, or an options object.

ReturnsPromise<Uint8Array> | Promise<string> | Uint8Array | string

The file contents, decoded when an encoding was given and raw bytes otherwise.

Throws
when the path does not exist
when the path is a directory
when the mount refuses the read

writeFile

asyncsync
writeFile(path: string, data: string | Uint8Array, options?: FileEncoding | FileOptions): Promise<void>
writeFileSync(path: string, data: string | Uint8Array, options?: FileEncoding | FileOptions): void

Writes data to a file, replacing any contents it already had.

Parameters
path
stringrequired

The path to operate on.

data
string | Uint8Arrayrequired

The bytes to write, or a string to encode.

options
FileEncoding | FileOptions

An encoding name, or an options object.

ReturnsPromise<void> | void

Nothing.

Throws
when the parent directory does not exist
when the path is a directory
when the mount is read only

appendFile

asyncsync
appendFile(path: string, data: string | Uint8Array, options?: FileEncoding | FileOptions): Promise<void>
appendFileSync(path: string, data: string | Uint8Array, options?: FileEncoding | FileOptions): void

Appends data to the end of a file, creating the file when it is absent.

Parameters
path
stringrequired

The path to operate on.

data
string | Uint8Arrayrequired

The bytes to write, or a string to encode.

options
FileEncoding | FileOptions

An encoding name, or an options object.

ReturnsPromise<void> | void

Nothing.

Throws
when the parent directory does not exist
when the path is a directory
when the mount is read only

copyFile

asyncsync
copyFile(path: string, destination: string, mode?: number): Promise<void>
copyFileSync(path: string, destination: string, mode?: number): void

Copies a file to another path.

Parameters
path
stringrequired

The path to operate on.

destination
stringrequired

The destination path.

mode
number

Copy behaviour, built from the COPYFILE_* constants.

ReturnsPromise<void> | void

Nothing.

Throws
when the source does not exist
when `COPYFILE_EXCL` was given and the destination exists
when the destination mount is read only

truncate

asyncsync
truncate(path: string, len?: number): Promise<void>
truncateSync(path: string, len?: number): void

Shortens or extends a file to a given length.

Parameters
path
stringrequired

The path to operate on.

len
number

The length to truncate to. Defaults to zero.

ReturnsPromise<void> | void

Nothing.

Throws
when the path does not exist
when the path is a directory

Directories

mkdir

asyncsync
mkdir(path: string, options?: MkdirOptions): Promise<string>
mkdirSync(path: string, options?: MkdirOptions): string

Creates a directory and returns the path it created.

Parameters
path
stringrequired

The path to operate on.

options
MkdirOptions

The directory creation options.

ReturnsPromise<string> | string

The path that was created.

Throws
when the parent does not exist and `recursive` was not set
when the path already exists

mkdtemp

asyncsync
mkdtemp(prefix: string): Promise<string>
mkdtempSync(prefix: string): string

Creates a uniquely named directory from a prefix and returns the path it created.

Parameters
prefix
stringrequired

The path prefix to create beneath.

ReturnsPromise<string> | string

The path that was created.

Throws
when the parent directory does not exist
when the mount is read only

readdir

asyncsync
readdir(path: string, options: ReaddirOptions & { withFileTypes: true }): Promise<Dirent[]>
readdir(path: string, options?: ReaddirOptions): Promise<string[]>
readdirSync(path: string, options: ReaddirOptions & { withFileTypes: true }): Dirent[]
readdirSync(path: string, options?: ReaddirOptions): string[]

Lists the entries directly inside a directory, sorted by name.

Parameters
path
stringrequired

The path to operate on.

options
ReaddirOptions

Directory listing options. withFileTypes changes the result to Dirent[], and recursive walks the whole tree.

ReturnsPromise<string[] | Dirent[]> | string[] | Dirent[]

A sorted list of names, or Dirent objects when withFileTypes was set.

Throws
when the path does not exist
when the path is not a directory

rmdir

asyncsync
rmdir(path: string, options?: RmdirOptions): Promise<void>
rmdirSync(path: string, options?: RmdirOptions): void

Removes a directory.

Parameters
path
stringrequired

The path to operate on.

options
RmdirOptions

Directory removal options.

ReturnsPromise<void> | void

Nothing.

Throws
when the path does not exist
when the path is not a directory
when the directory is not empty and `recursive` was not set

Removing and renaming

rm

asyncsync
rm(path: string, options?: RmOptions): Promise<void>
rmSync(path: string, options?: RmOptions): void

Removes a file, a symbolic link, or with recursive a whole directory tree.

Parameters
path
stringrequired

The path to operate on.

options
RmOptions

Removal options. A symbolic link is removed rather than followed.

ReturnsPromise<void> | void

Nothing.

Throws
when the path does not exist and `force` was not set
when the mount refuses the removal

unlink

asyncsync
unlink(path: string): Promise<void>
unlinkSync(path: string): void

Removes a file or a symbolic link.

Parameters
path
stringrequired

The path to operate on.

ReturnsPromise<void> | void

Nothing.

Throws
when the path does not exist
when the path is a directory

rename

asyncsync
rename(oldPath: string, newPath: string): Promise<void>
renameSync(oldPath: string, newPath: string): void

Moves a path to a new location.

Parameters
oldPath
stringrequired

The source path.

newPath
stringrequired

The destination path.

ReturnsPromise<void> | void

Nothing.

Throws
when the source does not exist
when the two paths live on different backends

Metadata and permissions

stat

asyncsync
stat(path: string): Promise<Stats>
statSync(path: string): Stats

Reads metadata about a path, following a final symbolic link.

Parameters
path
stringrequired

The path to operate on.

ReturnsPromise<Stats> | Stats

The path metadata.

Throws
when the path does not exist

lstat

asyncsync
lstat(path: string): Promise<Stats>
lstatSync(path: string): Stats

Reads metadata about a path without following a final symbolic link.

Parameters
path
stringrequired

The path to operate on.

ReturnsPromise<Stats> | Stats

The path metadata.

Throws
when the path does not exist

access

asyncsync
access(path: string, mode?: number): Promise<void>
accessSync(path: string, mode?: number): void

Checks that a path is reachable with a given access mode.

Parameters
path
stringrequired

The path to operate on.

mode
number

The access mode to check, built from the F_OK, R_OK, W_OK, and X_OK constants. Defaults to an existence check.

ReturnsPromise<void> | void

Nothing.

Throws
when the path does not exist
when the mode is refused

chmod

asyncsync
chmod(path: string, mode: number): Promise<void>
chmodSync(path: string, mode: number): void

Replaces the permission bits on a path.

Parameters
path
stringrequired

The path to operate on.

mode
numberrequired

The permission bits to set.

ReturnsPromise<void> | void

Nothing.

Throws
when the path does not exist
when the mount is read only

chown

asyncsync
chown(path: string, uid: number, gid: number): Promise<void>
chownSync(path: string, uid: number, gid: number): void

Replaces the owning user and group on a path.

Parameters
path
stringrequired

The path to operate on.

uid
numberrequired

The owning user, and the owning group.

gid
numberrequired

The owning user, and the owning group.

ReturnsPromise<void> | void

Nothing.

Throws
when the path does not exist
when the mount refuses the change

lchown

asyncsync
lchown(path: string, uid: number, gid: number): Promise<void>
lchownSync(path: string, uid: number, gid: number): void

Replaces the owning user and group on a symbolic link itself rather than on its target.

Parameters
path
stringrequired

The path to operate on.

uid
numberrequired

The owning user, and the owning group.

gid
numberrequired

The owning user, and the owning group.

ReturnsPromise<void> | void

Nothing.

Throws
when the path does not exist
when the mount refuses the change

Symbolic links

symlink

asyncsync
symlink(target: string, path: string, type?: string): Promise<void>
symlinkSync(target: string, path: string, type?: string): void

Creates a symbolic link at a path, pointing at a target.

Parameters
target
stringrequired

The target path. It is resolved against the working directory and stored absolute.

path
stringrequired

The path to operate on.

type
string

An optional link type hint.

ReturnsPromise<void> | void

Nothing.

Throws
when the link path already exists
when the mount is read only

readlink

asyncsync
readlink(path: string): Promise<string>
readlinkSync(path: string): string

Reads the absolute target of a symbolic link.

Parameters
path
stringrequired

The path to operate on.

ReturnsPromise<string> | string

The absolute target path.

Throws
when the path does not exist
when the path is not a symbolic link

File descriptors

open

asyncsync
open(path: string, flags?: string | number, mode?: number): Promise<FileHandle>
openSync(path: string, flags?: string | number, mode?: number): number

Opens a file, resolving to a FileHandle in the asynchronous form and returning a descriptor number in the synchronous form.

Parameters
path
stringrequired

The path to operate on.

flags
string | number

The open flags.

mode
number

The permission bits to set.

ReturnsPromise<FileHandle> | number

A FileHandle in the asynchronous form, or a descriptor number in the synchronous form.

Throws
when the path does not exist and `O_CREAT` was not given
when `O_EXCL` was given and the path exists

closeSync

sync only
closeSync(fd: number): void

Closes a descriptor.

Parameters
fd
numberrequired

A descriptor returned by openSync.

Returnsvoid

Nothing.

Throws
when the descriptor is invalid

readSync

sync only
readSync(fd: number, buffer: Uint8Array, offset?: number, length?: number, position?: number): number

Reads bytes from a descriptor into a buffer and returns how many were read.

Parameters
fd
numberrequired

A descriptor returned by openSync.

buffer
Uint8Arrayrequired

The buffer to fill.

offset
number

Where in the buffer to start.

length
number

How many bytes to transfer.

position
number

Where in the file to start. Defaults to the current position.

Returnsnumber

The number of bytes read.

Throws
when the descriptor is invalid

writeSync

sync only
writeSync(fd: number, buffer: Uint8Array, offset?: number, length?: number, position?: number): number

Writes bytes from a buffer to a descriptor and returns how many were written.

Parameters
fd
numberrequired

A descriptor returned by openSync.

buffer
Uint8Arrayrequired

The bytes to write, or a string to encode.

offset
number

Where in the buffer to start.

length
number

How many bytes to transfer.

position
number

Where in the file to start. Defaults to the current position.

Returnsnumber

The number of bytes written.

Throws
when the descriptor is invalid

fstatSync

sync only
fstatSync(fd: number): Stats

Reads metadata about an open descriptor.

Parameters
fd
numberrequired

A descriptor returned by openSync.

ReturnsStats

The descriptor metadata.

Throws
when the descriptor is invalid

ftruncateSync

sync only
ftruncateSync(fd: number, len?: number): void

Shortens or extends the file behind a descriptor.

Parameters
fd
numberrequired

A descriptor returned by openSync.

len
number

The length to truncate to. Defaults to zero.

Returnsvoid

Nothing.

Throws
when the descriptor is invalid

fsyncSync

sync only
fsyncSync(fd: number): void

Flushes the file behind a descriptor, both its data and its metadata.

Parameters
fd
numberrequired

A descriptor returned by openSync.

Returnsvoid

Nothing.

Throws
when the descriptor is invalid

fdatasyncSync

sync only
fdatasyncSync(fd: number): void

Flushes the data behind a descriptor, without its metadata.

Parameters
fd
numberrequired

A descriptor returned by openSync.

Returnsvoid

Nothing.

Throws
when the descriptor is invalid

Classes

FileHandle

not constructible

An open file, returned by open.

Properties
fd
numberread-only

The descriptor number behind this handle.

close

close(): Promise<void>

Closes this file handle.

ReturnsPromise<void>

Nothing.

stat

stat(): Promise<Stats>

Reads metadata about this file handle.

ReturnsPromise<Stats>

The file metadata.

chmod

chmod(mode: number): Promise<void>

Replaces the permission bits on this file.

Parameters
mode
numberrequired

The permission bits to set.

ReturnsPromise<void>

Nothing.

chown

chown(uid: number, gid: number): Promise<void>

Replaces the owning user and group on this file.

Parameters
uid
numberrequired

The owning user, and the owning group.

gid
numberrequired

The owning user, and the owning group.

ReturnsPromise<void>

Nothing.

truncate

truncate(len?: number): Promise<void>

Shortens or extends this file to a given length.

Parameters
len
number

The length to truncate to. Defaults to zero.

ReturnsPromise<void>

Nothing.

sync

sync(): Promise<void>

Flushes this file's data and metadata.

ReturnsPromise<void>

Nothing.

datasync

datasync(): Promise<void>

Flushes this file's data without its metadata.

ReturnsPromise<void>

Nothing.

readFile

readFile(options?: FileEncoding | FileOptions): Promise<string | Uint8Array>

Reads the entire contents of this file handle.

Parameters
options
FileEncoding | FileOptions

An encoding name, or an options object.

ReturnsPromise<string | Uint8Array>

The file contents, decoded when an encoding was given and raw bytes otherwise.

writeFile

writeFile(data: string | Uint8Array, options?: FileEncoding | FileOptions): Promise<void>

Writes data to this file handle.

Parameters
data
string | Uint8Arrayrequired

The bytes to write, or a string to encode.

options
FileEncoding | FileOptions

An encoding name, or an options object.

ReturnsPromise<void>

Nothing.

read

read(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<ReadResult>
read(options: ReadOptions): Promise<ReadResult>
read(): Promise<ReadResult>

Reads bytes from this handle.

Parameters
buffer
Uint8Array

The buffer to fill.

offset
number

Where in the buffer to start.

length
number

How many bytes to transfer.

position
number

Where in the file to start. Defaults to the current position.

options
ReadOptions

Low-level read options.

ReturnsPromise<ReadResult>

The number of bytes read and the filled buffer.

write

write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<WriteBufferResult>
write(data: string, position?: number, encoding?: FileEncoding): Promise<WriteStringResult>

Writes bytes or a string through this handle.

Parameters
buffer
Uint8Array

The bytes to write, or a string to encode.

data
string

The bytes to write, or a string to encode.

offset
number

Where in the buffer to start.

length
number

How many bytes to transfer.

position
number

Where in the file to start. Defaults to the current position.

encoding
FileEncoding

The string encoding to use.

ReturnsPromise<WriteBufferResult | WriteStringResult>

The number of bytes written and the original buffer or string.

Stats

not constructibleread-only

Metadata about a path, returned by stat, lstat, and fstatSync.

Properties
dev
numberread-only
ino
numberread-only
mode
numberread-only
nlink
numberread-only
uid
numberread-only
gid
numberread-only
rdev
numberread-only
size
numberread-only
blksize
numberread-only
blocks
numberread-only
atimeMs
numberread-only
mtimeMs
numberread-only
ctimeMs
numberread-only
birthtimeMs
numberread-only
atime
Dateread-only
mtime
Dateread-only
ctime
Dateread-only
birthtime
Dateread-only

isDir and isDirectory are the same test. isSymlink and isSymbolicLink are the same test.

isFile

isFile(): boolean

Checks whether the path is a regular file.

Returnsboolean

true when the path is a regular file.

isDir

isDir(): boolean

Checks whether the path is a directory.

Returnsboolean

true when the path is a directory.

isDirectory

isDirectory(): boolean

Checks whether the path is a directory.

Returnsboolean

true when the path is a directory.

isSymlink

isSymlink(): boolean

Checks whether the path is a symbolic link.

Returnsboolean

true when the path is a symbolic link.

isSymbolicLink

isSymbolicLink(): boolean

Checks whether the path is a symbolic link.

Returnsboolean

true when the path is a symbolic link.

isFIFO

isFIFO(): boolean

Checks whether the path is a FIFO.

Returnsboolean

true when the path is a FIFO.

isBlockDevice

isBlockDevice(): boolean

Checks whether the path is a block device.

Returnsboolean

true when the path is a block device.

isCharacterDevice

isCharacterDevice(): boolean

Checks whether the path is a character device.

Returnsboolean

true when the path is a character device.

isSocket

isSocket(): boolean

Checks whether the path is a socket.

Returnsboolean

true when the path is a socket.

Dirent

not constructibleread-only

A directory entry, returned by readdir when withFileTypes is set.

Properties
name
stringread-only
parentPath
stringread-only

isFile

isFile(): boolean

Checks whether this entry is a file.

Returnsboolean

true when this entry is a file.

isDirectory

isDirectory(): boolean

Checks whether this entry is a directory.

Returnsboolean

true when this entry is a directory.

isSymbolicLink

isSymbolicLink(): boolean

Checks whether this entry is a symbolic link.

Returnsboolean

true when this entry is a symbolic link.

isFIFO

isFIFO(): boolean

Checks whether this entry is a FIFO.

Returnsboolean

true when this entry is a FIFO.

isBlockDevice

isBlockDevice(): boolean

Checks whether this entry is a block device.

Returnsboolean

true when this entry is a block device.

isCharacterDevice

isCharacterDevice(): boolean

Checks whether this entry is a character device.

Returnsboolean

true when this entry is a character device.

isSocket

isSocket(): boolean

Checks whether this entry is a socket.

Returnsboolean

true when this entry is a socket.

Types

FileEncoding

type FileEncoding = 'utf8' | 'utf-8' | 'hex' | 'base64' | 'latin1' | 'binary' | 'ascii'

The supported string encodings.

FileOptions

Properties
encoding
FileEncodingoptional
mode
numberoptional
flag
stringoptional

MkdirOptions

Properties
recursive
booleanoptional
mode
numberoptional

ReaddirOptions

Properties
withFileTypes
booleanoptional
recursive
booleanoptional

RmOptions

Properties
recursive
booleanoptional
force
booleanoptional

RmdirOptions

Properties
recursive
booleanoptional

ReadOptions

Properties
buffer
Uint8Arrayoptional
offset
numberoptional
length
numberoptional
position
numberoptional

ReadResult

Properties
bytesRead
number
buffer
Uint8Array

WriteBufferResult

Properties
bytesWritten
number
buffer
Uint8Array

WriteStringResult

Properties
bytesWritten
number
buffer
string

Constants

constants

The exported constants object groups access modes, file kinds, permission bits, open flags, and copy flags.

GroupMembers
Access modesF_OK, R_OK, W_OK, X_OK
File kind mask and valuesS_IFMT, S_IFREG, S_IFDIR, S_IFCHR, S_IFBLK, S_IFIFO, S_IFLNK, S_IFSOCK
Permission bitsS_IRWXU, S_IRUSR, S_IWUSR, S_IXUSR, S_IRWXG, S_IRGRP, S_IWGRP, S_IXGRP, S_IRWXO, S_IROTH, S_IWOTH, S_IXOTH
Open flagsO_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_NOFOLLOW
Copy flagsCOPYFILE_EXCL, COPYFILE_FICLONE, COPYFILE_FICLONE_FORCE
← PreviousFilesystemNext →HTTP

© 2026 pogue.dev. All rights reserved.

Creative CommonsCC BY 4.0
On this pageOverviewReading and writing filesreadFilewriteFileappendFilecopyFiletruncateDirectoriesmkdirmkdtempreaddirrmdirRemoving and renamingrmunlinkrenameMetadata and permissionsstatlstataccesschmodchownlchownSymbolic linkssymlinkreadlinkFile descriptorsopencloseSyncreadSyncwriteSyncfstatSyncftruncateSyncfsyncSyncfdatasyncSyncClassesFileHandleclosestatchmodchowntruncatesyncdatasyncreadFilewriteFilereadwriteStatsisFileisDirisDirectoryisSymlinkisSymbolicLinkisFIFOisBlockDeviceisCharacterDeviceisSocketDirentisFileisDirectoryisSymbolicLinkisFIFOisBlockDeviceisCharacterDeviceisSocketTypesFileEncodingFileOptionsMkdirOptionsReaddirOptionsRmOptionsRmdirOptionsReadOptionsReadResultWriteBufferResultWriteStringResultConstantsconstants

Search docs

Search the agentc documentation