0
46
近 7 天 10
25.3
生态多维模型
3 个月前
2026-05-16
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-prompt-tracker@1.0.0"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-prompt-tracker@1.0.0"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-prompt-trackeropencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
An OpenCode plugin that automatically records each conversation's prompt, model, agent call chain, duration, and token usage, including costs, to Markdown files.
Features
- Automatic Logging: Records each conversation to Markdown files after completion
- Agent Chain Tracking: Records the complete agent call chain (e.g.,
oracle → build → explore) - Token Statistics: Records Input/Output tokens with cached/uncached breakdown
- Duration Tracking: Records conversation processing duration
- Step-by-Step Logging: Logs each assistant message as it completes
- Daily Archiving: Generates log files organized by date
- Cost Calculation: Optional billing based on model pricing (when configured)
Important Note
This project was entirely generated by OpenCode without strict code review or complete testing. At present, basic functionality has been verified to work.
Installation
Method 1: Install via npm (Recommended)
Add the plugin configuration in opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-prompt-tracker"]
}
Restart OpenCode, and the plugin will be automatically downloaded and installed.
Note: The plugin is installed to
~/.cache/opencode/node_modules/directory.
Method 2: Local Installation (Development)
Suitable for modifying the plugin or contributing to development.
Prerequisites
- OpenCode editor
- Node.js 18+ or Bun runtime
Installation Steps
# Clone the plugin repository
git clone https://github.com/CloudStrolling/opencode-prompt-tracker.git
or
git clone https://gitee.com/CloudStrolling/opencode-prompt-tracker.git
cd opencode-prompt-tracker
# Install dependencies
npm install
# or
bun install
# Build the plugin
npm run build
# or
bun run build
# Copy to OpenCode plugins directory
mkdir -p ~/.opencode/plugins/opencode-prompt-tracker
cp -r dist/release/* ~/.opencode/plugins/
Usage
The project supports zero-config startup - the plugin activates automatically when OpenCode starts.
By default, output files are written to <project>/.opencode/prompts/opencode-prompt-YYYY-MM-DD_<sessionID>.md
You can also create a config file in the project root: opencode-prompt-tracker.config.json
Configuration
Create opencode-prompt-tracker.config.json in your project root:
{
"outputPath": "prompts",
"filePrefix": "opencode-prompt-tracker",
"saveAllLogs": true,
"billing": {
"enabled": true,
"models": [
{
"model": "opencode/sonnet-4",
"input": 3.75,
"output": 15.0,
"cacheRead": 0.3,
"cacheWrite": 3.75
}
]
}
}
| Field | Default | Description |
|---|---|---|
outputPath |
.opencode/prompts |
Output directory relative to project root |
filePrefix |
opencode-prompt- |
File name prefix |
saveAllLogs |
false |
Save all AI thinking logs - if true, additional .md files with opencode-prompt-log prefix are created in the output directory to record detailed AI reasoning |
billing.enabled |
false |
Enable cost calculation |
billing.models |
[] |
Model pricing config (price per 1M tokens) |
When billing is enabled and the current model has pricing configured, the summary includes a cost line:
- **Cost**: $0.0123 (input: $0.005, output: $0.007, cache: $0.0003)
Without a config file, the plugin uses all defaults and works as before.
Log File Format
# Prompt-Tracker
## Prompt
Update detailed design document, including Chinese and English
### Step 1 — 13:24:15
- **Agent**: Sisyphus - Ultraworker
- **Model**: opencode/minimax-m2.5-free
- **Duration**: 11.16s
- **Total Tokens**: 30168 (input: 30001, output: 167)
- **Cached Tokens**: 0 (read: 0, write: 0)
- **Uncached Tokens**: 30001
- **Task**: Update detailed design document, including Chinese and English
### Step 2 — 13:24:24
- **Agent**: Sisyphus - Ultraworker
- **Model**: opencode/minimax-m2.5-free
- **Duration**: 9.82s
- **Total Tokens**: 3020 (input: 2723, output: 297)
- **Cached Tokens**: 29952 (read: 29952, write: 0)
- **Uncached Tokens**: 0
- **Task**: I found the current DESIGN.md and DESIGN_CN.md files. Let me read them to understand the current state...
### Step 3 — 13:24:41
- **Agent**: Sisyphus - Ultraworker
- **Model**: opencode/minimax-m2.5-free
- **Duration**: 16.39s
- **Total Tokens**: 66792 (input: 66605, output: 187)
- **Cached Tokens**: 0 (read: 0, write: 0)
- **Uncached Tokens**: 66605
- **Task**: 1. New `saveAllLogs` feature - need to record complete conversation logs
### Step 4 — 13:24:48
- **Agent**: Sisyphus - Ultraworker
- **Model**: opencode/minimax-m2.5-free
- **Duration**: 7.31s
- **Total Tokens**: 37404 (input: 37295, output: 109)
- **Cached Tokens**: 32640 (read: 32640, write: 0)
- **Uncached Tokens**: 4655
- **Task**: Let me also check the config.ts and other utility files to have a complete picture
---
### Summary — From 13:24:03 To 13:26:58
- **Model**: opencode/minimax-m2.5-free
- **Agent Chain**: Sisyphus - Ultraworker
- **Total Duration**: 174.20s
- **Steps**: 4
- **Total Tokens**: 137384 (input: 136624, output: 760)
- **Cached Tokens**: 62592 (read: 62592, write: 0)
- **Uncached Tokens**: 74032
- **Cost**: $0.3078 (input: $0.2776, output: $0.0114, cache: $0.0188)
Field Description
| Field | Description |
|---|---|
| Time | Conversation start time (HH:MM:SS) |
| Agent Chain | Complete agent call chain, e.g., main → code-review → test |
| Model | AI model used, e.g., opencode/hy3-preview-free |
| Prompt | User's original input text |
| Duration(s) | Conversation processing duration in seconds |
| Input Tokens | Total input token count (includes cached portions) |
| Output Tokens | Output token count |
| Cached Tokens | Total cache read + write tokens |
| Uncached Tokens | Input tokens minus cached tokens |
| Cache Read | Tokens read from cache (billed at discount) |
| Cache Write | Tokens written to cache (billed at premium) |
Development
Project Structure
opencode-prompt-tracker/
├── src/
│ ├── index.ts # Main plugin — hook handlers
│ ├── types.ts # TypeScript interfaces
│ └── utils/
│ ├── file-writer.ts # Writes .md logs to .opencode/prompts/
│ ├── agent-extractor.ts # Parses agent chain from message parts
│ ├── logger.ts # Plugin logging to OpenCode console
│ ├── config.ts # Config loader
│ └── billing.ts # Cost calculation
├── tests/ # Test files
├── dist/ # Build output
├── package.json
├── tsconfig.json
├── README.md # English README
├── README_CN.md # Chinese README
├── AGENTS.md # Developer instructions
└── opencode-prompt-tracker.config.example.json
Developer Commands
npm run build # Build TypeScript + esbuild → dist/release/opencode-prompt-tracker.js
npm run dev # Watch mode: tsc --watch
npm test # Run tests with Bun (bun test)
Local Testing
# 1. Build plugin
npm run build
# 2. Copy to test project
mkdir -p <test-project>/.opencode/plugins/
cp dist/release/opencode-prompt-tracker.js <test-project>/.opencode/plugins/
# 3. Add to opencode.json
{ "plugin": ["opencode-prompt-tracker"] }
Publishing
# Update version (patch/minor/major)
npm version patch
# Build
npm run build
# Publish
npm publish
# For scoped packages:
npm publish --access public
Technical Details
- Hooks:
chat.message,event.message.part.updated,event.message.updated,event.session.idle - Data Storage: Markdown format with step entries + summary
- Runtime: Supports both Bun and Node.js
- Type Safety: TypeScript with strict mode
License
Licensed under the Apache License 2.0. See LICENSE file for details.
Copyright 2026 jenemy8023 jenemy8023@163.com