Skip to content
Crystal CodeDocs
ENEnglish

Plugins

Add in-process extensions under plugins/. A project directory of the same name replaces the home plugin.

Setting Effect
"enabled": false in plugin.json Leaves the directory in place and does not load it
"plugins": false in config.json Skips discovery. true is omitted from the written file

A plugin can add tools, a protocol client, approval classifiers, slash commands, hooks, raw hooks, prompt placeholders, and syntax tokenizers for assistant code fences. It can read the current session model and whether review uses its own model.

Capability What it may do
IPluginDataDirectory Receives its global and project runtime-data directories
Model clients Calls the session model, and the review model while that switch is on. Separate clients. Not written to the transcript
Hooks Append prompt and compaction text. Rewrite a user message before it is stored. Revise one outbound request without changing the stored transcript. Read one completed response. Rewrite a tool call (approval runs again). Replace a tool result. Raise approval risk
Hooks may not Lower risk, or replace Work, Plan, or Review
Raw hooks Rebuild one outbound request. Replace composed prompt and compaction text with any string. Replace an approval classification with any risk, authority, summary, and prompt requirement. Named in a note at load

A plugin can replace a built-in tool or slash verb as a whole. The replacement takes effect under the built-in’s approval classification. A plugin cannot adjust a built-in’s description or schema in place. Disabling a built-in tool is the operator’s /tools builtin and --disable-tool, not a plugin capability. MCP servers are a separate client, not a plugin. See MCP servers.

Process commands (crystal <name>) are admitted but no runner runs them yet. More hook methods will be added later. Plugin dependencies on one another are not decided. A module system below plugins is not in this build.

/plugins lists them. /plugins on|off|reload controls discovery. /plugins enable|disable|show <directory> changes one plugin. crystal plugins list|show|enable|disable does the same outside a session and prints a Spectre.Console table unless --format text is set.

Details are in Plugins.

The terminal can color tokens in assistant Markdown fences when an installed plugin provides a tokenizer for that fence’s language alias. The first word of the info string is matched without case: CS extra-info asks for the cs alias. Aliases belong to plugins; filenames and extensions do not select a language. CrystalCode ships no language tokenizer. The tokenizer examples in this repository are test samples only. See the plugin contract to provide one.

Unmatched fences and text between tokens use code on codeBg. Existing diff colors take precedence over token colors. User messages, thinking, tool and result panels, inline code, and approval previews do not use tokenizers. Highlighting changes presentation only: saved conversations, model requests, and exports keep the original text. Server, Bridge, and crystal run keep original text without requesting tokenization or adding syntax fields.

A block longer than 65,536 UTF-16 code units is left in the ordinary code style. A tokenizer that throws, exceeds 200 ms, or returns invalid ranges is disabled until /plugins reload; a host-authored note identifies its plugin. Plugin code runs in the process, and a timeout cannot forcibly stop it. A busy or unavailable tokenizer falls back to the ordinary code style. Pending requests wait 150 ms, and identical bodies share work. If the queue fills, its oldest pending request is dropped, so some fences can stay in ordinary colors until you revisit them.

Color for these tokens comes from the active theme. All three built-in themes (default, dark, and light) define the names syntax.keyword, syntax.string, syntax.number, syntax.comment, syntax.type, syntax.function, syntax.operator, and syntax.punctuation. A custom theme file in ~/.crystal/themes/<name>.json overlays the default palette:

{
"syntax": { "keyword": "#7aa2f7", "string": "#9ece6a", "comment": "#737c94" },
"fallback256": {
"syntax": { "keyword": "lightsteelblue", "string": "darkseagreen", "comment": "grey70" }
}
}

The dotted form, such as "syntax.keyword": "lightsteelblue", works too. Unset names keep the default palette’s value. fallback256 replaces the corresponding colors when the terminal does not report 24-bit color. Token ranges do not depend on the theme, so switching themes reuses them.