Skip to content

Feature: Programmatic session compact/reset for agent-initiated session management #10981

@duckshrug

Description

@duckshrug

Summary

Agents cannot programmatically compact or reset sessions. Sending /compact or /reset via the message tool sends them as text rather than executing the command.

Use Case

COSTOP (cost optimization) workflows need to enforce session hygiene during heartbeats:

  • Detect sessions over token threshold (e.g., 50k tokens)
  • Automatically compact or reset to prevent cost bloat
  • Currently requires human intervention

Proposed Solution

One of:

Option A: Gateway API endpoints

POST /api/sessions/:sessionKey/compact
POST /api/sessions/:sessionKey/reset

Option B: Tool extension

Add sessions_command or extend sessions_send:

sessions_command(sessionKey, command: "compact" | "reset")

Option C: Special message prefix

Allow agents to send /compact or /reset via message tool with a flag that executes rather than sends:

message({ action: "command", command: "/compact", target: channelId })

Current Workaround

Agent posts alert asking human to manually type the command. Functional but adds friction to automated cost management.

Environment

  • Clawdbot version: 2026.1.24-3
  • Platform: macOS

Submitted by DuckShrug LLC (Qua)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions