Skip to content

Getting started

Install ctx, run a command in your repository, and open the evidence it returns. You can do this from a terminal before connecting a coding agent. For cross-harness work, see ACP setup and worker routing. For Gemini 4 model selection, see native Antigravity sessions.

  • Python 3.11 or newer.
  • A local repository.
  • A supported coding-agent host if you want automatic interception.

Host integration is optional. Every ctx command also works from a terminal.

rg, ctags, tree-sitter, Jedi, SCIP, and Semgrep can improve repository analysis. Capture and retrieval do not depend on them.

Captured stdout and stderr may contain source code, logs, credentials, or other sensitive data. Raw artifacts are stored as local plaintext today. Model-visible output is deterministically redacted by default, but redaction can be disabled explicitly; it does not encrypt the stored artifact.

Host-hook reads of secret-bearing paths require an explicit permission step and are excluded from automatic capture by default. A directly authorized ctx run can still capture them.

The store lives outside the repository by default under $CTX_STATE_HOME, then $XDG_STATE_HOME/ctx, then ~/.local/state/ctx. The default retention GC eligibility horizon is 30 days. There is no background collector: artifacts remain until ctx gc runs. ctx gc --retention-days N can override the horizon; pins and active checkpoint leases survive collection.

Do not capture secret-bearing commands when plaintext local retention is unacceptable.

Pin this release explicitly. Python package indexes rank 0.44.0 above 0.5.0.

Terminal window
python -m pip install 'ctx-harness==0.5.0'
ctx --version

Isolated installations also work:

Terminal window
pipx install 'ctx-harness==0.5.0'
# or
uv tool install 'ctx-harness==0.5.0'

For development:

Terminal window
git clone https://github.com/vamsiramakrishnan/straitjacket.git
cd straitjacket
python -m pip install -e '.[dev]'
pytest
Terminal window
ctx run -- pytest -q

For a large test result, the digest identifies failures and provides a retrieval address. An example:

[ctx run:ba3d1020ee8f profile=pytest/v2]
exit: 1
failures: 7
coverage:
identities: 7/7
detail shown: 2/7
next:
ctx get run:ba3d1020ee8f#stdout --lines 140:220

The handle in this example represents a run in your local store. Use the ID from your own run. The digest identifies omitted regions and gives retrieval instructions. When a stream crosses the capture limit, the result also identifies the discarded middle.

Retrieve an exact line range:

Terminal window
ctx get run:ba3d1020ee8f#stdout --lines 140:220

Search the stored output:

Terminal window
ctx search run:ba3d1020ee8f "MissingTenantError"

Use #stdout or #stderr to select a stream. Use --lines, --bytes, or a span address to select a region.

Retrieval remains bounded. If the requested region is too large, ctx get returns a smaller view with continuation addresses.

HostBirth-time containmentOversized result substitution
Claude CodeOutput bounded after the command runs; command not rewritten by default (steering = "rewrite" captures at birth)Yes
CodexCommands run as written under Codex’s own approval; rewrites withheldImplemented and contract-tested; live CLI receipt pending
AntigravityRewrite by default (it cannot replace output): run_command and read_file in place when the payload carries hookEventName (added in agy 1.5.4; observed on 1.5.5 only); deny and name the bounded command for other toolsNo
Hermes, OMP, OpenCodeNative plugin argument rewriteText-output replacement; contract-tested
DSHDeny with a bounded replacement commandNative text-output replacement; contract-tested

On Antigravity (observed on agy 1.5.5) a PreToolUse hook can rewrite a call’s arguments, and ctx does so for run_command and read_file; every other read or search tool is denied with the bounded command named. Its PostToolUse hook accepts only an empty reply and is not given the tool’s output, so it cannot replace output. straitjacket can prevent a known command flood before execution, but a verbose connector result can still enter the transcript unchanged.

See Host capabilities for the full matrix.

ctx setup configures the sidecar’s hooks and MCP integration with the selected coding harness. To opt into ACP orchestration, add --acp and an explicit --acp-model for one host. Existing CLI worker transports remain available for hosts without ACP configuration.

Terminal window
cd your-repository
ctx setup
ctx doctor

ctx setup:

  1. creates or updates ctx.toml and .ctxignore;
  2. detects supported agent CLIs;
  3. applies host configuration using host-specific preservation rules;
  4. runs the same checks as ctx doctor;
  5. records a content-free fingerprint of the managed setup surfaces for fast reruns.

It preserves unrelated user-owned settings. Codex TOML and OpenCode JSON/JSONC are edited through parsed source spans: comments, other integrations and unrelated formatting stay in place. Changes to a pre-existing configuration are previewed before the first write; rerun with --apply to accept safe additions. Explicit conflicts still refuse, including hooks = false or a different ctx-harness server. A matching readiness receipt can skip repeated writes; use ctx setup --repair to force all checks and repair owned entries. Use ctx setup --all to prepare all registered vendor integrations; antigravity-sdk remains an explicit opt-in. Hermes needs its installed CLI to activate profile settings; DSH needs the generated --patch at launch. See the additional agent integrations.

Setup reports host-configuration writes. The persistent host configuration is:

