Skip to content
Back to skills

Opencode Session Collector

ASecurity

OpenCode SDK/APIでセッション一覧を取得し、必要なメッセージだけ抽出する方法を学ぶときに使う

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 6, 2026
ai-agentsbashnodeapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned September 6, 2026

npx -y skills add tomoasleep/dotfiles --skill opencode-session-collector --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Opencode Session Collector?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Opencode Session Collector
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tomoasleep-opencode-session-collector/badge)](https://www.skillsdirectory.com/skills/tomoasleep-opencode-session-collector)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: opencode-session-collector
description: OpenCode SDK/APIでセッション一覧を取得し、必要なメッセージだけ抽出する方法を学ぶときに使う
---

# OpenCode セッション収集ガイド

## 目的

OpenCode のセッション情報を SDK / API で収集し、コンテキスト溢れを避けるために必要最小限のメッセージだけを抽出する。

## 使いどころ

- セッション一覧やセッション詳細を取得したい
- 特定のディレクトリやプロジェクトに関連するセッションを探したい
- メッセージ全量取得を避けたい(抽出スクリプトを推奨)

## サーバー起動

サーバー未起動なら SDK で起動する。起動済みならクライアントのみ作る。

```ts
import { createOpencode, createOpencodeClient } from '@opencode-ai/sdk'

const opencode = await createOpencode()
const { client } = opencode

const clientOnly = createOpencodeClient({ baseUrl: 'http://localhost:4096' })
```

## セッション収集フロー

1. セッション一覧を取得する
2. プロジェクトやディレクトリで絞り込む
3. 対象セッションのメッセージはスクリプトで必要分だけ抽出する

SDK

```ts
const sessions = await client.session.list()
```

API

```bash
curl -s "http://localhost:4096/session"
```

## プロジェクト / ディレクトリで絞り込み

セッション一覧の `projectID` と `directory` で絞る。

プロジェクト一覧(任意)

```ts
const projects = await client.project.list()
```

フィルタ方針

- `projectID` が一致するセッションだけ残す
- `directory` が指定パスのプレフィックスなら対象にする

## メッセージ抽出はスクリプト推奨

メッセージを直接 API で全量取得すると長くなり、コンテキストが溢れやすい。
同梱スクリプトで `user 全件 + 最終 assistant 1件` のみを抽出する運用を推奨する。

スクリプト

`config/opencode/skills/opencode-session-collector/scripts/extract-session-messages.js`

例

```bash
node config/opencode/skills/opencode-session-collector/scripts/extract-session-messages.js \
  --base-url http://localhost:4096 \
  --project-id PROJECT_ID
```

```bash
node config/opencode/skills/opencode-session-collector/scripts/extract-session-messages.js \
  --dir-prefix /path/to/worktree
```

```bash
node config/opencode/skills/opencode-session-collector/scripts/extract-session-messages.js \
  --session-id SESSION_ID
```

## 出力形式

JSON でセッションごとの抽出結果を返す。

```json
{
  "sessions": [
    {
      "session": {
        "id": "...",
        "title": "...",
        "directory": "...",
        "projectID": "...",
        "time": { "created": 0, "updated": 0 }
      },
      "messages": [
        { "role": "user", "time": { "created": 0 }, "text": "..." },
        { "role": "assistant", "time": { "created": 0 }, "text": "..." }
      ]
    }
  ]
}
```

Files in this skill

  • SKILL.md3 KB
  • scripts/extract-session-messages.js3.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.