Permission Mode: Full Bypass
This design is not configurable. If you need per-action permission prompts, use Claude Code directly instead.Threat Model
The bot is designed for personal use by trusted users. Primary threats:- Unauthorized access — Someone discovers/steals your bot token
- Prompt injection — Malicious content tries to manipulate Claude
- Accidental damage — You accidentally run destructive commands
- Credential exposure — Attackers extract API keys or passwords
Defense in Depth
Six layers protect against these threats:Layer 1: User Allowlist
Only Telegram users inTELEGRAM_ALLOWED_USERS can use the bot.
- User IDs are numeric and cannot be spoofed in Telegram
- Get your ID from @userinfobot
- Unauthorized attempts are logged
- Works as first-line defense against account takeover
Layer 2: Rate Limiting
Token bucket rate limiting prevents abuse even with valid credentials.- Maximum 20 requests per 60 seconds
- Automatically rejects excess requests
- Prevents runaway costs or DoS
Layer 3: Path Validation
File operations are restricted to explicitly allowed directories. Default allowed paths:CLAUDE_WORKING_DIR(or home if not set)~/Documents~/Downloads~/Desktop~/.claude(Claude Code data)/tmp/and/var/folders/(temp files for Telegram downloads)
- Symlinks are resolved before checking
- Path traversal attacks (
../) are prevented - Only exact directory matches are allowed
- Temp files (
/tmp/,/var/folders/) always permitted
Layer 4: Command Safety
Dangerous shell commands are blocked as defense-in-depth. Completely blocked patterns (always rejected):| Pattern | Reason |
|---|---|
rm -rf / | System destruction |
rm -rf ~ | Home directory wipe |
rm -rf $HOME | Home directory wipe |
sudo rm | Privileged deletion |
:(){ :|:& };: | Fork bomb |
> /dev/sd | Disk overwrite |
mkfs. | Filesystem formatting |
dd if= | Raw disk operations |
rm commands (that don’t match blocked patterns) are allowed but validated:
ALLOWED_PATHS before execution.
Risk: This is defense-in-depth for the rare case where system prompt fails. The system prompt (Layer 5) is the primary protection.
Layer 5: System Prompt
Claude receives safety instructions:- Never delete files without confirmation — Must ask “Are you sure?”
- Only access allowed directories — Refuse operations outside them
- Never run dangerous commands — Even if explicitly asked
- Ask for confirmation on destructive actions
Layer 6: Audit Logging
All interactions are logged for security review.message— User messages and Claude responsesauth— Authorization attemptstool_use— Claude tool usageerror— Errors during processingrate_limit— Rate limit events
What This Doesn’t Protect Against
- Malicious authorized users — If you add someone to the allowlist, they have full access
- Zero-day vulnerabilities — Unknown bugs in Claude, the SDK, or dependencies
- Physical access — Someone with access to your machine can compromise everything
- Network interception — Telegram uses encryption, but someone could still intercept tokens
- Sophisticated prompt injection — Adversarial users might find ways to manipulate Claude
Security Recommendations
Essential
- Keep allowlist small — Only add users you fully trust
- Use a dedicated working directory — Don’t point at
/or~ - Keep credentials private — Never share your bot token or Telegram ID
- Use a dedicated API key — Create a separate Anthropic key for the bot
- Enable email alerts — Get notified when new Claude Code sessions start (in Claude Code settings)
Important
- Review audit logs periodically — Look for suspicious patterns
- Keep dependencies updated — Run
bun installregularly for security patches - Set restrictive
ALLOWED_PATHS— Only include directories Claude needs - Enable rate limiting — Always keep
RATE_LIMIT_ENABLED=true - Use strong rate limits for sensitive work — Reduce
RATE_LIMIT_REQUESTSif needed
Nice to Have
- Rotate credentials regularly — Update bot token and API keys periodically
- Monitor for unusual activity — Check logs for excessive requests or errors
- Keep the bot offline when not in use — Reduces attack surface
- Use VPN for mobile access — Encrypts Telegram traffic
Incident Response
If you suspect unauthorized access:-
Stop the bot immediately:
-
Revoke the Telegram bot token:
- Message @BotFather
- Use
/revoketo invalidate the old token - Create a new token with
/newbot
-
Review audit logs:
-
Check for file changes:
- Review recent activity in
ALLOWED_PATHS - Look for unauthorized files or modifications
- Check git history if available:
git log --oneline -20
- Review recent activity in
-
Update credentials:
- Rotate
ANTHROPIC_API_KEYif needed - Update
OPENAI_API_KEYif compromised - Change any other API keys that may have been exposed
- Rotate
-
Restart with new token:
- Update
.envwith newTELEGRAM_BOT_TOKEN - Restart the bot service
- Verify it’s working with
/start
- Update
Security vs Usability Trade-offs
The bot makes deliberate security trade-offs:| Choice | Security | Usability |
|---|---|---|
| Full permission bypass | Lower (Layer 1-6 needed) | Higher (no prompts) |
| Rate limiting at 20/min | Medium (prevents abuse) | Lower (can feel slow) |
Broad ALLOWED_PATHS | Lower (more files exposed) | Higher (more access) |
| System prompt reliance | Lower (can be jailbroken) | Higher (responsive) |
- More security: Reduce
ALLOWED_PATHS, increaseRATE_LIMIT_REQUESTS - More usability: Expand
ALLOWED_PATHS, increaseRATE_LIMIT_REQUESTS
Compliance
This bot is not appropriate for:- Handling healthcare information (HIPAA)
- Financial data or payment processing (PCI-DSS)
- User data from other people (GDPR)
- Classified or confidential business information
- Multi-user shared environments
Reporting Security Issues
If you discover a security vulnerability:- Don’t open a public GitHub issue
- Contact the maintainer privately (see project README)
- Allow time for a fix before disclosure
- Follow responsible disclosure practices
Security Checklist
Before deploying in production:-
TELEGRAM_ALLOWED_USERSis set and limited -
ALLOWED_PATHSis restrictive (not/or~) -
RATE_LIMIT_ENABLEDis true -
AUDIT_LOG_PATHis set and monitored - Bot token is stored securely (in
.env, never in code) - Working directory exists and is readable
- API keys are rotated and secure
- You’ve reviewed SECURITY.md and understand the threat model
- LaunchAgent/systemd service is properly configured
- Logs are reviewed regularly
Next Steps
- Environment Variables — Configure paths and rate limits
- Platform Support — Deployment considerations by platform
- Drivers — Understanding Claude Code vs Codex security
