SAGE
This server lets AI agents run and manage local SAGE-wrapped terminal commands with compact summaries, error analysis, recovery, and file operations.
Run single local shell commands (
sage_call) and commands with automatic diagnosis/retry (sage_agentic_run)Explain failures and get fix suggestions (
sage_explain_error,sage_suggest_fix,sage_agentic_fix)List recent run history and recover exact raw output (
sage_get_history,sage_show_raw)Read, search, glob, and browse files with context-saving compression (
sage_read_file,sage_grep,sage_glob,sage_tree)Write or edit files with snapshots for reversibility (
sage_write_file,sage_edit_file)Run named local workflows such as test, lint, build, or ci (
sage_run_workflow)Spawn focused specialists for code, test, debug, security, or performance tasks (
sage_spawn_agent)Inspect the current agentic session state, failure streak, and intent chain (
sage_agentic_session)
SAGE - Smart Agent Guidance Engine
SAGE is a local-first command wrapper for AI coding agents. It keeps full terminal output on your machine, sends agents a clean compressed summary, and tracks proof metrics without uploading your raw logs.
Use it with Claude Code, Codex, Cursor, Windsurf, OpenCode, Cline, custom agents, CI scripts, and normal terminal workflows.
Start Here: Install SAGE, Use once sage run -- python -m pytest, Then Use Any AI Agent
Package installation is passive for package-registry safety. After installing, run sage install once to activate SAGE for supported local AI agents.
PyPI / pip
pip install psycgod-sage
# or
python -m pip install --upgrade psycgod-sage
sage install
sage run -- python -m pytestnpm / npx
npm install -g psycgod-sage
npx -y psycgod-sage install
npx -y psycgod-sage run -- npm testAfter install, restart any open AI-agent sessions. New sessions should read the SAGE instructions automatically and route terminal commands through SAGE.
Example prompt after restarting your AI agent:
Please help me with my general book in this folder.Natural shortcuts also work:
sage pytest
sage npm test
sage git statusThese are treated as:
sage run -- pytest
sage run -- npm test
sage run -- git statusRelated MCP server: knitbrain
What SAGE Does
Step | Result |
| Activates the machine locally, repairs global/project agent instructions, and verifies activation |
| Runs the command, stores raw output locally, and returns a compact useful summary |
Agent memory/hooks | Tell supported AI agents to use SAGE for noisy terminal work |
Local database | Keeps command history, compression proof, and retry context on the user's machine |
Local proof | Keeps command and compression metrics on the user's machine |
SAGE does not auto-enable MCP. MCP is optional and manual for users who want it.
Recorded Local Metrics
Latest pulled stats as of 2026-08-01:
Metric | Value |
SAGE telemetry command events | 27,892 |
Tokens processed | 799.5M |
Tokens saved | 783.7M |
Compression rate | 98.02% |
Estimated savings | $16,261.90 |
Command success rate | 88.3% |
PyPI downloads, last 7 days | 632 |
npm downloads, last 7 days | 362 |
GitHub clones, last 14 days | 574 |
Why It Helps
AI coding agents burn context on repeated logs, failed test output, install noise, stack traces, and build spam. SAGE sits between the command and the agent.
Without SAGE | With SAGE |
Agent sees full noisy terminal output | Agent sees the useful summary |
Context disappears fast | Context lasts longer |
Repeated failures waste tokens | Errors are grouped and explained |
Raw logs may enter prompts | Raw logs stay local |
Hard to prove savings | SAGE records proof metrics |
Distribution
Channel | Package | Status |
PyPI | Canonical Python package | |
npm / npx | Node launcher for the Python core | |
MCP Registry |
| Optional/manual MCP entry |
Glama | Optional/manual hosted MCP listing |
The npm package delegates to the Python implementation so both install paths use the same local database, telemetry rules, compression, and command behavior.
Common Commands
sage install # Activate this machine and AI-agent instructions
sage doctor --activation # Verify activation
npx -y psycgod-sage doctor --activation
sage run -- <command> # Wrap any command
sage run --cwd /project -- <command> # Explicit workspace for host integrations
sage pytest # Shortcut for: sage run -- pytest
sage npm test # Shortcut for: sage run -- npm test
sage git status # Shortcut for: sage run -- git status
sage context stats # Token savings summary
sage context report # Full compression report
sage history --limit 10 # Recent command history
sage explain --failed # Explain the latest failed command
sage suggest --failed # Suggest the next fix
sage fix --apply # Try an automatic fix
sage ml setup # Optional ML V2 dependencies
sage mcp install # Optional/manual MCP config
sage dashboard start # Local dashboardPrivacy Modes
Mode | Requires login? | Sends data? | What leaves the machine? |
Local-only | No | No | Nothing |
Debug telemetry | Optional | Opt-in only | Redacted diagnostic summaries |
SAGE is designed to keep prompts, source code, credentials, raw command output, and project files local unless the user deliberately enables a feature that requires sending data.
Known Limitations
Limitation | What To Do |
Already-open AI-agent sessions may not reload new instructions | Restart Claude/Codex/Cursor/Windsurf/OpenCode after |
Locked-down host apps can disable shell tools | SAGE cannot enable tools the host application has blocked |
A host starts its shell in the wrong folder | Pass |
npm/PyPI installs cannot safely auto-run activation | Run |
MCP can disconnect in some stdio agent sessions | Use normal |
Package installs are passive by design | Real activation starts with |
Demos
Flow | Preview |
PyPI install |
|
npm install |
|
| |
CLI run |
|
Links
License
MIT. See LICENSE.
Available Tools
16 toolssage_agentic_fixA
Return the single best fix candidate for a failed SAGE command. Use when you need one actionable repair plan, not a list of alternatives. Input is an optional SAGE run id; when omitted, the most recent failed run is analyzed. Returns fix_command, strategy, confidence, and explanation, or null when no safe fix is known. Read-only: does not execute the fix and does not edit files.
Inputs: command_id.
sage_agentic_runA
Run one local command with SAGE's failure-recovery loop. Use for development commands where automatic diagnosis and retry may help, such as tests or builds. Autonomy controls behavior: suggest reports fixes only, ask requires confirmation, auto may apply safe fixes and retry. Returns command result, recovery attempts, and verification status. Do not use for destructive commands, credential entry, production deploys, or external account changes.
Inputs: command (required), autonomy, max_retries.
sage_agentic_sessionA
Get the current agentic session state — failure streak, recent errors, intent chain. Useful for understanding context before deciding next action.
Inputs: no named parameters.
sage_callA
Run one local shell command through SAGE with a purpose label. Use when you need command execution and want the result categorized as read, search, test, build, deploy, audit, or unknown. Returns exit_code, compact output, run_id, purpose, and agent metadata. Side effects are exactly the side effects of the command itself. Do not use for secrets, credential prompts, or deployment unless explicitly requested.
Inputs: command (required), agent, purpose.
sage_edit_fileA
Exact string replacement in a file. Returns a compact change preview instead of the whole file, and snapshots the pre-edit content for undo. old must match exactly and be unique unless replace_all=true.
Inputs: new (required), old (required), path (required), replace_all.
sage_explain_errorA
Explain why a previous SAGE command failed. Use after a non-zero command exit before editing code or retrying. Input is an optional SAGE run id; when omitted, the most recent failed run is analyzed. Returns a structured object with error_type, summary, root_cause, affected_files, and suggestions. Read-only: does not run commands, edit files, or contact external services.
Inputs: command_id.
sage_get_historyA
List recent local SAGE command runs. Use to find a run_id for sage_show_raw, sage_explain_error, or sage_suggest_fix. Returns compact metadata such as run_id, command summary, exit_code, duration, timestamp, and compression ratio. Read-only: reads the local SAGE database only and does not execute commands.
Inputs: limit, failed_only.
sage_globA
Find files by pattern, newest first, junk directories ignored, capped output. Prefer over recursive directory listings.
Inputs: pattern (required), root, limit.
sage_grepA
Search files with compressed, grouped results (exact paths and line numbers kept). Prefer this over rg/grep when output may be large.
Inputs: pattern (required), glob, paths, ignore_case.
sage_read_fileA
Read a file with SAGE compression: small files exact, large files as outline + head with line references. Prefer this over cat/type/Get-Content to save context.
Inputs: path (required), raw, lines, symbols, +1 more.
sage_run_workflowA
Run a named local workflow through SAGE, such as test, lint, build, or ci. Use when the project has a repeatable workflow and you want one structured result instead of several separate shell calls. The workflow must be local/project-defined. Returns success, per-step status, duration, and compact output. Side effects: runs the workflow's local commands and may change files if the workflow commands do. Do not use for deployment unless the user explicitly requested deployment.
Inputs: workflow_name (required), workflow_path.
sage_show_rawA
Recover the exact stored output of a previous run by ID (compression never destroys the original).
Inputs: run_id.
sage_spawn_agentA
Run one focused local SAGE specialist for a bounded development task. Use only when a task clearly matches one specialization: code, test, debug, security, or performance. Returns agent_type, task, status, and a compact result. Side effects depend on the task: the specialist may inspect files, run local commands through SAGE, or propose edits. Do not use for open-ended chat, secrets, credentials, or tasks requiring external account access.
Inputs: task (required), agent_type (required).
sage_suggest_fixA
Suggest safe next steps for a failed SAGE command. Use after sage_explain_error when you want possible fixes but do not want them executed automatically. Returns a list of fix suggestions with explanation, confidence, and candidate command when available. Read-only: it never applies patches and never runs the suggested command.
Inputs: command_id.
sage_treeB
Compact depth-limited directory overview instead of ls -R noise.
Inputs: root, depth, limit.
sage_write_fileA
Create or update a file. Returns bytes/lines/sha256 confirmation instead of echoing the content back — saves the whole file's tokens. Existing files require overwrite=true (a snapshot is taken first so it is reversible).
Inputs: path (required), content (required), append, overwrite.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 16 tools
Most tools target distinct actions, but the failure-handling cluster (sage_explain_error, sage_suggest_fix, sage_agentic_fix) and the command-execution pair (sage_call vs sage_agentic_run) overlap enough that an agent could hesitate. Descriptions do a good job distinguishing them (single fix vs list vs explanation; recovery loop vs plain run), which keeps this above the mid range.
Every tool uses the sage_ prefix with snake_case, following a predictable verb_noun or verb form (write_file, read_file, run_workflow, spawn_agent, explain_error). The few bare names (call, grep, glob, tree) are conventional and still fit the pattern.
16 tools sits just above the ideal 3-15 band, but the domain is genuinely broad (file I/O, search, command execution, agentic recovery, workflows, history), so each tool earns roughly its place. Slightly over-scoped rather than bloated.
Covers read/write/edit, search (grep/glob/tree), command execution, workflows, history, error diagnosis, fix suggestion, and agent spawning — a near-complete lifecycle. A file delete/remove operation is the most visible gap, but agents can work around it.
Maintenance
Related MCP Connectors
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
Real-time chat hub for AI agents — Claude Code, Cursor, Cline, Codex over MCP or REST.
Real-time chat for AI agents. Claude Code, Cursor, Cline and Codex join channels over MCP.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Related MCP Servers
- FlicenseNot gradedqualityNot gradedmaintenanceA secure and pluggable MCP server to run terminal commands on your local machine or cloud server — remotely, safely, and with LLMs or agentic clients.-
- AlicenseAqualityCmaintenanceLocal-first MCP server that gives any AI coding agent per-project memory, workflow intelligence, and always-on, lossless token & context optimization.3765 npm6MIT
- AlicenseAqualityAmaintenanceAn agent-native shell as an MCP server, designed for LLM agents (like Claude Code) to execute commands with structured output, lazy detail retrieval, and effect tracking, minimizing token usage.99 npmMIT
- FlicenseNot gradedqualityAmaintenanceLocal MCP server that lets your AI coding agent query its own cross-tool project history - file/command freshness, past test failures, cost & token spend, cache status, and session handoff - over stdio, 100% local, no telemetry.58-


