Skip to main content
Glama
README.md
<div align="center">

# `logcut`

**Local-First Stacktrace, Runtime Log, Test & Compiler-Error Slicing for AI Coding Agents**

[![Crates.io](https://img.shields.io/crates/v/logcut.svg)](https://crates.io/crates/logcut)
[![docs.rs](https://docs.rs/logcut/badge.svg)](https://docs.rs/logcut)
[![CI](https://github.com/bigwalkdoe/logcut/actions/workflows/ci.yml/badge.svg)](https://github.com/bigwalkdoe/logcut/actions/workflows/ci.yml)
[![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](#license)
[![Built With Rust](https://img.shields.io/badge/built_with-Rust-CE422B.svg)](https://rust-lang.org)
[![MCP Compatible](https://img.shields.io/badge/MCP-compatible-8A2BE2.svg)](https://modelcontextprotocol.io)
[![MCP Registry](https://img.shields.io/badge/MCP_Registry-listed-4B5563.svg)](https://registry.modelcontextprotocol.io)
[![Homebrew](https://img.shields.io/badge/Homebrew-bigwalkdoe%2Ftap-FBB040.svg)](https://github.com/bigwalkdoe/homebrew-tap)

[![logcut MCP on mcprush](https://mcprush.com/badge/logcut-mcp/score.svg)](https://mcprush.com/to/logcut-mcp?ref=badge)

Stop pasting 10,000-line logs and compiler walls into your LLM.<br/>
`logcut` keeps the crashing frames, root causes, failing assertions, and exact source lines—and drops the rest.

[Why logcut?](#why-logcut) • [Quickstart](#quickstart) • [MCP Setup](#mcp-server-setup) • [CLI Usage](#cli-usage) • [Architecture](#architecture)

MCP Registry: `mcp-name: io.github.bigwalkdoe/logcut`

</div>

```text
$ wc -l app.log
10482 app.log

$ logcut slice app.log --stats
== Error bursts ==
[x3 | first: 02:14:02 | last: 02:14:58] ERROR Connection refused to <UUID>

== Stacktrace ==
thread 'main' panicked at src/handler.rs:42:9:
... [3 framework/runtime frames hidden] ...
at logcut::handler::process (src/handler.rs:42:9)

== Source context ==
--- src/handler.rs (39:45) ---
  39 | // line 39
> 42 | let conn = connect();
```

`--stats` writes JSON size/token savings to stderr, so the report on stdout stays pipe-safe.

---

## Why logcut?

`logcut` is one Rust binary with two interfaces over the same pure-Rust core: an MCP server for AI hosts and a CLI for terminal pipelines. Each mode is built for the moment an agent or an engineer needs the failure, not the whole file.

- **Stacktrace Slicing (`slice_log` / `logcut slice`)** — Redacts secrets, deduplicates error bursts, collapses consecutive vendor frames, and inlines the exact `path:line` source around surviving application frames.
- **Compiler Cascade Collapsing (`slice_build` / `logcut build`)** — Parses `rustc`/`cargo`, `tsc`, `go build`, and `gcc`/`clang` output, merges repeated cascades, and reports root causes with occurrence counts.
- **Test-Failure Slicing (`slice_test` / `logcut test`)** — Handles cargo, pytest, jest/vitest, and go test; strips passing lines while keeping assertion diffs and source context.
- **Structured NDJSON (`--min-level`, `--where`)** — Detects NDJSON automatically, drops static `pid`/`hostname`/`v` metadata, filters by severity and field value, and attaches up to five correlated `INFO`/`WARN` breadcrumbs to each error.
- **Redaction by Default** — Masks Bearer tokens, `sk-`/`rk-` keys, GitHub and AWS credentials, credential-bearing database URLs, and `api_key`/`password`/`secret` assignments before anything reaches your LLM.
- **Crash Capture (`logcut watch` / `get_last_crash`)** — Streams a command, keeps a 500-line ring buffer, and atomically writes `.logcut/last-crash.md` when a panic, traceback, fatal error, or non-zero exit appears.
- **Docker & systemd Sources (`slice_container` / `slice_service`)** — Runs the same slicing engine over `docker logs` and `journalctl` output, with explicit argument arrays instead of shell interpolation.
- **Hosted Streamable HTTP (`serve-http`)** — Serves the same six MCP tools at `/mcp` behind the `http` feature for managed hosting, with a stateless server and no persistent disk.
- **One Core, Two Interfaces** — `logcut mcp` and the CLI share one pure-Rust core, and MCP schemas are generated from the same structs so the contracts cannot drift.
- **Built to Pair with treecut** — `treecut` maps the codebase; `logcut` explains what broke at runtime. Together they give an agent the code map and the failure evidence.

---

## Quickstart

### Install via Cargo

```bash
cargo install logcut
```

### Homebrew (macOS/Linux)

```bash
brew install bigwalkdoe/tap/logcut
```

### Prebuilt archives

Prebuilt archives for Linux x86_64, macOS x86_64, macOS aarch64, and Windows x86_64 are attached to the [v0.3.0 release](https://github.com/bigwalkdoe/logcut/releases/tag/v0.3.0). Each archive has a matching `.sha256` checksum; unpack it and put the `logcut` binary on your `PATH`.

### Build from source

```bash
git clone https://github.com/bigwalkdoe/logcut.git
cd logcut
cargo install --path .
```

For an MCP-only build that leaves out the `ask` HTTP client:

```bash
cargo install --path . --no-default-features --features mcp
```

For a one-command install of both `logcut` and `treecut` with shared agent setup, see [agentcut](https://github.com/bigwalkdoe/agentcut).

---

## MCP Server Setup

`logcut mcp` speaks JSON-RPC 2.0 over standard `stdio` with no background daemons and no API keys. JSON-RPC stays on stdout; diagnostics and tracing go to stderr.

### Quick setup (`logcut init`)

```bash
logcut init --all          # or --opencode / --claude / --cursor
```

With no flags, `init` writes all three sets.

| Host | Server config | Slash command |
| --- | --- | --- |
| OpenCode | `opencode.json` | `.opencode/commands/debug-log.md` |
| Claude Code | `.mcp.json` | `.claude/commands/debug-log.md` |
| Cursor | `.cursor/mcp.json` | `.cursor/rules/debug-log.mdc` |

Existing files are left untouched, so rerunning `init` is safe.

### OpenCode (`opencode.json`)

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "logcut": {
        "type": "local",
        "command": ["logcut", "mcp"]
      }
    }
  }
}
```

### Claude Code (`.mcp.json`) and Cursor (`.cursor/mcp.json`)

```json
{
  "mcpServers": {
    "logcut": {
      "type": "stdio",
      "command": "logcut",
      "args": ["mcp"],
      "description": "Run logcut mcp over stdio"
    }
  }
}
```

### Exposed MCP tools

| Tool | Purpose | Key arguments |
| :--- | :--- | :--- |
| `slice_log` | Redacted, deduplicated logs with frames and source | `path`, `raw_text`, `workspace_root`, `tail_lines`, `context_lines`, `include_vendor_frames`, `max_chars`, `min_level`, `where_filters` |
| `slice_test` | Failing tests with assertion diffs and source | `path`, `raw_text`, `workspace_root`, `tail_lines`, `context_lines`, `max_chars` |
| `slice_build` | Compiler root causes and collapsed cascades | `path`, `raw_text`, `workspace_root`, `tail_lines`, `max_errors`, `context_lines`, `max_chars` |
| `slice_container` | Docker logs through the same engine | `container`, `tail_lines`, `since`, `workspace_root`, `max_chars` |
| `slice_service` | systemd journal through the same engine | `unit`, `lines`, `workspace_root`, `max_chars` |
| `get_last_crash` | Report written by `logcut watch` | `workspace_root` |

All tools accept an optional `workspace_root` for resolving `path:line` snippets. `slice_log` additionally accepts `min_level` and `where_filters` for NDJSON streams.

### Hosted HTTP

For hosted deployments (including MCPRush managed hosting), build with the `http` feature and run:

```bash
cargo build --release --features http
logcut serve-http --host 0.0.0.0 --port 8080   # MCP at /mcp
```

`--host` and `--port` default to `0.0.0.0` and `8080` and read `LOGCUT_HTTP_HOST` / `LOGCUT_HTTP_PORT` from the environment. A root `Dockerfile` builds the same binary into a small Alpine image. The hosted server declares all six tools, but `slice_container`, `slice_service`, and `get_last_crash` need the host machine and return a "requires a local logcut install" error there; use a local install for those three.

---

## CLI Usage

Use `logcut` directly in terminal pipelines, Git hooks, or standalone debugging sessions.

```bash
# Slice a file, piped output, or inline text
logcut slice /var/log/app.log --context-lines 10 --stats
cargo test 2>&1 | logcut slice --stats

# Filter structured NDJSON by severity and fields
logcut slice app.ndjson --min-level warn --where 'status>=500' --where 'service=auth'

# Keep only failing tests with source context
cargo test 2>&1 | logcut test --stats
logcut test pytest-output.txt --workspace-root /path/to/repo

# Watch a command and save its last crash
logcut watch --workspace-root /path/to/repo -- cargo test

# Collapse compiler error walls into root causes
cargo build 2>&1 | logcut build --stats
logcut build compiler.log --workspace-root /path/to/repo --max-errors 5

# Container and systemd sources
logcut docker my-api --tail-lines 2000 --since 1h
logcut journal api.service --lines 1000

# Agentic loop (needs OPENAI_API_KEY; optional OPENAI_BASE_URL / OPENAI_MODEL)
logcut ask "why does the worker panic on startup?"
```

`--stats` writes JSON size/token statistics to **stderr**, so stdout stays pipe-safe. `--workspace-root` controls which frames count as application code and where `path:line` snippets are read from.

Defaults: `slice` tails 5,000 lines (`--tail-lines 5000`), keeps 3 context lines (`--context-lines 3`), and caps rendered text at 12,000 characters (`--max-chars 12000`); `build` reports 10 root causes (`--max-errors 10`) with 3 context lines (`--context-lines 3`) and a 12,000-character cap (`--max-chars 12000`), and tails the last 5,000 lines when reading a file (`--tail-lines 5000`); `watch` keeps a 500-line ring (`--ring-lines 500`); `docker` tails 2,000 lines and `journal` 1,000 lines. `ask` requires `OPENAI_API_KEY`; `OPENAI_MODEL` defaults to `gpt-4o-mini` and `OPENAI_BASE_URL` to `https://api.openai.com/v1`.

---

## Reports

A `slice` report deduplicates error bursts, keeps surviving stack frames, and inlines source around application frames. A compiler report collapses cascades into root causes. Structured NDJSON keeps entries and breadcrumbs. Test reports keep failures and assertion diffs.

### Stacktrace report

```text
== Error bursts ==
[x3 | first: 02:14:02 | last: 02:14:58] ERROR Connection refused to <UUID>

== Stacktrace ==
thread 'main' panicked at src/handler.rs:42:9:
... [3 framework/runtime frames hidden] ...
at logcut::handler::process (src/handler.rs:42:9)

== Source context ==
--- src/handler.rs (39:45) ---
  39 | // line 39
> 42 | let conn = connect();
```

### Compiler report

```text
== Compiler errors ==
[1] E0277 src/api.rs:42:18 — the trait bound `User: Serialize` is not satisfied
    [+3 trait/note lines collapsed]
    | serde_json::to_string(user)

== Source context ==
--- src/api.rs (39:45) ---
  39 | // line 39
> 42 | serde_json::to_string(user)
```

### Structured NDJSON report

```text
== Structured logs ==
02:14:58 ERROR Connection refused
  fields: service=auth status=500
  breadcrumbs:
  02:14:57 INFO retrying request
```

### Test report

```text
== Test failures ==
--- failure 1 ---
name: checkout_rejects_expired_card
location: tests/checkout.rs:88
message:
assertion `left == right` failed
  left: 402
 right: 200

== Source context ==
--- tests/checkout.rs (85:91) ---
  85 | // line 85
> 88 | assert_eq!(status, 200);

[passing lines stripped: 1204 | failures: 1]
```

`slice` keeps the last 5,000 lines by default. `--max-chars` truncates rendered text only, while structured fields stay complete.

---

## Working with treecut

[`treecut`](https://crates.io/crates/treecut) maps a codebase; `logcut` explains what broke at runtime. Use them together in OpenCode, Claude Code, or Cursor:

1. Ask the agent to run `treecut` on the repository to find the modules involved.
2. Reproduce the failure and pipe runtime output into `logcut slice` or compiler output into `logcut build` (or let the agent call the MCP tools).
3. `logcut` returns redacted, deduplicated errors, vendor-collapsed stack frames, collapsed compiler cascades, and inlined `path:line` snippets.
4. The agent uses the treecut map to navigate from those frames to related code, then proposes a fix.

The `/debug-log` command created by `logcut init` gives the agent that workflow in one step.

---

## Architecture

`logcut` is structured around a pure, UI-agnostic Rust core shared identically by the MCP server, the CLI, and the hosted HTTP layer:

```text
                    ┌──────────────────────────┐
                    │      logcut (binary)     │
                    └────────────┬─────────────┘
                                 │
            ┌────────────────────┼────────────────────┐
            ▼                    ▼                    ▼
   ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
   │ MCP stdio (rmcp) │ │ CLI (clap)       │ │ HTTP (axum)      │
   │ JSON-RPC / stdio │ │ slice · test ·   │ │ /mcp             │
   │                  │ │ watch · build    │ │                  │
   └────────┬─────────┘ └────────┬─────────┘ └────────┬─────────┘
            └────────────────────┼────────────────────┘
                                 ▼
   ┌──────────────────────────────────────────────────────────┐
   │                     Pure core engine                     │
   │  redaction · dedup · stacktraces · NDJSON · tests ·      │
   │  compiler cascades · source snippets · bounded reads     │
   └──────────────────────────────────────────────────────────┘
```

- **stdout is reserved for reports and JSON-RPC.** Diagnostics, tracing, and `--stats` go to stderr, so MCP framing and terminal pipelines stay clean.
- **Redaction runs before rendering and again over the final text.** Structured `snippets` remain raw source lines; treat them as sensitive if your sources hold credentials.
- **File input is tailed backwards in 8 KiB chunks.** The reader never seeks from the beginning or allocates the whole file, and `max_chars` truncates rendered text only.
- **MCP schemas are generated from the same Rust structs (`schemars`).** The published contract cannot drift from the implementation.
- **Hosted mode is stateless.** No tool writes files, creates caches, or needs a persistent disk, and host-dependent tools are refused there.

---

## Feature flags

| Feature | Default | Provides |
| --- | --- | --- |
| `cli` | yes | `logcut ask` agent loop (`reqwest`) |
| `mcp` | yes | `logcut mcp` stdio server (`rmcp`) |
| `http` | no | `logcut serve-http` (`axum`; implies `mcp`) |

`slice`, `test`, `watch`, `build`, `docker`, `journal`, and `init` are available in every build.

```bash
cargo build --no-default-features --features mcp   # MCP-only server
```

---

## Documentation

Start with the [documentation index](docs/README.md):

- [Usage guide](docs/usage.md) — commands, flags, defaults, and examples
- [MCP and agent reference](docs/mcp.md) — stdio tools, host setup, and `logcut ask`
- [Architecture guide](docs/architecture.md) — modules, invariants, and extension points
- [Troubleshooting](docs/troubleshooting.md) — common symptoms and fixes

---

## Development

```bash
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test
cargo check --no-default-features --features mcp
cargo publish --dry-run
```

## Contributing

Contributions are welcome—especially new language parsers, compiler-output fixtures, and redaction edge cases. See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, validation expectations, and PR guidance, and [CHANGELOG.md](CHANGELOG.md) for release notes.

## Privacy

`logcut` is local-first and collects no telemetry. `logcut` itself makes no network calls in `slice`, `test`, `watch`, `build`, `docker`, or `journal`; `ask` is the exception and sends the sliced context to the OpenAI-compatible endpoint you configure. Redaction is on by default, but structured `snippets` are raw source lines.

## License

Dual-licensed under either of:

- **Apache License, Version 2.0** ([LICENSE-APACHE](LICENSE-APACHE) or http://apache.org)
- **MIT License** ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org)

at your option.