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):
Java's
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:
Java's
The Java options above also apply to
Listen for the
The user data directory stores session history, resources, logs, and other user-level CLI data. Set
Java's CLI subprocess inherits only
query()) or connection (Python's QoderSDKClient; Java's client.query() / client.openSession()). 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 (TypeScript, Python)
Let the caller determine the session UUID (suitable when the host manages its own session index):
Resuming Sessions
Resume by ID
resume(...) accepts only IDs made of ASCII letters, digits, _, and -; any other character makes build() throw InvalidOptionsException.
Resume the Most Recent
When you don't know the session ID, use continue: true (TypeScript) / continue_conversation=True (Python) / continueSession(true) (Java) to pick up the most recently modified session:
resume together with continue (continue_conversation in Python). In Java, setting both resume(...) and continueSession(true) makes build() throw InvalidOptionsException.
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:
forkSession(true) must be combined with resume(...) or continueSession(true); otherwise build() throws InvalidOptionsException.
To specify an ID for the forked new session (TypeScript, Python):
Field Reference
| Field (TypeScript / Python / Java) | 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 / resume(String) | string / str / String | The session ID to resume |
continue / continue_conversation / continueSession(boolean) | boolean / bool / boolean | true resumes the most recent session |
forkSession / fork_session / forkSession(boolean) | boolean / bool / boolean | Used with resume to fork instead of continuing |
Opening sessions with SessionRepository (Java)
The Java options above also apply to client.openSession(options). You can also open a multi-turn session directly through the SessionRepository returned by client.sessions():
Java
continueSession(null, options) continues the most recent session; the session ID passed to fork must not be null. Each call starts a new CLI process, and the caller closes the returned session. The repository's list(), get(), and delete() require external session storage; see External session storage.
Getting the Current Session ID
Listen for the init system message; in Python, ResultMessage also carries session_id—either works for bookkeeping. In Java, read sessionId() from the initialization() result; messages also carry the session ID in sessionId():
User data directory
The user data directory stores session history, resources, logs, and other user-level CLI data. Set QODER_CONFIG_DIR through options.env (putEnvironment(...) in Java) to select this directory:
PATH by default (plus system directory variables such as TEMP on Windows), so you do not need to spread process.env as in TypeScript. Pass any other variable the CLI needs explicitly; see Subprocess environment.