Husk
GitHub

Guides

Chat transcript to Discord bot

A conversation you already had, distilled into a husk.yaml, served by husk serve, and answering in your Discord channel.

What you will build: a Discord bot that answers in your channel, backed by a husk.yaml distilled from a real conversation you already had.

What you will learn: how husk import and husk distill turn a chat into a spec, how the control plane runs it, and how its discord trigger connects it to your server.

Prerequisites

  • Husk installed (npm install -g @husk-ai/cli) and husk doctor showing a reachable model.
  • A transcript worth distilling — a Claude Code or Codex session, a ChatGPT export, a Cursor chat, or a markdown file.
  • A Discord server you can add a bot to.

Step 1: Find a transcript

husk import

With no path, Husk searches the places chat apps keep their history and lists what it found. When it finds nothing, it says where it looked:

husk looked in:
  ~/.claude/projects   Claude Code sessions
  ~/.codex/sessions    Codex sessions
  ~/Downloads          ChatGPT exports, and ~/Documents
  ~/.gemini/tmp        Gemini CLI chats
  Cursor's state.vscdb Cursor chat history
  ./                   markdown and jsonl

Pick one by number, or skip the picker:

husk import --pick 1
husk import ./support-chat.md --source markdown
husk import

Every transcript in the file is written to ~/.husk/transcripts/<id>.json.

Step 2: Distill it

husk distill tr_01hxyzabcd --no-model --out support-bot.yaml

--no-model forces the heuristic path: free, deterministic, offline, and it needs no API key. It mines standing instructions by how often they recur, pulls durable facts out of long user turns, samples clean question-and-answer pairs as examples, and reads the tool list off what actually got called.

Drop --no-model to have a model do the extraction instead. It reads the whole transcript in overlapping windows, extracts a candidate agent from each, and merges them. It is better at persona and worse at nothing, and it costs a few cents.

husk distill

The confidence bar is not decoration. On the heuristic path it is capped at 0.75 by construction, and below 0.5 Husk warns you outright:

warning low confidence — 12 user turns is thin signal. Read the persona before serving
        this, and consider distilling a longer conversation.

Step 3: Read the file, then fix it

Distillation is a draft, not an oracle. The file says so in its own header:

support-bot.yaml (as generated, abridged)
# Distilled by husk from tr_01hxyzabcd (claude-code).
# 214 messages · confidence 0.58 · heuristic
# Review the persona before you serve this. Distillation is a draft, not an oracle.
 
apiVersion: husk/v1
name: users-me-support
displayName: users-me-support
description: Support triage for the billing API
model: auto
persona: |-
  You are an assistant distilled from a real working session about support triage.
 
  How you work:
  - Check the customer's plan before quoting a limit
  - Never promise a refund; escalate to #billing instead
tools:
  - files
computer:
  enabled: false
metadata:
  distilledConfidence: 0.58
  distillerNotes:
    - Heuristic distillation: no model was used. Review the persona before shipping.

Four things to fix before this goes anywhere near a channel.

The name. The distiller slugs the transcript's title, and transcript titles are usually a file path. Rename it — this is the URL segment and the CLI handle.

The model and the ceilings. A chat bot answers in one turn and should be cheap and fast. The defaults (24 steps, $0.50, 300 s) are sized for an agent with a computer.

The persona's last line. Discord is not a terminal. Tell it so.

Anything the bot needs to know. A chat trigger passes the message and nothing else, so a {{name}} placeholder in the persona is never filled in Discord. Write the product name into the file.

support-bot.yaml (edited)
apiVersion: husk/v1
name: support-bot
displayName: Support Bot
description: Answers billing questions in #support.
 
model: haiku
fallbackModels: [flash]
temperature: 0.3
 
persona: |-
  You answer billing questions for Acme in a Discord channel.
 
  - Check the customer's plan before quoting a limit.
  - Never promise a refund; tell them to open a ticket in #billing.
  - Answer in at most three sentences. No preamble, no bullet lists.
 
tools: [files]
 
computer:
  enabled: false          # a chat bot does not need a Linux machine
 
limits:
  maxSteps: 4
  maxCostUsd: 0.02
  timeoutSec: 60
 
guardrails:
  approvalMode: readonly  # nothing this bot does should change state
  refuse:
    - issuing refunds, credits, or account changes
 
triggers:
  # Not the Discord bot — that is step 6. This mounts a plain HTTP endpoint at
  # /v1/t/support-bot, which is handy for testing without a Discord client.
  - type: http
husk validate support-bot.yaml

Step 4: Test it before Discord sees it

husk run support-bot.yaml "what's the API rate limit on the starter plan?"

Iterate on the persona here, where the feedback loop is two seconds and nobody is watching. When it answers the way you want, register it with the control plane and start serving:

husk serve &
curl -s localhost:7377/v1/husks \
  -H 'content-type: application/json' \
  --data-binary "$(jq -Rs '{yaml: .}' < support-bot.yaml)"

