Codex Log Guard logo

Codex Log Guard

Community
majiayu000
codex-log-guard

Diagnose excessive Codex local SQLite diagnostic log writes with read-only evidence by default. Use when a user mentions logs_2.sqlite, logs_2.sqlite-wal, block_log_inserts, SSD/TBW wear, or explicitly asks to protect, clean up, verify, or restore Codex diagnostic logging.

Overview

Publishermajiayu000
Repositoryspellbook
Skill namecodex-log-guard
Stars
280
Forks
26
Bundled files
1
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by majiayu000 on GitHub. Read the source before you install it.

Installation

Install the Codex Log Guard AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/majiayu000/spellbook.git /tmp/spellbook
mkdir -p .claude/skills
cp -r /tmp/spellbook/skills/codex-log-guard .claude/skills/codex-log-guard
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Codex Log Guard in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Codex Log Guard on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Codex Log Guard is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Codex Log Guard

Overview

Diagnose Codex persistent diagnostic logging from local evidence, then give a concise conclusion and the safest next action. Do not make the user choose from a command menu.

Operating Contract

Select one mode from the current user request:

  • diagnose_only is the default for check, inspect, explain, or verify requests. It is read-only.
  • protect requires an explicit request to stop or mitigate log writes. It may install and verify block_log_inserts, but it does not delete rows or vacuum files.
  • cleanup requires an explicit current request to reclaim disk space or clean up logs. It first installs protection when needed, creates and verifies a timestamped backup, and only then deletes log rows and vacuums.
  • restore requires an explicit request to resume diagnostic logging. It may drop only the known block_log_inserts trigger.

Generic wording such as "处理", "修一下", or "止血" selects protect, not cleanup. Prior approval does not carry into a later run. If the requested write mode is ambiguous, return the diagnose_only report and the exact proposed mutation without applying it.

Direct actions:

  • Run local read-only file, SQLite schema, row, and open-process checks.
  • Apply only the mutation authorized by the selected mode and verify its result.

Escalate before:

  • Touching any database outside the two declared Codex log paths, deleting a backup, killing a process, or changing remote telemetry or credentials.

Evidence-backed pushback:

  • Reject cleanup when protection is unverified, the backup check failed, or sampled row IDs still move. Cite the exact database path and failed command instead of treating file size as proof.

Feedback loop:

  • When a new schema, active path, or false-success signal is confirmed more than once, update this Skill's diagnosis rules and a focused contract test before automating that case.

agents/openai.yaml contains discovery UI metadata only; it is not an operational instruction source.

Default Flow

When the user asks to "check", "看看", "诊断", or asks whether the local machine is affected:

  1. Inspect all candidate live database files and schemas:
    • ~/.codex/logs_2.sqlite
    • ~/.codex/sqlite/logs_2.sqlite
  2. Identify which candidate database is currently held by Codex processes.
  3. Check whether block_log_inserts already exists on each candidate with a logs table.
  4. Measure whether logs is still being written using COUNT(*), MIN(id), MAX(id) samples. Treat MAX(id) or MIN(id) movement with stable COUNT(*) as active churn, not necessarily disk growth.
  5. Inspect low-level log volume with TRACE/DEBUG counts and top noisy targets.
  6. Check which Codex processes currently hold each candidate database.
  7. Return a diagnosis with:
    • current state: healthy / protected / affected historically / actively writing / actively growing on disk / missing database / blocked
    • evidence: file sizes, trigger state, row/min-id/max-id samples, level distribution, active path
    • recommended next action: do nothing / install trigger / cleanup later / cleanup now / restore logging
  8. Do not ask the user which command to run. Choose the diagnosis path from the evidence.

In protect mode:

  1. Install block_log_inserts first.
  2. Verify that COUNT(*), MAX(id) stops growing.
  3. Report the protected database path and fresh samples. Do not delete or vacuum rows.

In cleanup mode:

  1. Complete and verify protection first.
  2. Create a timestamped SQLite .backup and require a non-empty file plus a successful PRAGMA quick_check result.
  3. Delete log rows, vacuum, and checkpoint the WAL.
  4. Report the backup path and final file sizes.

In restore mode:

  1. Drop block_log_inserts.
  2. Sample COUNT(*), MAX(id) to confirm logging resumes or stays quiet.

Evidence Commands

Run direct shell/SQLite commands. Use only the needed subset for the user's request; do not paste a menu back to the user.

Inspect files:

bash
for db in ~/.codex/logs_2.sqlite ~/.codex/sqlite/logs_2.sqlite; do
  ls -lh "$db"* 2>/dev/null
  du -h "$db"* 2>/dev/null
done

After lsof identifies the active candidate, validate the selected path in the same shell command before running any later SQLite snippet:

bash
: "${CODEX_LOG_DB:?set CODEX_LOG_DB to the verified active candidate}"
case "$CODEX_LOG_DB" in
  "$HOME/.codex/logs_2.sqlite"|"$HOME/.codex/sqlite/logs_2.sqlite") ;;
  *) echo "refusing unexpected Codex log database path" >&2; exit 2 ;;
esac
readonly db="$CODEX_LOG_DB"

Do not supply a default. If no active path can be proven, stay in diagnose_only and report the ambiguity.

Check schema and trigger:

