Repository

ctx

██████╗████████╗██╗ ██╗ ██╔════╝╚══██╔══╝╚██╗██╔╝ ██║ ██║ ╚███╔╝ ██║ ██║ ██╔██╗ ╚██████╗ ██║ ██╔╝ ██╗ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ Context (ctx) - The Context Engine for AI Agents Slash AI · License MIT · Maintenance unknown

License
MIT
Agent
Links
Flag
Environment Variable
--token-model
CTX_TOKEN_MODEL

Specs

  • AgentLinks
  • FlagEnvironment Variable
  • --token-modelCTX_TOKEN_MODEL
  • --max-tokensCTX_MAX_TOKENS
  • --max-output-bytesCTX_MAX_OUTPUT_BYTES
  • --max-linesCTX_MAX_LINES
  • --max-pipeline-stagesCTX_MAX_PIPELINE_STAGES
  • --privateCTX_PRIVATE
  • --no-historyCTX_NO_HISTORY
  • --no-telemetryCTX_NO_TELEMETRY
  • --timeoutCTX_TIMEOUT
  • -CTX_WAIT_DELAY
  • -CTX_SIGTERM_GRACE
  • --stream-
  • -CTX_API_ENDPOINT
  • Aspectgo build -o ctx .
  • LocationCurrent directory
  • PATH availabilityNo (unless you add . to PATH)
  • PurposeLocal testing/development
  • Clean uprm ctx

README

     ██████╗████████╗██╗  ██╗
    ██╔════╝╚══██╔══╝╚██╗██╔╝
    ██║        ██║    ╚███╔╝ 
    ██║        ██║    ██╔██╗ 
    ╚██████╗   ██║   ██╔╝ ██╗
     ╚═════╝   ╚═╝   ╚═╝  ╚═╝

Context (ctx) - The Context Engine for AI Agents

Slash AI costs by 95%: From $1,125 to just $10/agent/month - the price of the upcoming ctx Pro subscription!

Version
Beta
Schema
Go
License

Beta Software: ctx is in beta. The API and schema may change. See CHANGELOG.md for release history.

Modern AI agents struggle with external tools because raw command output is token-expensive, unstructured, and lacks metadata. This wastes context windows and drives up costs.

ctx solves this by wrapping any command in a structured JSON "context envelope." It adds precise token counts, execution metadata, and telemetry, enabling agents to make smarter, cost-aware decisions.

The ctx Advantage: Drastic Cost Reduction

ctx enables a "measure-then-act" workflow that can reduce token consumption by over 95%.

Before ctx (Expensive): An agent gets a huge, raw text blob.

# Agent sends the entire raw output to the LLM
psql -c "SELECT * FROM users" | llm -p 'Summarize users'
# Result: ~25,000 tokens consumed (~$1,125/month)

With ctx (Efficient): The agent first checks the cost, then refines its query.

# 1. Measure the token cost first
ctx psql -c "SELECT * FROM users" | jq '.tokens'
# Result: 25000

# 2. Refine the query and execute safely
ctx psql -c "SELECT status, COUNT(*) FROM users GROUP BY status" | llm
# Result: ~100 tokens consumed (99.6% reduction)

This simple pattern transforms an expensive operation into a negligible one.

Supported Coding Agents

ctx integrates with leading AI coding assistants and agentic IDEs through simple setup commands. We're constantly expanding support to include more tools based on community needs.

AGENTS.md Support - ctx now supports the AGENTS.md standard, an open format for guiding coding agents that works across multiple AI tools. Run ctx setup agents to generate a universal AGENTS.md file that's compatible with Cursor, RooCode, OpenCode, and other agents that support this standard.

Want to see your favorite AI tool supported? Request a new integration by creating a GitHub issue.

