MCPcopy Index your code
hub / github.com/aymanbagabas/go-pty

github.com/aymanbagabas/go-pty @v0.2.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.3 ↗ · + Follow
81 symbols 168 edges 17 files 50 documented · 62% 2 cross-repo links updated 1d agov0.2.3 · 2026-05-17★ 734 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Go Pty

<a href="https://github.com/aymanbagabas/go-pty/releases"><img src="https://img.shields.io/github/release/aymanbagabas/go-pty.svg" alt="Latest Release"></a>
<a href="https://pkg.go.dev/github.com/aymanbagabas/go-pty?tab=doc"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a>
<a href="https://github.com/aymanbagabas/go-pty/actions"><img src="https://github.com/aymanbagabas/go-pty/workflows/build/badge.svg" alt="Build Status"></a>

Go-Pty is a package for using pseudo-terminal interfaces in Go. It supports Unix PTYs and Windows through ConPty.

Why can't we just use os/exec?

Windows requires updating the process running in the PTY with a special attribute to enable ConPty support. This is not possible with os/exec see go#62708 and go#6271. On Unix, pty.Cmd is just a wrapper around os/exec.Cmd that sets up the PTY.

Usage

go get github.com/aymanbagabas/go-pty

Example running grep

package main

import (
    "io"
    "log"
    "os"

    "github.com/aymanbagabas/go-pty"
)

func main() {
    pty, err := pty.New()
    if err != nil {
        log.Fatalf("failed to open pty: %s", err)
    }

    defer pty.Close()
    c := pty.Command("grep", "--color=auto", "bar")
    if err := c.Start(); err != nil {
        log.Fatalf("failed to start: %s", err)
    }

    go func() {
        pty.Write([]byte("foo\n"))
        pty.Write([]byte("bar\n"))
        pty.Write([]byte("baz\n"))
        pty.Write([]byte{4}) // EOT
    }()
    go io.Copy(os.Stdout, pty)

    if err := c.Wait(); err != nil {
        panic(err)
    }
}

Refer to ./examples for more examples.

Credits

License

This project is licensed under the MIT License - see the LICENSE for details.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Method 46
Function 26
Struct 5
Interface 4

Languages

Go100%

Modules by API surface

pty_unix.go15 symbols
pty.go15 symbols
pty_windows.go13 symbols
cmd_windows.go13 symbols
examples/shell/main.go4 symbols
cmd.go4 symbols
examples/shell/size_windows.go3 symbols
examples/shell/size_other.go3 symbols
cmd_unix.go2 symbols
cmd_other.go2 symbols
winsize_other.go1 symbols
ssh_unix.go1 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add go-pty \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page