Session Monitoring
This guide explains how ccremote monitors your Claude Code sessions, what it detects, and how it responds to different situations.
How Monitoring Works
ccremote uses a sophisticated pattern detection system to monitor your Claude Code sessions:
- tmux Integration: Sessions run inside tmux, allowing ccremote to capture all output
- Intelligent Polling: Monitors session output every 2 seconds (configurable)
- Pattern Matching: Uses regex patterns to detect specific Claude Code messages
- State Management: Tracks session state and responds appropriately
- Error Recovery: Automatically retries and recovers from temporary issues
What ccremote Detects
Usage Limits
ccremote detects when Claude Code hits usage limits with patterns like:
- "5-hour limit reached" messages
- "usage limit" followed by reset information
- Specific limit reset times and countdowns
Response:
- Sends Discord notification about the limit
- Calculates reset time (typically 5 hours from limit)
- Automatically continues session when limit resets
- Sends confirmation when session resumes
Approval Dialogs
ccremote recognizes when Claude Code needs user approval:
- Questions followed by numbered options
- Selection arrows (
>) indicating current choice - Sensitive operation confirmation dialogs
- File operation approvals
Response:
- Sends Discord notification with approval details
- Includes the question and available options
- Waits for user to respond in the Claude Code session
- Continues monitoring after user responds
Session Errors
ccremote detects various error conditions:
- Process crashes or unexpected exits
- Network connectivity issues
- Authentication problems
- Resource exhaustion
Response:
- Sends Discord notification with error details
- Attempts automatic recovery (configurable retries)
- Stops monitoring if session ends permanently
- Logs error information for troubleshooting
Task Completion Detection
ccremote detects when Claude finishes tasks and is ready for new input:
- Command prompt visible (
>pattern) - No active processing indicators (analyzing, processing, working, etc.)
- Session idle for at least 10 seconds
- No completion notification sent in the last 5 minutes (cooldown)
Response:
- Sends Discord notification that task is complete
- Includes idle duration for context
- Helps you know when to check back without constant monitoring
- Respects cooldown period to avoid notification spam
Session State Changes
ccremote tracks different session states:
- Active: Session running normally
- Waiting: Waiting for usage limit reset
- Waiting Approval: Waiting for user approval
- Ended: Session terminated or crashed
- Error: Encountered unrecoverable error
Pattern Detection Examples
Usage Limit Detection
5-hour limit reached. Your limit will reset at 3:30 PM PST (in 4 hours 23 minutes).ccremote extracts:
- Limit type: "5-hour limit"
- Reset time: "3:30 PM PST"
- Duration: "4 hours 23 minutes"
Approval Detection
This operation requires approval. Do you want to continue?
1. Yes, proceed
2. No, cancel
> 1
Please confirm your choice:ccremote detects:
- Question: "This operation requires approval"
- Options: "Yes, proceed" / "No, cancel"
- Current selection: Option 1
- Waiting for user confirmation
Task Completion Detection
File analysis complete. Found 15 issues that need attention.
Summary:
- 8 type errors fixed
- 3 performance optimizations applied
- 4 code style improvements made
>ccremote detects:
- Task finished: "complete", "Summary"
- Command prompt visible:
> - No processing indicators present
- Session idle for 10+ seconds
Monitoring Configuration
Polling Interval
Control how often ccremote checks session output:
# Check every 2 seconds (default)
CCREMOTE_MONITORING_INTERVAL=2000
# More frequent (1 second) - higher resource usage
CCREMOTE_MONITORING_INTERVAL=1000
# Less frequent (5 seconds) - lower resource usage
CCREMOTE_MONITORING_INTERVAL=5000Considerations:
- Shorter intervals: Faster detection, higher resource usage
- Longer intervals: Slower detection, lower resource usage
- Recommended: 1-3 seconds for most use cases
Error Handling
Configure how ccremote handles monitoring errors:
# Maximum retry attempts (default: 3)
CCREMOTE_MAX_RETRIES=5
# Auto-restart monitoring after failures (default: true)
CCREMOTE_AUTO_RESTART=falseMultiple Sessions
ccremote can monitor multiple sessions simultaneously:
# Start multiple sessions
ccremote start --name project-a
ccremote start --name project-b
ccremote start --name client-work
# Each session is monitored independently
ccremote listEach session:
- Has its own monitoring process
- Sends separate Discord notifications
- Maintains independent state tracking
- Can be stopped/started individually
Session Lifecycle
Starting a Session
When you run ccremote start:
- tmux Creation: Creates new tmux session with unique name
- Claude Code Launch: Starts Claude Code inside the tmux session
- State Initialization: Initializes session state as "active"
- Monitoring Start: Begins polling session output
- User Attachment: Automatically attaches you to the session
During Monitoring
While monitoring is active:
- Output Capture: Captures all tmux session output
- Pattern Analysis: Analyzes output against known patterns
- State Updates: Updates session state based on detected patterns
- Notifications: Sends Discord notifications for important events
- Action Triggers: Performs automatic actions (like continuing sessions)
Session End
When a session ends:
- End Detection: Detects session termination or crash
- Final Notification: Sends Discord notification about session end
- State Cleanup: Updates session state to "ended"
- Monitoring Stop: Stops polling for that session
- Resource Cleanup: Cleans up monitoring resources
Monitoring Output Examples
Normal Session Output
[ccremote] Session: ccremote-1 (my-project)
[ccremote] Status: active
[ccremote] Monitoring: ✓ Running
[ccremote] Last check: 2025-01-20 10:30:15Usage Limit Detected
[ccremote] Session: ccremote-1 (my-project)
[ccremote] Status: waiting_limit_reset
[ccremote] Limit detected at: 2025-01-20 10:30:00
[ccremote] Reset expected: 2025-01-20 15:30:00
[ccremote] Discord notification: ✓ SentApproval Required
[ccremote] Session: ccremote-1 (my-project)
[ccremote] Status: waiting_approval
[ccremote] Approval detected at: 2025-01-20 10:30:00
[ccremote] Question: "Do you want to continue?"
[ccremote] Discord notification: ✓ SentAdvanced Monitoring
Custom Patterns
For advanced users, ccremote supports custom pattern detection:
# Add custom patterns for specific use cases
CCREMOTE_CUSTOM_PATTERNS="error:|warning:|custom_trigger"Logging
Enable detailed logging for troubleshooting:
# Enable debug logging
export DEBUG=ccremote:*
ccremote start --name debug-session
# Or use verbose mode
ccremote start --name test --verboseWebhook Integration
Send notifications to custom webhooks instead of Discord:
CCREMOTE_WEBHOOK_URL=https://your-webhook-url.com/notifyPerformance Considerations
Resource Usage
Monitoring consumes some system resources:
- CPU: Minimal (regex pattern matching)
- Memory: ~10-20MB per monitored session
- Network: Only for Discord notifications
- Disk: Session state files in
.ccremote/
Optimization Tips
- Adjust polling interval: Balance responsiveness vs resource usage
- Limit concurrent sessions: More sessions = more resource usage
- Use efficient patterns: Custom patterns should be optimized
- Monitor system load: Check if monitoring affects performance
Scaling
ccremote can handle multiple sessions efficiently:
- Recommended: Up to 10 concurrent sessions per user
- Maximum tested: 25+ sessions (depends on system resources)
- Best practice: Stop unused sessions to free resources
Troubleshooting Monitoring
Monitoring Not Working
- Check session exists:
ccremote listto verify session - Verify tmux access:
tmux list-sessionsshould show session - Test pattern detection: Check logs for pattern matches
- Restart monitoring: Stop and start session to reset monitoring
Missing Notifications
- Test Discord connection:
ccremote test-discord - Check notification settings: Verify bot permissions
- Review patterns: Make sure detected patterns trigger notifications
- Check session state: Session must be in correct state for notifications
Performance Issues
- Reduce polling frequency: Increase
CCREMOTE_MONITORING_INTERVAL - Limit sessions: Stop unused sessions to free resources
- Check system load: Monitor CPU/memory usage during operation
- Optimize patterns: Simplify custom patterns if used
Pattern Detection Issues
- Enable debug logging: See exactly what patterns are detected
- Check session output: Manually verify the output contains expected patterns
- Test patterns: Use regex tools to test pattern matching
- Update patterns: ccremote patterns may need updates for new Claude Code versions
Next Steps
Now that you understand monitoring:
- Commands Reference - Complete command reference
- Troubleshooting - Solve common issues
- Configuration - Customize monitoring behavior
For advanced monitoring setups, see the GitHub repository for additional configuration options.