К основному содержанию
скилл CX Codex

process-api-net11 — скилл для Claude Code: что делает и как установить

Скилл подсказывает ИИ новые методы System.Diagnostics.Process в .NET 11: запуск утилит без дедлоков в пайпах, чтение stdout и завершение дочерних процессов.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add dotnet/skills --skill process-api-net11 -a claude-code
Открыть на GitHub

Что делает process-api-net11

Скилл обучает ассистента сигнатурам и правилам работы с новыми API в System.Diagnostics.Process, добавленными в .NET 11. Он помогает писать код для Process.Run, Process.RunAndCaptureText, Process.StartAndForget и методов прямого чтения потоков вроде ReadAllTextAsync. Это избавляет от громоздкого ручного кода и предотвращает дедлоки при переполнении буферов ОС во время перенаправления вывода.

Справочник содержит описания типов ProcessExitStatus, ProcessTextOutput и новых свойств конфигурации, включая KillOnParentExit. Этот флаг гарантирует аварийную остановку дочерних процессов при падении родителя на Windows, Linux и Android.

Главное ограничение строгое: проект обязан использовать целевую платформу net11.0 или выше. Для .NET 10 эти вызовы недоступны, код просто не скомпилируется. При вызове Process.StartAndForget нельзя включать перенаправление потоков или выставлять UseShellExecute = true, иначе среда выполнения сразу выбросит InvalidOperationException.

Какие задачи решает

  • перехватить stdout и stderr внешнего процесса без риска дедлока
  • гарантированно завершить дочерний процесс при аварийном падении родительского
  • запустить фоновую утилиту в .NET 11 без ручного вызова Dispose
  • прочитать построчно вывод команды через ReadAllLinesAsync

Примеры запросов агенту

  • Перепиши вызов внешней утилиты на новый Process.RunAndCaptureTextAsync для проекта на .NET 11
  • Запусти фоновый процесс через Process.StartAndForget без перенаправления потоков
  • Настрой завершение дочернего процесса через KillOnParentExit при падении хоста

Как установить process-api-net11

1Через Skills CLI (Vercel)

npx skills add dotnet/skills --skill process-api-net11 -a claude-code

2Вручную: положить файлы

~/.claude/skills/process-api-net11/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/process-api-net11/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Из того же набора101

use-igniteui-blazor Скилл помогает подключить и настроить библиотеки Ignite UI for Blazor Lite в проектах на .NET 8.0 и новее. Он проверяет зависимости, стили и интерактивный режим. CX Codex +1 1 500установок msbuild Скилл для разбора упавших сборок MSBuild, анализа их скорости и ревью XML-файлов проекта. Пригодится, когда dotnet build падает или собирается слишком долго. CX Codex +1 1 000установок winforms-expert Скилл для работы с Windows Forms: правит код так, чтобы проект собирался, работал в рантайме и оставался редактируемым в Visual Studio Designer. CX Codex +1 955установок csharp-expert Скилл-диспетчер для C# и .NET: определяет, какой установленный специалист должен взять задачу, и даёт команды установки недостающего плагина из dotnet/skills. CX Codex +1 902установок code-testing Скилл для генерации, починки и усиления тестов: xUnit, MSTest, NUnit, pytest, Vitest/Jest, Go. Точечную работу делает сам, широкую отдаёт субагенту test-engineer. CX Codex +1 863установок test-value-evidence Проверяет тесты на конкретное изменение: PR, коммит или новую фичу. Показывает, что тест действительно ловит дефект до фикса. CX Codex +1 565установок eliminate-redundant-restores Безопасно убирает повторные шаги NuGet restore из многоэтапных сборок .NET в CI и скриптах. Помогает избежать ошибок NETSDK1004 и NETSDK1047 при добавлении флага --no-restore. CX Codex +1 404установок dotnet Набор скиллов по C# и .NET плюс языковой сервер для файлов .cs. Пригодится, когда агент правит код на C#. ★ 5 730звёзд репо

Похожие

