A CLI tool that wraps coding agents via git hooks to inject architectural memory.
Project description
klyd
888 / 888 Y88b / 888~-_
888 / 888 Y88b / 888 \
888/\ 888 Y88b/ 888 |
888 \ 888 Y8Y 888 |
888 \ 888 Y 888 /
888 \ 888____ / 888_-~
An open-source project, not affiliated with the Klyd SaaS
What is klyd?
klyd is a decision memory harness for terminal coding agents (aider, opencode, claude code). It wraps your agent workflow to inject persistent architectural memory into every session.
The Problem
Agentic coding tools fail in a specific, reproducible way:
- Agent writes a file
- Something breaks (test, CI)
- Agent patches the nearest thing to make the signal go green
- It doesn't fix the root — it satisfies the metric
- Next session: agent reads the patched code as ground truth, builds on top of it
- After ~20 turns: slop fortress — a codebase that compiles but nobody understands
This is not a model quality problem. It's a memory and context architecture problem.
The Solution
klyd extracts architectural decisions from every commit and injects them into your agent's context at the exact moment of file write — when architectural damage happens.
- Two LLM calls per commit cycle maximum
- All state lives in
.klyd/(local to your repo) - BYOK — bring your own API key
- Zero infrastructure — no cloud, no servers
Installation
# From PyPI (recommended)
pip install klyd
# Or from source
pip install .
After installation, verify:
kl --help
Quickstart
# 1. Initialize in your project repository
cd your-project
kl init
# 2. Configure your API key
kl config --api-key sk-ant-...
# 3. Make commits with architectural decisions
# (e.g., adding auth, changing DB, adopting a new library)
# 4. Check extracted decisions
kl status
# 5. Run your agent with injected memory
kl run aider
Configuration
klyd supports multiple LLM providers via BYOK (Bring Your Own Key).
Anthropic (Default)
kl config --api-key sk-ant-... --model claude-sonnet-4-6
OpenAI
kl config --openai-key sk-proj-... --model gpt-4o
OpenRouter
kl config --openrouter-key sk-or-... --model openrouter/free
Google Gemini
kl config --gemini-key AIza... --model gemini-1.5-pro
Groq
kl config --groq-key gsk_... --model llama3-8b-8192
View Current Configuration
kl config --show
Commands
kl init
Initialize klyd in the current git repository.
kl init
This:
- Creates
.klyd/directory - Initializes SQLite database at
.klyd/memory.db - Installs git hooks (post-commit, pre-commit)
- Creates default config at
.klyd/config.json
kl config
Configure klyd settings.
# Set API key
kl config --api-key sk-ant-...
# Set model
kl config --model claude-sonnet-4-6
# Show current config
kl config --show
kl status
View the current decision memory store.
kl status
Shows:
- Active decisions (sorted by reinforcement count)
- Confidence levels (HIGH/MEDIUM/LOW)
- Event types (NEW/REINFORCE/CONTRADICT)
- Flagged conflicts requiring review
kl run <agent>
Run a coding agent with injected architectural memory.
kl run aider --message "Add user authentication"
kl run opencode
Options:
--no-inject- Skip generating injection file
The agent receives your stored architectural decisions as context, preventing contradiction of established patterns.
kl review
Review flagged conflicting decisions.
kl review
When klyd detects a CONTRADICT (a new decision that conflicts with existing memory), it flags it for human review. This interactive command lets you:
- Accept new decision (archive old)
- Reject new decision (keep old)
- Edit decision manually
- Skip for now
kl extract-commit
Manually trigger decision extraction for the last commit.
kl extract-commit
Usually called automatically by the post-commit hook.
kl prepare-injection
Generate the injection file for agent sessions.
kl prepare-injection
Usually called automatically by the pre-commit hook. Outputs to .klyd/injection.txt.
How It Works
Git Hooks
klyd installs two git hooks:
post-commit (hooks/post-commit.sh):
#!/bin/sh
kl extract-commit >> .klyd/errors.log 2>&1 || true
After every commit, extracts architectural decisions via LLM and stores them in SQLite.
pre-commit (hooks/pre-commit.sh):
#!/bin/sh
kl prepare-injection >> .klyd/errors.log 2>&1 || true
Before files are committed, queries relevant decisions and writes injection file.
Extraction Flow
- Get diff:
git diff HEAD~1 HEAD - Get commit message:
git log -1 --format=%B - Get touched files
- Query existing decisions for those files
- Call LLM with prompt
- Store results:
- NEW →
store_decision() - REINFORCE →
reinforce_decision()on matching existing - CONTRADICT →
store_decision()withflagged=True
- NEW →
Injection Flow
- Get staged files:
git diff --cached --name-only - Query top-k decisions for those files (excludes flagged, archived)
- Format as injection message
- Write to
.klyd/injection.txt
Decision Schema
CREATE TABLE decisions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
decision TEXT NOT NULL,
module TEXT NOT NULL,
file_patterns TEXT NOT NULL,
confidence TEXT NOT NULL, -- LOW | MEDIUM | HIGH
event_type TEXT NOT NULL, -- NEW | REINFORCE | CONTRADICT
reinforcement_count INTEGER DEFAULT 1,
last_seen_commit TEXT,
created_at TEXT DEFAULT (datetime('now')),
flagged INTEGER DEFAULT 0, -- 1 = needs human review
archived INTEGER DEFAULT 0 -- 1 = soft-deleted
);
Examples
Example 1: First-Time Setup
$ cd my-project
$ kl init
# Configure with your API key
$ kl config --api-key sk-ant-...
# Make your first architectural commit
$ echo "import sqlite3" > db.py
$ git add db.py && git commit -m "feat: add sqlite for data storage"
# Check extracted decisions
$ kl status
Example 2: Resolving Conflicts
# Make a commit that contradicts existing decision
$ echo "import mongoengine" > nosql.py
$ git add nosql.py && git commit -m "feat: switch to mongodb"
# LLM detects contradiction, flags for review
$ kl status
# Shows flagged decision in NEEDS REVIEW section
$ kl review
# Interactive resolution
Example 3: Running Agent with Memory
# Inject memory and run aider
$ kl run aider --message "Add user login to the app"
# Agent receives your architectural decisions as context
# Won't contradict established patterns (e.g., "use SQLite, not sessions")
File Structure
your-project/
├── .klyd/ # klyd's working directory
│ ├── memory.db # SQLite decision store
│ ├── config.json # Your API keys & settings
│ ├── injection.txt # Generated for agent sessions
│ └── errors.log # Error logs
├── .git/hooks/
│ ├── post-commit # Installed by kl init
│ └── pre-commit # Installed by kl init
└── [your project files]
Troubleshooting
"klyd is not initialized. Run kl init."
kl init
API Key Errors
Check your config:
kl config --show
Ensure the key is correct. Errors are logged to .klyd/errors.log.
No Decisions Extracted
- Make commits with clear architectural changes (not just style fixes)
- Ensure API key has credits/quota
- Check
.klyd/errors.logfor details
Hook Not Firing
Verify hooks are installed:
ls -la .git/hooks/post-commit
ls -la .git/hooks/pre-commit
If missing, re-run:
kl init
Requirements
- Python 3.11+
- click
- anthropic
- Git repository
License
MIT License - see LICENSE file.
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file klyd-0.2.1.tar.gz.
File metadata
- Download URL: klyd-0.2.1.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07384ddc4c1a94c3193977b3fb05094ccbbfd47c27dcd00fa5597552e6287573
|
|
| MD5 |
4ae7254a0022b1d6ed24f68e5d2b3049
|
|
| BLAKE2b-256 |
dc671b4535809c1ca6bb7aa591d9df259a012dba9c83779b3591e0f71f7c65e4
|
File details
Details for the file klyd-0.2.1-py3-none-any.whl.
File metadata
- Download URL: klyd-0.2.1-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcb0aa1bc89e1b1c5d311b7196d7b7e9cdcef9c9520ada5a180d0e4ca61e02f1
|
|
| MD5 |
6a1751a894bea34807ba4155e7200902
|
|
| BLAKE2b-256 |
3357a68f988bcacdd70b9572616dcaf526c04989105c992eb1c93e63f2c18813
|