Scripting and RPC
Scripting
panda --print "Where are sessions stored?"
panda --mode json "Read Cargo.toml and identify the workspace members"
git diff | panda --print --provider deepseek --model deepseek-flash --thinking high --no-session "Review this change"
panda --continue --mode rpc
Print mode writes the final answer. JSON mode emits one object per line, ending with a done object containing the answer and session ID. Both accept a prompt from standard input. If you also supply a prompt argument, Panda prepends the piped text verbatim, separates it from the prompt with a blank line, and resolves attachments from the argument.
See workspace trust, Markdown packages and MCP for installation, activation and server configuration.
The terminal and workspace guide covers cross-workspace sessions, private checkpoint recovery, themes and picker shortcuts.
To follow up on a specific conversation, pass its numeric session_id from the JSON done object to either output mode, for example panda --print --session 42 "Explain the first finding". The ID must identify an existing session in the current workspace. A JSON follow-up returns the same ID. The --session flag conflicts with --continue and --no-session.
Import a Pi v3 JSONL file in the workspace where you want to continue it. Import prints a new Panda session ID. For example, if it prints {"session_id":42}, run:
panda --import-session review.jsonl
panda --print --session 42 "Continue the review"
panda --export-session 42 continued.jsonl
panda --export-session 42 review.html
pi --session continued.jsonl
Open the standalone HTML file offline in a browser to see the active branch. Use the branch selector to review a sibling, including its tool output and compaction checkpoints. Export requires a new destination file and preserves the order used by --continue.
Import and export also accept a trailing --session-dir DIR. Export includes all branches. Pi opens the selected branch, including its compaction checkpoint. Imported entries retain their IDs, parent links and extension payloads. The exported header points to the importing workspace. Panda uses its own configured model and tools when continuing. For Panda-authored entries that lack original timestamps or model metadata, the export uses the time of first export and identifies the model as unknown.
Use --session-dir DIR to choose where a print or JSON run creates and looks up sessions, for example panda --print --session-dir ../review-sessions --continue "Summarize the review". The SQLite database and session locks live in that directory. Both --session ID and --continue look there for conversations in the current workspace. Choose a private directory outside the workspace and configured toolchains. Panda creates it if needed. Credentials, model settings, and user instructions still come from PANDA_HOME, which is also the default session store. With --no-session, Panda skips the session directory entirely.
For print and JSON runs, put options before the prompt. Use --model MODEL for an exact model ID on the configured provider, or add --provider PROVIDER to select a different provider. --thinking LEVEL accepts the same levels as :thinking, including default. These choices apply to this invocation. Add --no-session to keep the conversation in memory. In this mode the JSON session ID is null, and --continue is incompatible.
Select tools for a print or JSON run with --tools read,search,repo_map,ls. The list takes exact tool names and replaces the default selection. Use --tools codemode,read to enable Codemode with only tools.read() available inside scripts. Use --no-tools for a prompt-only run, such as git diff HEAD | panda --print --no-tools "Review this diff". An explicit selection takes precedence over --codemode. The session’s plan or code mode still controls which selected tools can run.
Use --system-prompt TEXT|PATH to replace Panda’s built-in base prompt for a print or JSON run. Workspace instructions and guidance for enabled tools still follow the base. Each --append-system-prompt TEXT|PATH adds a final instruction in command-line order. Both flags accept literal text or the contents of an existing UTF-8 file. Relative paths resolve from the current directory.
git diff HEAD | panda --print --no-tools --system-prompt "You are a code reviewer." --append-system-prompt ./review-rubric.md --append-system-prompt "List findings by severity." "Review this diff."
RPC accepts one JSON object per input line and echoes its id on replies and turn events.
{"id":1,"type":"prompt","text":"Read Cargo.toml and describe the workspace"}
During an RPC turn, send steer or follow_up with a text field, or send cancel. The terminal reply for that turn includes any undelivered input. Once the turn ends, send session to inspect the saved transcript, or ack after inspecting an interrupted tool call.
Select the Pi JSONL adapter with panda --mode rpc --rpc-version pi-v1. Send a request such as {"id":"run-1","type":"prompt","message":"Describe this workspace"}. Its correlated response carries the prompt disposition. Read the event stream until agent_settled to observe completion. While the run is active, clients can query state, steer, queue a follow-up or abort. Clear the queue before aborting to discard pending text.
Pi clients can inspect messages, tree entries and the active leaf, select models and thinking levels, change queue delivery, switch or fork sessions, execute cancellable shell commands, compact or retry. Pass the sessionFile value from get_state to switch_session to reopen a Panda session. The SQLite host also accepts Pi JSONL files for import. Extension UI requests and responses depend on a future Panda extension UI contract.
Embedded Rust hosts use panda_core::sdk::SessionSdk with panda_memory::MemoryStore or panda_local::store::Disk. Supply your provider, toolset, cancellation handle and queue to prompt and retry. Reuse the queue between turns to preserve its delivery policy. The SDK integration test exercises both stores through the same sequence. Rust host example