iTranslated by AI
The Fastest Way to Connect Slack and Codex CLI: Building an AI Slack Bot with Bolt
I created a lightweight Slack bot using an AI Agent as a personal project. Since I already built it, I've decided to share it as is. Using Bolt and the Codex CLI, it was surprisingly easy to get an AI bot running on Slack.
This article is both a personal memo and a summary for those who want to try the same setup. In addition to introducing the implementation, I’ve written in some detail about "how to run it" and "how to operate it."
It’s a humble work created through what you might call "vibe coding," so if you have any suggestions for improvement, please feel free to submit a PR.
What you can do
- Respond concisely to mentions

- Example of a custom slash command (this repository includes
/hangoutas a sample)

- Pass Slack context (recent conversations / channel members / threads) as needed
Architecture
What is Bolt?
Bolt is an official SDK provided by Slack that allows you to easily handle events (app_mention) and slash commands. While there is a method to receive requests via an HTTP server, this setup uses Socket Mode (described later).
What is Codex CLI?
Codex CLI is a coding agent that runs in the terminal, allowing you to call OpenAI models from your local environment. Since it provides features like WebSearch, it can also be used for research purposes.
How to Use
1) Create a Slack App
Create an app in the Slack management console and enable the following:
- Enable Socket Mode
-
Slash Commands: Define your own (e.g.,
/hangoutis provided as a sample implementation) -
Event Subscriptions:
app_mention -
Bot Token Scopes:
chat:writeconversations:readchannels:historyusers:read
Also, please obtain the SLACK_BOT_TOKEN, SLACK_APP_TOKEN, and SLACK_SIGNING_SECRET for the app.
2) Set Environment Variables
Create a .env file and set the environment variables with the tokens from the Slack app you created.
SLACK_BOT_TOKEN=...
SLACK_APP_TOKEN=...
SLACK_SIGNING_SECRET=...
OPENAI_API_KEY=...
Optional settings (if necessary):
CODEX_MODEL=gpt-5.2
CODEX_REASONING_EFFORT=low
CODEX_WEB_SEARCH=1
PLANNER_DEBUG=1
3) Start Locally
npm install
npm run dev
Upon startup, Socket Mode will be enabled, putting the app in a state where it can receive events from Slack without requiring a webhook.
4) Try It Out
Mentions
@App What does 〇〇 mean?
→ Codex responds and replies back to Slack.
Slash Command (Sample)
/hangout Shibuya 40 4 19:00
→ As a sample implementation, it returns three candidates plus message suggestions.
Key Points of Socket Mode
Why Socket Mode?
- No need for a publicly accessible HTTP endpoint
- Self-contained in the development environment
- Easy to run even within a corporate internal network
Notes
- Requires constant uptime
- Token management is crucial (Keep your App Token secure)
- Countermeasures for response delays (Codex can be slow, making it prone to timeouts)
Room for Expansion
Since Codex is available via the CLI, with some extension, it can even be linked to external tools like MCP. By creating a flow of "Slack → Codex → Additional Tools," the design can easily evolve into one that calls internal data sources or business systems, creating value that goes beyond simple chat purposes.
How to Add New Commands
Adding new slash commands is also simple. To put it simply, you just need to add three things: the "entry point," the "prompt," and the "output formatting."
-
Add the entry point
Just addapp.command("/newcmd", ...)and pass the received input to the service layer. -
Prepare the prompt
Write a short and clear description of "what you want it to return." Since ambiguity can be filled by the model's imagination, specifying the format (bullet points, JSON, single line, etc.) will make it more stable. -
Format the output for Slack
Converting Markdown to Slack format or adjusting the indentation of bullet points makes it much easier to read.
The key point is to "decide on the model's output format first." There is a subtle difference between a format that is easy for humans to read and how it looks when posted on Slack, so the trick is to handle that in the final formatting.
Codex Adjustment Points
It is important for Codex to run stably, so it is worth diving deep into the settings. Here, I have organized "which parts to touch to change the behavior."
-
Model Specification: Control the model used with
CODEX_MODEL(e.g., gpt-5.2). -
Reasoning Effort: Control speed and quality with the
CODEX_REASONING_EFFORTsetting (e.g., low / high). -
Web Search: Control whether Web search is enabled with
CODEX_WEB_SEARCH(0 or 1).
In this project, I am calling codex exec directly and specifying the model and reasoning effort via the -c flag. Tuning in the order of CLI settings → Prompt → Output formatting makes the effects easy to understand.
Personally, the most effective order was "Fixing the output format" → "Deciding on speed settings" → "Adjusting context volume."
※ There are concerns regarding the execution of arbitrary code or the theft of environment variables in the execution environment. Please configure slack-codex-bridge and Codex CLI strictly according to your environment's security requirements.
Introduction to Prompts
The core of this configuration is the prompt. Simply refining the input to look "proper" can significantly improve the quality of the response.
For example, adding just a single sentence like this makes a big difference:
You are a helpful assistant responding in a Slack channel.
Respond naturally in English. Be concise and friendly.
For instance, the prompt for the sample /hangout command is defined here, so feel free to modify it to your preferred style. In particular, if you want replies in Japanese, be sure to state that there.
Notes on Deploying to a VM (Ubuntu)
Here are the key points from when I actually ran this on Ubuntu on Google Compute Engine.
1) Installing Requirements
sudo apt update
sudo apt -y upgrade
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt -y install nodejs git build-essential
2) Repository and Environment Variables
git clone https://github.com/usuginus/slack-codex-bridge
cd slack-codex-bridge
npm install
cp .env.sample .env
Then, set the Slack App tokens and other variables in .env.
3) Build & Start
npm run build
npm start
4) Installing Codex CLI (User Space)
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.profile
source ~/.profile
npm i -g @openai/codex
5) Logging into Codex
Please authenticate using your preferred method. Any method is fine as long as codex works in the terminal.
To log in via device code, use the following command:
codex login --device-auth
This method involves entering a code in your browser for authentication, so CLI operations are minimal.
6) Persistence with systemd
sudo nano /etc/systemd/system/slack-codex-bridge.service
[Service]
Type=simple
User={your-user-name}
WorkingDirectory=/home/{your-user-name}/slack-codex-bridge
EnvironmentFile=/home/{your-user-name}/slack-codex-bridge/.env
Environment=PATH=/home/{your-user-name}/.npm-global/bin:/usr/bin:/bin
ExecStart=/usr/bin/node /home/{your-user-name}/slack-codex-bridge/dist/app/index.js
Restart=always
RestartSec=5
sudo systemctl daemon-reload
sudo systemctl enable slack-codex-bridge
sudo systemctl start slack-codex-bridge
journalctl -u slack-codex-bridge -f
Common Pitfall
If you get a codex not found error, it is likely because codex is not included in the systemd PATH. Adding the result of which codex to Environment=PATH=... should resolve the issue.
Checking after a Reboot
Even if the VM reboots, it will basically start automatically if systemd is enabled. However, checking if it's "running" is the fastest way.
systemctl status slack-codex-bridge
If it's not running, start it.
sudo systemctl start slack-codex-bridge
If startup fails, you can find the cause by checking the logs.
journalctl -u slack-codex-bridge -b
Common causes after a reboot
- PATH not working (Review
Environment=PATH=...) - Incorrect
.envpath (CheckEnvironmentFile=...) - Node path mismatch (Match
ExecStartwithwhich node)
Restarting when making changes (deployment update)
After updating the code, reflect the changes in the order of build → restart.
cd /home/{your-user-name}/slack-codex-bridge
git pull
npm install
npm run build
sudo systemctl restart slack-codex-bridge
Confirming the update:
journalctl -u slack-codex-bridge -f
If git pull is not necessary, you can just skip that step.
Summary
The combination of Bolt + Codex CLI is suitable for "those who want to run a lightweight Slack integration while keeping future expansion in mind." Since it's a lightweight setup, adding other commands should be completed quickly by delegating them to the agent... or so I hope.
Discussion