Optimizing Claude Code Token Cost with a Custom SQLite-Backed Feedback Skill
Software engineer Jack Franklin built a custom SQLite and Deno CLI skill for Claude Code to manage playtest feedback. Replacing a massive 7,000-line Markdown file with database queries radically reduced context-token bloat and improved query efficiency.
Impact: Medium
Why it matters
You can drastically cut your agentic token spend by switching from text logs to local structured database queries using a simple CLI.
TL;DR
- 01Massive text logs like Markdown rapidly bloat LLM context window costs.
- 02Relational databases (SQLite) let agents query only what they need, minimizing active token consumption.
- 03Implementing a strict 'list before show' policy in custom agent skills is crucial for cost optimization.
Key facts
- Original Markdown Size
- 7,000 lines
- Database Technology
- SQLite + Deno CLI
- Storage Location
- Local single file (added to .gitignore)
The Problem: Markdown Context Bloat
Managing project feedback and bugs inside plain text files eventually hits a scaling wall. As a Markdown document grows—in this case, reaching 3,000 lines of active items and 4,000 lines of completed tasks—Claude Code is forced to re-read thousands of lines for simple operations, such as categorizing bugs or listing open tickets. This significantly inflates token cost and slows down the agentic feedback loop.
The Solution: SQLite + Deno CLI Wrapper
The SQLite-backed skill replaces raw text file updates with structured database queries. A Deno-based CLI allows Claude to log, query, and modify feedback items via terminal commands. The database schema tracks fields like title, detail, priority, status, category, project, and a done boolean flag. Completed items are hidden from default outputs to minimize token usage while retaining history.
Key Token-Saving Patterns
1. List Before Show: The skill forces Claude to query lightweight lists (titles and IDs) rather than full issue details. 2. Contextual Project Inference: Claude automatically infers the active project from the current workspace context, minimizing user prompt overhead. 3. Duplicate Prevention: Before writing a new entry, Claude is instructed to run a search query to detect existing duplicate bugs described in different words.
Try it in 2 minutes
# Example CLI command Claude uses to add structured feedback
./feedback-cli add --project "ontrack" --title "Train delay bar bug" --detail "Journey bar clobbers schedule state when delayed" --priority "high" --category "UI"bash
✓ When to use
- Use when building or debugging projects with Claude Code or other CLI-based agents, especially when managing long-lived backlogs, task lists, or logs.
✕ When NOT to use
- Not necessary for very short sessions where context window consumption is negligible and task history is not required.
What to do today
- Audit your agentic developer logs and migrate growing text-based history files to local SQLite databases.
- Wrap database interactions in a clean, documented CLI and teach it to Claude Code as a custom skill.
Sources