count-claude-config.jsā¢3.26 kB
#!/usr/bin/env node
import { readFile } from 'fs/promises';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
// Import the TokenMeasurementEngine from the deprecated analyzer
const deprecatedPath = '/home/cordlesssteve/projects/Utility/DEV-TOOLS/mcp-workspace/archive/deprecated-token-analyzer/src/TokenMeasurementEngine.js';
const { TokenMeasurementEngine } = await import(deprecatedPath);
async function countClaudeConfigTokens() {
console.log('š Counting tokens in CLAUDE.md and all imports...\n');
const engine = new TokenMeasurementEngine();
const configBase = '/home/cordlesssteve/.claude';
// Read all config files
const files = [
{ path: `${configBase}/CLAUDE.md`, name: 'CLAUDE.md' },
{ path: `${configBase}/config/intellectual-honesty.md`, name: 'intellectual-honesty.md' },
{ path: `${configBase}/config/verification-protocols.md`, name: 'verification-protocols.md' },
{ path: `${configBase}/config/file-organization.md`, name: 'file-organization.md' },
{ path: `${configBase}/config/backup-systems.md`, name: 'backup-systems.md' },
{ path: `${configBase}/config/mcp-discovery-protocol.md`, name: 'mcp-discovery-protocol.md' },
{ path: `${configBase}/config/anti-pattern-guardrails.md`, name: 'anti-pattern-guardrails.md' }
];
let totalTokens = 0;
let totalChars = 0;
const results = [];
for (const file of files) {
try {
const content = await readFile(file.path, 'utf-8');
const tokens = engine.approximateTokenCount(content);
const chars = content.length;
totalTokens += tokens;
totalChars += chars;
results.push({
name: file.name,
tokens,
chars,
percentage: 0 // Will calculate after we have total
});
console.log(`ā ${file.name.padEnd(30)} ${tokens.toLocaleString().padStart(6)} tokens (${chars.toLocaleString()} chars)`);
} catch (error) {
console.log(`ā ${file.name.padEnd(30)} ERROR: ${error.message}`);
}
}
// Calculate percentages
results.forEach(r => {
r.percentage = ((r.tokens / totalTokens) * 100).toFixed(1);
});
console.log('\n' + 'ā'.repeat(70));
console.log(`Total: ${totalTokens.toLocaleString()} tokens (${totalChars.toLocaleString()} characters)`);
console.log('ā'.repeat(70));
console.log(`\nš Context Window Analysis:`);
console.log(` Total config tokens: ${totalTokens.toLocaleString()}`);
console.log(` Context window size: 200,000 tokens`);
console.log(` Config overhead: ${((totalTokens / 200000) * 100).toFixed(2)}%`);
console.log(` Remaining context: ${(200000 - totalTokens).toLocaleString()} tokens`);
console.log(`\nš Breakdown by file:`);
results
.sort((a, b) => b.tokens - a.tokens)
.forEach(r => {
console.log(` ${r.name.padEnd(30)} ${r.percentage.padStart(5)}% (${r.tokens.toLocaleString()} tokens)`);
});
console.log(`\nš” Token Estimation Method:`);
console.log(` Using character-based approximation (~3.5-4 chars/token for technical content)`);
console.log(` This is the same method used by the deprecated-token-analyzer`);
}
countClaudeConfigTokens().catch(error => {
console.error('ā Error:', error.message);
process.exit(1);
});