bash
sqlite3 "$db" ".tables"
sqlite3 "$db" "PRAGMA table_info(logs);"
sqlite3 "$db" "SELECT name, tbl_name, sql FROM sqlite_master WHERE type='trigger' AND name='block_log_inserts';"

Sample writes and growth:

bash
for i in 1 2 3; do
  date '+%F %T'
  sqlite3 "$db" "SELECT COUNT(*) AS rows, MIN(id) AS min_id, MAX(id) AS max_id FROM logs;"
  stat -f '%N %z bytes mtime=%Sm' "$db" "$db-wal" "$db-shm" 2>/dev/null
  sleep 10
done

Inspect levels and noisy targets:

bash
sqlite3 "$db" "SELECT level, COUNT(*) AS n, ROUND(SUM(estimated_bytes)/1024.0/1024.0, 1) AS estimated_mib FROM logs GROUP BY level ORDER BY n DESC;"
sqlite3 "$db" "SELECT target, level, COUNT(*) AS n, ROUND(SUM(estimated_bytes)/1024.0/1024.0, 1) AS estimated_mib FROM logs GROUP BY target, level ORDER BY n DESC LIMIT 15;"

Check open processes:

bash
lsof ~/.codex/logs_2.sqlite ~/.codex/logs_2.sqlite-wal ~/.codex/logs_2.sqlite-shm \
     ~/.codex/sqlite/logs_2.sqlite ~/.codex/sqlite/logs_2.sqlite-wal ~/.codex/sqlite/logs_2.sqlite-shm 2>/dev/null

Install protection:

bash
sqlite3 "$db" "PRAGMA busy_timeout=10000; CREATE TRIGGER IF NOT EXISTS block_log_inserts BEFORE INSERT ON logs BEGIN SELECT RAISE(IGNORE); END;"

Clean up after protection:

bash
backup="$db.bak.$(date +%Y%m%d-%H%M%S)"
sqlite3 "$db" ".backup '$backup'"
test -s "$backup"
test "$(sqlite3 "$backup" 'PRAGMA quick_check;')" = "ok"
sqlite3 "$db" "PRAGMA busy_timeout=10000; PRAGMA wal_checkpoint(TRUNCATE); DELETE FROM logs; VACUUM; PRAGMA wal_checkpoint(TRUNCATE);"
echo "$backup"

Restore persistent logging:

bash
sqlite3 "$db" "DROP TRIGGER IF EXISTS block_log_inserts;"

Diagnosis Rules

  • Missing all candidate logs_2.sqlite files: healthy/not applicable unless the user expects Codex to have run.
  • If multiple candidates exist, call out the active path from lsof; do not assume the top-level path is the only live database.
  • Trigger present and COUNT/MIN(id)/MAX(id) stable: protected.
  • Trigger absent and MIN(id) or MAX(id) moves: affected and actively writing.
  • If row ids move but file sizes do not materially increase, say "actively writing/churning" rather than "actively growing on disk".
  • Trigger absent, database large, high TRACE/DEBUG, but no sample movement: affected historically; recommend protection, cleanup optional.
  • Main DB or WAL above hundreds of MB: recommend cleanup after installing protection if the active path is affected.
  • WAL mtime or tiny WAL growth alone is not enough; use row/max-id samples.
  • If logs is absent or schema differs, stop and report that the known workaround is not safely applicable.

Safety Rules

  • Run read-only diagnosis before write operations unless the user explicitly asks for a specific command.
  • Do not claim the issue is fixed from file size alone; verify with COUNT(*), MAX(id) sampling.
  • Treat cleanup as reversible only through its timestamped backup. Mention the backup path in the final answer.
  • Do not delete backups automatically.
  • If SQLite reports lock or corruption errors, stop and report the exact error. Do not kill Codex processes unless the user explicitly asks.
  • This skill only manages Codex local SQLite diagnostic logs (~/.codex/logs_2.sqlite* and ~/.codex/sqlite/logs_2.sqlite*); it does not manage conversation archives, repo files, credentials, or remote telemetry.

Gotchas

  • COUNT(*) can stay constant while MIN(id) and MAX(id) move; classify this as churn, not a quiet database.
  • A WAL mtime change alone does not prove material disk growth.
  • Two database candidates may exist. Mutate only the path proven active or explicitly selected; never mirror a write to both paths by assumption.
  • Protection success does not authorize cleanup. Cleanup success requires a verified backup and fresh final sizes.
  • An unknown schema, lock error, failed backup check, or post-write verification failure is a hard error. Do not continue to the next mutation.

Answer Shape

Keep the user-facing answer short:

  1. One-line conclusion.
  2. Key evidence in 3-5 bullets.
  3. Recommended action and whether it was already applied.
  4. Backup path only if cleanup ran.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Codex Log Guard AI skill do?

Diagnose excessive Codex local SQLite diagnostic log writes with read-only evidence by default. Use when a user mentions logs_2.sqlite, logs_2.sqlite-wal, block_log_inserts, SSD/TBW wear, or explicitly asks to protect, clean up, verify, or restore Codex diagnostic logging.

Why use Codex Log Guard on TypingMind?

Because you install it once and use it with any model. Codex Log Guard is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Codex Log Guard in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/majiayu000/spellbook/tree/main/skills/codex-log-guard. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Codex Log Guard?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Codex Log Guard?

As many as you like. As long as a model supports skills, you can use Codex Log Guard with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Codex Log Guard AI skill free?

Yes. It is published on GitHub by majiayu000 under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