The harness that stops terminal coding agents from silently drifting your architecture.
Klyd is an open-source decision memory harness for terminal coding agents like Aider, OpenCode, and Claude Code. It extracts architectural decisions at commit time and reinjects them into the agent's context when files are written.
Slop fortresses build one green CI at a time.
Terminal coding agents patch code just to make CI go green. Without architectural memory, each fix is locally optimal and globally destructive. Over time, this creates "slop fortresses" — codebases where no human understands the structure, and no agent can safely modify anything without breaking something else.
Commit-level decision memory.
Klyd extracts decisions from every commit via an LLM and stores them in a local SQLite database. Before the agent writes files, Klyd queries the top relevant decisions and injects them into context. The agent now knows the architectural rules before it breaks them.
Installation
Install from PyPI:
pip install klydVerify installation:
kl --helpRequirements
- Python 3.11+
- Click
- Anthropic
- Git repository
Providers
Quickstart
Initialize in your project repository:
kl initConfigure your API key:
kl config --api-key sk-ant-...Make commits with architectural decisions, then check status:
kl statusRun your agent with injected memory:
kl run aiderThis creates a local .klyd/memory.db SQLite database and installs post-commit and pre-commit Git hooks.
BYOK — Bring Your Own Key
Anthropic (Default)
kl config --api-key sk-ant-... --model claude-sonnet-4-6OpenAI
kl config --openai-key sk-proj-... --model gpt-4oOpenRouter
kl config --openrouter-key sk-or-... --model openrouter/freeView Config
kl config --showkl run <agent>Runs a coding agent with injected memory. Prepares the context window with relevant architectural decisions before the agent writes files.
kl statusViews the current decision memory store. Shows active decisions, confidence levels, and flagged architectural conflicts.
kl reviewInteractive command to accept, reject, edit, or skip flagged conflicts. Manual override for incorrect LLM extractions.
kl configConfigure API keys and model settings. Supports Anthropic, OpenAI, OpenRouter, Gemini, and Groq providers.
kl extract-commitManually trigger decision extraction for the last commit. Usually called automatically by the post-commit hook.
kl prepare-injectionGenerate the injection file for agent sessions. Usually called automatically by the pre-commit hook. Outputs to .klyd/injection.txt.
Two hooks. One harness.
post-commit
After every commit, the hook sends the diff to an LLM and extracts architectural decisions. Stored in .klyd/memory.db with confidence scores. Conflicts are flagged for review.
pre-commit
Before the agent writes files, the hook queries top-k relevant decisions from the memory store. Writes an injection file into the agent's context so it knows constraints before generating code.
Efficiency
Maximum 2 LLM calls per commit — one for extraction, one for conflict detection. All state lives locally. No cloud dependency, no sync latency, no vendor lock-in.
Extraction Flow
- 01Get diff: git diff HEAD~1 HEAD
- 02Get commit message: git log -1 --format=%B
- 03Get touched files
- 04Query existing decisions for those files
- 05Call LLM with prompt
- 06Store results: NEW, REINFORCE, or CONTRADICT
Injection Flow
- 01Get staged files: git diff --cached --name-only
- 02Query top-k decisions for those files (excludes flagged, archived)
- 03Format as injection message
- 04Write to .klyd/injection.txt