OSC 7577
Tell the terminal how to bring your program back after it restarts, with OSC 7577.
Features
- Report and clear:
report(argv, cwd=...)andclear(), with the spec'stimeand token hash (mac) - Spec checks before sending: relative paths, control characters, an empty first argument, and the 2048-byte and 64-element limits. A command that cannot be reported sends
clear, so an older command is not resumed in its place - Token hygiene: the token never appears in output, and
scrub_env()dropsOSC7577_TOKENfor child processes - Verifier:
verify()parses and checks a report the way a terminal must (ignored or rejected), for terminal authors and tests - CLI:
osc7577 report,osc7577 clear,osc7577 wrap -- CMD, andosc7577 claude-hook - Windows paths:
C:\...,C:/...and\\server\sharecount as absolute;\code,/code,C:codeand/C:/...do not - Zero dependencies: the library only uses the Python standard library
- Spec examples as tests: every published example in the spec is reproduced byte for byte
Why OSC 7577?
When a terminal restarts, it can reopen its tabs and their directories, but not the programs that ran in them. A shell does not know that your REPL was open on session 42, or that an agent was in the middle of a conversation.
OSC 7577 lets the program tell the terminal the exact command that brings it back. The terminal hands each program a random token in OSC7577_TOKEN, and every report carries a hash of that token, so another program cannot register a command in your name. A terminal that does not know the sequence never sets the token, and this library then sends nothing.
Spec: Program Resume Protocol, revision 0.6 (2026-12-01).
Sibling of osc7501, which reports program status.
Installation
pip install osc7577
Usage Examples
Report and clear
import atexit
from osc7577 import clear, report, supported
if supported(): # the terminal set OSC7577_TOKEN
report(["myrepl", "--session", "/home/me/.local/state/myrepl/42.json"], cwd="/home/me/proj")
atexit.register(clear) # a normal quit should not be resumed
The first argument must be an absolute path or a bare command name, and cwd must be an absolute path. A command that breaks a rule sends clear and raises ReportError.
report() and clear() write to /dev/tty. They return True only when bytes were written, and False when the terminal did not set the token.
Child processes
import subprocess
from osc7577 import scrub_env
subprocess.run(["git", "--version"], env=scrub_env(), check=True)
Start children with env=scrub_env() so they cannot see the token or report commands in your place.
Wrap any command
osc7577 wrap -- ssh devbox
wrap reports osc7577 wrap ssh devbox with the current directory, then runs the command without the token. osc7577 report -- CMD and osc7577 clear report for the parent shell.
Claude Code
Until Claude Code reports OSC 7577 itself (anthropics/claude-code#112408), add a hook in ~/.claude/settings.json:
{
"hooks": {
"SessionStart": [{"hooks": [{"type": "command", "command": "osc7577 claude-hook"}]}],
"SessionEnd": [{"hooks": [{"type": "command", "command": "osc7577 claude-hook"}]}]
}
}
On start, resume and clear it reports claude --resume <session id> with the session's directory, owned by the claude process and written to its tty (hook output is captured, so stdout would not reach the terminal). On a normal quit it clears the record. Other endings leave it, so the terminal can resume.
Verify (terminal side)
from osc7577 import Ignored, Rejected, encode, verify
token = "dummy-token-replace-me"
sequence = encode(token=token, pid=74877, argv=["lazygit"], cwd="/home/user/src/project")
try:
rep = verify(sequence, token) # checks mac first, then time (60 s window), then keys
print(rep.pid, rep.argv, rep.cwd)
except Ignored:
pass # no effect
except Rejected:
pass # remove this owner's records
API Reference
| Name | Description |
|---|---|
report(argv, *, cwd, pid, token, stream, tty_path, env) -> bool |
Write a resume report. Sends clear and raises ReportError when the command cannot be reported. |
clear(*, pid, token, stream, tty_path, env) -> bool |
Remove this program's record. Send it on a normal quit. |
supported(env=None) -> bool |
True when the terminal set OSC7577_TOKEN. |
scrub_env(env=None) -> dict |
A copy of the environment without OSC7577_TOKEN. |
encode(*, token, pid, argv, cwd, clear, time, terminator, strict_limits, windows) -> str |
Build one full sequence. Does not write. |
build_body(*, pid, argv, cwd, clear, time, windows) -> str |
The body without the final :mac= pair. |
compute_mac(body, token) -> str |
SHA-256 of body:token as 64 hex characters (not an HMAC). |
verify(data, token, *, now, window, implemented, windows) -> Report |
Check a report as a terminal must. Raises Ignored or Rejected. |
Report |
pid, time, argv, cwd, clear, extra. |
is_absolute(path, windows=None), is_bare_command(name, windows=None) |
The spec's path rules. windows defaults to the running platform. |
ReportError, Ignored, Rejected |
Errors. ReportError is a ValueError. |
TOKEN_ENV |
"OSC7577_TOKEN". |
Learn More
- Program Resume Protocol (OSC 7577)
- Rex
- osc7501, the Program Status Protocol for Python
Acknowledgments
- Superlogical, for the Rex terminal and the Program Resume Protocol
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Built and maintained by
OSC 7577 is built and maintained by:
| Name | GitHub | Role | |
|---|---|---|---|
| Y. Siva Sai Krishna | @ysskrishna | Creator |
Changelog
See CHANGELOG for release history.
Support
If you find this library helpful:
- ⭐ Star the repository
- 🐛 Report issues
- 🔀 Submit pull requests
- 💝 Sponsor on GitHub
License
MIT © Y. Siva Sai Krishna - see LICENSE for details.
Author's GitHub • Author's LinkedIn • Author's site • Package on PyPI • Report Issues
Metadata
Release files for osc7577 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| osc7577-1.0.0.tar.gz | 20.1 kB | With provenance | Details for osc7577-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| osc7577-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for osc7577-1.0.0-py3-none-any.whl |
Total release size: 34.0 kB
Release files / osc7577-1.0.0.tar.gz
| Download URL | osc7577-1.0.0.tar.gz |
|---|---|
| Size | 20.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9603e5b4c4832fc5831a1b50e8e0276dd89013bd0b8774d2cf8f76c94ee9b827
|
|
BLAKE2b-256 checksum How to use checksums |
3135012398f079b3924b2942422bf93848c2643454a81e832178d5475bb30ce9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.13 {"installer":{"name":"uv","version":"0.13.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logRelease files / osc7577-1.0.0-py3-none-any.whl
| Download URL | osc7577-1.0.0-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9785b1a66dd45bb51bc3544d6e9a37751f8158be6aa02dac05ab5841c7362df4
|
|
BLAKE2b-256 checksum How to use checksums |
dc8410eb026d92d87bb9a7377e308aa5f3642773b645d14b12124c874f54437f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.13 {"installer":{"name":"uv","version":"0.13.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logSecurity for osc7577 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for osc7577-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.