Troubleshooting
Troubleshooting
Section titled “Troubleshooting”Fixes for common problems, and the tokensave doctor health check.
tokensave doctor
Section titled “tokensave doctor”Run a comprehensive health check of your tokensave installation:
tokensave doctorChecks: binary location, project index, global DB, user config, where project state lives, agent integration (MCP server, hooks, permissions, prompt rules), and network connectivity. If any tool permissions are missing after an upgrade, it tells you to run tokensave install. Use --agent to check a specific agent only.
Doctor also validates that each installed hook uses the correct tokensave subcommand and auto-repairs broken hooks.
Debug diagnostics
Section titled “Debug diagnostics”Diagnostic events are off by default. Use --debug for one command, set
TOKENSAVE_LOG=debug in the environment before starting an agent, or persist
"log_level": "debug" in the project’s .tokensave/config.json, so new
TokenSave MCP servers and hooks inherit it. An explicit --log-level takes
precedence over --debug, which takes precedence over TOKENSAVE_LOG, which
takes precedence over the project configuration. Levels
are off, error, warn, info, debug, and trace. Use trace only for
short captures that need per-file extraction outcomes. Unset the variable or
set it to off, or remove the project setting, then restart the agent to turn
logging off. An explicit TOKENSAVE_LOG=off temporarily disables a persisted
project level.
For example, capture a sync or an MCP session from the project directory. Choose a file outside the indexed checkout if the capture will outlive the command.
tokensave --debug sync 2> /path/to/private/sync.stderrTOKENSAVE_LOG=debug tokensave serve 2> /path/to/private/mcp.stderrFor an agent-managed server, keep its normal stdio connection and use the agent’s MCP stderr log. Stdout still carries the MCP JSON-RPC protocol.
To reproduce a Claude-compatible Bash hook decision, run this from an indexed project with a known symbol and adjust the example to match the search:
printf '%s\n' '{"tool_name":"Bash","tool_input":{"command":"rg KnownSymbol src/lib.rs"}}' | TOKENSAVE_LOG=debug tokensave hook-pre-tool-use 2> /path/to/private/hook.stderrLook for grep_check, grep_classification, grep_index_probe, and
grep_decision events. Together they show the recognized grep program, code
target eligibility, pattern shape, index lookup result, and final redirect
decision. The index probe also identifies failures that trigger the hook’s
fail-closed policy.
Each diagnostic event is a JSON line with a Unix timestamp in milliseconds,
severity, subsystem, operation, process ID, and request ID. Match an MCP request’s
events using the process and request IDs together. Process-level and background
events use request ID 0. Diagnostic fields include counts, flags, and outcomes.
They omit raw commands, query text, branch names, paths, configuration secrets,
source contents, MCP payloads, SQL text, and bound values.
Before attaching logs to a GitHub bug report, extract the relevant diagnostic lines and review them. The full stderr capture also includes ordinary errors and status messages, which can contain local paths or input values. Share the sanitized excerpt, the TokenSave version, and a minimal reproduction with private inputs replaced.
“tokensave not initialized”
Section titled ““tokensave not initialized””The .tokensave/ directory doesn’t exist in your project, or, with a base state directory set, the project has no state there yet.
tokensave initState is not where state_dir says
Section titled “State is not where state_dir says”tokensave doctor warns that a project’s state “is not at” the configured location when the project already had state before you set or changed TOKENSAVE_STATE_DIR or state_dir. tokensave keeps using the existing state, so nothing is lost. To follow the setting, stop the project’s MCP servers and move the directory doctor names to the location it gives. Doctor also lists relocated state whose project directory was deleted; tokensave state prune --dry-run shows what tokensave state prune would delete. See Keeping state outside the repository.
MCP server not connecting
Section titled “MCP server not connecting”The AI agent doesn’t see tokensave tools.
- Ensure the agent config includes the tokensave MCP server (run
tokensave doctor) - Restart the agent completely
- Check that
tokensaveis in your PATH:which tokensave
Missing symbols in search
Section titled “Missing symbols in search”- Run
tokensave syncto update the index - Check that the language is supported (see Supported Languages)
- Verify the file isn’t excluded by
.gitignore - Check the
excludeglobs in.tokensave/config.json: the defaults skip directories such asbuild/,out/andbin/, which some projects use for source (see Default excludes)
GitHub Copilot clients in doctor
Section titled “GitHub Copilot clients in doctor”tokensave install --agent copilot configures VS Code and the Copilot CLI, and VS Code Insiders and JetBrains IDEs when they are present. Doctor reports each of them separately:
- not detected: the client is not on this machine
- detected, tokensave not configured there: for example a Copilot CLI-only setup on a machine that also has VS Code. This is not counted as a problem.
- configured: the MCP registration and the instructions are both checked
- partially configured: one of the two is missing, so doctor reports an issue. When the VS Code instructions are current but
User/mcp.jsonhas notokensaveserver, the registration was removed after installation, for example by a manual edit, a reset or Settings Sync replacingmcp.jsonfrom another machine. Runtokensave install --agent copilotto restore it.
VS Code profiles that do not share the default profile’s settings read their own mcp.json under User/profiles/<id>/. Doctor lists how many profiles exist and how many of them register tokensave. Add the server to a profile from that profile with MCP: Add Server.
“branch ‘…’ is not tracked” after a checkout
Section titled ““branch ‘…’ is not tracked” after a checkout”Automatic branch tracking is on by default, but a project can turn it off. With auto_track disabled, the post-checkout hook runs on every checkout but intentionally does not register new branches, and tokensave serves them from the nearest tracked ancestor’s index. Projects initialized before tracking became the default have "auto_track": false written in their config and keep it after an upgrade.
- Run
tokensave status(or calltokensave_status) to see whetherauto_trackis enabled and why the branch was not tracked - Track the branch now with
tokensave branch add - Track new branches automatically by setting
"auto_track": truein.tokensave/config.json, orTOKENSAVE_AUTO_TRACK=1for one run; check thatTOKENSAVE_AUTO_TRACKis not set to0,false,no,off, or empty in your environment - Run
TOKENSAVE_HOOK_DEBUG=1 git checkout <branch>and read.tokensave/hook-debug.logto see what the hook decided
See Automatic branch tracking for details.
“refusing to open …: the WAL holds …-byte pages”
Section titled ““refusing to open …: the WAL holds …-byte pages””tokensave found a -wal file beside the database whose page size differs from the database’s. SQLite never writes such a file, so the database or its sidecar is corrupt or was crafted, for example a .tokensave/ directory committed to a repository. Opening it could return uninitialized memory into tool output (CVE-2026-119375), so tokensave refuses it and leaves the files untouched.
- If you don’t trust where the
.tokensave/directory came from, delete it and runtokensave init - Otherwise delete the
-waland-shmfiles named in the message and runtokensave sync --force
See Database channel compatibility for details.
“Access denied (os error 5)” on Windows
Section titled ““Access denied (os error 5)” on Windows”If sync, init, install or doctor fail with “Access denied” on lockfiles, .tokensave/, the SQLite database or .git\hooks, while your user account has full control over those folders, tokensave is probably running at low integrity level. Windows starts a program at the integrity level of its executable’s mandatory label, and a low-integrity process cannot write to ordinary (medium-integrity) folders, whatever their ACLs say. cargo install builds in %TEMP%, so if %TEMP% carries a Low mandatory label (some sandboxing tools apply one), the installed tokensave.exe inherits it.
tokensave detects this case: a failed command prints a Hint: line, and tokensave doctor reports it under Binary.
- Check the executable:
icacls "%USERPROFILE%\.cargo\bin\tokensave.exe". AMandatory Label\Low Mandatory Levelentry confirms the cause - Reset it:
icacls "%USERPROFILE%\.cargo\bin\tokensave.exe" /setintegritylevel medium - Check
%TEMP%withicacls "%TEMP%". While it carries the Low label, every latercargo installreapplies it to the new binary, so reset the binary after each upgrade or remove the label from%TEMP%
Indexing is slow
Section titled “Indexing is slow”Large projects take longer on the first full index.
- Subsequent runs use incremental sync and are much faster
- Use
tokensave sync(not--force) for day-to-day updates - Staleness is checked automatically on every MCP tool call while an agent is connected
Disabling tokensave for specific projects
Section titled “Disabling tokensave for specific projects”If a project is too large and tokensave uses too much RAM, you can disable the MCP server per-project by setting TOKENSAVE_DISABLE_SERVER=true in its environment. The server exits cleanly without initializing.
Claude Code — add to your project’s .claude/settings.json:
{ "mcpServers": { "tokensave": { "command": "tokensave", "args": ["serve"], "env": { "TOKENSAVE_DISABLE_SERVER": "true" } } }}Other agents — set the environment variable in whatever config your agent uses to launch MCP servers.
You can also set it globally via the shell (TOKENSAVE_DISABLE_SERVER=true claude), but this disables the tokensave MCP server for every project in the session.
DISABLE_TOKENSAVE=true remains supported as a deprecated compatibility alias for configurations created before this variable was namespaced.