context-usage
Skill19 starsChanged 3 months agoMITView on GitHub
Analyze current session context and token usage from OpenCode SQLite database
1 other project uses a version of this.
Adopted by
Most recently taken up by
- TheLatentSpaceLab/Qubitotheir own version, first seen Apr 1, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- TheLatentSpaceLab/Qubito★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository25 other files it gives its agents.
- assess-findingsSkill
- autopilotSkill
- build-fixSkill
- code-searchSkill
- debugSkill
- decideSkill
- designSkill
- docsSkill
- forgetSkill
- gitSkill
- implementSkill
- memoriseSkill
- patternsSkill
- perfSkill
- plan-swarmSkill
- recallSkill
- reflectSkill
- reviewSkill
- semgrepSkill
- surveySkill
- swarmSkill
- swarm-statusSkill
- testSkill
- verifySkill
- worktree-resolveSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 32
If $OPENCODE is not 1 or $AIDE_PLATFORM is not opencode, abort immediately and inform the user that this skill is only supported on …
- Distinctive: line 34
Do not attempt to query other databases (e.g.
- Very specific: line 37
If $AIDE_SESSION_ID is not set, abort with a message explaining that the session ID could not be determined.
- Very specific: line 42
Run the following queries sequentially in a single Bash call (chain with &&).
- Very specific: line 53
If OPENCODE is not 1, stop immediately — this skill cannot work outside OpenCode.
- Very specific: line 54
If AIDE_SESSION_ID is not set, stop and inform the user.
- Distinctive: line 157
If any single tool call exceeds 20KB, flag it as a potential optimization target.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Context Usage Analysis
Recommended model tier: balanced (sonnet) - straightforward SQL queries
Analyze the current session's context window consumption, tool usage breakdown, and token costs by querying the OpenCode SQLite database directly.
Prerequisites
- This skill only works on OpenCode. Verify by checking the environment:
$OPENCODE=1— set by the OpenCode runtime$AIDE_PLATFORM=opencode— set by aide when running under OpenCode$AIDE_SESSION_ID— the current session ID (injected by aide)
- The OpenCode database is at
~/.local/share/opencode/opencode.db. sqlite3must be available on the system.
If $OPENCODE is not 1 or $AIDE_PLATFORM is not opencode, abort immediately
and inform the user that this skill is only supported on OpenCode.
Do not attempt to query other databases (e.g. Claude Code's storage) — the
schema is OpenCode-specific.
If $AIDE_SESSION_ID is not set, abort with a message explaining that the
session ID could not be determined.
Workflow
Run the following queries sequentially in a single Bash call (chain with &&).
Present results to the user in a formatted summary after all queries complete.
Step 1: Validate environment
test "$OPENCODE" = "1" && echo "Platform: OpenCode" || echo "ERROR: Not running on OpenCode (OPENCODE=$OPENCODE)"
test "$AIDE_PLATFORM" = "opencode" && echo "AIDE Platform: opencode" || echo "WARNING: AIDE_PLATFORM=$AIDE_PLATFORM"
test -n "$AIDE_SESSION_ID" && echo "Session: $AIDE_SESSION_ID" || echo "ERROR: AIDE_SESSION_ID not set"If OPENCODE is not 1, stop immediately — this skill cannot work outside OpenCode.
If AIDE_SESSION_ID is not set, stop and inform the user.
Step 2: Session overview
sqlite3 ~/.local/share/opencode/opencode.db "
SELECT
s.title,
s.slug,
ROUND((julianday('now') - julianday(datetime(s.time_created/1000, 'unixepoch'))) * 24, 1) as hours_old,
(SELECT COUNT(*) FROM message m WHERE m.session_id = s.id) as messages,
CASE WHEN s.time_compacting IS NOT NULL THEN 'yes' ELSE 'no' END as compacted
FROM session s
WHERE s.id = '$AIDE_SESSION_ID';
"Step 3: Token totals
Sum tokens from step-finish parts (each represents one LLM turn):
sqlite3 ~/.local/share/opencode/opencode.db "
SELECT
SUM(json_extract(data, '$.tokens.input')) as input_tokens,
SUM(json_extract(data, '$.tokens.output')) as output_tokens,
SUM(json_extract(data, '$.tokens.cache.read')) as cache_read_tokens,
SUM(json_extract(data, '$.tokens.cache.write')) as cache_write_tokens,
SUM(json_extract(data, '$.tokens.total')) as total_tokens,
COUNT(*) as llm_turns
FROM part
WHERE session_id = '$AIDE_SESSION_ID'
AND json_extract(data, '$.type') = 'step-finish';
"Step 4: Tool output breakdown
Show tool usage ranked by total output size:
sqlite3 ~/.local/share/opencode/opencode.db "
SELECT
json_extract(data, '$.tool') as tool,
COUNT(*) as calls,
SUM(length(json_extract(data, '$.state.output'))) as total_output_bytes,
ROUND(AVG(length(json_extract(data, '$.state.output')))) as avg_bytes,
MAX(length(json_extract(data, '$.state.output'))) as max_bytes
FROM part
WHERE session_id = '$AIDE_SESSION_ID'
AND json_extract(data, '$.type') = 'tool'
GROUP BY tool
ORDER BY total_output_bytes DESC;
"Step 5: Total session size
sqlite3 ~/.local/share/opencode/opencode.db "
SELECT
SUM(length(json_extract(data, '$.state.output'))) as tool_output_bytes,
SUM(length(json_extract(data, '$.state.input'))) as tool_input_bytes,
SUM(length(data)) as total_part_bytes
FROM part
WHERE session_id = '$AIDE_SESSION_ID'
AND json_extract(data, '$.type') = 'tool';
"Output Format
Present the results as a structured summary:
## Session Context Usage
**Session:** <title> (<slug>)
**Age:** <hours> hours | **Messages:** <count> | **Compacted:** yes/no
### Token Usage
| Metric | Count |
|--------|-------|
| Input tokens | <n> |
| Output tokens | <n> |
| Cache read | <n> |
| Cache write | <n> |
| **Total tokens** | **<n>** |
| LLM turns | <n> |
### Tool Output Breakdown (by total bytes)
| Tool | Calls | Total Output | Avg/call | Max |
|------|-------|-------------|----------|-----|
| ... | ... | ... | ... | ... |
### Session Size
- Tool outputs: <n> KB
- Tool inputs: <n> KB
- Total part storage: <n> KB (includes JSON metadata overhead)Format byte values as KB (divide by 1024, round to 1 decimal). Highlight the top 3 tools by total output as the biggest context consumers. If any single tool call exceeds 20KB, flag it as a potential optimization target.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

