Contextile
Contextile is a Python toolkit for managing, retrieving, and compacting AI project instructions, lessons learned, and contextual rules for LLM workflows.
Documentation guides:
The MVP focuses on a small local workflow:
- initialize a
.contextile/workspace; - store durable lessons in JSONL;
- validate lesson records;
- search relevant lessons for a task;
- build a compact Markdown context block for an LLM;
- run a thin MCP server layer on top of the same core functions.
Install locally
pip install -e .
Initialize a project
contextile init
This creates:
.contextile/
config.json
lessons.jsonl
project-rules.json
instructions/
project-context.md
architecture-rules.md
code-standards.md
validation.md
Add a lesson
contextile add-lesson \
--id preserve-domain-terms \
--when "Editing existing domain terms in code, docs, routes, schemas, enums, or API contracts." \
--do "Preserve domain terms exactly as used in the project." \
--avoid "Do not translate established domain terms." \
--scope "Code, docs, API, DB, routes, enums, UI." \
--tags domain,terminology,api,routes,enums
Search lessons
contextile search "api validation reports" --limit 5
Build compact context
contextile build-context \
--task "Refactor API validation for reports" \
--file src/schemas/par/relatorio.py \
--tag api \
--tag validation \
--rule-limit 6 \
--max-tokens 800
By default, build-context selects relevant rules from:
- bundled default rule catalog (ships with Contextile);
- optional project overrides/extensions in
.aiassistant/rules.
Selection uses:
- project profiles from
.contextile/project-rules.json; - detected stack/dependencies (
pyproject.toml,requirements*.txt, directories); - task text, file hints, and tags.
When rules are selected, they are always included in full (not token-truncated). --max-tokens applies to non-rule sections.
Use --no-rules to disable rule selection for a call.
Validate records
contextile validate
Compact records
contextile compact
Detect and manage rule profiles
contextile detect-rules
contextile detect-rules --write
contextile list-rule-scenarios
contextile apply-rule-scenario --scenario python-core
contextile apply-rule-scenario --scenario fastapi-api
contextile select-rules --task "add sqlalchemy pagination" --file src/repositories/orders.py
contextile validate-rules
detect-rules --write updates .contextile/project-rules.json (enable_profiles) so existing projects can adopt rule selection quickly.
apply-rule-scenario updates enabled_scenarios using predefined scenario groups from the bundled catalog plus any project rules.
Run MCP server
Install MCP extra:
pip install -e ".[mcp]"
Run over stdio (default):
contextile mcp-server --root .
or:
contextile-mcp --root .
Run over HTTP transport:
contextile mcp-server --root . --transport streamable-http
Available MCP tools:
build_context_toolbuild_agents_md_tooladd_lesson_toolsearch_lessons_toolselect_rules_tooldetect_rules_toolvalidate_rules_toollist_rule_scenarios_toolapply_rule_scenario_tool
Lesson JSONL schema
Each line in .contextile/lessons.jsonl is one lesson:
{"id":"preserve-domain-terms","when":"Editing existing domain terms.","do":"Preserve terms exactly as used.","avoid":"Do not translate established terms.","scope":"Code, docs, API, DB, routes, enums, UI.","tags":["domain","terms","api"]}
Required fields:
idwhendoavoid
Recommended fields:
scopetagswhyupdated_at
Metadata
Release files for contextile 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| contextile-0.2.0.tar.gz | 114.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| contextile-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 252.3 kB
Release files / contextile-0.2.0.tar.gz
| Download URL | contextile-0.2.0.tar.gz |
|---|---|
| Size | 114.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c0b5cc4f4496bd6b3e046fef6edd562d5fe74ee14a9ec6077f24f88643164ef1
|
|
BLAKE2b-256 checksum How to use checksums |
58680c65422fbffb3225698517d6ddf22f5b24d4799697297543ac8b90faaab3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Release files / contextile-0.2.0-py3-none-any.whl
| Download URL | contextile-0.2.0-py3-none-any.whl |
|---|---|
| Size | 138.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a311b7adeac7db5d495987124665331622162aee8832a695a47ac94c27d98ab2
|
|
BLAKE2b-256 checksum How to use checksums |
2d0a7ad27ad270b2ee4593cd4eefdf0d438072308af970e95ca57cba062bf99c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|