Skip to main content

Slack Code out-of-the-box

Want to quickly see code channels in action in your own workspace? Copy and paste the prompt below into a coding agent such as Claude Code, Cursor, or Codex to see what Slack Code has to offer.

This prompt builds a Bolt for JavaScript app from a starter template, installs it to your developer sandbox, and runs it in your workspace. Before you begin, you'll just need a few things:

This app is scripted rather than powered by a language model, so it needs no AI provider keys.

Copying the prompt​

Start your coding agent in an empty folder, then enter this prompt:

Build and run a Slack Code app, end to end. Only stop to ask me something if you're blocked.

## Setup
1. Use the public Slack CLI. If `slack _fingerprint` doesn't print d41d8cd98f00b204e9800998ecf8427e, use ~/.slack/bin/slack instead.
2. Find my developer sandbox: run `slack sandbox list --team <team_id>` with any team ID from `slack auth list`. If it lists more than one sandbox, ask me which to use. If I'm not logged in to that sandbox, run `slack login --no-prompt`, give me the /slackauthticket command to send in the sandbox, and ask me for the challenge code. Never install to a workspace that isn't a sandbox.
3. Pass `--team <sandbox team ID>` to every Slack CLI command that targets the sandbox, including `slack run`, `slack manifest validate`, and `slack api`, so the CLI doesn't stop to ask. Run them from the project folder. Once `slack run` has installed the app, also pass `--app <app ID>` to `slack api` so it uses the bot token.
4. Create the project: `slack create slack-code-agent --template slack-samples/bolt-js-starter-template`. Remove the template's sample shortcut, slash command, view, message, and action listeners and their tests. Update the listener `index.js` files that import them, and remove the sample shortcut and slash command from manifest.json.
5. Run it in the background with `slack run --org-workspace-grant=all --team <sandbox team ID>`.

## Manifest (manifest.json)
- Name the app "Slack Code Agent" and set the bot display name to "slack-code-agent" (display names allow only lowercase letters, numbers, hyphens, underscores, and periods).
- features.code_channels: { "enabled": true }
- Socket Mode on, interactivity on, org_deploy_enabled true.
- Bot scopes: app_mentions:read, channels:history, channels:read, chat:write, code_channels:manage, commands, groups:history, groups:read
- Bot events: agent_session_stopped, app_home_opened, app_mention, message.session

## Behavior
Script everything. Don't call a language model. The demo scenario is fixing a flaky checkout test in a repo called borant/checkout.

1. When someone mentions the app outside a code channel, call agents.conversations.create with origin_channel_id, origin_message_ts, a session_id built from them, and the name "Fix the flaky checkout test". Reply in the origin thread with a link to the new channel.
2. Set up the new channel in this order:
a. agents.sessions.setStatus to processing.
b. agents.conversations.setProperties with context bar items: repo "borant/checkout" (folder icon), branch "agent/fix-flaky-checkout" (branch icon), CI "Tests failing: 1 of 24" (terminal icon).
c. Post a message with a plan block titled "Fixing the flaky checkout test" and four tasks, each with a unique task_id: "Reproduce the failure", "Find the race condition", and "Fix the test" with status complete, and "Run the suite" with status in_progress. Task statuses can be pending, in_progress, complete, or error.
d. agents.conversations.setView with type diff: a realistic unified diff that replaces a fixed sleep in tests/checkout.test.js with an await on the order-confirmed event. Set base_branch main and head_branch agent/fix-flaky-checkout.
e. agents.conversations.setView with type html, view_key "reports/test-report.html", name "Test report": a self-contained test report page with inline CSS that shows 23 passing tests and 1 failing.
f. agents.conversations.setCommands with run-tests, open-pr, and wrap-up, each with a description.
g. Post a welcome message that explains what to try, with links to the Code tab and the Test report tab.
h. agents.sessions.setStatus to active.
3. In the code channel, respond to messages without needing a mention, and to the matching slash commands:
- "run tests", "run the tests", or /run-tests: set status processing, update the test report to 24 of 24 passing, update the CI item to "Tests passing: 24 of 24", mark every plan task complete in a new plan message, then set status active.
- "open a PR" or /open-pr: add a context bar item "PR #42 is open" (hierarchy icon, linking to https://github.com/borant/checkout/pull/42) and post a short PR summary.
- "wrap up" or /wrap-up: post a summary of what changed, with an "Archive this channel" button. When it's clicked, call agents.conversations.archive with summary_message_ts set to that summary message.
- Anything else that mentions the app: reply with what you can do. Ignore other chatter.
4. On agent_session_stopped, stop posting for that channel until someone sends a new message.
5. The Home tab explains how to start the demo.

## Details to get right
- Detect a code channel by calling conversations.info and checking channel.properties.record_channel.record_type === "agent_channel". Skip app_mention events from code channels, because message.session delivers those messages too.
- The first setView on a brand-new channel can fail with view_creation_failed. Wait 2 seconds and retry once.
- Each setProperties call replaces the whole context bar. Send every item each time, five at most. Icons must be one of: branch, folder, hierarchy, life-ring, link, globe, terminal, code, search, lock.
- An html view must be a complete HTML document with no external scripts or stylesheets.
- To link to a view tab from a message, use a rich_text block with a channel element: { "type": "channel", "channel_id": <code channel ID>, "tab_id": <view_id from setView> }. For the Code tab, use the tab_id "code".
- For a code channel, call agents.sessions.setStatus with channel_id and no thread_ts.
- Reply at the top level of the code channel. Only reply in a thread when the person wrote in one.
- Ignore messages from bots and messages with a subtype.
- Agent command names have no leading slash. Socket Mode delivers them to app.command("/run-tests") and so on.
- agents.conversations.create gets the workspace from origin_channel_id, so don't pass team_id to it. It returns the new channel's ID as channel_id, and setView returns the view's ID as view_id.
- message.session events arrive as regular message events, so handle them with app.message.

## Done when
`npm run lint:fix` and `npm test` pass, with tests for the scripted behavior. `slack run` shows the app is running, and you've told me exactly what to type in Slack to start the demo.

Interacting with the app​

Once the app is running in your workspace, do the following to see code channels in action:

  1. In any channel, enter @slack-code-agent (local) fix the flaky checkout test.
  2. Slack Code Agent replies in thread with a link to a code channel.
  3. Open the code channel. You'll see the plan, context bar, and tabs for the diff and test report.
  4. Enter /run-tests. The test report and CI status update to show all tests passing.
  5. Enter /open-pr to add a pull request to the context bar.
  6. Enter /wrap-up, then click Archive this channel. Slack archives the channel and records the summary.

This app demonstrates the following API methods:

What you seeAPI method
A code channel created from your messageagents.conversations.create
The Working… status while the app worksagents.sessions.setStatus
Repo, branch, CI, and PR at the top of the channelagents.conversations.setProperties
The diff in the Code tab and the Test report tabagents.conversations.setView
The /run-tests, /open-pr, and /wrap-up commandsagents.conversations.setCommands
The archived channel and its summaryagents.conversations.archive

Next steps​

To build an agent that does more complex work in a code channel, try one of the coding agent sample apps. Each one clones a repo, writes a plan you can comment on, edits code with approvals, and publishes its diff:

Or, read on to learn more about Slack Code: