Skip to main content

CLI tools for LLM conversations

Project description

ctools

Context tools for LLM conversations. Extracted from Gab n' Go. Named after GNU mtools, which does the same thing for DOS floppies because your context window is about the size of a DOS-floppy. Maybe we can use that for inspiration.

The Problem

You talk to LLMs all day. Over weeks, you build up a set of constraints, preferences, and goals. "Use C17 standard." "Prefer snake_case." "Always check for null returns." These things live in your conversations as system messages. They are valuable. They are also trapped.

Say you have been working with opencode for a month. You have refined your coding style through dozens of sessions. Now you start a new Claude Code project and you want those same preferences. You could copy them by hand. Or you could use ctools.

ccopy @opencode/ses_abc123 preferences.json
ccopy preferences.json @claude-code/ses_xyz

Or skip the file entirely:

ccopy @opencode/ses_abc123 @claude-code/ses_xyz

The concepts are embedded in your conversations as "Use the following :

GNU mtools ctools Does what
mdir cdir List sessions
mcopy ccopy Copy concepts
mdu cdu Token usage
mtype cgrep Search content

Tools

ccopy

Extract, inject, and copy concepts between sessions and files. The @ prefix means "this is a session reference." Plain paths are files. Directories get one file per concept.

ccopy @opencode/ses_abc123 concepts/              # extract to directory (one file per concept)
ccopy @opencode/ses_abc123 constraints.json       # extract to single file
ccopy concepts/ @opencode/ses_abc123               # inject all concepts from directory
ccopy constraints.json @opencode/ses_abc123       # inject from file
ccopy @opencode/ses_abc123 @claude-code/ses_xyz   # session to session
ccopy --strategy my-strategy.json @opencode/ses_abc123 concepts/  # custom extraction

When you extract to a directory, each concept becomes its own file. This is the core abstraction: the directory is the concept set. rm a file to exclude it. cp files in to merge. Edit the json to modify. git add . to share.

ls concepts/
constraint_0aa712d89fbb067a.json
preference_a1b2c3d4e5f6g7h8.json
observation_x9y8z7w6v5u4t3s2.json

Strategies let you define how concepts are extracted using an LLM. Ontology is contestable, so different strategies produce different chunkings:

{
  "host": "http://localhost:11434",
  "model": "qwen2.5:3b",
  "api_key": null,
  "prompt": "Extract the key concepts from this conversation..."
}

cdir

Lists sessions. Think ls for your conversation history. Subagents appear indented under their parent with tree connectors.

cdir                        # list all known agents
cdir opencode/              # sessions for opencode
cdir claude-code/           # sessions for claude code
cdir -R                     # all agents, recursive
cdir opencode/ses_abc123    # export a session as JSON

Output shows Found/Not Found with actual paths:

Found:
  Claude Code  Claude Code CLI             ~/.claude/projects/
  Opencode     Opencode CLI                ~/.local/share/opencode/opencode.db

Not Found:
  Claude       Claude Desktop (Anthropic)  ~/.config/Claude/conversations/
  Codex        OpenAI Codex CLI            ~/.codex/sessions/

Sort by time (-t), size (-s), reverse (-r). Output as json, xml, or markdown with -f.

cgrep

Searches conversation content. Regex supported. Works across agents.

cgrep "pattern" "opencode/*"
cgrep -i "error" "claude-code/"
cgrep -c "def " "opencode/"              # count per session
cgrep -C 2 "exception" "claude-code/"    # context lines
cgrep "TODO" "opencode/" "claude-code/"  # multiple agents

Flags: -l list files, -c count, -v invert, -i case-insensitive, -A/-B/-C context.

cdu

Token usage. Like du but for context windows. Uses tiktoken for accurate counts.

cdu                           # total across all agents
cdu opencode/                 # sessions by token count
cdu opencode/ses_abc123       # breakdown by role
cdu --json opencode/          # machine-readable

For opencode, it reads actual input/output tokens from the database. For other agents, it counts with tiktoken from the conversation content.

Supported Agents

Agent Storage
claude JSON
claude-code JSONL
opencode SQLite
codex JSONL

Run cdir to see which agents are found on your system and where they store data.

MCP Server

There is an MCP server for use from Claude, opencode, Cursor, or anything else that speaks MCP.

Tools: list_agents, list_sessions, search_sessions, export_session, extract_concepts, copy_concepts, get_session_concepts.

Add to your MCP config:

{
  "mcpServers": {
    "ctools": {
      "command": "python",
      "args": ["/ABSOLUTE/PATH/TO/ctools/ctools_mcp.py"]
    }
  }
}

Installation

pip install ctxttools

For MCP server support:

pip install ctxttools[mcp]

Library

Works as a Python library too.

from ctools.lib import AGENTS, get_formatter
from ctools.cdir import get_opencode_sessions
from ctools.cgrep import grep_session
from ctools.ccopy import extract_concepts_from_messages, inject_concepts_to_session
from ctools.cdu import count_tokens, get_session_tokens

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

ctxttools-0.1.1.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ctxttools-0.1.1-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file ctxttools-0.1.1.tar.gz.

File metadata

  • Download URL: ctxttools-0.1.1.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ctxttools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ec4009262a4279e9b0c26e24c0e2cbf1d3e8a25a03a265ad05b17196c0134099
MD5 5f34d74680e60ce28e68b4d0a4f08bc5
BLAKE2b-256 73c0931c4b9d1aacca8699d49efbe0cd1a94800accad82464d880216a4bae93b

See more details on using hashes here.

File details

Details for the file ctxttools-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ctxttools-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ctxttools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27879534ecc43a9f58bd51f79a0c0886a959dafe421f3c61d61f1c489c709888
MD5 5f6bdef87dc3739721678cb39d02a48e
BLAKE2b-256 5b80565f2816597cbc4e6d12c94e131e8b71c2090c99faedfb832f9ff00c35db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page