Skip to content

Built-in Functions

These functions are always available without any import:

// No import needed - available everywhere
print("Hello, World!")
let apiKey = env("ANTHROPIC_API_KEY")

Print to console:

print("Hello, World!")
print(someVariable)
print({ key: "value" })
ParameterTypeDescription
messageanyValue to print

Get environment variable:

let apiKey = env("ANTHROPIC_API_KEY")
let port = env("PORT", "3000") // With default value
ParameterTypeDescription
nametextEnvironment variable name
defaultValuetext?Default if not set
ReturnstextVariable value

Access CLI arguments passed after the .vibe filename:

let all = args() // All args as text[]
let first = args(0) // Arg at index (or null)
let name = args("name") // Value of --name flag (or null)
ParameterTypeDescription
(none)Returns all args as array
indexnumberReturns arg at index (or null)
nametextReturns value of --name flag (or null)
Returnstext[] / text / nullDepends on argument

Named flags return "" (empty string) for boolean-style flags like --dry-run. Returns null when the flag is not present.

Check if a CLI flag is present:

if hasArg("verbose") {
print("Verbose mode enabled")
}
ParameterTypeDescription
nametextFlag name without dashes
ReturnsbooleanWhether flag is present

Import from "system/utils":

import { uuid, now, random, jsonParse, jsonStringify } from "system/utils"

Generate UUID v4:

let id = uuid() // "550e8400-e29b-41d4-a716-446655440000"

| Returns | text | UUID string |

Current timestamp in milliseconds:

let timestamp = now() // 1705123456789

| Returns | number | Unix timestamp (ms) |

Generate random number:

let r = random() // 0.0 to 1.0
let n = random(1, 10) // 1 to 10 (integer)
ParameterTypeDescription
minnumber?Minimum (inclusive)
maxnumber?Maximum (inclusive)
ReturnsnumberRandom number

Parse JSON string:

let data = jsonParse('{"name": "Alice"}')
ParameterTypeDescription
texttextJSON string
ReturnsjsonParsed object

Convert to JSON string:

let str = jsonStringify({ name: "Alice" })
let pretty = jsonStringify({ name: "Alice" }, true)
ParameterTypeDescription
valuejsonValue to stringify
prettyboolean?Pretty print (default: false)
ReturnstextJSON string

Import from "system/tools" for AI tool use:

import { readFile, writeFile, bash } from "system/tools"
model agent = {
tools: [readFile, writeFile, bash]
}

Read file contents:

let content = readFile("data.txt")
let lines = readFile("data.txt", 1, 10) // Lines 1-10
ParameterTypeDescription
pathtextFile path
startLinenumber?Starting line (1-indexed)
endLinenumber?Ending line
ReturnstextFile contents

Write to file:

writeFile("output.txt", "Hello, World!")
ParameterTypeDescription
pathtextFile path
contenttextContent to write
ReturnsbooleanSuccess

Append to file:

appendFile("log.txt", "New entry\n")
ParameterTypeDescription
pathtextFile path
contenttextContent to append
ReturnsbooleanSuccess

Check if file exists:

if fileExists("config.json") {
// ...
}
ParameterTypeDescription
pathtextFile path
ReturnsbooleanExists

List directory contents:

let files = listDir("./src")
ParameterTypeDescription
pathtextDirectory path
Returnstext[]File/folder names

Edit specific lines in file:

edit("file.txt", 5, 10, "new content")
ParameterTypeDescription
pathtextFile path
startLinenumberStart line (1-indexed)
endLinenumberEnd line
newTexttextReplacement text
ReturnstextUpdated content

Find files by pattern:

let tsFiles = glob("**/*.ts")
let srcFiles = glob("*.js", "./src")
ParameterTypeDescription
patterntextGlob pattern
cwdtext?Working directory
Returnstext[]Matching paths

Search file contents:

let matches = grep("TODO", "./src", true)
ParameterTypeDescription
patterntextSearch pattern
pathtextFile/directory
ignoreCaseboolean?Case insensitive
Returnsjson[]Matches with line info

Create directory:

mkdir("./output")
mkdir("./a/b/c", true) // Recursive
ParameterTypeDescription
pathtextDirectory path
recursiveboolean?Create parents
ReturnsbooleanSuccess

Check if directory exists:

if dirExists("./output") {
// ...
}
ParameterTypeDescription
pathtextDirectory path
ReturnsbooleanExists

Execute shell command:

let result = bash("npm run build")
let result = bash("ls -la", "./src")
let result = bash("slow-command", ".", 60000)
ParameterTypeDescription
commandtextShell command
cwdtext?Working directory
timeoutnumber?Timeout (ms)
Returnsjson{ stdout, stderr, exitCode }

Run code snippet:

let result = runCode("python", "print('Hello')")
let result = runCode("javascript", "console.log(1+1)")
ParameterTypeDescription
languagetextLanguage name
codetextCode to run
ReturnsjsonExecution result

Add element to array (mutates array, returns array for chaining):

let items: text[] = []
items.push("first")
items.push("second")
// Chaining
let arr = [].push(1).push(2).push(3)
ParameterTypeDescription
elementanyElement to add
ReturnsarrayThe array (for chaining)

Remove and return last element:

let items = [1, 2, 3]
let last = items.pop() // 3
// items is now [1, 2]

| Returns | any | The removed element |

Get length of array or string:

let arr = [1, 2, 3, 4, 5]
let count = arr.len() // 5
let str = "hello"
let length = str.len() // 5

| Returns | number | Length |