Skip to content

AST Syntax & Data

Complete AST syntax reference covering prefixes, variable storage, chat arguments, escaping, arrays, operators, conditionals, loops, deletes, command references, and timers.

Use this page as your syntax lookup when writing AST commands. If you’re just getting started with AST, read the AST overview first.

The parser only evaluates chunks that begin with an AST prefix. Everything outside a prefix is sent to chat verbatim, including quotation marks, punctuation, and emoticons.

Terminal window
Hi $(user)! Welcome to "the stream" :)
→ Hi Carlos! Welcome to "the stream" :)

Once you enter a prefix, different parsing rules kick in:

  • Each prefix stays open until its matching closing ).
  • Double quotes, ${ } interpolation, and %[ ] literal arrays only work inside a prefix.

The AST parser recognizes 6 prefixes:

PrefixSyntaxPurposeExample
$( $(funcName arg1 arg2)Call a function$(random 10) (a number from 0 to 9)
%( %(name) or %(name value)Read or write a variable%(wins), %(wins 5)
%del( %del(name)Delete a variable or a list entry%del(wins)
*( *(condition ? yes : no)Run math, logic, or a loop*(5 > 3 ? "yes" : "no")
^( ^(name)Check if a variable or slot exists^(#wins)
#( #(commandName args...)Trigger another command#(othercmd arg1)

Variables only exist once you create them, and the prefix in front of a variable’s name controls where it’s stored and how long it survives.

PrefixStorageHow long it lastsPlanExample
noneMemoryOnly for the current command runFree%(temp)
#Cache24 hours after the last writeFree%(#wins)
##Cache, per viewer24 hours after the last writeFree%(##chips)
*DatabasePermanentPremium / Pro%(*wins)
**Database, per viewerPermanentPremium / Pro%(**rank)

Storage eligibility follows the streamer’s plan, not the viewer’s.

  1. Writing to a # or ## variable resets its 24-hour clock. Simply reading it does not refresh the timer.
  2. Reading an expired or never-set variable returns blank, not 0.
  3. Writing always overwrites the existing value: %(#wins 1) sets the value to 1 instead of adding 1.
  4. On Free, writes to * and ** variables are silently ignored with no error message.
Terminal window
%(#wins 1)

The snippet above sets the value to 1—it does not increment it by 1.

Terminal window
%(#wins *(%(#wins) + 1))

## and ** variables store a separate value for each viewer. Without a selector, they target whoever ran the command. To read or write another viewer’s value, pass their login in parentheses right after the variable name (an optional leading @ is accepted).

Terminal window
%(##rank)
%(##rank(&p1))
%(**rank)
%(**rank(&p1))

Words typed by a viewer after the command name are exposed through placeholders, starting at word 1 right after the command.

PlaceholderMeaningExample
&p1, &p2, &p3…Word number 1, 2, 3…&p1 = first word
&tEverything after the highest numbered word&t = the rest of the message
  • Any missing word resolves to blank text.
  • &t captures everything following the highest &pN used earlier in the template.
  • Reusing an already-used &pN after &t is allowed, but introducing a new &pN after &t fails with [Parser error: cannot create new &pN after &t].
  • Viewer input in chat commands is always treated as plain text and can never execute AST code.
Terminal window
Command: !greet Hello World
Message: Hello &p1 and &p2!
→ Hello Hello and World!
Terminal window
Command: !echo lots of args here
Message: &p1 &p2 &t
→ lots of args here
Terminal window
Message: &t &p1
→ [Parser error: cannot create new &pN after &t]

Inside any prefix, double quotes group text into a single string argument. Wrap expressions in ${ } to interpolate values inside quoted text.

Terminal window
%(greeting "Hello ${$(user)}!")%(greeting)
→ Hello Carlos!

Any valid AST expression works inside ${ }, such as ${%(#wins)}. To put a literal double quote inside a quoted string, escape it as \".

When you need special characters treated as ordinary text inside a prefix, you have three options:

  1. Balanced pairs work. Any ( matched with a ) inside a prefix stays literal text.

    Terminal window
    $(upper score (5-3))
    → SCORE ( 5 - 3 )
  2. Quotes protect text. Everything wrapped in double quotes is preserved as text, even unbalanced symbols.

    Terminal window
    $(upper "quoted :) here")
    → QUOTED :) HERE
  3. A backslash protects one character. Escape individual characters with \( \) \[ \] \{ \} \; \? \: and \\.

    Terminal window
    $(upper hello \:\))
    → HELLO :)
    %(mood \:\)) %(mood)
    → :)

To print an AST prefix literally without triggering evaluation, put a backslash before its $, %, *, #, or ^—for example, \$(user) prints $(user) and 100\% prints 100%.

Lists let a variable hold multiple items that you can read, update, remove, and count.

Terminal window
%(items[] extra)
%(items)
→ ["extra"]

Reading the whole list prints it as JSON, such as ["a","b"].

Literal lists let you write items inline inside a prefix. Assign them with [] to append their items to a list variable—a plain assignment without [] stores the items as one comma-separated string rather than a list.

Terminal window
%(colors[] %[red, green, blue]) %(colors)
→ ["red","green","blue"]
%(pick %[1, 2, 3][random]) %(pick)
→ 2 (a random 1, 2, or 3)
SyntaxMeaningExample
%(arr[0])Item at an index, starting from 0%(items[0])
%(arr[-1])Item counted backward from the end%(items[-1]) = last item
%(arr[random])Random item from the list%(items[random])
%(arr[].length)Total number of items%(items[].length)
%(arr[] value)Append a new item to the end%(items[] extra)
%(arr[2] value)Overwrite the item at a specific index%(items[2] updated)
%del(arr[1])Delete the item at a specific index%del(items[1])
%del(arr[])Empty the entire list%del(items[])

Reading an out-of-range index returns blank, and trying to overwrite an index that doesn’t exist does nothing.

Terminal window
%(items[0])
%(items[random])
%(items[].length)
%(items[] extra)
%(items[1] replacement)
%(pick %[1, 2, 3][random]) %(pick)

When both sides are numbers, they compare numerically; otherwise they compare as text. Every comparison evaluates to true or false.

OperatorMeaningExample
== or =Equal (text comparison ignores case)%(wins) == 5
!= or <>Not equal (text comparison ignores case)%(status) != "offline"
>Greater than%(level) > 3
<Less than%(age) < 18
>=Greater than or equal%(wins) >= 10
<=Less than or equal%(wins) <= 5
~=Contains substring, ignoring case%(tags) ~= "gaming"
OperatorMeaningExample
+Add*(%(#wins) + 1)
-Subtract*(%(#wins) - 1)
*Multiply*(%(x) * 2)
/Divide*(%(total) / 2)
%Remainder*(%(count) % 10)
  • Dividing or taking a remainder by 0 evaluates to 0 instead of throwing an error.
  • Math operators read any leading number from text (so 5abc counts as 5, while text with no leading number counts as 0). Comparisons require the entire value to be numeric.
  • Numeric results are rounded to 6 decimal places.
OperatorMeaning
+Unary plus
-Negation

These operators work exclusively on loop variables such as #i. See Loops.

OperatorMeaning
=Assign
++Increment by 1
--Decrement by 1
+=Add and assign
-=Subtract and assign
*=Multiply and assign
/=Divide and assign
%=Remainder and assign

Use a ternary inside *(...) to pick between two outcomes:

Terminal window
*(condition ? trueValue : falseValue)
*(%(#wins) > 10 ? "Champion" : "Keep trying")
*(%(islive) == 1 ? "Stream is live!" : "Stream is offline")

A condition evaluates as false if its value is empty, 0, or false. Everything else counts as true.

Reference a loop variable directly without %( ), such as #i. Writing %(#i) looks up a cache variable named i instead of the loop counter.

Terminal window
*(for #i = 0; #i < 3; #i++ { %(out[] #i) }) %(out[])
→ ["0","1","2"]
Terminal window
%(items[] a) %(items[] b) *(for #item in %(items[]) { %(result[] #item) }) %(result[])
→ ["a","b"]

Foreach loops also accept literal lists directly: *(for #c in %[red, green] { ... }).

FunctionPurpose
$(break)Stop the loop immediately
$(continue)Skip the rest of the current pass and move to the next
Terminal window
*(for #i = 0; #i < 4; #i++ { *(#i == 2 ? $(continue) : "") %(o[] #i) }) %(o[])
→ ["0","1","3"]
PlanLoops nested inside each otherPasses per loop
Free225
Premium350
Pro4100

Any loop nested deeper than your plan’s limit is skipped, and loops stop once they hit their pass cap.

Terminal window
%(count 3) *(for #i = 0; #i < %(count); #i++ { %(output[] #i) }) %(output[])
→ ["0","1","2"]

%del(...) removes a variable or clears part of a list without outputting text.

Terminal window
%(list[] a) %(list[] b) %(list[] c) %del(list[1]) %(list[])
→ ["a","c"]
%del(wins)

%del(name) deletes the variable along with any list stored in it, %del(name[0]) removes a single index, and %del(name[]) clears every entry in the list. Per-viewer variables support selectors here as well: %del(##rank(&p1)).

Check whether a variable or list entry exists with ^(), which returns true or false.

Terminal window
^(#wins)
^(#items[0])
^(##balance)

Trigger another custom command from inside your reply with #(...):

Terminal window
#(othercmd arg1 arg2)

Any words after the command name are passed along as its arguments. The reference itself outputs nothing in the outer message.

  • Command references can nest up to 5 levels deep.
  • A command cannot appear twice in the same call chain, blocking infinite loops.
  • One message can trigger up to 50 total references across all levels.
  • The outer message posts first. Sibling references then execute in written order, with each reference’s nested calls finishing before moving to the next sibling.
  • Every referenced command posts its own chat message, and its output is not re-parsed as AST.
  • If a referenced command can’t run—for instance, because it’s disabled or on cooldown—it is simply skipped.

$(timer seconds message_and_actions) schedules its body to run after a delay. The command itself finishes immediately, and the scheduled body runs once the timer fires.

Terminal window
$(timer 300 "Five minutes are up!" $(trigger.send airhorn))
  • Delays must fall between 1 and 604800 seconds (seven days).
  • Scheduled timers are only available in Twitch channels.
  • Every call creates an independent timer that runs at most once.
  • Saved timers survive bot restarts. If the bot is offline when a timer is due, it still runs as long as it is within a 10-minute grace period; at or past 10 minutes late, it expires. A crash right after a timer is claimed can lose the action, so execution is not guaranteed.
  • Timers can schedule other timers up to five levels deep.
  • Each channel can hold up to 100 pending timers at once. Scheduling can also fail at the shared 10,000-timer cap, if the saved job exceeds 64 KiB, or if cache storage fails, returning timer: could not schedule timer.

Timer errors print inline starting with timer:, such as timer: seconds must be between 1 and 604800.

Docs assistant

Ask in your own words. Answers come from these docs, with links to the right page.

Try asking

Current page: AST Syntax & Data

AI can make mistakes. Check the linked page.