Documentation // Klyd

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.

The Problem

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.

The Solution

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 & Setup01

Installation

Install from PyPI:

bash
pip install klyd

Verify installation:

bash
kl --help

Requirements

  • Python 3.11+
  • Click
  • Anthropic
  • Git repository

Providers

AnthropicOpenAIOpenRouterGeminiGroq

Quickstart

Initialize in your project repository:

bash
kl init

Configure your API key:

bash
kl config --api-key sk-ant-...

Make commits with architectural decisions, then check status:

bash
kl status

Run your agent with injected memory:

bash
kl run aider

This creates a local .klyd/memory.db SQLite database and installs post-commit and pre-commit Git hooks.

Configuration02

BYOK — Bring Your Own Key

Anthropic (Default)

bash
kl config --api-key sk-ant-... --model claude-sonnet-4-6

OpenAI

bash
kl config --openai-key sk-proj-... --model gpt-4o

OpenRouter

bash
kl config --openrouter-key sk-or-... --model openrouter/free

View Config

bash
kl config --show
Command Reference03
kl run <agent>

Runs a coding agent with injected memory. Prepares the context window with relevant architectural decisions before the agent writes files.

kl status

Views the current decision memory store. Shows active decisions, confidence levels, and flagged architectural conflicts.

kl review

Interactive command to accept, reject, edit, or skip flagged conflicts. Manual override for incorrect LLM extractions.

kl config

Configure API keys and model settings. Supports Anthropic, OpenAI, OpenRouter, Gemini, and Groq providers.

kl extract-commit

Manually trigger decision extraction for the last commit. Usually called automatically by the post-commit hook.

kl prepare-injection

Generate the injection file for agent sessions. Usually called automatically by the pre-commit hook. Outputs to .klyd/injection.txt.

Under the Hood04

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

  1. 01Get diff: git diff HEAD~1 HEAD
  2. 02Get commit message: git log -1 --format=%B
  3. 03Get touched files
  4. 04Query existing decisions for those files
  5. 05Call LLM with prompt
  6. 06Store results: NEW, REINFORCE, or CONTRADICT

Injection Flow

  1. 01Get staged files: git diff --cached --name-only
  2. 02Query top-k decisions for those files (excludes flagged, archived)
  3. 03Format as injection message
  4. 04Write to .klyd/injection.txt