mcp-builder официальный anthropics Скилл проводит через создание MCP-сервера на TypeScript или Python: от изучения протокола до тестов и оценки качества. 130 949установок claude-api официальный anthropics Справочник по Anthropic SDK и API Claude для генерации кода без устаревших параметров и выдуманных методов. 74 198установок lark-im larksuite Скилл подключает Lark IM к агенту: он отправляет сообщения, ищет историю, управляет чатами и файлами. Подойдёт для задач вокруг командных коммуникаций. CX Codex +1 472 900установок lark-event larksuite Слушает события Lark/Feishu и отдаёт их потоком NDJSON. Подходит для ботов, обработчиков сообщений и долгих подписчиков. CX Codex +1 466 800установок caveman-discover JuliusBrussee Находит точки вызова LLM в репозитории и размечает их воркфлоу для Caveman Cloud, чтобы расходы на токены не сливались в одну общую кучу. CX Codex +1 104 400установок migration JuliusBrussee Скилл задаёт правила безопасных миграций схем, данных и API с обязательным откатом. Пригодится при изменениях, где нельзя терять данные или ломать совместимость. CX Codex +1 103 900установок

Рядом в теме «Бэкенд и API»

Всё по теме «Бэкенд и API» →

Вопросы о process-api-net11

Как установить process-api-net11 в Claude Code?

Выполните команду npx skills add dotnet/skills --skill process-api-net11 -a claude-code. Также можно вручную сохранить файл по пути ~/.claude/skills/process-api-net11/SKILL.md.

Что делает скилл process-api-net11?

Он передаёт языковой модели точные сигнатуры и сценарии использования новых методов System.Diagnostics.Process из .NET 11. Ассистент перестаёт генерировать устаревший код на Process.Start с ручной синхронизацией потоков.

Можно ли использовать этот скилл в проектах на .NET 10?

Нет, эти методы добавлены только в целевой платформе net11.0. В проектах на .NET 10 или более ранних версиях они вызовут ошибку компиляции.

Исходный текст

SKILL.md · MIT
---
name: process-api-net11
description: >
  Provides guidance on the new System.Diagnostics.Process APIs introduced in .NET 11:
  Process.Run, Process.RunAndCaptureText, Process.StartAndForget, Process.ReadAllText/Bytes/Lines,
  KillOnParentExit, InheritedHandles, and StartDetached.
  USE FOR: starting, orchestrating, or capturing output from external processes in applications targeting net11.0 or later.
  DO NOT USE FOR: applications targeting .NET 10 or earlier, or basic pre-.NET 11 Process.Start usage without new APIs.
license: MIT
---

# Process API Improvements — .NET 11

New APIs added to `System.Diagnostics.Process` in .NET 11 simplify process management, eliminate boilerplate, and prevent common deadlock patterns when capturing output in .NET 11 or later applications.

## When to Use

- Running or orchestrating external processes in a .NET 11 (or later) project.
- Needing to start a process, wait for it to exit, and capture its output/error streams without risking deadlocks (`Process.RunAndCaptureText[Async]`).
- Wanting to ensure child processes are automatically terminated when the parent process exits (`KillOnParentExit`).
- Requiring lightweight, low-overhead process creation via `SafeProcessHandle` on supported platforms.
- Requiring fine-grained control over handle inheritance (`InheritedHandles`) or starting detached processes (`StartDetached`).

## When Not to Use

- The project targets .NET 10 or earlier — these APIs are not available before .NET 11.
- The default `Process.Start()` is sufficient and does not require output capturing or advanced lifecycle rules.

## Target Framework

```xml
<TargetFramework>net11.0</TargetFramework>
```

## New APIs

### Types

Before using the new convenience methods, note the following types. Use the framework types directly:

| Type | Kind | Read-only properties |
|------|------|----------------------|
| `ProcessExitStatus` | Sealed class | `int ExitCode`, `bool Canceled`, `PosixSignal? Signal` |
| `ProcessTextOutput` | Sealed class | `ProcessExitStatus ExitStatus`, `string StandardOutput`, `string StandardError`, `int ProcessId` |
| `ProcessOutputLine` | Readonly struct | `string Content`, `bool StandardError` |

`ProcessExitStatus` describes the outcome of a completed process. Interpret `ExitCode` using the external command's contract; there is no universal `Success` property. `ProcessTextOutput` contains the exit status, captured output and error text, and process ID. `ProcessOutputLine` identifies one output line and whether it came from standard error.

### High-Level Convenience APIs

#### Static Methods

The `ProcessStartInfo` overloads below require `UseShellExecute = false`, which is the default for .NET.

