> ## Documentation Index
> Fetch the complete documentation index at: https://platform.stepfun.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Sessions and context

Step Code saves sessions automatically and supports restoring, navigating branches, forking, and exporting. Compact context as it approaches the model's window to retain important information and continue working.

## Starting and restoring sessions

| Command | Action |
| - | - |
| `step` | Start a new session in the current directory |
| `step -c` | Continue the most recent session |
| `step -r` | Browse history and choose a session |
| `step --session <path-or-ID>` | Restore a specific session, including by partial ID |
| `step --fork <path-or-ID>` | Fork an existing session into a new file |
| `step --name "Auth migration"` | Set the session name |

The Ultracode switch persists per session: restoring the same session restores its previous state, and a new session without saved state defaults to off. Check it with `/ultracode status`.

## Switching sessions in the TUI

| Command | Action |
| - | - |
| `/new`, `/clear` | Create a session and clear the current conversation context |
| `/resume` | Open the session picker |
| `/name` | Name the current session |
| `/session` | Show file path, ID, message count, token usage, and cost information |
| `/fork` | Fork an independent session |

Type to search in the session picker. Ctrl+S changes sorting, Ctrl+N filters named sessions, Ctrl+R renames, and Ctrl+D deletes. Confirm that you no longer need a record before deleting it.

See [Interaction and task control](https://platform.stepfun.ai/docs/en/step-code/guides/interaction.md) for input controls and permission modes.

## Session trees and forks

| Command | Behavior | Use case |
| - | - | - |
| `/tree` | Continue from a historical node in the same file | Try another approach from an earlier decision |
| `/fork` | Create a session from a selected user message | Separate conversation experiments |
| `/clone` | Copy the full current branch to a new session | Save the current state before continuing |

In `/tree`, navigate with arrow keys, select with Enter, cycle filters with Ctrl+O, and edit labels with Shift+L. Filters include default, no tools, user messages only, and labeled only. Selecting a user message can restore its text to the input box; edit and resend to form a branch.

When switching branches, you can generate a summary of the branch you are leaving. Configure this under `[branchSummary]`.

> [!NOTE]
>
> Session branches separate conversation records. They do not undo disk changes or create Git branches. Use Git branches or worktrees to isolate code experiments. Summaries and subsequent model calls may still consume tokens.

See [Common use cases](https://platform.stepfun.ai/docs/en/step-code/guides/use-cases.md) for project task examples.

## Manage context

From v0.1.4, when automatic compaction is enabled and no context mode is specified, CLM (Context Language Models) is used by default. The model selectively trims earlier working context without overwriting the original session log. When trimming fails or is insufficient, Step Code falls back to summary compaction. Model usage is included in session statistics.

| Command | Description |
| - | - |
| `/clm [status\|on\|off\|diff\|reset]` | Inspect state, toggle the current session, view changes, or clear trimmed results |
| `/clm-compact [instructions]` | Ask the model to organize current context |
| `/compact [preservation-instructions]` | Use summary compaction |

`/clm reset` does not undo summary compaction that already happened. Organization adds model calls, counted in session statistics.

## Context compaction

Summary compaction retains recent messages and summarizes earlier content. For manual compaction, specify what should be preserved:

```text theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
/compact Preserve the authentication migration goals, interface contracts, changed files, verification results, and unresolved issues.
```

For automatic summary compaction, reserved context, and retained recent messages, see [Configuration files](https://platform.stepfun.ai/docs/en/step-code/configuration/files.md#section-settings). Keep important agreements and acceptance results in project files as well.

## Exporting and sharing

```text theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
/export session.html
/export session.jsonl
```

You can also export from the command line:

```bash theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
step --export /path/to/session.jsonl session.html
```

`/export [file]` defaults to HTML; a `.jsonl` extension exports JSONL. Exports can contain code, command output, and paths; review them before sharing.

## Import a session

Import a saved JSONL session from the interactive interface:

```text theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
/import session.jsonl
```

Replace the filename with your session file. HTML exports are for reading; session restoration uses JSONL.

## Search sessions

Web and desktop clients search session content through a SQLite full-text index. JSONL remains the only data source and the index can be rebuilt at any time. Subagent sessions are excluded from search.

Use `step session-index status`, `step session-index reindex`, and `step session-index clear` to inspect, rebuild, or clear the index.

## Session storage

Sessions are grouped by working directory. Use `/session` to find the current file. `--session-dir` selects a directory; `--no-session` disables saving for that session. See [Data paths](https://platform.stepfun.ai/docs/en/step-code/configuration/data-paths.md#session-data) for storage and cleanup.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.