{"meta":{"title":"设置 GitHub Codespaces 超时期限","intro":"可以在个人设置页中设置 GitHub Codespaces 默认超时。","product":"Codespaces","breadcrumbs":[{"href":"/zh/codespaces","title":"Codespaces"},{"href":"/zh/codespaces/setting-your-user-preferences","title":"设置用户首选项"},{"href":"/zh/codespaces/setting-your-user-preferences/setting-your-timeout-period-for-github-codespaces","title":"设置超时值"}],"documentType":"article"},"body":"# 设置 GitHub Codespaces 超时期限\n\n可以在个人设置页中设置 GitHub Codespaces 默认超时。\n\n## 关于空闲超时\n\n代码空间将在一段时间不活动后停止运行。 默认情况下，此时间段为 30 分钟，但你可以在个人设置 GitHub中指定更长或更短的默认超时期限。 更新的设置将应用于你创建的任何新代码空间。 还可以在用于 GitHub CLI 创建代码空间时指定超时。\n\n> \\[!WARNING]\n> Codespaces 计算资源使用量是根据 Codespaces 处于活动状态的使用时长来计费的。 如果未使用 codespace，但它仍在运行，并且尚未超时，则无论是否正在使用 codespace，你都需按 codespace 处于活动状态的总时间付费。 有关详细信息，请参阅“[GitHub Codespaces 计费](/zh/billing/concepts/product-billing/github-codespaces#pricing)”。\n\n### 不活动的定义\n\n在 Codespaces 空闲超时的上下文中，非活动定义为用户状态缺少活动指示性。 与 Codespaces 进行个人交互（例如输入或使用鼠标）会重置空闲超时期限。 此外，终端活动（输入或输出）也会重置空闲超时期限。 例如，如果从 codespace 在端口上发布一个 Web 应用且页面请求在 codespace 上的终端中生成输出，则每当发生终端输出时都会重置超时。 但是，如果共享端口，然后不与 codespace 交互并且不生成终端输出，则 codespace 将在配置的时间段后超时。\n\n### 组织拥有的存储库的超时时段\n\n组织可以为从其部分或所有存储库创建的 codespace 设置最大空闲超时策略。 如果组织策略设置的最大超时时间少于你设置的默认超时时间，将使用组织的超时时间而不是你设置的超时时间。 你将在 codespace 创建后收到此通知。 有关详细信息，请参阅“[限制空闲超时期限](/zh/codespaces/managing-codespaces-for-your-organization/restricting-the-idle-timeout-period)”。\n\n<div class=\"ghd-tool webui\">\n\n## 设置默认超时期限\n\n1. 在 GitHub 任意页面的右上角，单击你的个人资料照片，然后单击“<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-gear\" aria-label=\"gear\" role=\"img\"><path d=\"M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.146a6.6 6.6 0 0 0-1.142 0ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM9.5 8a1.5 1.5 0 1 0-3.001.001A1.5 1.5 0 0 0 9.5 8Z\"></path></svg> Settings”\\*\\*\\*\\*。\n2. 在边栏中的“代码、规划和自动化”下， 单击 **<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-codespaces\" aria-label=\"codespaces\" role=\"img\"><path d=\"M0 11.25c0-.966.784-1.75 1.75-1.75h12.5c.966 0 1.75.784 1.75 1.75v3A1.75 1.75 0 0 1 14.25 16H1.75A1.75 1.75 0 0 1 0 14.25Zm2-9.5C2 .784 2.784 0 3.75 0h8.5C13.216 0 14 .784 14 1.75v5a1.75 1.75 0 0 1-1.75 1.75h-8.5A1.75 1.75 0 0 1 2 6.75Zm1.75-.25a.25.25 0 0 0-.25.25v5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-5a.25.25 0 0 0-.25-.25Zm-2 9.5a.25.25 0 0 0-.25.25v3c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25v-3a.25.25 0 0 0-.25-.25Z\"></path><path d=\"M7 12.75a.75.75 0 0 1 .75-.75h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1-.75-.75Zm-4 0a.75.75 0 0 1 .75-.75h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1-.75-.75Z\"></path></svg> Codespaces**。\n3. 在“默认空闲超时”下，输入所需时间，然后单击“保存”。 时间必须在 5 分钟到 240 分钟（4 小时）之间。\n\n   ![Codespaces 设置的“默认空闲超时”部分的屏幕截图，其中输入了“90 分钟”。](/assets/images/help/codespaces/setting-default-timeout.png)\n\n</div>\n\n<div class=\"ghd-tool cli\">\n\n## 设置 codespace 的超时期限\n\n> \\[!NOTE]\n> 若要详细了解 GitHub CLI，请参阅“[关于 GitHub CLI](/zh/github-cli/github-cli/about-github-cli)”。\n\n若要设置创建代码空间时的超时期限，请将 `idle-timeout` 参数与 `codespace create` 子命令一起使用。 指定以分钟为单位的时间，后跟 `m`。 时间必须在 5 分钟到 240 分钟（4 小时）之间。\n\n```shell\ngh codespace create --idle-timeout 90m\n```\n\n如果在创建代码空间时未指定超时期限，则将使用默认超时期限。 有关设置默认超时期限的信息，请单击此页面上的“Web browser（Web 浏览器）”选项卡。 当前无法指定默认超时期限。GitHub CLI\n\n</div>\n\n<div class=\"ghd-tool vscode\">\n\n## 设置超时期限\n\n可以在 Web 浏览器中设置默认超时期限。GitHub 或者，如果用于 GitHub CLI 创建代码空间，则可以为该特定代码空间设置超时期限。 有关详细信息，请单击上面相应的选项卡。\n\n</div>\n\n## 延伸阅读\n\n* [自定义代码空间](/zh/codespaces/customizing-your-codespace)\n* [管理代码空间](/zh/codespaces/managing-your-codespaces)"}