##### `Process.Run` / `Process.RunAsync`
Starts a process and waits for it to exit, returning the exit status. Does not capture standard output or error. Passing `silent: true` discards standard output and error by internally redirecting standard handles to the `NUL` device. On timeout or cancellation, the process is killed.
```csharp
public static ProcessExitStatus Run(string fileName, IEnumerable<string>? arguments = null, bool silent = false, TimeSpan? timeout = null)
public static Task<ProcessExitStatus> RunAsync(string fileName, IEnumerable<string>? arguments = null, bool silent = false, CancellationToken cancellationToken = default)
public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeout = null)
public static Task<ProcessExitStatus> RunAsync(ProcessStartInfo startInfo, CancellationToken cancellationToken = default)
```

##### `Process.RunAndCaptureText` / `Process.RunAndCaptureTextAsync`
Starts a process, captures both standard output and error, and waits for it to exit. Extremely useful for avoiding deadlocks on stream redirection. On timeout or cancellation, the process is killed.

When using the `ProcessStartInfo` overloads, the caller is responsible for setting `RedirectStandardOutput = true` and `RedirectStandardError = true` on `ProcessStartInfo` (because BCL APIs cannot modify the input arguments they were given).
```csharp
public static ProcessTextOutput RunAndCaptureText(string fileName, IEnumerable<string>? arguments = null, TimeSpan? timeout = null)
public static Task<ProcessTextOutput> RunAndCaptureTextAsync(string fileName, IEnumerable<string>? arguments = null, CancellationToken cancellationToken = default)
public static ProcessTextOutput RunAndCaptureText(ProcessStartInfo startInfo, TimeSpan? timeout = null)
public static Task<ProcessTextOutput> RunAndCaptureTextAsync(ProcessStartInfo startInfo, CancellationToken cancellationToken = default)
```

##### `Process.StartAndForget`
There is a common misconception that when a process is disposed, it's also being killed. This is not the case, as `Process.Dispose` only releases the resources associated with the process, but does not kill it.

To make it easier to start a process without the need to worry about disposing it, `Process.StartAndForget` was introduced. The method starts an executable, returns its ID, and immediately releases all handle resources associated with it. Standard handles not supplied through `StandardInputHandle`, `StandardOutputHandle`, or `StandardErrorHandle` go to the null device by default.

`StartAndForget` throws `InvalidOperationException` if `UseShellExecute` or any `RedirectStandardInput`, `RedirectStandardOutput`, or `RedirectStandardError` flag is true. Use a capture or streaming API if output needs to be read.
```csharp
public static int StartAndForget(string fileName, IEnumerable<string>? arguments = null)
public static int StartAndForget(ProcessStartInfo startInfo)
```

#### Instance Methods
These methods are called on a `Process` instance to directly read stdout and stderr, guaranteeing no OS pipe buffer overflow deadlocks.

*Note: Calling these methods requires `RedirectStandardOutput = true` and `RedirectStandardError = true` on the `ProcessStartInfo` passed to `Process.Start`.*

```csharp
public (string StandardOutput, string StandardError) ReadAllText(TimeSpan? timeout = null)
public Task<(string StandardOutput, string StandardError)> ReadAllTextAsync(CancellationToken cancellationToken = default)
public (byte[] StandardOutput, byte[] StandardError) ReadAllBytes(TimeSpan? timeout = null)
public Task<(byte[] StandardOutput, byte[] StandardError)> ReadAllBytesAsync(CancellationToken cancellationToken = default)
public IEnumerable<ProcessOutputLine> ReadAllLines(TimeSpan? timeout = null)
public IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(CancellationToken cancellationToken = default)
```

Example of deconstructing the tuple return:
```csharp
var (stdout, stderr) = await process.ReadAllTextAsync();
```

### ProcessStartInfo Properties

#### `KillOnParentExit`
Ensures that the spawned child process is terminated when the current (parent) process exits (including fatal crash and being force killed). Works across Windows, Linux, and Android.
```csharp
public bool KillOnParentExit { get; set; }
```

In cross-platform code, guard the property assignment with a supported-platform check, not only the assigned value. If automatic teardown is required, fail explicitly on an unsupported platform instead of starting an unprotected child process.
`KillOnParentExit` requires `UseShellExecute = false`.