Agent Links AGENTS.md Support Compatible with ctx
Claude Code Official site | Docs ✗ ✓ (via ctx setup claude)
Gemini CLI Official site | GitHub | Docs ✗ ✓ (via ctx setup gemini)
Kilo Code Official site | Docs ✗ ✓ (via ctx setup kilo-code)
Roo Code Official site | Docs ✓ ✓ (via ctx setup roo-code)
Cursor Official site | Docs ✓ ✓ (via ctx setup cursor)
Aider Official site | GitHub | Docs ✗ ✓ (via ctx setup aider)
JetBrains AI Assistant Official site | Docs ✗ ✓ (via ctx setup jetbrains)
Zed Official site | GitHub | Docs ✗ ✓ (via ctx setup zed)
GitHub Copilot Official site | Docs ✗ ✓ (via ctx setup github-copilot)
Windsurf Official site | GitHub | Docs ✗ ✓ (via ctx setup windsurf)
Cline Official site | GitHub ✗ ✓ (via ctx setup cline)
Goose Official site | GitHub | Docs ✗ ✓ (via ctx setup goose)
Visual Studio Code Official site | GitHub | Docs ✗ ✓ (via ctx setup vscode)
Visual Studio 2022 Official site | Docs ✗ ✓ (via ctx setup visualstudio)
Augment Code Official site | Docs ✗ ✓ (via ctx setup augmentcode)
OpenCode Official site | Docs ✓ ✓ (via ctx setup opencode)
Trae Official site | Docs ✗ ✓ (via ctx setup trae)
Amazon Q Developer Official site | Docs ✗ ✓ (via ctx setup amazonq)
Zencoder Official site | GitHub ✗ ✓ (via ctx setup zencoder)
Qodo Gen Official site | Docs ✗ ✓ (via ctx setup qodo)
Warp Terminal Official site | Docs ✗ ✓ (via ctx setup warp)
Crush Official site | GitHub ✗ ✓ (via ctx setup crush)
Rovo Dev CLI Official site | GitHub ✗ ✗
LM Studio Official site | Docs ✗ ✗
BoltAI Official site | Docs ✗ ✗
Perplexity Desktop Official site | Docs ✗ ✗
Claude Desktop Official site | Docs ✗ ✗

Key Features

  • Universal Tool Wrapper: Works with any CLI tool out-of-the-box (psql, git, docker, kubectl, ls, etc.).
  • Structured JSON Output: Enriches raw output with vital metadata for LLMs.
    {
      "tokens": 42,
      "output": "...",
      "input": "...",
      "metadata": { "success": true, "exit_code": 0, "duration": 127 },
      "telemetry": { "trace_id": "...", "span_id": "..." },
      "schema_version": "0.1"
    }
  • Precise Token Counting: Supports OpenAI, Anthropic, and Gemini tokenizers.
  • Safety Controls: Set limits on tokens, output size, lines, and pipeline stages to prevent runaway costs.
  • Streaming Support: Terminate long-running commands in real-time when limits are breached.
  • Privacy-Aware: Instantly disable history and telemetry with a --private flag.

Installation & Updates

The recommended method is the one-liner script, which provides full versioning and auto-update capabilities:

curl -sSL https://raw.githubusercontent.com/slavakurilyak/ctx/main/scripts/install-remote.sh | bash

Features:

  • Full version information
  • Auto-update notifications
  • ctx update command support
  • Proper build metadata

Alternative Methods

Pre-built Releases (Full Features):
Download binaries from the Releases page.

  • Full version information
  • ctx update command support
  • No auto-update notifications

Go Install (Limited Features):

go install github.com/slavakurilyak/ctx@latest
  • Shows "ctx version unknown (built from source)"
  • No auto-update capabilities
  • Automatic Go module updates
  • Tip: Run ctx update after installing to upgrade to a full-featured version

Updating ctx

Automatic Updates (Install Script & Pre-built):

ctx update                    # Update to latest stable version
ctx update --pre-release      # Include pre-releases
ctx update --check            # Check for updates without installing

Go Install Users:

go install github.com/slavakurilyak/ctx@latest  # Manual update
# Or upgrade to full version:
ctx update  # Replaces go install version with full-featured version

Verify installation: ctx version

Quick Start: Set Up Your AI Assistant

After installation, configure ctx for your development environment:

# Default setup (generates AGENTS.md for universal compatibility):
ctx setup

# Or agent-specific setup:
ctx setup claude        # Claude Code/Desktop  
ctx setup cursor        # Cursor IDE
ctx setup aider         # Aider
ctx setup augmentcode   # Augment Code
ctx setup windsurf      # Windsurf IDE
ctx setup jetbrains     # JetBrains AI Assistant
ctx setup vscode        # VS Code with GitHub Copilot
ctx setup visualstudio  # Visual Studio 2022
ctx setup gemini        # Gemini CLI
ctx setup goose         # Goose AI Agent
ctx setup trae          # Trae IDE
ctx setup opencode      # OpenCode

# See all supported tools:
ctx setup

This creates configuration files that teach your AI assistant to use ctx automatically, enabling token-efficient workflows.

Usage

Simply prefix any command you want to enrich with ctx.

# Basic command
ctx ls -la

# Database query with a specific tokenizer
ctx --token-model openai psql -c "SELECT id FROM users LIMIT 10"

# Pipeline: filter data before tokenizing
ctx cat large.json | jq .items[0:5]

