KLYD
Decision memory for coding agents.
Coding agents can generate code quickly but often lose the architectural decisions that shaped a repository.
Klyd records, retrieves, and reintroduces those decisions so future agent sessions can work with the project's existing reasoning instead of repeatedly rediscovering it.
PyPI: klyd · GitHub · License: MIT
The problem
A coding agent may know the current files but not the reasons behind them:
- why a database choice was made;
- why a workaround exists;
- why an API must remain stable;
- why a previous approach was rejected;
- which architectural constraints are non-negotiable.
Without that context, agents can produce locally plausible changes that violate the system's existing design. Over multiple sessions, a codebase accumulates conflicting architectural patterns, turning into a patchwork of fragmented decisions.
The workflow
Klyd operates invisibly through standard Git hooks without requiring a background daemon or wrapping agent subprocesses with intrusive proxies:
graph TD
A[Developer commits] --> B["post-commit hook
kl extract-commit"]
B --> C["LLM Extraction
classify: NEW / REINFORCE / CONTRADICT"]
C -->|NEW or REINFORCE| D[("SQLite Store
.klyd/memory.db")]
C -->|CONTRADICT| E["Flagged for Review
kl review"]
E -->|Resolve: Accept / Merge / Edit| D
F[Agent stages changes] --> G["pre-commit hook
kl prepare-injection"]
G --> H["Single-pass query:
glob match + cosine similarity"]
H --> D
H --> I[".klyd/injection.txt
formatted context"]
I --> J["kl run aider
context injected"]
All state remains strictly local to .klyd/ inside the target git repository.
Example
A repository previously decided:
Authentication must remain inside the existing WebCrypto-based boundary. External token libraries must not be introduced.
Months later, an autonomous agent tasked with fixing an auth endpoint proposes adding a third-party token parser.
Before the change is committed, Klyd inspects the staged files, retrieves the earlier decision and its rationale from .klyd/memory.db, and injects the constraint directly into the agent's context window. The agent refactors the code within the established WebCrypto pattern instead of introducing an incompatible dependency.
(Note: This is an illustrative example of an architectural boundary constraint captured from commit history and reintroduced to guide subsequent agent turns).
Technical design
Klyd currently uses:
- SQLite for persistent decision storage: Embedded relational database maintaining schema versions, embeddings, and decision records.
- Git hooks for repository lifecycle integration:
post-commitextracts decisions asynchronously from diffs;pre-commitprepares context from staged changes. - Semantic similarity for retrieval: Optional vector embeddings paired with lexical glob matching for relevant context ranking.
- Recursive decision ancestry: Tracking parent-child relationships across decision versions using recursive Common Table Expressions.
- Conflict resolution between related decisions: Interactive terminal UI (
kl review) supporting accept, reject, manual edit, and LLM-assisted decision merging. - Multiple model-provider integrations: Bring-Your-Own-Key (BYOK) support for Anthropic, OpenAI, OpenRouter, Google Gemini, and Groq.
- CLI-oriented workflow for coding-agent environments: Direct compatibility flags for tools like
aiderandopencode.
Design choice: SQLite
SQLite keeps the decision history:
- local to the repository or workspace;
- inspectable with standard SQL tools or CLI commands;
- easy to back up by copying
.klyd/; - usable without requiring any cloud service, daemon, or database server;
- available to low-latency command-line workflows and shell scripts.
The trade-off is that Klyd prioritizes local developer infrastructure and explicit Git workflow integration over centralized multi-user cloud coordination.
Engineering details
In-database custom multi-glob matching
When staged files are evaluated (e.g. auth/login.py), Klyd must match them against comma-separated glob patterns (e.g. auth/*, security/*) stored in the decisions table. Standard SQL lacks native glob-list evaluation, and loading all rows into Python memory for full-table scanning creates unnecessary overhead.
Klyd solves this by registering a custom Python callback function (match_files) directly into the SQLite C-runtime using sqlite3.Connection.create_function:
def _match_any_file(file_patterns: str, file_list_str: str) -> int:
patterns = [p.strip() for p in file_patterns.split(",")]
files = file_list_str.split("|")
for f in files:
for p in patterns:
if fnmatch.fnmatch(f, p):
return 1
return 0
conn.create_function("match_files", 2, _match_any_file)
This allows the SQLite query planner to filter rows atomically in a single pass at the database layer before sorting by relevance and recency.
Decision lineage with recursive CTEs
When conflicting decisions are merged or updated during human review, older decisions are soft-archived rather than overwritten. Lineage is tracked through parent_decision_id, allowing complete evolutionary trees to be reconstructed using recursive Common Table Expressions:
WITH RECURSIVE ancestors(id, decision, parent_decision_id) AS (
SELECT id, decision, parent_decision_id FROM decisions WHERE id = ?
UNION ALL
SELECT d.id, d.decision, d.parent_decision_id
FROM decisions d JOIN ancestors a ON d.id = a.parent_decision_id
)
SELECT * FROM ancestors;
Quickstart
1. Install Klyd
0.2.3 is not on PyPI yet. The published 0.2.2 wheel is missing its hook templates and SQL schema, so
pip install klydinstalls a CLI that cannot initialise a repository. Until 0.2.3 ships, install from this branch:git clone -b fix/clean-install-audit https://github.com/klyd-studio/klyd-harness cd klyd-harness pip install .
Once 0.2.3 is released:
pip install klyd
2. Initialize a repository
Run inside the root of your Git repository:
kl init
This creates .klyd/memory.db, initializes the configuration file, and installs the Git hooks into .git/hooks/.
3. Configure a model provider
Set your preferred API key (BYOK):
kl config --api-key sk-ant-...
# or: kl config --openai-key sk-...
# or: kl config --gemini-key ...
# or: kl config --groq-key ...
Inspect active configuration:
kl config --show
4. Record decisions from commits
Decisions are automatically extracted by the post-commit hook whenever you make a Git commit:
git commit -m "refactor(db): use SQLite connection pooling instead of global instances"
You can also trigger extraction manually for the latest commit:
kl extract-commit
5. Retrieve relevant decisions
View stored architectural decisions in a table:
kl status
Filter decisions by search keyword:
kl status --search "database"
View decisions grouped by module hierarchy:
kl status --tree
6. Run an agent with decision memory
Launch your coding agent wrapped with Klyd context:
kl run aider
For custom agent invocations, generate the injection context directly:
kl prepare-injection
# Context is written to .klyd/injection.txt
Commands reference
| Command | Description |
|---|---|
kl init |
Initialise .klyd/ storage and install Git hooks. |
kl config |
Configure model API keys, templates, and extraction thresholds. |
kl extract-commit |
Extract architectural decisions from the latest Git commit. |
kl prepare-injection |
Query matching decisions for staged files and generate .klyd/injection.txt. |
kl preview-injection |
Preview the injection prompt without writing it to disk. |
kl status |
Display active decisions, conflict summaries, and drift statistics. |
kl review |
Interactive CLI to resolve flagged architectural conflicts (accept, merge, edit, reject). |
kl pin <id> |
Pin a non-negotiable architectural constraint so it is always injected. |
kl unpin <id> |
Remove a pinned decision constraint. |
kl run <agent> |
Execute a coding agent with memory injected via command-line arguments. |
kl metrics |
Display aggregated decision counts, average confidence, and conflict rates. |
Current status
Klyd is an actively developed developer-tooling project (v0.2.2 distributed on PyPI).
The current implementation is focused on local decision persistence, retrieval, Git lifecycle integration, and terminal coding-agent workflows.
- Local scope: Designed for single-developer repository workspaces. Remote peer sync and multi-user concurrent locking are not included.
- LLM extraction dependency: Quality of extracted decisions correlates with commit message clarity and the reasoning capabilities of the configured model.
- Agent support: Native argument injection is configured for
aiderandopencode; other agents consume.klyd/injection.txtvia their respective context-file arguments.
License
MIT License — see LICENSE.
Metadata
Release files for klyd 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| klyd-0.2.3.tar.gz | 37.2 kB | Without provenance | Details for klyd-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| klyd-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for klyd-0.2.3-py3-none-any.whl |
Total release size: 73.5 kB
Release files / klyd-0.2.3.tar.gz
| Download URL | klyd-0.2.3.tar.gz |
|---|---|
| Size | 37.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4dcd486bcc62aa0914edee2768a6f571d2807b895470e568f4db2ecfed03acb6
|
|
BLAKE2b-256 checksum How to use checksums |
d8cae367a551fc705fd30128d098f1a3fee6ded854c8178957ea86e1ec6ca7b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / klyd-0.2.3-py3-none-any.whl
| Download URL | klyd-0.2.3-py3-none-any.whl |
|---|---|
| Size | 36.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc5dacff33b592120be477822bea0850eb01b2758d0d21a28aa21adbfc939b28
|
|
BLAKE2b-256 checksum How to use checksums |
82cd5d712e08b1aa5b38c431e622c227f8f3e9abe74d7c50188b420f071baf8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for klyd 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.