#### `InheritedHandles`
Provides precise control over which handles (file descriptors) are inherited by the child process, preventing accidental resource leaks.
- Standard handles (`stdin`, `stdout`, `stderr`) are always included (no need to add them to the list).
- Setting the list to an empty list means only standard handles get inherited.
- Only `SafeFileHandle` and `SafePipeHandle` instances are allowed as of today.
- No global lock is used when spawning new processes on Windows (important for tuning projects that spawn multiple processes in parallel).
- Concurrent process starts must not pass the same handle in `InheritedHandles`: the runtime temporarily changes its inheritance flags. Serialize starts that share a handle, or use separate handles for each concurrent start.
- Do not enable inheritance on the handles before passing them; other process-start APIs could then inherit them unintentionally.
- On Unix systems without native handle-inheritance control, setting this property can severely reduce process-start performance.
- A non-null list requires `UseShellExecute = false` and cannot be combined with a non-empty `UserName`.
```csharp
public IList<SafeHandle>? InheritedHandles { get; set; }
```

#### `StartDetached`
Starts the process detached from the parent's terminal or job session, ensuring it survives the parent's exit.
```csharp
public bool StartDetached { get; set; }
```

`StartDetached` requires `UseShellExecute = false`.

---

## Examples

### 1. One-Line Run and Capture Output

Run a process and safely read all output text without stream deadlock risks. For simple CLI operations that don't need cancellation or async scalability, prefer the synchronous overload:

```csharp
using System;
using System.Diagnostics;

// Run 'git status' and capture output
ProcessTextOutput result = Process.RunAndCaptureText("git", ["status"]);

if (result.ExitStatus.ExitCode == 0)
{
    Console.WriteLine($"Git Output: {result.StandardOutput}");
}
else
{
    Console.WriteLine($"Failed with exit code: {result.ExitStatus.ExitCode}");
    Console.WriteLine($"Error: {result.StandardError}");
}
```

### 2. Auto-Killing Child Processes on Parent Exit

On Windows, Linux, and Android, ensure a long-running background worker process is killed when the main application terminates. On other platforms, this example stops before starting the child process:

```csharp
using System;
using System.Diagnostics;

ProcessStartInfo startInfo = new("dotnet", ["run", "--project", "BackgroundWorker.csproj"]);

if (OperatingSystem.IsWindows() || OperatingSystem.IsLinux() || OperatingSystem.IsAndroid())
{
    startInfo.KillOnParentExit = true;
}
else
{
    throw new PlatformNotSupportedException("This example requires Windows, Linux, or Android.");
}

using Process process = Process.Start(startInfo)!;
// The background worker is now tied to this process's lifecycle
```

### 3. Read All Lines From Output

Start a process and read its output lines safely:

```csharp
using System;
using System.Diagnostics;
using System.Threading.Tasks;

ProcessStartInfo startInfo = new("ping", ["127.0.0.1"])
{
    RedirectStandardOutput = true,
    RedirectStandardError = true
};

using Process process = Process.Start(startInfo)!;
// Read all output lines safely and asynchronously
await foreach (ProcessOutputLine line in process.ReadAllLinesAsync())
{
    string prefix = line.StandardError ? "[Err]" : "[Out]";
    Console.WriteLine($"{prefix} > {line.Content}");
}
```

### 4. Read Entire Output Deadlock-Free (Tuple Return)

Start a process with custom `ProcessStartInfo` and read both stdout and stderr into a deconstructed tuple without buffer deadlocks:

```csharp
using System;
using System.Diagnostics;
using System.Threading.Tasks;

ProcessStartInfo startInfo = new("git", ["diff"])
{
    RedirectStandardOutput = true,
    RedirectStandardError = true
};

using Process process = Process.Start(startInfo)!;
var (stdout, stderr) = await process.ReadAllTextAsync();

Console.WriteLine($"Diff output: {stdout}");
```

### 5. Start and Forget (Fire & Forget)

Launch a helper executable without holding onto system handle structures:

```csharp
using System;
using System.Diagnostics;

// Fire and forget, getting back only the process ID
int pid = Process.StartAndForget("notepad.exe");
Console.WriteLine($"Notepad started with PID: {pid}");
```

© dotnet · MIT · dotnet/skills

Смотрите также

Спонсоры проекта

Компании, которые помогают держать аналитику открытой