Multi-Session Binding Specification
Version: 1.0.0 Status: ACTIVE Created: 2025-12-29 Task: T1016 Related: MULTI-SESSION-SPEC.md, LLM-AGENT-FIRST-SPEC.mdRFC 2119 Conformance
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” are to be interpreted as described in RFC 2119.Executive Summary
This specification defines how session context is automatically bound and resolved across CLI commands in multi-session mode. It complements MULTI-SESSION-SPEC.md by specifying:- Session context auto-binding after
session start - Agent identity detection and assignment
- Consistent session resolution across all commands
- Actionable error handling for session-related failures
Key Capabilities
| Capability | Description |
|---|---|
| Auto-Binding | .current-session file written on session start |
| Agent Detection | Automatic LLM agent identification |
| Consistent Resolution | All commands resolve session in same order |
| Actionable Errors | Errors include error.fix and error.alternatives |
Part 1: Session Context Binding
1.1 Session ID Sources
Session context MUST be resolved from these sources in priority order:| Priority | Source | Type | Description |
|---|---|---|---|
| 1 | --session ID | Explicit | CLI flag, highest priority |
| 2 | CLEO_SESSION | Environment | Env var for persistent context |
| 3 | .current-session | File | Auto-written on session start |
| 4 | Auto-detect | Computed | Single active session inference |
1.2 Resolution Algorithm
1.3 Auto-Binding on Session Start
Whensession start succeeds, the CLI MUST:
- Write session ID to
.cleo/.current-session - Include export instruction in output
- Detect and bind agent identity (if detectable)
1.4 Session Start Output (JSON)
Part 2: Agent Detection
2.1 Detection Sources
| Priority | Source | Example Value | Agent ID |
|---|---|---|---|
| 1 | CLEO_AGENT env | my-custom-agent | As specified |
| 2 | CURSOR_AGENT env | 1 | cursor-agent |
| 3 | Non-interactive shell | N/A | llm-agent |
| 4 | Unknown | N/A | null |
2.2 Detection Algorithm
2.3 Agent ID Storage
Agent ID is stored in session entry:Part 3: Command Integration
3.1 Commands Using Session Context
All commands that operate within a session MUST callresolve_current_session_id():
| Command | Session Required | Behavior |
|---|---|---|
focus set/clear/show | Yes | Uses resolved session |
session end | Yes | Ends resolved session |
session suspend | Yes | Suspends resolved session |
complete | No | Uses session if available |
update | No | Uses session if available |
list | No | Filters by session scope if available |
3.2 Command Pattern
3.3 Session End Behavior
session end MUST:
- Resolve session using standard algorithm
- Clear
.current-sessionfile after ending - Provide actionable error if ambiguous
Part 4: Error Handling
4.1 Error JSON Requirements
All session errors MUST include:4.2 Error Code Table
| Exit Code | Constant | Meaning | Recoverable |
|---|---|---|---|
| 31 | E_SESSION_NOT_FOUND | Session ID not found | Yes |
| 35 | E_TASK_CLAIMED | Task focused by another session | Yes |
| 36 | E_SESSION_REQUIRED | Session context required | Yes |
| 38 | E_FOCUS_REQUIRED | Focus task required for session start | Yes |
4.3 Error Recovery
All recoverable errors MUST includeerror.fix - a copy-paste command:
| Error | fix Command |
|---|---|
E_SESSION_REQUIRED | cleo session start --scope epic:T001 --auto-focus |
E_AMBIGUOUS_SESSION | cleo session list --status active |
E_TASK_CLAIMED | cleo session suspend --session <claiming-session> |
E_FOCUS_REQUIRED | cleo session start --scope <scope> --focus <task> |
Part 5: Configuration
5.1 Config Options
| Option | Type | Default | Description |
|---|---|---|---|
autoBindSession | boolean | true | Write .current-session on start |
agentDetection | boolean | true | Detect agent identity |
clearCurrentSessionOnEnd | boolean | true | Remove .current-session on end |
Part 6: Files
6.1 .current-session File
Location:.cleo/.current-session
Format: Single line containing session ID
- Created: On
session start(ifautoBindSession = true) - Read: On all session-aware commands
- Deleted: On
session end(ifclearCurrentSessionOnEnd = true) - Validated: Session existence checked before use; file cleared if invalid
6.2 File Permissions
.current-session SHOULD be created with mode 0600 to prevent cross-user access.
Part 7: Implementation Checklist
Phase 1: Core Functions
- Create
lib/agent-detection.sh - Add
resolve_current_session_id()tolib/sessions.sh - Add
auto_bind_session()tolib/sessions.sh
Phase 2: Command Updates
- Update
scripts/session.shcmd_start() for auto-binding - Update
scripts/session.shcmd_end() for consistent resolution - Update
scripts/focus.shfor session resolution
Phase 3: Error Handling
- Add
E_SESSION_REQUIRED(36) to exit-codes.sh - Add
E_AMBIGUOUS_SESSION(36 with different context) - Update
output_error_actionable()for session errors
Phase 4: Testing
- Test auto-binding on session start
- Test resolution from .current-session file
- Test resolution from CLEO_SESSION env var
- Test auto-detect single active session
- Test error recovery commands
Phase 5: Documentation
- Update LLM-AGENT-FIRST-SPEC.md with exit codes 35-39
- Update docs/commands/session.md
- Update CLAUDE.md injection template
Appendix A: Migration Notes
From v0.41.x
.current-sessionfile is new (v0.42.0)- Existing sessions continue to work
- CLEO_SESSION env var takes precedence over .current-session
- No breaking changes to existing workflows
Backwards Compatibility
Single-session mode (multiSession.enabled = false):
- All binding features disabled
- Legacy
._meta.activeSessionin todo.json used - No .current-session file created
End of Specification
