By default the SDK starts a brand-new session on every call (TypeScript's
A session corresponds to a persisted conversation history on the CLI side (including context, tool call records, compaction boundaries, etc.), identified by a UUID. The
Without passing any session-related fields, a new session is created each time:
Let the caller determine the session UUID (suitable when the host manages its own session index):
When you don't know the session ID, use
Do not pass
Derive a new session from an existing one, preserving the original context but obtaining a new session ID. The original session is unaffected:
To specify an ID for the forked new session:
Listen for the
The user data directory stores session history, resources, logs, and other user-level CLI data. Set
query()) or connection (Python's QoderSDKClient). A few fields in options let you specify a session ID, resume a historical session, or fork an existing one.
Concepts
A session corresponds to a persisted conversation history on the CLI side (including context, tool call records, compaction boundaries, etc.), identified by a UUID. The init system message contains the current session_id, which also serves as the anchor point for subsequent resume/fork operations.
The authentication in the examples below can be replaced with whichever method your project uses; see SDK Authentication.
Creating New Sessions
Default
Without passing any session-related fields, a new session is created each time:
Specifying a Session ID
Let the caller determine the session UUID (suitable when the host manages its own session index):
Resuming Sessions
Resume by ID
Resume the Most Recent
When you don't know the session ID, use continue: true (TypeScript) / continue_conversation=True (Python) to pick up the most recently modified session:
resume together with continue (continue_conversation in Python).
Forking Sessions
Derive a new session from an existing one, preserving the original context but obtaining a new session ID. The original session is unaffected:
Field Reference
| Field (TypeScript / Python) | Type | Behavior |
|---|---|---|
sessionId / session_id | string / str | Alone: create a new session with this ID; with the fork field: the ID of the forked session |
resume / resume | string / str | The session ID to resume |
continue / continue_conversation | boolean / bool | true resumes the most recent session |
forkSession / fork_session | boolean / bool | Used with resume to fork instead of continuing |
Getting the Current Session ID
Listen for the init system message; in Python, ResultMessage also carries session_id—either works for bookkeeping:
User data directory
The user data directory stores session history, resources, logs, and other user-level CLI data. Set QODERCN_CONFIG_DIR through options.env to select this directory: