session
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| Session codexed.client.session Runtime handle for an active Codex thread. |
🛈 DocStrings¶
Codex session — runtime handle for an active thread.
ABANDONED_TURN_INTERRUPT_TIMEOUT
module-attribute
¶
Seconds a cancelled or abandoned turn stream waits for its turn/interrupt.
Session
¶
Runtime handle for an active Codex thread.
Wraps a :class:CodexClient and a thread_id so that every
thread-scoped operation can be called without passing the ID again.
Returned by :meth:CodexClient.thread_start,
:meth:CodexClient.thread_resume, and :meth:CodexClient.thread_fork.
Example::
session = await client.thread_start(cwd="/my/project")
async for event in session.turn_stream("Explain this repo"):
...
await session.set_name("exploration")
Source code in src/codexed/client/session.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
approve_guardian_denied_action
async
¶
Send a request to the server to approve a guardian denied action.
Source code in src/codexed/client/session.py
archive
async
¶
Archive this thread.
compact_start
async
¶
Trigger context compaction for this thread.
fork
async
¶
fork(
*,
path: str | None = None,
cwd: str | None = None,
model: str | None = None,
model_provider: str | None = None,
base_instructions: str | None = None,
developer_instructions: str | None = None,
approval_policy: AskForApproval | None = None,
approvals_reviewer: ApprovalsReviewer | None = None,
sandbox: SandboxMode | None = None,
config: dict[str, Any] | None = None,
tools: list[ToolConfig] | None = None,
code_mode: bool | None = None,
service_tier: str | None = None,
ephemeral: bool | None = None,
mcp_servers: Mapping[str, McpServerConfig] | None = None,
last_turn_id: str | None = None,
before_turn_id: str | None = None,
exclude_turns: bool | None = None,
permissions: str | None = None,
) -> Session
Fork this thread into a new thread with copied history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | None
|
Path to thread storage |
None
|
cwd
|
str | None
|
Working directory for the forked thread |
None
|
model
|
str | None
|
Model override for forked thread |
None
|
model_provider
|
str | None
|
Model provider override |
None
|
base_instructions
|
str | None
|
Base system instructions for forked thread |
None
|
developer_instructions
|
str | None
|
Developer instructions for forked thread |
None
|
approval_policy
|
AskForApproval | None
|
Tool approval policy for forked thread |
None
|
approvals_reviewer
|
ApprovalsReviewer | None
|
Where approval requests are routed for review |
None
|
sandbox
|
SandboxMode | None
|
Sandbox mode for forked thread |
None
|
config
|
dict[str, Any] | None
|
Additional configuration overrides |
None
|
tools
|
list[ToolConfig] | None
|
Builtin tool configurations for forked thread |
None
|
code_mode
|
bool | None
|
Enable experimental code mode feature flag |
None
|
service_tier
|
str | None
|
Service tier |
None
|
ephemeral
|
bool | None
|
If true, forked thread is not persisted |
None
|
mcp_servers
|
Mapping[str, McpServerConfig] | None
|
Per-thread MCP server configurations |
None
|
last_turn_id
|
str | None
|
Fork through this turn (inclusive), omitting later turns |
None
|
before_turn_id
|
str | None
|
Fork before this turn, excluding it and all later turns |
None
|
exclude_turns
|
bool | None
|
When true, return only thread metadata and live fork state
without populating |
None
|
permissions
|
str | None
|
Named permissions profile ID (cannot be combined with sandbox) |
None
|
Returns:
| Type | Description |
|---|---|
Session
|
Session wrapping the new forked thread |
Source code in src/codexed/client/session.py
guardian_warning
async
¶
Send a thread-related guardian warning message to the app-server.
Source code in src/codexed/client/session.py
inject_items
async
¶
Inject raw responses-API Items into the thread's model-visible history.
Source code in src/codexed/client/session.py
list_turns
async
¶
list_turns(
cursor: str | None = None, limit: int | None = None, sort_direction: SortDirection | None = None
) -> ThreadTurnsListResponse
List all turns in this thread.
Source code in src/codexed/client/session.py
read
async
¶
read(*, include_turns: bool = False) -> ThreadReadResponse
Read thread data.
Source code in src/codexed/client/session.py
read_resource
async
¶
Read a resource from the MCP server.
Source code in src/codexed/client/session.py
realtime
¶
realtime(
output_modality: RealtimeOutputModality,
prompt: str | None = None,
*,
realtime_session_id: str | None = None,
) -> RealtimeSession
Open a realtime voice session on this thread.
Returns an async context manager that sends thread/realtime/start
on enter and thread/realtime/stop on exit. Iterate over the
returned object to receive realtime events.
Example::
async with session.realtime(prompt="You are helpful") as rt:
await rt.send_text("hello")
async for event in rt:
...
Source code in src/codexed/client/session.py
revert
async
¶
revert(before_turn_id: str) -> ThreadRevertResponse
Replace the thread's persisted history with the turns before before_turn_id.
The given turn and all later turns are dropped. Only conversation history changes; local file changes are not reverted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
before_turn_id
|
str
|
First turn to drop (it and every later turn are removed) |
required |
Returns:
| Type | Description |
|---|---|
ThreadRevertResponse
|
Updated thread metadata and cursors for re-hydrating the retained history |
Source code in src/codexed/client/session.py
review_start
async
¶
review_start(target: ReviewTarget, *, delivery: ReviewDelivery = 'inline') -> ReviewStartResponse
Start a code review.
Inline delivery runs the review on the same thread, so review items appear in the existing thread history. Detached delivery creates a new thread for the review, keeping the original thread's history clean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
ReviewTarget
|
Review target (uncommittedChanges, baseBranch, commit, or custom) |
required |
delivery
|
ReviewDelivery
|
Where to run the review (inline or detached) |
'inline'
|
Returns:
| Type | Description |
|---|---|
ReviewStartResponse
|
ReviewStartResponse with turn and review thread ID |
Source code in src/codexed/client/session.py
review_stream
async
¶
review_stream(
target: ReviewTarget, *, delivery: ReviewDelivery = "inline"
) -> AsyncIterator[CodexEvent]
Start a code review and stream events.
Inline delivery runs the review on the same thread, so review items appear in the existing thread history. Detached delivery creates a new thread for the review, keeping the original thread's history clean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
ReviewTarget
|
Review target (uncommittedChanges, baseBranch, commit, or custom) |
required |
delivery
|
ReviewDelivery
|
Where to run the review (inline or detached) |
'inline'
|
Yields:
| Name | Type | Description |
|---|---|---|
CodexEvent |
AsyncIterator[CodexEvent]
|
Streaming events from the review turn |
Cancelling the consumer, or closing the stream before the turn completes, interrupts the review turn.
Source code in src/codexed/client/session.py
set_memory_mode
async
¶
Set the thread's memory mode.
Source code in src/codexed/client/session.py
set_name
async
¶
Set a user-facing name for this thread.
shell_command
async
¶
Run a user-initiated shell command against this thread.
Executes the command unsandboxed, as if the user typed !command
in the Codex CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
Shell command to execute. |
required |
Source code in src/codexed/client/session.py
tool_call
async
¶
tool_call(
server: str, tool: str, arguments: Any | None = None, meta: dict[str, Any] | None = None
) -> CallToolResult
Call a tool on the MCP server.
Source code in src/codexed/client/session.py
turn_interrupt
async
¶
Interrupt a running turn.
turn_steer
async
¶
turn_steer(
user_input: str | Sequence[UserInput],
*,
expected_turn_id: str,
responsesapi_client_metadata: dict[str, Any] | None = None,
) -> TurnSteerResponse
Steer a running turn with additional input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_input
|
str | Sequence[UserInput]
|
Additional user input |
required |
expected_turn_id
|
str
|
The expected active turn ID (precondition) |
required |
responsesapi_client_metadata
|
dict[str, Any] | None
|
Optional turn-scoped Responses API client metadata. |
None
|
Returns:
| Type | Description |
|---|---|
TurnSteerResponse
|
TurnSteerResponse with the turn ID |
Source code in src/codexed/client/session.py
turn_stream
async
¶
turn_stream(
user_input: str | Sequence[UserInput],
*,
model: str | None = None,
effort: ReasoningEffort | None = None,
approval_policy: AskForApproval | None = None,
approvals_reviewer: ApprovalsReviewer | None = None,
cwd: str | None = None,
sandbox_policy: SandboxMode | SandboxPolicy | None = None,
output_schema: dict[str, Any] | type[Any] | None = None,
personality: Personality | None = None,
service_tier: str | None = None,
summary: ReasoningSummary | None = None,
collaboration_mode: CollaborationMode | None = None,
responsesapi_client_metadata: dict[str, Any] | None = None,
environments: list[TurnEnvironmentParams] | None = None,
permissions: str | None = None,
) -> AsyncIterator[CodexEvent]
Start a turn and stream events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_input
|
str | Sequence[UserInput]
|
User input as string or list of input items (text/image) |
required |
model
|
str | None
|
Optional model override for this turn |
None
|
effort
|
ReasoningEffort | None
|
Optional reasoning effort override |
None
|
approval_policy
|
AskForApproval | None
|
Optional approval policy |
None
|
approvals_reviewer
|
ApprovalsReviewer | None
|
Where approval requests are routed for review |
None
|
cwd
|
str | None
|
Optional working directory override for this and subsequent turns |
None
|
sandbox_policy
|
SandboxMode | SandboxPolicy | None
|
Optional sandbox mode or policy dict |
None
|
output_schema
|
dict[str, Any] | type[Any] | None
|
Optional JSON Schema dict or Pydantic type to constrain output |
None
|
personality
|
Personality | None
|
Optional personality override |
None
|
service_tier
|
str | None
|
Optional service tier (fast/flex) |
None
|
summary
|
ReasoningSummary | None
|
Optional reasoning summary mode |
None
|
collaboration_mode
|
CollaborationMode | None
|
Optional collaboration mode preset (experimental) |
None
|
responsesapi_client_metadata
|
dict[str, Any] | None
|
Optional turn-scoped Responses API client metadata. |
None
|
environments
|
list[TurnEnvironmentParams] | None
|
Optional list of environment variables to set for this turn. |
None
|
permissions
|
str | None
|
Named permissions profile ID (cannot be combined with sandbox) |
None
|
Yields:
| Name | Type | Description |
|---|---|---|
CodexEvent |
AsyncIterator[CodexEvent]
|
Streaming events from the turn |
Cancelling the consumer, or closing the stream before turn/completed,
interrupts the turn (turn/interrupt).
Source code in src/codexed/client/session.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
turn_stream_structured
async
¶
turn_stream_structured(
user_input: str | list[UserInput],
result_type: type[ResultType],
*,
model: str | None = None,
effort: ReasoningEffort | None = None,
approval_policy: AskForApproval | None = None,
approvals_reviewer: ApprovalsReviewer | None = None,
cwd: str | None = None,
sandbox_policy: SandboxMode | SandboxPolicy | None = None,
personality: Personality | None = None,
service_tier: str | None = None,
summary: ReasoningSummary | None = None,
collaboration_mode: CollaborationMode | None = None,
) -> ResultType
Start a turn with structured output and return the parsed result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_input
|
str | list[UserInput]
|
User input as string or list of items |
required |
result_type
|
type[ResultType]
|
Pydantic model class for the expected result |
required |
model
|
str | None
|
Optional model override for this turn |
None
|
effort
|
ReasoningEffort | None
|
Optional reasoning effort override |
None
|
approval_policy
|
AskForApproval | None
|
Optional approval policy |
None
|
approvals_reviewer
|
ApprovalsReviewer | None
|
Where approval requests are routed for review |
None
|
cwd
|
str | None
|
Optional working directory override |
None
|
sandbox_policy
|
SandboxMode | SandboxPolicy | None
|
Optional sandbox mode or policy dict |
None
|
personality
|
Personality | None
|
Optional personality override |
None
|
service_tier
|
str | None
|
Optional service tier (fast/flex) |
None
|
summary
|
ReasoningSummary | None
|
Optional reasoning summary mode |
None
|
collaboration_mode
|
CollaborationMode | None
|
Optional collaboration mode preset (experimental) |
None
|
Returns:
| Type | Description |
|---|---|
ResultType
|
Parsed Pydantic model instance of type result_type |
Source code in src/codexed/client/session.py
unarchive
async
¶
unarchive() -> ThreadUnarchiveResponse
Unarchive this thread.
Source code in src/codexed/client/session.py
unsubscribe
async
¶
Stop listening to this thread's events.
Source code in src/codexed/client/session.py
warning
async
¶
Send a thread-related warning message to the app-server.