Confirm it runs on the server. The adapter does not call this route: inside husk serve it runs the husk in the same process, with the message as the input and nothing else. This is the same run, over HTTP:

curl -s localhost:7377/v1/husks/support-bot/run \
  -H 'content-type: application/json' \
  -d '{"input":"what is the rate limit?"}' | jq -r .text
the real response shape

trace holds every model response the run got. A run that fails also carries error.

Step 5: The Discord application

  1. discord.com/developers/applications → New Application.
  2. Bot → Reset Token → copy it. This is DISCORD_BOT_TOKEN.
  3. Still on Bot, scroll to Privileged Gateway Intents and enable MESSAGE CONTENT INTENT.
  4. OAuth2 → URL Generator: scope bot, permissions Send Messages, Read Message History, View Channels. Open the generated URL and add the bot to your server.

Get the channel id you want it to answer in: enable Settings → Advanced → Developer Mode in Discord, then right-click the channel → Copy Channel ID.

Step 6: Turn on the trigger

Add a discord trigger to the husk:

support-bot.yaml
triggers:
  - type: discord
    channels: ['1234567890123456789']   # the channel id from step 5
    mentionOnly: true

Then start the control plane with the token in its environment:

export DISCORD_BOT_TOKEN='…'
husk serve
curl -s localhost:7377/v1/triggers -H "authorization: Bearer $HUSK_TOKEN" | jq '.triggers'

The discord entry should read DISCORD_BOT_TOKEN is set. If it reads idle -- DISCORD_BOT_TOKEN is not set, the variable did not reach the husk serve process. Mention the bot in that channel and it answers.

What the adapter does for you

All of this is behaviour you would otherwise have to write:

Gateway lifecycleJittered first heartbeat, ack tracking, RESUME with the right sequence, exponential backoff from 1 s to 60 s
Fatal closes4004, 4010–4014 are never retried. Reconnecting on a bad token just burns the rate limit
IdempotencyA gateway that redelivers on reconnect does not run the agent twice
Rate limitingPer user, 5 messages a minute by default. Over it, the bot replies Rate limited. Try again in 42s.
FilteringSkips bots, skips itself, answers only in the channels you list, and with mentionOnly only mentions and replies to its own messages
Mention strippingThe bot's own <@id> is removed before the text reaches the agent
Typing indicatorKept alive for the whole run, stopped when the answer lands
ChunkingAnswers are split at Discord's 2,000-character limit
Discord's own 429Honoured: it waits retry_after and sends once more

A missing DISCORD_BOT_TOKEN is a one-line note, not a crash:

info  discord adapter idle -- DISCORD_BOT_TOKEN is not set

Keeping it up

The bot runs inside husk serve, so keeping husk serve up keeps the bot up. Use the unit from Self-hosting and put DISCORD_BOT_TOKEN in its EnvironmentFile.

Slack and Telegram

The same shape: a trigger in the husk and a token in the server's environment. A slack trigger needs channels, as discord does, and a telegram trigger an allowlist of usernames, user ids or chat ids (any case, @ optional). Without one the trigger is not started, since it would answer anyone, and GET /v1/triggers says what to set.

TriggerToken variableTransport
discordDISCORD_BOT_TOKENGateway WebSocket
slackSLACK_BOT_TOKEN, plus SLACK_APP_TOKENSocket Mode
slackSLACK_BOT_TOKEN, plus SLACK_SIGNING_SECRETEvents API at POST /v1/a/<husk>/slack/events
telegramTELEGRAM_BOT_TOKENLong polling

Socket Mode and long polling are outbound only, so they work from a laptop. The Events API needs Slack to reach husk serve over HTTPS. With both Slack secrets set, the Events API is used and Socket Mode never connects. GET /v1/triggers says which one Slack listens on, or that it is idle for want of either.

Troubleshooting

The bot is online and ignores everything. MESSAGE CONTENT INTENT is off, so every content is empty and shouldHandle returns empty content. Turn it on in the portal, then restart the bot.

It ignores messages in the channel. mentionOnly defaults to true. Mention the bot, reply to one of its messages, or set mentionOnly: false.

It does not answer DMs. A DM has a channel of its own, and the bot answers only in the channels you list.

It never starts. A discord trigger needs channels. With none, it would answer anywhere the bot can see, so husk serve does not start it, and GET /v1/triggers reads not started -- set channels (channel ids).

Something went wrong: … is the adapter relaying an error the run threw, such as no husk named support-bot after the husk was deleted. The adapter runs the husk inside husk serve, so no network or token stands between them. A run that fails without writing anything answers (the agent produced no text); its error is in GET /v1/runs?husk=support-bot.

Answers are truncated at three sentences and you did not ask for that. You did — it is in the persona. Discord bots are better short, but the file is where the decision lives.

Next

  • Triggers — what the server does mount, and how.
  • The distiller — what it extracts and how it decides.
  • Self-hosting — putting husk serve, and the bot with it, on a box you own.