| name | codex-hygiene-skill |
| description | Audit and tune Codex Desktop context surfaces, tool availability, and token usage through telemetry measurement |
| triggers | ["measure my Codex context usage","check Codex tool availability","audit token usage in this thread","show me Codex telemetry stats","analyze Codex Desktop performance","review MCP server status","optimize Codex context size","check why Codex is slow"] |
Codex Hygiene Skill
Skill by ara.so — Codex Skills collection.
This skill provides expertise in using codex-hygiene, a tool for auditing and tuning Codex Desktop context and tool surfaces. It measures recent telemetry, reviews MCP/app/skill availability, and helps keep long-running goal workflows scoped to current work.
What Codex Hygiene Does
Codex Hygiene is a diagnostic skill that:
- Measures token usage: Queries Codex Desktop SQLite telemetry databases to show recent token consumption per thread and window
- Audits tool availability: Distinguishes actual tool calls from tool availability, enabled state from cached inventory
- Identifies bottlenecks: Helps correlate elevated usage with app surface size, MCP/plugin state, snapshot reuse, stale project stanzas, long-thread replay, or background fan-out
- Suggests reversible hygiene: Recommends cleanup steps without deleting logs, caches, or projects
- Maintains quality: Keeps long-running goal work quality-aware by narrowing replay and tool scope
Installation
Install codex-hygiene into your Codex skills directory:
mkdir -p "$HOME/.agents/skills"
git clone https://github.com/sunflower-of-parchman/codex-hygiene.git \
"$HOME/.agents/skills/codex-hygiene"
After installation, invoke the skill with $codex-hygiene. Codex normally detects newly installed skills automatically. Restart Codex Desktop if the skill doesn't appear.
Key Commands
Measure Context Usage
The primary command is measure_codex_context.sh, which queries Codex telemetry:
"$HOME/.agents/skills/codex-hygiene/scripts/measure_codex_context.sh"
"$HOME/.agents/skills/codex-hygiene/scripts/measure_codex_context.sh" 5
"$HOME/.agents/skills/codex-hygiene/scripts/measure_codex_context.sh" 30
"$HOME/.agents/skills/codex-hygiene/scripts/measure_codex_context.sh" 5 <thread_id>
Script Parameters
- First argument: Number of recent entries to examine (default: recent activity)
- Second argument: Specific thread ID to analyze (optional)
Environment Variables
export CODEX_HOME="$HOME/.codex-custom"
export SKILL_DIR="$HOME/my-custom-path/codex-hygiene"
Understanding Output
The measurement script provides compact counts covering:
Token Telemetry
- Input tokens by thread
- Output tokens by thread
- Total tokens per interaction
- Window-level aggregates
Tool Availability
- Number of tools reported as available
- Tools actually called
- MCP servers enabled vs. cached
- App integrations active
Context Sources
- Snapshot reuse frequency
- Project stanza count
- Thread replay depth
- Background task count
Safety note: The script does NOT dump full logs, configs, tool schemas, secrets, or environment values.
Configuration
Codex Configuration File
Codex Hygiene reads but does not modify ~/.codex/config.toml. Always back up before manual edits:
cp ~/.codex/config.toml ~/.codex/config.toml.backup
cat ~/.codex/config.toml | grep -A 10 "\[mcp\]"
Custom Data Locations
If your Codex data lives elsewhere:
export CODEX_HOME="/path/to/codex/data"
"$SKILL_DIR/scripts/measure_codex_context.sh"
Common Patterns
Diagnose High Token Usage
SKILL_DIR="$HOME/.agents/skills/codex-hygiene"
"$SKILL_DIR/scripts/measure_codex_context.sh" 10
Audit MCP Server State
codex mcp list
cat ~/.codex/config.toml | grep -A 5 "\\[mcp.servers"
"$SKILL_DIR/scripts/measure_codex_context.sh" 5
Optimize Long-Running Threads
For threads with elevated token usage:
"$SKILL_DIR/scripts/measure_codex_context.sh" 20 thread_abc123
cat "$SKILL_DIR/references/long-thread-replay.md"
Pre-Deploy Hygiene Check
Before starting a large goal or project:
"$SKILL_DIR/scripts/measure_codex_context.sh" 5
codex mcp list
Real Code Examples
Shell Integration
#!/bin/bash
codex_measure() {
local skill_dir="$HOME/.agents/skills/codex-hygiene"
if [ -d "$skill_dir" ]; then
"$skill_dir/scripts/measure_codex_context.sh" "${1:-10}"
else
echo "codex-hygiene not installed"
fi
}
Pre-Commit Hook
#!/bin/bash
SKILL_DIR="$HOME/.agents/skills/codex-hygiene"
if [ -f "$SKILL_DIR/scripts/measure_codex_context.sh" ]; then
echo "Running Codex hygiene check..."
"$SKILL_DIR/scripts/measure_codex_context.sh" 3
fi
Periodic Monitoring Script
#!/bin/bash
SKILL_DIR="$HOME/.agents/skills/codex-hygiene"
LOG_FILE="$HOME/.codex-hygiene-history.log"
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
echo "=== $timestamp ===" >> "$LOG_FILE"
"$SKILL_DIR/scripts/measure_codex_context.sh" 5 >> "$LOG_FILE" 2>&1
echo "" >> "$LOG_FILE"
tail -50 "$LOG_FILE"
Troubleshooting
Script Not Found
Problem: command not found: measure_codex_context.sh
Solution:
ls "$HOME/.agents/skills/codex-hygiene/scripts/"
SKILL_DIR="$HOME/.agents/skills/codex-hygiene"
"$SKILL_DIR/scripts/measure_codex_context.sh"
export PATH="$HOME/.agents/skills/codex-hygiene/scripts:$PATH"
SQLite Database Locked
Problem: database is locked
Solution:
"$SKILL_DIR/scripts/measure_codex_context.sh" 5
No Telemetry Data
Problem: Script shows no data or zero counts
Solution:
ls -lh ~/.codex/telemetry.db
echo $CODEX_HOME
jq or codex CLI Not Found
Problem: Optional tools missing
Solution:
brew install jq
sudo apt-get install jq
sudo yum install jq
which codex
Permission Denied
Problem: Cannot read telemetry database
Solution:
ls -l ~/.codex/telemetry.db
chmod 644 ~/.codex/telemetry.db
ls -l ~/.codex/
Advanced Usage
Custom Telemetry Queries
The measurement script uses read-only SQLite queries. You can run custom queries:
sqlite3 -readonly ~/.codex/telemetry.db
.tables
.schema
SELECT COUNT(*) FROM interactions;
.quit
Combining with Other Tools
"$SKILL_DIR/scripts/measure_codex_context.sh" 20 | \
awk '/tokens/{print}' | \
tee codex-usage.txt
watch -n 5 "$SKILL_DIR/scripts/measure_codex_context.sh" 3
"$SKILL_DIR/scripts/measure_codex_context.sh" 5 > before.txt
"$SKILL_DIR/scripts/measure_codex_context.sh" 5 > after.txt
diff before.txt after.txt
References
The skill includes detailed references:
- references/remediation.md: Step-by-step cleanup recommendations
- references/long-thread-replay.md: Managing token usage in long conversations
cat "$HOME/.agents/skills/codex-hygiene/references/remediation.md"
cat "$HOME/.agents/skills/codex-hygiene/references/long-thread-replay.md"
Safety & Best Practices
- Read-only by default: Scripts use
sqlite3 -readonly flag
- No secrets dumped: Output excludes configs, schemas, env vars, API keys
- Backup configs: Always backup
~/.codex/config.toml before editing
- Reversible actions: Recommendations focus on disable/restart, not delete
- Version awareness: Telemetry schemas may change across Codex versions
Testing
Run the included test suite:
cd "$HOME/.agents/skills/codex-hygiene"
bash tests/measure_codex_context_test.sh
Compatibility
- OS: macOS, Linux, Unix-like systems
- Requirements: Bash,
sqlite3, Perl, awk, sort
- Optional:
jq, codex CLI for enhanced app-cache and plugin summaries
- Codex: Designed for Codex Desktop with local telemetry databases
When to Use This Skill
Use codex-hygiene when:
- Codex Desktop feels slow or unresponsive
- Token usage seems unexpectedly high
- You want to audit which tools are actually being called
- Long-running threads are accumulating context
- You're debugging MCP server configuration
- You need to optimize before a large coding session
- You want visibility into Codex's internal state
Project: sunflower-of-parchman/codex-hygiene
License: MIT