# AI use cases for Context Mode (mksglu/context-mode)

Repo: [mksglu/context-mode](https://github.com/mksglu/context-mode) | Use cases: 5 | Page: https://dedupedai.com/use-cases/mksglu-context-mode/

Context Mode is an MCP server and hook set for AI coding agents that keeps raw tool output out of the context window, persists session memory in SQLite, and routes work across many clients.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Keep large tool output out of Claude Code's context: https://dedupedai.com/use-cases/mksglu-context-mode/cut-claude-code-context-bloat/
- Count or summarize code with one script, not many reads: https://dedupedai.com/use-cases/mksglu-context-mode/run-analysis-as-a-script/
- Pick up a coding task after the chat compacts: https://dedupedai.com/use-cases/mksglu-context-mode/resume-after-context-compaction/
- Index a local docs folder and search it from the chat: https://dedupedai.com/use-cases/mksglu-context-mode/index-local-docs-for-search/
- Add Context Mode to Gemini CLI with one settings file: https://dedupedai.com/use-cases/mksglu-context-mode/use-context-mode-in-gemini-cli/

## How to keep large tool output out of Claude Code's context with Context Mode

Repo: [mksglu/context-mode](https://github.com/mksglu/context-mode) | Difficulty: Beginner | Time: 15 minutes | Basis: From the README

Install the Claude Code plugin so sandbox tools handle big outputs instead of the chat window.

**Who it is for:** A developer using Claude Code who sees context run out after a few tool calls on a large repo or browser task.

**The problem:** Each MCP tool call dumps raw data into the context window, so a single snapshot or issue list can use a large share of the budget.

**The outcome:** Raw tool output stays in sandbox tools, the context window stays smaller, and /context-mode:ctx-stats shows the savings per tool.

### Steps

1. Run `/plugin marketplace add mksglu/context-mode` in Claude Code.
2. Run `/plugin install context-mode@context-mode`.
3. Restart Claude Code or run `/reload-plugins`.
4. Run `/context-mode:ctx-doctor` and confirm all checks show `[x]`.
5. Work as usual, then run `/context-mode:ctx-stats` to see context savings by tool.

### Prompt to paste into your agent

```text
In the context-mode repo, install the Claude Code plugin with the two /plugin commands in the README, then run /context-mode:ctx-doctor. Report whether every check shows [x]. Then run /context-mode:ctx-stats and report the savings ratio for the session.
```

### Caveat

The README says routing is automatic in the plugin, but the status line needs a manual edit to ~/.claude/settings.json, and the README excerpt does not show every routing rule.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/mksglu-context-mode/cut-claude-code-context-bloat/

## How to count or summarize code with one script, not many reads with Context Mode

Repo: [mksglu/context-mode](https://github.com/mksglu/context-mode) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Have the agent write a short script that prints only the result, using ctx_execute.

**Who it is for:** A developer or reviewer who wants a quick count or summary across many source files without loading each file into the chat.

**The problem:** Reading 50 files into context to count functions or lines uses far more context than the answer needs.

**The outcome:** The agent runs one ctx_execute call and gets back only the printed summary, such as a line count per file.

### Steps

1. Install Context Mode in Claude Code using the plugin steps from the README.
2. Ask the agent to answer a question about many files by writing a script.
3. Have the agent call ctx_execute with a javascript script that uses console.log() for the final result only.
4. Check that the printed output matches a spot check on one or two files.

### Prompt to paste into your agent

```text
Using the context-mode ctx_execute tool, write a javascript script that lists each .ts file in <target-directory> with its line count and prints only those lines. Return the printed output and confirm the count for one file by reading it directly.
```

### Caveat

The README example uses fs and a src folder, so the script must match the file layout of the target project.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/mksglu-context-mode/run-analysis-as-a-script/

## How to pick up a coding task after the chat compacts with Context Mode

Repo: [mksglu/context-mode](https://github.com/mksglu/context-mode) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Keep edits, tasks, and decisions in SQLite so the agent can recover them after compaction.

**Who it is for:** A developer on a multi-hour refactor who loses track of which files and tasks were in progress after the agent compacts the conversation.

**The problem:** When the conversation compacts, the agent forgets which files it was editing, what tasks are open, and what the user last asked for.

**The outcome:** After compaction the agent retrieves the relevant events through BM25 search and continues the same task.

### Steps

1. Install Context Mode with the Claude Code plugin steps from the README.
2. Work on the task so that file edits, git operations, and decisions are recorded.
3. When the session compacts, let the agent continue in the same session.
4. If you need the earlier data in a later session, start that session with `--continue`, because without it previous session data is deleted immediately.

### Prompt to paste into your agent

```text
After a context compaction in the <project-name> repo, use context-mode to search the session events for the last edited files and open tasks. List them and ask me to confirm before continuing the work.
```

### Caveat

The README says previous session data is deleted unless you use --continue, so plan which sessions you want to keep before starting a new one.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/mksglu-context-mode/resume-after-context-compaction/

## How to index a local docs folder and search it from the chat with Context Mode

Repo: [mksglu/context-mode](https://github.com/mksglu/context-mode) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Add a local file or folder to the FTS5 knowledge base and query it later.

**Who it is for:** A developer who wants the agent to search project docs or notes without pasting them into each prompt.

**The problem:** Reference material pasted into the chat takes up context on every turn and is lost when the session ends.

**The outcome:** The docs are stored in the persistent FTS5 knowledge base and returned by search results when relevant.

### Steps

1. Install Context Mode with the Claude Code plugin steps from the README.
2. Run `/context-mode:ctx-index` and give it the path to a local docs folder.
3. Run `/context-mode:ctx-search` with a question about the docs.
4. Check that the returned passage comes from the indexed files.
5. Run `/context-mode:ctx-purge` when you no longer need the indexed content, since it deletes everything in the knowledge base.

### Prompt to paste into your agent

```text
Index the folder <docs-path> with the context-mode ctx-index command, then search it with ctx-search for <question>. Return the matching passages with their source file names and confirm that each passage appears in the original file.
```

### Caveat

ctx-purge permanently deletes all indexed content, not just one folder, so use it only when you want a full reset.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/mksglu-context-mode/index-local-docs-for-search/

## How to add Context Mode to Gemini CLI with one settings file with Context Mode

Repo: [mksglu/context-mode](https://github.com/mksglu/context-mode) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Install the npm package and register the MCP server and four hooks in settings.json.

**Who it is for:** A developer who uses Gemini CLI on large repos and wants the same context savings without the Claude Code plugin.

**The problem:** Gemini CLI tool output can fill the context window quickly, and the default setup has no sandbox for it.

**The outcome:** The MCP server shows as connected and the BeforeTool, AfterTool, PreCompress, and SessionStart hooks route large output through Context Mode.

### Steps

1. Run `npm install -g context-mode`.
2. Add the mcpServers and hooks block from the README to `~/.gemini/settings.json`.
3. Restart Gemini CLI.
4. Run `/mcp list` and confirm `context-mode: ... - Connected`.
5. Optionally copy `configs/gemini-cli/GEMINI.md` into your project as `./GEMINI.md` for routing instructions. (inferred, check the README)

### Prompt to paste into your agent

```text
Install context-mode globally with npm, add the Gemini CLI settings from the context-mode README to ~/.gemini/settings.json, then run /mcp list in Gemini CLI. Report whether context-mode shows as Connected and list the four hooks that are registered.
```

### Caveat

The README says Gemini CLI needs Node.js >= 22.5 or Bun, so check your runtime before editing the settings file.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/mksglu-context-mode/use-context-mode-in-gemini-cli/
