Skip to content
←  Home 日本語

CLI & API

Overview

Mimicry ships with the mimicry CLI tool, so a terminal or an AI agent can search traffic logs, author mock rules, and set up the proxy without ever touching the GUI. At its core is the rule command: starting from a captured request, you can swap in an error response, rewrite a single field, or inject a delay with one command.

Prerequisite: Commands that rely on the app's traffic log and rules, such as status / logs / rule / setup, work only while the Mimicry GUI app is running; otherwise they fail with guiNotRunning (exit 4). serve / compare / docs / init / completions / mcp-server run without the app. If the app is not running, start it with open -a Mimicry, or add --start-gui to a command that uses the app to have it start automatically and wait (this opens a window on your desktop).

Installation

Install with Homebrew (recommended)

When installed with Homebrew, the CLI is added to your PATH automatically.

brew tap kusumotoa/tap
brew install --cask mimicry

When installed manually from the DMG

The CLI binary is bundled in the app. Create a symbolic link with the following command to put it on your PATH.

sudo ln -sf /Applications/Mimicry.app/Contents/MacOS/Mimicry /usr/local/bin/mimicry

Verify the installation

mimicry status

Command list

CommandDescription
mimicry statusCheck proxy status and log count
mimicry logs / mimicry log <id>Search traffic logs (filter with --domain, --status-code, --url, etc.) and inspect one in detail
mimicry domains / mimicry endpoints <domain>List captured domains, and endpoints for a given domain
mimicry curl <id>Output a curl command that reproduces the request. By default the values of Authorization / Cookie and similar headers are [REDACTED] (you can turn that off in Global Settings)
mimicry save <path>.harSave logs to a .har file
mimicry rule ...Create (set / generate), get (get / list), delete (delete / clear), enable and disable mock rules, and export or import settings (export / import) (the CLI's core feature)
mimicry script ...Register, list, get, enable, disable and delete JavaScript scripts (onRequest / onResponse hooks). set --watch re-registers the file whenever it changes
mimicry project ...List, create, rename, duplicate, enable and disable projects, plus the folders inside them (project folder). Only delete is deliberately missing, so rules a human made in the GUI can't be wiped out by accident
mimicry device listList iOS Simulators / Android emulators / Android devices (including ones that aren't booted)
mimicry device restart-app --device <spec> --app <id>Restart the app under test (iOS Simulator and Android; physical iOS devices are not supported)
mimicry firewall statusShow the Simulator Firewall status (read-only — there is deliberately no command to change the settings)
mimicry setup ...Start the proxy (proxy-start), point a device at it (device), list this Mac's network interfaces (network-interfaces), change the domain filter and caching settings (proxy-config), undo the changes (teardown), and install or delete the CA certificate (cert). Check the state with status
mimicry docs ...List and show the practical documentation embedded in the binary
mimicry recording ...Start (start), stop (stop), discard (discard), check (status), list (list), show (show) and delete (delete) Time-Travel recordings, list the devices that can be screen-recorded (list-devices), and mutate (mutate), trim (trim) and export the video (export-video)
mimicry serve --rules <file>Start a standalone proxy server without the GUI
mimicry compare --rules <file> <url>Diff mock rules against a live server (--fail-on-diff to gate CI)
mimicry dry-run-script --script <file> --input <json>Run one script hook against a synthetic request/response and report console output, thrown errors and the modified result (for CI; needs the app running)
mimicry mcp-serverRun as an MCP stdio server that exposes 29 tools (it starts without the app)
mimicry init --client claudeWrite the Agent Skill in Claude Code / AGENTS format
mimicry completions <shell>Generate a shell completion script (bash / zsh / fish / elvish / powershell)

--json (a single-line JSON envelope, whose exit code maps to 0-7) is common to every command. --start-gui (auto-launch the GUI app and wait if it isn't running yet) takes effect only on commands that use the app, and is ignored by the standalone ones.

rule: verify behavior by injecting errors

The typical flow has four steps: capture the target request with logs, build a rule from its ID, re-operate the app to verify, then revert. The rule takes effect the moment the command returns, so there is no need to sleep.

# 1. Find the ID of the target request
mimicry logs --domain api.example.com --limit 5

# 2. Swap that request for a 500 error (takes effect immediately, no sleep needed)
mimicry rule set --from-log req-abc123 --status 500
# → Rule saved: rule-xyz789  GET  /api/orders/*  [full mock]

# 3. Re-operate the app to verify the error handling

# 4. Once verified, revert
mimicry rule delete rule-xyz789

Beyond swapping in a full mock, you can also let the real response through and rewrite just one field. A delay (--delay) works either way — on a full mock and on a passthrough rule (--patch / --merge / --against-real) alike. It fires before the request reaches the upstream, so the client-side latency is the same in both cases. The app deletes a rule with --ttl once the given time has passed, and a rule with --times once it has been applied that many times. You can see how many times it has been applied in ruleUse of mimicry logs --json.

# Let the real response through and rewrite just one field
mimicry rule set --from-log req-abc123 --patch '/user/isPremium=true'

# Inject a delay into a full mock
mimicry rule set --url '/api/heavy' --status 200 --body '{}' --delay 3000

# Or add a delay to a passthrough rule (combining it with --patch is fine)
mimicry rule set --url '/api/heavy' --patch '/flag=true' --delay 3000

# A temporary rule that deletes itself after 5 minutes
mimicry rule set --from-log req-abc123 --status 500 --ttl 5m

# Fail only the first request (the rule deletes itself after one use)
mimicry rule set --from-log req-abc123 --status 500 --times 1

project: a safety net for humans' rules

rule set --id, rule delete, rule enable and rule disable are refused if the target rule sits outside the project named by --project (the auto-created "CLI Rules" project, if omitted). This keeps an AI agent from accidentally rewriting or deleting a mock rule a human authored in the GUI. Use project list to see which projects exist. Creating, renaming, duplicating, enabling and disabling projects — and managing the folders inside them (project folder ...) — are all available from the CLI too; only delete is deliberately missing, because it can't be undone, so it stays a GUI-only action.

# See what projects exist
mimicry project list

# Name the project explicitly to touch a rule outside "CLI Rules"
mimicry rule delete rule-xyz789 --project "QA"

There's also a per-project lock. A newly created project starts locked by default, and the CLI cannot read or write anything inside it until a human unlocks it from the lock icon in the GUI sidebar (or its right-click menu). There is deliberately no CLI command to unlock a project — letting the CLI unlock itself would defeat the point of the safety net. An operation on a locked project is refused with a projectLocked error (exit 4), and project list still shows a locked project's existence and name, but redacts its folders and rule count.

# A locked project's existence is visible, but its contents are redacted
mimicry project list --json
# → {"id": "...", "name": "QA", "locked": true, "ruleCount": 0, "folders": []}

# An operation on a locked project is refused
mimicry rule list --project "QA"
# → Error: this project is locked to CLI access — unlock it from the lock icon
#    next to the project in the Mimicry sidebar (or its right-click menu)

rule export / import: writing and reading settings

rule export writes projects, scripts, and settings to JSON, and rule import reads that file back. Without --out, it goes to standard output.

# Take a backup (written with mode 0600; an existing file is not overwritten without --force)
mimicry rule export --out backup.json

# Read it back (projects only by default; widen it with --scope)
mimicry rule import backup.json --scope projects,scripts

By default, values that may be secrets are left out of the export: the header values of header injections, and the headers, bodies and URL query strings of saved requests. They are written only with --reveal-secrets. Environment variables are written by name and description only, never their values. On the other hand, mock rules' response headers and bodies, and script sources, are written as they are, so check that you have not typed a token or cookie into them before exporting.

An import keeps what is already there: a header injection, script or saved request whose ID already exists is left as it is, and projects are updated by ID. To create rules from an OpenAPI definition, use rule import --openapi <path>.

setup: get the proxy and device ready

Covers starting the proxy, pointing a device (iOS Simulator / Android) at it, installing the CA certificate (setup cert install), and removing the macOS one (setup cert delete). Start with setup status to see what's ready and what's missing. setup device for an iOS Simulator changes the macOS system proxy, so traffic from every app on this Mac goes through Mimicry (setup teardown reverts it). Installing the certificate with --target macos writes to this Mac's login keychain and affects every app that trusts the keychain. There is deliberately no command to stop the proxy — that keeps an AI agent from disabling the monitoring of its own traffic; stop it from the GUI instead.

# See what's ready and what's missing
mimicry setup status

# Point the simulator at the proxy (this does not install the CA)
mimicry setup device sim:0B4F1234-5678-90AB-CDEF-1234567890AB

# Install the CA certificate
mimicry setup cert install --target sim:0B4F1234-5678-90AB-CDEF-1234567890AB

# Revert once you're done
mimicry setup teardown

docs: read the embedded documentation

The binary embeds 30 chapters of practical documentation, which you can read even while the app and proxy are not running. mimicry docs list shows them all. Start from cli/getting-started; cli/rule-loop covers swapping rules and verifying, cli/output-envelope covers the --json output, and cli/mcp covers MCP. cli/output-contract is an alias for cli/output (the index of the output chapters), not a canonical name.

mimicry docs list
mimicry docs show cli/rule-loop

--json output and exit codes

With --json, standard output is always exactly one line of JSON. Success and failure share the same shape (the envelope).

{"ok":true,"schema":1,"command":"rule.set","exitCode":0,"data":{...},"warnings":[{"kind":"...","message":"...","next":["..."]}]}
{"ok":false,"schema":1,"command":"rule.set","exitCode":4,"error":{"kind":"guiNotRunning","message":"...","detail":{},"docs":"cli/getting-started","next":["mimicry status --start-gui"]}}
exit codeMeaning
0Success
1Ran fine, but the answer is "no" (only compare --fail-on-diff returns it)
2Argument error
3Target not found, or could not be narrowed to one
4A precondition isn't met (app not running, proxy stopped, confirmation needed, and so on)
5Not supported on this platform or from this CLI
6An external tool or network call failed
7Internal error (a bug in the CLI)
  • Branch on ok and error.kind, not on the wording of message. ok: false happens only for exit codes 2-7.
  • On a failure, run error.next[0] first; if that does not fix it, pass the name in error.docs to mimicry docs show and read it.
  • Warnings are in the envelope's warnings[] and are also printed to standard error, one per line. Reading both streams together breaks the JSON parse, so read standard output on its own.

Other features

There's also mimicry recording to capture traffic plus screen recordings (recording trim cuts the head and tail off a recording; a range that would keep zero entries is refused, and you re-run it with --allow-empty if that really is what you meant. The pre-trim contents are kept next to the recording as <id>.mimicry.bak), mimicry serve to serve mock rules without the GUI, and mimicry compare to diff mock rules against a live server (a diff is exit 0 by default; add --fail-on-diff to get exit 1 for CI gating).

REST API

Mimicry exposes the same functionality as a REST API on port 19852. AI agents and automation scripts are expected to use the CLI in practice, so details are omitted here. The API listens on 127.0.0.1 only and validates the Host / Origin headers. Every route except the two used by Mimicry Capture requires Authorization: Bearer <token>. The token is generated on every launch and written to ~/Library/Application Support/com.mimicry.proxy/mimicry-token (mode 0600), and the CLI reads that file automatically.

AI tool integration

Run mimicry init --client claude and it writes a Claude Code Agent Skill to ~/.claude/skills/mimicry/SKILL.md. --client takes auto (the default; writes to every one of ~/.claude and ~/.agents that exists), claude, or agents (~/.agents/skills/mimicry/SKILL.md, for AGENTS-style clients such as codex). --dest names a directory directly and writes just that one copy.

mimicry init --client claude
# → wrote ~/.claude/skills/mimicry/SKILL.md

The skill itself carries no command examples — at runtime it simply points the agent at mimicry docs show. That keeps the skill from drifting out of sync with the CLI's version, since it always references documentation embedded in the binary you actually have installed.

MCP server

An AI agent running inside a container or sandbox cannot run mimicry on the Mac. mimicry mcp-server is a stdio server that exposes 29 of the CLI's commands as MCP tools. The MCP client starts it as a subprocess, and it exits when the client disconnects.

# Register it with Claude Code
claude mcp add mimicry -- mimicry mcp-server

The MCP tools have no commands that delete things and none from the setup family, so it is safer to have the agent give the rules it creates a ttl. rule_export always returns the JSON inline (it never writes a file) and leaves secrets out. rule_set takes body and merge as the text itself, and does not read @file or - as a file or stdin. You can switch each tool on or off in the app's Global Settings (see Advanced).