Skip to content

Repository files navigation

ContextSniper

ContextSniper

License Python Version Claude Code OpenClaw ContextSniper Filter AGFS

Make a local codebase searchable from Claude Code or OpenClaw with semantic code search, filtered long outputs, and exact-replacement file edits.

中文文档

Usage Cost Reduction

The SWE Lite verification reports include token and turn breakdowns for Claude Code and OpenClaw runs. We chose text-embedding-3-large as the embedding model.

Claude Code OpenClaw
Average usage cost, Claude Code Average usage cost, OpenClaw

Claude Average Per Task

Metric Legacy     ContextSniper     ContextSniper Filter     ContextSniper Reduction ContextSniper Filter Reduction
Input tokens 1,534,963 941,761 810,396 -39% -47%
Output tokens 16,969 11,656 11,946 -31% -30%
Total tokens 1,551,933 953,417 822,342 -39% -47%

OpenClaw Average Per Task

Metric Legacy     ContextSniper     ContextSniper Filter     ContextSniper Reduction ContextSniper Filter Reduction
Input tokens 1,309,937 769,590 622,321 -41% -52%
Output tokens 17,439 10,399 12,982 -40% -26%
Total tokens 1,327,377 779,989 635,303 -41% -52%

Overview

ContextSniper ships two local plugins:

Host Plugin What it adds
Claude Code claude-plugin/ MCP tools for code search/edit plus prompt policy injection
OpenClaw openclaw-plugin/ Native tools, prompt policy injection, and read/exec filtering

Both plugins can start the local ContextSniper backend and AGFS service for you, then stop the services they started when the host exits.

Runtime architecture

Quickstart

Prepare a fresh checkout once:

git clone https://github.com/Calluking/ContextSniper.git
cd ContextSniper
./bootstrap.sh

bootstrap.sh is interactive for setup steps: if Ubuntu packages or Python .venv are missing, it asks before installing anything. It also checks whether OpenClaw and Claude Code are installed, then asks which integration to set up. It does not ask you to type API keys into the installer.

Export your model and embedding settings: (Use deepseek and text-embedding-3-small as example)

export DEEPSEEK_API_KEY="<your-deepseek-key>"
export DEEPSEEK_BASE_URL="https://api.deepseek.com"
export OPENCLAW_MODEL="deepseek/deepseek-v4-flash"
export CONTEXTSNIPER_EMBEDDING_API_KEY="<your-embedding-key>"
export CONTEXTSNIPER_EMBEDDING_BASE_URL="https://api.openai-proxy.org"
export CONTEXTSNIPER_EMBEDDING_MODEL="text-embedding-3-small"
export ANTHROPIC_MODEL="haiku"

Then load the settings:

source setup_env.sh

./bootstrap.sh creates .venv, installs the runtime dependencies in requirements.txt, and builds agfs/build/agfs-server. Full SWE-bench validation is optional; install that heavier stack only when needed with ./bootstrap.sh --install-swe-deps.

Fresh clone quickstart

Start Claude

From the project you want Claude to edit:

cd /path/to/project
claude --plugin-dir "$CONTEXTSNIPER_DIR/claude-plugin"

Do not pass --mcp-config; the Claude plugin owns its .mcp.json.

Start OpenClaw

From the project you want OpenClaw to edit:

cd /path/to/project
openclaw chat --local

Requirements

  • Python 3.11+
  • Go 1.22+
  • Claude Code CLI, OpenClaw CLI, or both
  • An OpenAI-compatible embedding endpoint and API key
  • Conda, only if you use the SWE runner's default local validation environment

Verify

Claude:

/plugin

Expected status:

contextsniper Plugin · inline · ✔ enabled
└ contextsniper MCP · ✔ connected

OpenClaw:

openclaw plugins inspect contextsniper --runtime --json

The runtime output should include:

contextsniper_health
contextsniper_index_codebase
contextsniper_search_code
contextsniper_edit_file

To confirm a run used ContextSniper search/filtering:

latest=$(ls -t ~/.openclaw/agents/*/sessions/*.jsonl | grep -v trajectory | head -1)
rg -n "ContextSniper|FILTER IS TRIGGERED|contextsniper_search_code|contextsniper_edit_file" "$latest"

For Claude, inspect the current Claude debug log or the /plugin panel. A healthy code run should show MCP tool names containing search_code and edit_file.

Code task flow

Configuration

Local settings should come from your shell environment or shell profile, which setup_env.sh imports before applying repo defaults. Do not commit real API keys.

Common settings:

Variable Purpose
CONTEXTSNIPER_EMBEDDING_API_KEY API key for real semantic code search
CONTEXTSNIPER_EMBEDDING_BASE_URL OpenAI-compatible embedding endpoint
CONTEXTSNIPER_EMBEDDING_MODEL Embedding model name
PY_BIN Optional Python override for plugin/backend runtime
CONTEXTSNIPER_FILTER_ENABLED Toggle read/exec filtering, default 1
CONTEXTSNIPER_INJECT_FILTERING_PROMPT Toggle the filtering-strategy prompt section

requirements.txt includes httpx[socks], and setup_env.sh sets NO_PROXY/no_proxy for 127.0.0.1, localhost, and ::1 so local ContextSniper/AGFS traffic bypasses HTTP(S)/SOCKS proxies.

Useful Files

SWE Lite Runner

The SWE runners build a task prompt and start Claude or OpenClaw non-interactively. See scripts/SWE/README.md for the six runner modes, run commands, output locations, and log checks.

License

This project is licensed under the Mulan Permissive Software License v2 (MulanPSL-2.0). See LICENSE.

References

  • AGFS: ContextSniper bundles and builds the local AGFS server under agfs/ and uses pyagfs for local memory/file-service operations.

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages