An autonomous ticket loop built from plain Claude Code primitives — no agent framework, no orchestrator service, nothing to host. A Claude Code session works your Linear board: it takes approved tickets, asks clarifying questions in a Telegram group, implements each ticket in an isolated git worktree, and opens one reviewable PR per ticket — then babysits that PR like an employee would: addresses your review comments and failing CI, heals merge conflicts, closes the ticket when the PR merges, and reports in with a once-a-day digest. Anyone on the team — including non-engineers — reports bugs and features by typing (or dropping a screenshot) in the group.
The entire system is this folder:
| File | What it is |
|---|---|
SKILL.md |
The orchestrator — a Claude Code skill. The whole agent’s behavior, including its security guardrails, lives here in plain English. |
telegram.py |
The Telegram bridge — Python stdlib only. send / send-photo / send-document / poll / discover subcommands wrapping sendMessage, sendPhoto, sendDocument, and long-polled getUpdates. Inbound photos are downloaded locally so the agent can look at bug screenshots. |
loop-lock.sh |
A shared singleton lock so a scheduled pass and an interactive /loop session never run at once (no double-drained Telegram offset, no double-builds). |
cron-run.sh / run-pass.sh / install-cron.sh |
Optional always-on: one headless pass under the lock. cron-run.sh is the config-driven runner (laptop launchd or container); run-pass.sh is the in-container entrypoint; install-cron.sh is the macOS launchd installer (adapt for Linux cron/systemd). |
docker/ |
The containerized deployment — Dockerfile, loop-mcp.json, systemd unit templates, and a runbook (docker/README.md). |
env.example |
The two env vars the bridge needs, plus the optional runner env. |
/loop; a single
pass works in any session.claude mcp add). Linear is the state store — swap-able for
another tracker by editing SKILL.md, the loop only needs labels + comments.gh CLI, authenticated — the agent opens PRs
with it.python3 — any version; the bridge is stdlib-only, nothing to pip-install.dev in the skill text; adjust if
your trunk is main)..claude/skills/ticket-loop/./newbot
→ copy the token./setprivacy → Disable,
then remove + re-add the bot to the group). Without this the bot cannot see
plain group messages — they vanish silently.python3 .claude/skills/ticket-loop/telegram.py discover → grab the chat id.env.example values into your repo-root .env
(or export them). Add .agent-loop/ to .gitignore (poll offset + downloaded
media live there).agent (approved to build), agent-blocked
(waiting on an answer), manual (humans only — the agent refuses these).TEAM-123 key
matches./ticket-loop --dry-run, then go live with
/loop /ticket-loop in a dedicated worktree session.Beyond /loop in a live session, this folder ships a macOS launchd variant so
the loop runs headless on a schedule even when no session is open:
loop-lock.sh — the singleton lock both the scheduled pass and any interactive
/loop honour, so they never overlap.cron-run.sh — runs one headless pass under the lock. It uses
--dangerously-skip-permissions (there’s no human to approve tool calls when
unattended); it’s bounded by the SKILL’s own guardrails and worktree-isolated
build subagents. Understand that trade-off before enabling it.install-cron.sh — TICKET_LOOP_WORKTREE=/path/to/worktree install-cron.sh
loads a LaunchAgent that runs a pass every 30 min, 09:00–20:00 local; the daily
digest rides the first pass of each day. --refresh pulls the worktree up to
origin/dev; --uninstall removes it. On Linux, point cron or a systemd timer
at cron-run.sh instead.dev-workflow.ymlcron-run.sh reads the target repo’s dev-workflow.yml (via
dev-workflow/dw-config.py) when present, so the same runner drives any repo:
repo.base_branch (the branch it resets to and PRs target), build.model (pins
--model), schedule.tz (the digest’s “new day”), runtime.state_dir, and a
hooks.pre_pass command run before each pass. With no config file it degrades to
sane defaults (base dev, no --model, system timezone, .agent-loop). Env vars
override the config — see env.example for DW_WORK_TREE, DW_PLUGIN_DIR,
DW_SKILL_INVOCATION, DW_ENV_FILE, TICKET_LOOP_STATE_DIR, and the
TICKET_LOOP_* knobs.
For a headless host, docker/ packages the loop as a pinned image that bakes the
runner + plugin root-owned at /opt/dev-workflow and runs one pass per tick against
a mounted work-tree volume. Full runbook: docker/README.md —
build (with a required CLAUDE_CODE_VERSION pin), seed the volume, write
agent.env, and render the agent.service/agent.timer templates. Secrets stay on
the volume (never baked, never in docker inspect).
Same runner and skills as the container, minus the container. install-cron.sh grows
an external-runner mode: instead of a checkout driving its own cron-run.sh, the
LaunchAgent runs the framework’s run-pass.sh against a separate target repo —
the runner lives outside the work tree it drives (the read-only-runner property the
container gets from boundary rule 2, on bare macOS).
--opt to copy the runner + plugin root-owned
to /opt/dev-workflow so the agent’s own account can’t edit its leash (this keeps the
read-only-runner property; without it the plist points at your clone, which the agent
user could modify).Worked example (framework clone drives a separate target repo, hardened):
git clone https://github.com/singlas/dev-workflow ~/dev-workflow
mkdir -p ~/dev-workflow/.local # gitignored — secrets live with the clone, never in git
$EDITOR ~/dev-workflow/.local/agent.env && chmod 600 ~/dev-workflow/.local/agent.env
~/dev-workflow/skills/ticket-loop/install-cron.sh \
--work-tree ~/repos/your-repo --opt --mcp-keyed
--work-tree is the repo the loop builds against (must be a git checkout with a
dev-workflow.yml at its root). --env-file is the agent.env secrets file
run-pass.sh sources (mode 600; it’s warned about, never printed) — when omitted,
the installer defaults to the clone’s gitignored .local/agent.env if it exists,
as above. --mcp-keyed
wires the keyed tracker MCP so Linear needs a static LINEAR_API_KEY instead of a
browser OAuth — required on any headless box. --refresh/--uninstall work as in the
legacy mode; with no new flags the script is byte-for-byte its old in-tree self.
Day-to-day controls — drive the loop with dw-loop:
A hardened (--opt) install writes /usr/local/bin/dw-loop for you — a real command
in any shell, pinned to that install’s label (no alias needed). On a clone-mode install
(no --opt), set the alias yourself:
# ~/.zshrc — clone-mode only; --opt installs create dw-loop on PATH already.
# Set YOUR label + clone path.
alias dw-loop='TICKET_LOOP_LABEL=com.example.ticket-loop ~/dev-workflow/skills/ticket-loop/install-cron.sh'
dw-loop status # is it alive + what it did today: running pass / work-tree
# HEAD / digest sent? / scout + idle flags / open questions /
# pass counts / log tail / next tick
dw-loop run-now # trigger a pass by hand (refuses while one is running)
dw-loop run-now --force # SIGTERM the running pass (graceful — lock released), start fresh
Watch a pass live with tail -f <state-dir>/logs/ticket-loop-cron.log. Don’t run
dw-telegram poll by hand to “check messages” — polling advances the shared offset
and eats updates the loop hasn’t seen (send/send-photo/send-document are safe
anytime).
Dedicated Mac mini. For an always-on agent host:
agent.env, and ~/.claude auth, nothing of yours.claude setup-token once, then put the resulting
CLAUDE_CODE_OAUTH_TOKEN in the env file. With --mcp-keyed there’s no browser
step anywhere in the loop.caffeinate -s. A sleeping Mac fires no LaunchAgent.loop-lock.sh) is local — it can’t
arbitrate across machines. Install exactly one schedule per repo across every host
(laptop + mini included); two schedules on the same board double-drain Telegram and
double-build.ticket-loop ships inside the dev-workflow plugin (manifest at
.claude-plugin/plugin.json). Install it with claude plugin install (plugin name
dev-workflow), or point Claude Code at a checkout with --plugin-dir <path> and
invoke /dev-workflow:ticket-loop. The container runner does exactly this — it
passes --plugin-dir /opt/dev-workflow/plugin when the pinned claude supports the
flag, and falls back to a repo-local /ticket-loop (with a logged warning) when it
doesn’t.
dw-telegram)telegram.py is a public interface, not just loop plumbing — stdlib-only, so any
repo skill or script can use it to talk to the team group. Both hardened installs
expose it on PATH as dw-telegram (the --opt native install symlinks it into
/usr/local/bin; the Docker image does the same):
dw-telegram send "🚀 Released v1.2 — highlights…"
dw-telegram send-photo screenshot.png --caption "before/after"
dw-telegram send-document report.pdf --caption "weekly review"
dw-telegram discover # find the group's chat id when setting up
Auth: TELEGRAM_BOT_TOKEN + AGENT_TELEGRAM_CHAT_ID from the environment, falling
back to the current repo’s .env. Target-repo skills should call dw-telegram
(and can fall back to /opt/dev-workflow/bin/telegram.py or a framework clone when
the symlink isn’t installed) — don’t vendor a copy of the bridge into each repo;
copies drift.
| You type in Telegram | What happens |
|---|---|
bug: <what's broken> |
Linear issue created (labeled Bug, reporter credited), labeled agent, and the loop investigates it — no go/skip gate |
feature: … / ticket: … |
Same — created, labeled agent, then scoped/planned before any build |
take ABC-123 |
Green-light an existing backlog ticket into the queue |
go (reply to a 🙋 scout proposal) |
Approves a ticket the loop proposed when the queue ran empty |
Reply to a ❓ question, or ABC-123 <answer> |
Answer recorded on the ticket; it unblocks |
| A screenshot (with optional caption) | Downloaded locally; the agent reads it as evidence and attaches the context to the ticket |
stop / hold (during a build) |
The build aborts — branch kept, ticket skip-listed, reason commented |
The agent posts back: ❓ clarifying questions, 🔨 when it starts a build,
✅ with the PR link (and ✅ again when the PR merges and the ticket closes),
🔁 when it has addressed review feedback and updated a PR, ⚠️ on failures,
🔀 when it heals a conflicted PR, 🙋 proposals when the queue runs empty (it
scouts your backlog for agent-suitable tickets at most once a day rather than
pinging every pass — still approval-gated), and one morning digest: merged /
awaiting review / blocked on answers / queued (--report triggers it on demand,
e.g. from cron).
manual label fences a ticket off entirely; an older backlog ticket the loop
wants to pick up is still take-approval-gated.main. Agent PRs are
marked [agent] in the title..agent-loop/state.json — the Telegram poll offset and the last-digest date
(plus a last-batch.json crash-recovery copy of the most recent poll).getUpdates retains messages ~24h. A loop that’s off overnight is fine;
off for a weekend loses messages sent in the gap.go).ABC-123 <answer> prefix convention is the workhorse; reply-matching is the
bonus.From the team at Niptao — the write-up with the full story is on our blog.