ScopeFiles or entries
Workspacectx.toml, .ctxignore
Antigravity.agents/plugins/ctx-harness/; a ctx statusLine in ~/.gemini/antigravity-cli/settings.json only when no status line already exists
Claude Codectx hook entries and, when absent, a ctx statusLine in .claude/settings.json; .claude/agents/ctx-explorer.md only when absent; a managed block in CLAUDE.md
Codexctx entries in .codex/config.toml and .codex/hooks.json, a managed block in AGENTS.md
HermesActive profile’s MCP entry and enabled straitjacket plugin; .ctx/hosts/hermes.json records the recipe
OMPmcpServers.ctx-harness in .omp/mcp.json
OpenCodemcp.ctx-harness in the existing opencode.json or opencode.jsonc, plus .opencode/plugins/straitjacket.js; two project configs refuse
DSH.ctx/hosts/dsh.cordis.patch.yml, loaded with --patch

Setup also writes a content-free readiness receipt to .ctx-session-reads/setup.json; this is not host configuration.

Preview the exact changes to your existing configuration without writing:

Terminal window
ctx setup --host codex --host opencode --preview
ctx setup --host codex --host opencode --apply
ctx doctor

--preview requires explicit Codex/OpenCode hosts. It creates no files or readiness receipt. The default ctx setup also stops for review before editing a pre-existing configuration. Fresh installs retain the existing setup flow. ctx wrap codex --print-config still renders a generic configuration; use --preview for a diff against your actual files.

A conflict prints a unified diff naming the exact key and proposed value. --apply does not override conflicting user settings. Reconcile those entries using the diff, then rerun preview. Duplicate keys, invalid syntax, symlinks and ambiguous config files refuse with a diagnostic. A parse error must be fixed before a trustworthy structural diff can be generated.

Setup never writes through a symlink: for any host, a target that is a link, or that sits behind a linked directory leaving the workspace, is not written, and the message names the file (for example “did not update CLAUDE.md: …: it is a symlink; ctx never writes through a link”).

Setup records individual contributions in .ctx/host-config.json; the readiness receipt remains content-free. Repair updates a previously owned value only when its value and source still match the installed contribution, and restores missing contributions. Comments added inside an owned value are user edits; repair/removal refuses to overwrite them and shows the exact diff. A banner comment alone never authorizes replacing a whole file. Existing matching entries are not claimed by setup.

To remove contributions introduced by this flow:

Terminal window
ctx setup --host codex --host opencode --remove
ctx setup --host codex --host opencode --remove --apply

Removal defaults to a preview. An untouched configuration is restored exactly; if unrelated settings changed afterward, removal deletes only owned entries and retains those settings and comments. Modified owned values refuse removal. Pre-existing unowned entries, workspace policy, and captured artifacts remain. For older installs without ownership records, use the manual removal steps.

WorkCommand
One commandctx run -- <command>
Pipeline or shell syntaxctx run --shell '<pipeline>'
Known sequencectx seq
Computed branching or aggregationctx py <script>
Typed bounded compositionctx q '<pipeline>'
Long-running workctx run --bg-after <seconds> -- <command>

Use the least expressive option. Batch operations whose sequence is already known. Return to the model when evidence can change the plan.

Terminal window
ctx run --bg-after 30 -- pytest tests/integration -q

If the process is still running after 30 seconds, ctx returns a job: handle and continues capturing in the background.

Terminal window
ctx job <id>
ctx job <id> --wait
ctx job <id> --kill

A completed job becomes an ordinary run: artifact.

Build a bounded repository map:

Terminal window
ctx map --budget 500 --focus payments

Ask a typed question:

Terminal window
ctx ask "Where is TokenBucket defined and used?" --intent locate

Run a compiled investigation:

Terminal window
ctx plan run investigation.json

Use ctx q for bounded pipelines over typed facts:

Terminal window
ctx q 'refs TokenBucket | group file | top 5'
ctx q 'fails last | in-changed' # after the tests ran through `ctx run`

fails last, records run:<id>… and ctx ask --intent diagnose read output captured by ctx run; for a file that already exists (a log), use grep, Read windows, or ctx search repo:<file> PATTERN.

ctx q has bounded stage counts and no recursion or unbounded loops. This keeps execution cost predictable.

Run Claude Code under the harness without changing persistent configuration:

Terminal window
ctx wrap claude -- -p "fix the failing tests"

Add --proxy to measure wire traffic through the local observer:

Terminal window
ctx wrap claude --proxy -- -p "fix the failing tests"

The observer records usage and window metadata. It does not record request bodies or authentication headers.

Terminal window
ctx stats --session
ctx gain

The scorecard reports captured versus model-visible bytes, profile use, retrievals, reruns, cache classes, and intervention outcomes. Treat it as a diagnostic receipt.

straitjacket provides:

  • output containment;
  • deterministic rendering;
  • bounded retrieval;
  • workspace-relative confinement for ctx-managed repository reads and searches;
  • traversal and symlink-escape rejection on those ctx-managed paths;
  • timeouts and process-group handling;
  • secret-aware controls.

It is not a complete process sandbox. Child processes launched through ctx run keep the invoking user’s filesystem and execution authority.