Code Refinements logo

Code Refinements

Community
alexandru
code-refinements

Defines what refined code looks like through the three lenses of constraints, simplicity, and parametricity, with rules for type proofs, no partial calls, explicit signatures, unrepresentable wrong states, hot-path discipline, and style. Use when writing, changing, or reviewing code to a refinement bar, or whenever the user asks for code to follow the rules in code-refinements.

Overview

Publisheralexandru
Repositoryskills
Skill namecode-refinements
Stars
51
Forks
3
Bundled files
1
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by alexandru on GitHub. Read the source before you install it.

Installation

Install the Code Refinements AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/alexandru/skills/tree/main/skills/engineering/code-refinements
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/alexandru/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/skills/engineering/code-refinements .claude/skills/code-refinements
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Code Refinements in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Code Refinements on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Code Refinements is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Code Refinements

Refined code does the same job with less design: fewer states that can be wrong, fewer concerns braided together, fewer properties resting on discipline. What it does without is nameable — a runtime check, a branch, a partial call, a parameter, a stored field, a duplicate definition, a dependency between two components, a convention the reader had to remember — and every type or abstraction it carries earns its keep by the checks and conventions it makes unnecessary. Line count is not the measure: fewer lines often accompany refinement, but code shrunk to fit a count is not refined.

The deepest refinement is in the model, not in the tidiness: a core data model in which the invalid states cannot be written, one pass where a lesser design needs two, no module beyond what the job needs, a contract carried by signatures, with no checks needed on either side. Edge cases belong to the model, not to the branches: a check, a table entry or a branch per case is complexity, not refinement.

Lenses

Each lens asks one question and names a different kind of complexity.

Constraints (Bjarnason, "Constraints Liberate, Liberties Constrain")

What freedom can we remove so fewer incorrect implementations are possible?

The more a piece of code can do, the less a reader can predict what it will do. Freedom at one level becomes constraint at the next. A function allowed to return an empty list forces every caller to handle one; a function allowed to mutate shared state forces every reader to track it. Pick the least powerful type, signature or abstraction that still does the job, and put the constraint where the value is created, so the checks it replaces disappear downstream.

In refined code, invalid states do not compile, so no check guards against them. Unrefined code shows invalid states the types allow, invariants held up by runtime checks or convention (a first element taken after an emptiness guard, flags that must agree with other fields), types wider than the values they carry, functions handed more capability than they use, and defensive branches nothing can reach. A reachable invalid state is a bug.

Simplicity (Hickey, "Simple Made Easy")

Which independent concerns have become entangled? Can they be understood separately?

Simple means one fold, not braided with anything else. It is objective, and it is a different axis from easy, which only means familiar or close at hand. Two concerns are complected when a reader can't think about one without the other. Separate files don't fix that on their own, because modules can still be braided through shared state, flags or conventions. Judge the running artifact, not how pleasant the code was to write.

In refined code, a question about one concern is answered without any other concern's code. Unrefined code defines one concept twice, keeps caches and side maps apart from the data they describe, weaves fast paths into logic, stores fields that could be derived, threads state through code that only needs a value, and encodes in conditionals decisions made elsewhere.

Parametricity (Wadler, "Theorems for free!")

What does the type actually guarantee, and what still depends on implementation discipline?

Read a type as a theorem. A function from a list of A to a list of A, for any A, can only drop, repeat or reorder elements, because it has no operations on A. So mapping a function over the input before or after calling it gives the same result, for every such function. The more general and precise the type, the more it proves. Concrete types like strings, integers and booleans prove almost nothing, and escape hatches like null, casts, runtime type tests, reflection, exceptions and side effects weaken whatever the type did prove. Any property they carry rests on discipline.

In refined code, properties hold by signature, not by comment, convention or caller check. Unrefined code leans on unnamed tuples whose order matters, strings standing in for closed sets, cached results that depend on arguments missing from the cache key, functions that take a concrete type they never inspect, and invariants a signature could enforce that only a comment states.

Rules

The lenses name the complexity; these rules state what code free of it looks like.

No partial calls

Refined code holds no partial call, an operation that fails on some input its type allows: the first element of a list that may be empty, a map or dictionary lookup that throws on a missing key, an unchecked unwrap of an optional value (Option.get, unwrap(), a ! non-null assertion), a cast, or a match or switch that misses a case. The type carries the proof: a non-empty type from where the list is built, the looked-up value in place of its key, a match that covers every case. An optional value is a type, not a sentinel default that code must remember to check. A hot path is the one exception, only when an established invariant makes the call safe and performance evidence shows the safe form adds meaningful cost.

Explicit signatures

Every top-level function declares its parameter and return types; every field declares its type. In languages with optional type annotations, keep these contracts explicit.

Prefer type inference for local values and nested helpers when the inferred types preserve the intended constraints. Add explicit annotations where inference is unavailable, loses constraints, or permits unintended widening.

Required annotations state the contract to readers and the compiler. Inside implementations, annotate only to enforce a constraint or clarify an otherwise unclear type.

Wrong states are unrepresentable

A bug shows where the design lets a wrong state through; refined code admits no such state. Parse, don't validate: turn less-structured input into a representation that preserves the proof of its invariants, not a check whose result is discarded. Wrong input cannot be represented, or it flows through the mechanism that already handles its kind — one cause, one mechanism. A downstream runtime guard holding up an invariant, or an if carrying an edge case, marks a wrong state the design still admits.

Hot paths stay fast

Code that runs per request, per entity, per item or per field does no more work per call than the job needs. The smells: an allocation the job never asked for, a scan doing a lookup's job, two passes doing one pass's work, a fast path missing where one belongs.

Style

Code reads like its neighbors: the project's formatter, import style, naming and idioms. A comment belongs only where the code alone would mislead; a comment that restates a name says nothing. A doc comment states the contract the signature cannot, in the project's doc-comment conventions.

Foundations

See the philosophical foundations for original sources and how parsing preserves type proofs.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Code Refinements AI skill do?

Defines what refined code looks like through the three lenses of constraints, simplicity, and parametricity, with rules for type proofs, no partial calls, explicit signatures, unrepresentable wrong states, hot-path discipline, and style. Use when writing, changing, or reviewing code to a refinement bar, or whenever the user asks for code to follow the rules in code-refinements.

Why use Code Refinements on TypingMind?

Because you install it once and use it with any model. Code Refinements is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Code Refinements in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/alexandru/skills/tree/main/skills/engineering/code-refinements. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Code Refinements?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Code Refinements?

As many as you like. As long as a model supports skills, you can use Code Refinements with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Code Refinements AI skill free?

It is published on GitHub by alexandru. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