gemini-cli-session
Gemini CLI Session
Use this skill when the user wants the primary agent to send a prompt to Gemini CLI against an existing Gemini session, so Gemini keeps the prior conversation history.
Do not use wrapper scripts. Run Gemini CLI directly.
Default to --approval-mode auto_edit so Gemini CLI can use its own write_file and replace tools without interactive approval.
Use the project-root .gemini-cli-session-id file as the primary source of truth for the session to resume.
The main user task must never run without an active session ID.
If .gemini-cli-session-id does not exist, first look up the current project's local Gemini history under ~/.gemini/tmp/<project_hash>/logs.json and recover the latest sessionId. Write that value into .gemini-cli-session-id.
If the project has no local Gemini session history yet, start a fresh headless run only for session bootstrap, capture the session_id from the init event in stream-json, and immediately persist it into .gemini-cli-session-id. After that, run the real user task by reading the session ID from .gemini-cli-session-id and using gemini -r.
Workflow
- Read
<project-root>/.gemini-cli-session-idfirst. - If the file exists and contains a valid session ID, use that value for the real Gemini command.
- If the file is missing or empty, inspect
~/.gemini/projects.jsonto get the current project's hash, then inspect~/.gemini/tmp/<project_hash>/logs.jsonfor the latestsessionId. - If a local project
sessionIdis found, write it to.gemini-cli-session-id. - If no session can be recovered locally, start a fresh bootstrap session, capture the new
session_idfrom theinitevent, and write it to.gemini-cli-session-id. - When bootstrapping a brand-new session, use a short bootstrap prompt that tells Gemini CLI to inspect the current directory, for example:
Inspect the current directory and get ready to continue work in this project. - If session creation or recovery fails and
.gemini-cli-session-idstill does not contain an active session ID, do not run the main user prompt. Report the failure and stop. - Only after
.gemini-cli-session-idcontains an active session ID, run the real user task withgemini -r. - Always include
-m "gemini-3-flash-preview"unless the user explicitly asks for another model. - Always include
--approval-mode auto_editunless the user explicitly asks for another approval behavior. - Default to
stream-jsonoutput unless the user explicitly asks for plain text or another Gemini output mode. - For file creation or edits, let Gemini CLI perform the write through its own
write_fileorreplacetools. - Do not manually write the file yourself as a fallback. If Gemini CLI does not have the required edit tool registered, report that clearly and stop.
- If the user wants the exact Gemini output, relay it faithfully. Otherwise, summarize the relevant answer from the command output.
Command Pattern
Use:
gemini -r "<session-id>" -p "<prompt>" -m "gemini-3-flash-preview" -o "stream-json" --approval-mode auto_edit
If there is no session yet, use this only as a bootstrap step:
gemini -p "Inspect the current directory and get ready to continue work in this project." -m "gemini-3-flash-preview" -o "stream-json" --approval-mode auto_edit
The first init event contains the new session_id. Save that value into .gemini-cli-session-id. Then run the real task by reading the session ID from .gemini-cli-session-id and using gemini -r.
File Rules
- The session file must live at
<project-root>/.gemini-cli-session-id. - The file should contain only the session ID string and a trailing newline.
- Treat the file as the project's pinned Gemini conversation.
- The real user prompt must be executed only after this file contains an active session ID.
- If the user gives a different explicit session ID, update
.gemini-cli-session-idto that value before running the next Gemini command.
Notes
- Treat the resume ID as required whenever the user expects Gemini to remember earlier context.
-rcannot create a missing session. It only resumes an existing one.- Local Gemini session history is project-scoped; prefer the current project's own history before falling back to a brand new session.
- No main task execution without a session ID. Recovery or bootstrap comes first; if neither works, stop.
- Prefer Gemini CLI's own edit tools for file writes. Successful
write_fileorreplacecalls mean Gemini itself performed the modification. - If Gemini CLI reports that
write_fileorreplaceis not registered, do not patch the file manually as a substitute unless the user explicitly changes the requirement. - Keep the user's prompt text exact unless they explicitly ask you to rewrite it.
- If
geminiis missing, report that clearly and stop. - If Gemini returns streaming JSON events, inspect them and extract the meaningful assistant response for the user unless the user asked for the raw event stream.
- If the user asks what Gemini previously saw or said, use the active session ID with a direct prompt such as
What was my last message to you?
More from erdinccurebal/cli-session-skills
claude-cli-session
Use when the user wants Claude Code session continuity across repeated CLI runs. Read the session ID from a project-root `.claude-cli-session-id` file when available; otherwise create a new UUID-backed Claude session, persist that ID, and then run the real task through the same pinned session. Covers `--resume`, `--session-id`, `-p`, `--output-format stream-json`, `--permission-mode acceptEdits`, and optional `ollama launch claude --model ...` integration.
4codex-cli-session
Use when the user wants Codex CLI session continuity across repeated non-interactive runs. Read the session ID from a project-root `.codex-cli-session-id` file when available; otherwise bootstrap a new Codex session, persist the new session ID, and then run the real task with `codex exec resume`. Covers session continuity, `--json`, `-m`, and project-scoped session pinning.
4