# AI Agent workflow: generate a commit message
ctx git diff --staged | claude -p 'Generate a conventional commit message.'

AI Assistant Setup

ctx supports major AI agents and agentic IDEs, making it easy to integrate token-aware command execution into your existing AI-powered development workflow. With support for 10+ popular tools, you can teach your AI coding assistant to use ctx automatically.

# Default: Set up AGENTS.md (universal format for multiple agents)
ctx setup

# Or set up a specific AI tool:
ctx setup claude        # Explicit Claude Code setup
ctx setup cursor        # Cursor IDE
ctx setup aider         # Aider
[...]

These commands create local configuration files that instruct your IDE's AI to wrap shell commands with ctx, promoting token-efficient workflows.

About AGENTS.md: The AGENTS.md format is an open standard supported by OpenAI Codex, Cursor, RooCode, and many other agents. It provides a standardized way to give instructions to AI coding assistants, making your setup portable across different tools.

Coming Soon: ctx Pro

ctx Pro enhances your ctx experience with powerful analytics and team collaboration features for just $10/agent/month.

  • Web Dashboard: Access a comprehensive dashboard to visualize your command-line usage patterns, most frequently used tools, and command history analytics.
  • Usage Insights: Discover which tools consume the most tokens, identify optimization opportunities, and track your token savings over time.
  • Team Features: Centralized policies, audit logs, and shared configurations for teams to maintain consistency across development workflows.
  • Support Open Source: Your subscription directly supports the continued development and maintenance of the ctx project, ensuring regular updates and new features.

Pro features will activate with ctx login. Learn More About Pro Pricing.

Configuration

ctx is configured via CLI flags, environment variables, or a ~/.config/ctx/config.yaml file.

Flag Environment Variable Description Default
--token-model CTX_TOKEN_MODEL Set tokenizer provider (anthropic, openai, gemini) anthropic
--max-tokens CTX_MAX_TOKENS Maximum tokens allowed in output (0 = unlimited) 0
--max-output-bytes CTX_MAX_OUTPUT_BYTES Maximum bytes allowed in output (0 = unlimited) 0
--max-lines CTX_MAX_LINES Maximum lines allowed in output (0 = unlimited) 0
--max-pipeline-stages CTX_MAX_PIPELINE_STAGES Maximum pipeline stages allowed (0 = unlimited) 0
--private CTX_PRIVATE Disable history and telemetry false
--no-history CTX_NO_HISTORY Disable history recording false
--no-telemetry CTX_NO_TELEMETRY Disable OpenTelemetry tracing false
--timeout CTX_TIMEOUT Set command timeout (e.g., 30s, 1m) 2m
- CTX_WAIT_DELAY Time to wait after SIGTERM before SIGKILL (e.g., 5s) 3s
- CTX_SIGTERM_GRACE Grace period after SIGTERM for cleanup (e.g., 500ms) 100ms
--stream - Stream output line by line for long-running commands false
- CTX_API_ENDPOINT API endpoint for ctx Pro features (set in .env) Coming soon

Timeout Behavior

ctx properly terminates entire process trees when timeouts occur, including all child processes spawned by build tools, language runtimes, and shell scripts.

Examples

# Terminates after 2 seconds (including child processes)
ctx --timeout 2s -- go run main.go      # Go compilation + execution
ctx --timeout 2s -- cargo run           # Rust build + run
ctx --timeout 2s -- npm run dev         # Node.js dev server
ctx --timeout 2s -- bash script.sh      # Shell script + subprocesses

# Default timeout is 2 minutes
ctx -- docker build .

# Custom grace period for cleanup
CTX_WAIT_DELAY=5s ctx --timeout 10s -- docker-compose up

Development

Building from Source

Local Development Build:

git clone https://github.com/slavakurilyak/ctx.git
cd ctx
go build -o ctx        # Creates ./ctx binary for testing
./ctx version          # Test local build

Global Installation:

go install .           # Install to $GOPATH/bin (usually ~/bin or ~/go/bin)
ctx version            # Test global installation

Understanding go build vs go install:

Aspect go build -o ctx . go install .
Location Current directory $GOPATH/bin
PATH availability No (unless you add . to PATH) Yes (if $GOPATH/bin in PATH)
Purpose Local testing/development System-wide installation
Clean up rm ctx rm $GOPATH/bin/ctx

Contributing

Contributions are welcome! Please see the Issues page for areas where help is needed.

Resources

Acknowledgments

  • Anthropic for pioneering token-efficient tool use
  • The creators of countless open-source CLI tools

License

This project is licensed under the MIT License.