Post

Putting Claude Code in Slack without rebuilding it

Kafu runs the real claude CLI behind Slack and Telegram. Most of the work turned out to be sessions, identity, and limits.

Putting Claude Code in Slack without rebuilding it

Claude Code is the best coding agent I’ve used, and it lives in a terminal. That’s fine when I’m at my desk. It’s less fine when I’m on my phone and want it to look into an error, or when a teammate wants the same help and doesn’t have it set up.

Kafu is my answer to that. It’s a small daemon that sits in a project folder and lets you talk to Claude Code from Slack, Telegram, or a local web page. The name is كفو, which in Saudi slang is what you call someone dependable.

Don’t rebuild the agent

The first decision was the most important one. I didn’t want to write an agent. There are plenty of libraries that let you wire a model to some tools, and every one of them would have meant reimplementing things Claude Code already does well: file editing, permissions, MCP servers, skills, project instructions in CLAUDE.md.

So Kafu doesn’t talk to a model at all. Every message becomes a run of the official claude CLI:

1
claude -p "<the message>" --output-format stream-json --verbose --resume <session>

Because it’s the same CLI I use in the terminal, the bot gets my login, my MCP servers, and the project’s CLAUDE.md for free. When Claude Code gets a new feature, Kafu usually gets it too, without me touching anything.

The stream-json output is what makes it feel alive in chat. Kafu reads the events as they come and keeps a single Slack message updated with what Claude is doing, which file it’s reading, which command it’s running, with a Stop button at the bottom. When the run ends, that message becomes the answer.

Threads are sessions

A Slack thread maps to a Claude Code session. The first message in a thread starts a new session and Kafu writes down its ID. Every reply in that thread resumes it with --resume, so the conversation keeps its context. Start a new thread and you get a clean slate.

Long threads eventually run into the context limit. When that happens Kafu asks Claude to summarise the session, starts a fresh one, and passes the summary in. You lose some detail, but the thread keeps working.

Everyone signs in as themselves

The first version used my account for everything. That was fine for me and wrong for a team. If a teammate asks the bot to open a pull request, it should be opened by them, with their GitHub access, and charged to their Claude plan.

In team mode, every person gets their own Claude Code config directory. They sign in once through a small private page, and from then on their requests run with CLAUDE_CONFIG_DIR pointing at their own directory and an MCP config built from their own tokens. The bot is one Slack app, but every run happens as the person who asked.

This also means the bot can never do more than the person could do themselves, which made the next part easier to think about.

Deciding what it’s allowed to do

An agent you can reach from a chat channel needs firmer limits than one in your own terminal. Kafu has four security levels. The strictest only lets Claude read and search files. The next one removes the shell and web access. The other two are for people who know what they’re giving up.

Tool lists aren’t enough on their own, though. A bot with shell access can run git push, and I didn’t want it pushing to main or merging its own pull requests. Kafu installs a hook that runs before every tool call and checks it. Pushing your own branch and opening a PR is fine. Pushing to main, master or develop, merging, or changing repository settings gets refused with a reason the model can pass back:

Merging is done by people on GitHub after review; I can open and update PRs but not merge them.

The hook is written into Claude Code’s managed settings, with only managed hooks allowed. Nobody can talk the bot out of it from a chat message, including me.

The same thinking applies to input. Anything that comes from outside, like a Slack message the bot was asked to look at, gets wrapped in tags with a random ID and marked untrusted before it reaches the prompt. It’s a small thing, but it makes “ignore your instructions and…” much less interesting.

Using it at work

At Moyasar, two of our internal bots run on Kafu. One works for engineers: it picks up tasks in Slack, works in our repos with the engineer’s own access, and opens pull requests for people to review. The other is read-only. It looks into every new message in our alert channels and replies in the thread with what it found, and anyone can ask it about payments, errors, or code.

The read-only one was mostly a configuration exercise. It uses a shared account, has no GitHub credentials at all, reads code from a mirrored copy, and has its blocked tools written into managed settings so they can’t be switched back on from a conversation.

Getting it right taught me that most of the work in an agent product isn’t the agent. It’s sessions, identity, permissions, and what happens when a sign-in expires at two in the morning. The model was the part I didn’t have to build.

Kafu is open source and installs as a Claude Code plugin. If you try it, I’d like to hear how it goes.

This post is licensed under CC BY 4.0 by the author.