How mqthys62/cork-ai works
cork-ai is a Claude Code companion that intercepts file reads, selectively substitutes outlines for whole-file content, and reports context-related costs and savings. Its principal workflow runs from Claude Code tool events through the hook’s read decision and outline response; a separate context guard estimates the cost of growing context and can issue threshold notices. The repository also contains a public SDK compression pipeline with budget management, validation, and statistics. The CLI and pipeline relationships are supported by excerpts or the source index; SDK compressor dispatch details were not sampled, so those connections are shown as unverified.
Main entry points: hook.ts Tool hook · index.ts CLI commands · pipeline.ts SDK pipeline · context-guard.ts Context guard
Components 23
CLI and settings
- CLI commands
src/cli/index.ts - Hook settings
src/cli/claude-settings.ts - Configuration
src/cli/config.ts
Hook processing
- Tool hook
src/cli/hook.ts - Bash read handling
src/cli/bash-read.ts - File eligibility
src/cli/file-eligibility.ts - Read policy
src/cli/policy.ts - File outlines
src/cli/outline.ts
Cost and analytics
- Context guard
src/cli/context-guard.ts - Transcript usage
src/cli/transcript-usage.ts - Model pricing
src/pricing/index.ts - Savings analysis
src/cli/savings.ts - Persistent statistics
src/cli/persistent-stats.ts - Telemetry
src/cli/telemetry.ts
SDK compression
- SDK pipeline
src/sdk/core/pipeline.ts - Budget manager
src/sdk/managers/budget.ts - Compression modules
src/sdk/compressors - Tool pairing validation
src/sdk/core/validate.ts - SDK statistics
src/sdk/stats/tracker.ts
Shared primitives
- Token counting
src/core/tokenizer.ts - Atomic file helpers
src/cli/fs-utils.ts
Other components
- Claude Code
- CLI operator
Connections 23
- CLI operator → CLI commands: runs commands
- CLI commands → Hook settings: manages hooks
src/cli/index.ts - CLI commands → Tool hook: installs hooks
src/cli/index.ts - Claude Code → Tool hook: sends tool events
- Tool hook → Bash read handling: handles shell reads
src/cli/hook.ts - Tool hook → File eligibility: checks files
src/cli/hook.ts - Tool hook → Read policy: evaluates policy
src/cli/hook.ts - Tool hook → File outlines: returns outline
src/cli/hook.ts - Tool hook → Context guard: checks context
src/cli/hook.ts - Claude Code → Tool hook: receives outline
- Context guard → Transcript usage: reads usage
src/cli/context-guard.ts - Context guard → Model pricing: estimates cost
src/cli/context-guard.ts - Context guard → Atomic file helpers: persists guard state
src/cli/context-guard.ts - CLI commands → Persistent statistics: reads session stats
src/cli/index.ts - CLI commands → Configuration: loads settings
src/cli/index.ts - Savings analysis → Persistent statistics: reads savings data
src/cli/savings.ts - Transcript usage → Model pricing: calculates usage cost
src/cli/transcript-usage.ts - Persistent statistics → Model pricing: prices saved tokens
src/cli/persistent-stats.ts - SDK pipeline → Budget manager: compresses to budget
src/sdk/core/pipeline.ts - SDK pipeline → Token counting: counts tokens
src/sdk/core/pipeline.ts - SDK pipeline → Tool pairing validation: validates output
src/sdk/core/pipeline.ts - SDK pipeline → SDK statistics: records module stats
src/sdk/core/pipeline.ts - Budget manager → Compression modules: dispatches compression
src/sdk/managers/budget.ts