openclaw - 💡(How to fix) Fix feat: add --new-session flag to openclaw agent CLI [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#54864Fetched 2026-04-08 01:35:03
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
1
Participants

The openclaw agent CLI derives a session key from the agent name when no --session-id or --session-key is provided. This means repeated calls to the same agent reuse conversation history by default.

Tools that want isolated sessions (like workflow engines or batch scripts) currently have to generate a UUID externally and pass --session-id <uuid>. This works but pushes session-management responsibility to every caller.

Root Cause

The openclaw agent CLI derives a session key from the agent name when no --session-id or --session-key is provided. This means repeated calls to the same agent reuse conversation history by default.

Tools that want isolated sessions (like workflow engines or batch scripts) currently have to generate a UUID externally and pass --session-id <uuid>. This works but pushes session-management responsibility to every caller.

Code Example

# Before: caller must generate UUID
openclaw agent --agent oz --session-id $(uuidgen) --message "do something" --json

# After: CLI handles it
openclaw agent --agent oz --new-session --message "do something" --json
# JSON output includes { "sessionId": "<auto-generated-uuid>", ... }
RAW_BUFFERClick to expand / collapse

Context

The openclaw agent CLI derives a session key from the agent name when no --session-id or --session-key is provided. This means repeated calls to the same agent reuse conversation history by default.

Tools that want isolated sessions (like workflow engines or batch scripts) currently have to generate a UUID externally and pass --session-id <uuid>. This works but pushes session-management responsibility to every caller.

Proposal

Add a --new-session flag to openclaw agent that:

  1. Auto-generates a fresh session ID internally
  2. Uses that session ID for the current invocation
  3. Returns the generated session ID in JSON output so callers can reconnect later via --session-id

Example

# Before: caller must generate UUID
openclaw agent --agent oz --session-id $(uuidgen) --message "do something" --json

# After: CLI handles it
openclaw agent --agent oz --new-session --message "do something" --json
# JSON output includes { "sessionId": "<auto-generated-uuid>", ... }

Motivation

Any tool that delegates to OpenClaw agents in a loop (workflow engines, batch processors, CI) needs session isolation. Without this flag, every caller independently implements UUID generation + --session-id passthrough. A native flag makes the common case simple.

extent analysis

Fix Plan

To implement the proposed --new-session flag, follow these steps:

  • Update the openclaw agent CLI to accept the new flag
  • Auto-generate a fresh session ID when the flag is present
  • Use the generated session ID for the current invocation
  • Return the generated session ID in JSON output

Example Code

import uuid
import json

# ...

def parse_args():
    # ...
    parser.add_argument('--new-session', action='store_true')
    # ...

def main():
    args = parse_args()
    if args.new_session:
        session_id = str(uuid.uuid4())
        # Use the generated session ID for the current invocation
        # ...
        # Return the generated session ID in JSON output
        output = {'sessionId': session_id, 'message': 'Session created'}
        print(json.dumps(output))
    else:
        # ...

Verification

To verify the fix, run the following command:

openclaw agent --agent oz --new-session --message "do something" --json

The output should include a JSON object with a sessionId property containing the auto-generated UUID.

Extra Tips

  • Ensure the uuid library is properly imported and used to generate unique session IDs.
  • Consider adding error handling for cases where the --new-session flag is used in conjunction with --session-id or --session-key.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix feat: add --new-session flag to openclaw agent CLI [1 participants]